diff --git a/crates/reims-vgpu/src/graphics/decode/cmdbuf.rs b/crates/reims-vgpu/src/graphics/decode/cmdbuf.rs index 9aea123e4..8a968f42c 100644 --- a/crates/reims-vgpu/src/graphics/decode/cmdbuf.rs +++ b/crates/reims-vgpu/src/graphics/decode/cmdbuf.rs @@ -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::() 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::::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