From f8d29324d5d57fb83c8d03178b58f1c9cd862ddb Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Mon, 16 Nov 2026 18:55:58 -0800 Subject: [PATCH] start_stamp: the first work's span is held against the same fill's GPU time, not the life it adds The Iris runtime leg (ANV, m3-max-38516) failed a_command_buffer_s_gpu_span_holds_its_batch_s_first_work: with a new 256 MiB Private buffer the fill's life grew by 65.3 ms, of which 54.1 ms lay from the kernel end to the GPU start and 11.37 ms in the GPU span (0.004 ms without the buffer). The span held the first work: 11.37 ms is the zero fill's one vkCmdFillBuffer of 256 MiB. The 54 ms lay before the GPU's first timestamp, after the start of the driver's submission call (the kernel end, command_buffer/group.rs's call time), where the runtime does nothing: no GPU span holds it, nor would Metal's. The test's claim (the span holds half the life the first work adds) counted it. The test now runs the same fill again after the batch (one vkCmdFillBuffer of the buffer's 256 MiB, its first work done, which it asserts) and holds the batch's span to at least half of that fill's span: GPU time against GPU time. A start written after the first work would leave a span of about 0.004 ms against a bound of about 5.7 ms there, so the test still fails on that. Each line also prints the submission call's own time where the process set METAL2VULKAN_QUEUE_TIMES (CommandBuffer::submit_returned_time), so a run can show where the time before the GPU start goes. Test only; the product is unchanged. --- .../src/tests/start_stamp.rs | 70 +++++++++++++------ 1 file changed, 48 insertions(+), 22 deletions(-) diff --git a/crates/metal2vulkan-runtime/src/tests/start_stamp.rs b/crates/metal2vulkan-runtime/src/tests/start_stamp.rs index af3f72849..34a0271dd 100644 --- a/crates/metal2vulkan-runtime/src/tests/start_stamp.rs +++ b/crates/metal2vulkan-runtime/src/tests/start_stamp.rs @@ -6,17 +6,22 @@ //! time to its GPU end, as the GPU starts the work once the submission reaches it, not at its //! end. //! - **The batch's first work.** The next command buffer after a new `Private` buffer of -//! [`FIRST`] bytes (its fill with zeros, `texture/first_move.rs`) and, on a device without -//! unified memory, a `Managed` buffer of [`FIRST`] bytes whose whole range `did_modify_range` -//! named (its copy in, `managed.rs`), the command buffer one blit fill of a word of the -//! `Managed` buffer (else of a buffer made before): its GPU span holds at least half the time -//! that work adds to its life against the same fill without it, as the work runs in its own -//! submission, before its commands. Where the device's fill queue took the work -//! (`device/staging.rs`: it runs before the batch, outside it), the leg says so and checks -//! nothing. +//! [`FIRST`] bytes (its fill with zeros, one `vkCmdFillBuffer`, `texture/first_move.rs`) and, +//! on a device without unified memory, a `Managed` buffer of [`FIRST`] bytes whose whole range +//! `did_modify_range` named (its copy in, `managed.rs`), the command buffer one blit fill of a +//! word of the `Managed` buffer (else of a buffer made before): its GPU span holds at least half +//! the GPU span of a blit fill of the new buffer's [`FIRST`] bytes after it (one +//! `vkCmdFillBuffer` too, its first work done), as the work runs in the batch's submission, +//! before its commands, after its GPU start. Its life is not the measure: from its kernel end, +//! the start of the driver's submission call, to its GPU start lies time no GPU span holds, +//! which the new memory can lengthen (on the Iris Xe under ANV, 54 ms before a span of 11.4 ms, +//! where the same fill's life without the new buffer was 0.12 ms). Where the device's fill +//! queue took the work (`device/staging.rs`: it runs before the batch, outside it), the leg +//! says so and checks nothing. //! -//! Each leg prints its times (`START-STAMP`). Device tests: compiled only under the GPU safety -//! cfgs (`m2v_gpu`, `m2v_cpu_icd`), on the kind of device the cfg selects. +//! Each leg prints its times (`START-STAMP`), with the submission call's own time where the +//! process set `METAL2VULKAN_QUEUE_TIMES`. Device tests: compiled only under the GPU safety cfgs +//! (`m2v_gpu`, `m2v_cpu_icd`), on the kind of device the cfg selects. use super::blit_holds::{device, Scratch, WAIT}; use super::encoder_holds::library; @@ -50,6 +55,9 @@ struct Times { kernel_end: f64, start: f64, end: f64, + /// The driver's submission that carried its last batch returned; 0 where the process did not + /// set `METAL2VULKAN_QUEUE_TIMES` (`CommandBuffer::submit_returned_time`). + returned: f64, } impl Times { @@ -69,8 +77,15 @@ impl Times { } fn line(self) -> String { + let call = match self.returned > 0.0 { + true => format!( + ", the submission call {:.3} ms", + (self.returned - self.kernel_end) * 1e3 + ), + false => String::new(), + }; format!( - "life {:.3} ms, kernel end to GPU start {:.3} ms, GPU span {:.3} ms", + "life {:.3} ms, kernel end to GPU start {:.3} ms, GPU span {:.3} ms{call}", self.life() * 1e3, self.lead() * 1e3, self.span() * 1e3 @@ -87,6 +102,7 @@ fn run(command_buffer: &CommandBuffer) -> Times { kernel_end: command_buffer.kernel_end_time(), start: command_buffer.gpu_start_time().unwrap(), end: command_buffer.gpu_end_time().unwrap(), + returned: command_buffer.submit_returned_time(), } } @@ -111,11 +127,11 @@ fn scale( command_buffer } -/// A command buffer of `queue`'s of one blit fill of `target`'s first word. -fn fill(queue: &CommandQueue, target: &Buffer) -> CommandBuffer { +/// A command buffer of `queue`'s of one blit fill of `target`'s first `bytes` with zeros. +fn fill(queue: &CommandQueue, target: &Buffer, bytes: u64) -> CommandBuffer { let command_buffer = queue.command_buffer().unwrap(); let mut blit = command_buffer.blit_command_encoder().unwrap(); - blit.fill_buffer(target, 0..4, 7).unwrap(); + blit.fill_buffer(target, 0..bytes, 0).unwrap(); blit.end_encoding().unwrap(); command_buffer } @@ -161,8 +177,8 @@ fn a_command_buffer_s_gpu_span_holds_its_batch_s_first_work() { let two_copies = !device.properties().has_unified_memory; let small = device.new_buffer(4096, ResourceOptions::private()).unwrap(); // Its first work done, then the fill alone. - run(&fill(&queue, &small)); - let alone = run(&fill(&queue, &small)); + run(&fill(&queue, &small, 4)); + let alone = run(&fill(&queue, &small, 4)); let before = device.work_counts(); let fresh = device .new_buffer(FIRST, ResourceOptions::private()) @@ -180,7 +196,7 @@ fn a_command_buffer_s_gpu_span_holds_its_batch_s_first_work() { buffer.did_modify_range(0..FIRST).unwrap(); buffer }); - let with = run(&fill(&queue, managed.as_ref().unwrap_or(&small))); + let with = run(&fill(&queue, managed.as_ref().unwrap_or(&small), 4)); let after = device.work_counts(); let zero_fills = after.new_buffer_zero_fills - before.new_buffer_zero_fills; let on_fill_queue = after.fill_queue_submissions - before.fill_queue_submissions; @@ -193,16 +209,26 @@ fn a_command_buffer_s_gpu_span_holds_its_batch_s_first_work() { with.line(), added * 1e3 ); - drop(fresh); if on_fill_queue > 0 { eprintln!("START-STAMP first work: the fill queue took it, before the batch: no check"); return; } assert!(zero_fills > 0, "the new buffer took no fill with zeros"); + // The zero fill's GPU time again: the same `vkCmdFillBuffer` of the new buffer's bytes, its + // first work done. + let whole = run(&fill(&queue, &fresh, FIRST)); + let again = device.work_counts(); + assert_eq!( + (again.new_buffer_zero_fills, again.fill_queue_submissions), + (after.new_buffer_zero_fills, after.fill_queue_submissions), + "the fill of the new buffer's bytes took first work" + ); + eprintln!("START-STAMP first work: its fill again: {}", whole.line()); + drop(fresh); assert!( - with.span() >= added / 2.0, - "the GPU span leaves out the batch's first work: {:.3} ms added, span {:.3} ms", - added * 1e3, - with.span() * 1e3 + with.span() >= whole.span() / 2.0, + "the GPU span leaves out the batch's first work: span {:.3} ms, its fill again {:.3} ms", + with.span() * 1e3, + whole.span() * 1e3 ); }