✅ Check that an encode's buffer waits for its session
encode_op hands the frame to the session, which reads the source in place, and then has the command buffer wait for the session's event to reach the encode's value, so that the buffer completes, and the guest writes the source again, only after the session is done with it. No test held that wait: a decode's is checked (a_video_encoder_hands_its_session_each_decode), an encode's was not. This test walks an encode on the fake platform and checks that encodeWaitForEvent:value: on the encode session's event, at the value the encode answered, is encoded before the buffer's commit. Nothing changes for the guest. (cherry picked from commit 0b740157c80589378936562ef4e429cb43804610)
This commit is contained in:
1 parent
3fd3114085
commit
8f3eb42f3b
1 file changed
+66
@@ -5875,6 +5875,72 @@ mod tests {
|
||||
assert_eq!(wait.args.get(1), Some(&Arg::U64(1)));
|
||||
}
|
||||
|
||||
/// A video encoder hands its session each encode, and the command buffer then waits for the
|
||||
/// session's event to reach the value the encode answers, before its commit: the session
|
||||
/// reads the source in place, which the guest writes again only after the command buffer
|
||||
/// completes (`super::super::video`'s `encode_op`).
|
||||
#[test]
|
||||
fn a_video_encoder_s_buffer_waits_for_its_session_s_encode_before_its_commit() {
|
||||
use reims_vgpu_graphics::ops::video::{RGFX_OP_VIDEO_ENCODE_H264, RgfxVideoOpEncode};
|
||||
|
||||
let (p, mut dec) = setup();
|
||||
let device = p.device();
|
||||
let seen = decode_setup(&p, &mut dec);
|
||||
let session = RgfxVideoSessionCreate {
|
||||
header: RgfxMsgHeader {
|
||||
r#type: RGFX_CMD_VIDEO_SESSION_CREATE,
|
||||
size: size_of::<RgfxVideoSessionCreate>() as u32,
|
||||
seqno: 0,
|
||||
},
|
||||
obj_id: 41,
|
||||
codec: RGFX_VIDEO_CODEC_H264,
|
||||
direction: reims_vgpu_graphics::wire::RGFX_VIDEO_ENCODE,
|
||||
};
|
||||
assert_eq!(dec.decode(&device, session.as_bytes()).unwrap(), Ok(()));
|
||||
let encode = RgfxVideoOpEncode {
|
||||
source_luma_texture_obj_id: 7,
|
||||
source_chroma_texture_obj_id: 8,
|
||||
bitstream_buffer_obj_id: 2,
|
||||
bitstream_offset: 0,
|
||||
bitstream_capacity: 1024,
|
||||
result_buffer_obj_id: 2,
|
||||
result_offset: 2048,
|
||||
frame_index: 0,
|
||||
..RgfxVideoOpEncode::default()
|
||||
};
|
||||
let pass = RgfxOpVideoPass { session_obj_id: 41 };
|
||||
let mut ops = op(RGFX_OP_ENCODER_BEGIN_VIDEO, pass.as_bytes());
|
||||
ops.extend(op(RGFX_OP_VIDEO_ENCODE_H264, encode.as_bytes()));
|
||||
ops.extend(op(RGFX_OP_ENCODER_END, &[]));
|
||||
let mark = p.call_log().mark();
|
||||
assert_eq!(
|
||||
dec.decode(&device, &command_buffer_message(100, 1, &ops))
|
||||
.unwrap(),
|
||||
Ok(())
|
||||
);
|
||||
assert_eq!(*seen.encodes.lock(), [0], "the session took the encode");
|
||||
let calls = p.call_log().since(mark);
|
||||
let sels: Vec<&str> = calls
|
||||
.iter()
|
||||
.map(|c| c.sel)
|
||||
.filter(|&sel| sel == "encodeWaitForEvent:value:" || sel == "commit")
|
||||
.collect();
|
||||
assert_eq!(sels, ["encodeWaitForEvent:value:", "commit"]);
|
||||
let wait = calls
|
||||
.iter()
|
||||
.find(|c| c.sel == "encodeWaitForEvent:value:")
|
||||
.unwrap();
|
||||
let event = seen.events.lock()[1].clone_ref();
|
||||
assert_eq!(
|
||||
wait.args,
|
||||
[
|
||||
Arg::Obj(Some(EventRef::<FakePlatform>::Shared(&event).id())),
|
||||
Arg::U64(1),
|
||||
],
|
||||
"the encode session's event, at the encode's value"
|
||||
);
|
||||
}
|
||||
|
||||
/// A decode's command buffer completes as its GPU work did where its picture landed, and
|
||||
/// failed, Metal's internal error with its code and its GPU times, where it did not (its
|
||||
/// planes refused, or a decode the hardware failed once it ran), which the guest's video
|
||||
|
||||
Reference in new issue
Block a user