From adfe6b72072bf896eff56ba5258d9675c8e995ff Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Mon, 16 Nov 2026 18:29:10 -0800 Subject: [PATCH] gpu_times: the one-after-another fills start after an untimed fill that takes the buffer's first work What: command_buffers_one_after_another_are_each_timed_on_their_own commits one untimed fill of its new private buffer, and waits for it, before the counted window, so the eight timed fills carry no first work. Why: since RUNTIME 2466 (35ac917d6f) a timed command buffer whose first batch carries first work (here the new buffer's zeros) writes its start in that work's command buffer, before the work (command_buffer/submit.rs, GPU times), not in its first encoder's prefix, so it is no prefixed start. The XTX lane (m3-max-38545, ea202ab28f) counted (7, 0, 0) prefixed, kept and reused against (8, 0, 0), command buffer 0's GPU span 12.0 us against 3.6 to 5.4 us for the others. The product does what its docs say; the test's claim missed the first work. The start of a batch with first work is start_stamp.rs's test. Verified: the fix tip's XTX run, in the lane report. --- .../src/runtime_lane/gpu_times.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/crates/metal2vulkan-validation/src/runtime_lane/gpu_times.rs b/crates/metal2vulkan-validation/src/runtime_lane/gpu_times.rs index 656e9f0b4..717110197 100644 --- a/crates/metal2vulkan-validation/src/runtime_lane/gpu_times.rs +++ b/crates/metal2vulkan-validation/src/runtime_lane/gpu_times.rs @@ -465,7 +465,9 @@ fn calibrated_within_slack(device: &Device) { /// [`ONE_AFTER_ANOTHER`] command buffers on one queue, each a fill committed once the one before it /// completed, each taking the slot the one before gave back: each is timed inside its own commit /// and wait, and starts no earlier than the one before it ended, so none reads a timestamp an -/// earlier command buffer wrote into the slot. Where the first encoder writes the start +/// earlier command buffer wrote into the slot. An untimed fill before them takes the buffer's +/// first work (its zeros), in whose command buffer a batch that carries it writes its start +/// (`command_buffer/submit.rs`, **GPU times**). Where the first encoder writes the start /// ([`starts_in_the_first_encoder`]), each fill's own command buffer wrote its start as its /// encoder opened, and its batch began with no command buffer of barriers /// (`WorkCounts::prefixed_starts`, one each; no stamped command buffer recorded or taken again). @@ -495,6 +497,15 @@ fn command_buffers_one_after_another_are_each_timed_on_their_own() { let buffer = device .new_buffer(LENGTH, ResourceOptions::private()) .unwrap(); + // The buffer's first work goes with the first batch after its making, before the counted + // command buffers. + let first = queue.command_buffer().unwrap(); + let mut blit = first.blit_command_encoder().unwrap(); + blit.fill_buffer(&buffer, 0..LENGTH, u8::MAX).unwrap(); + blit.end_encoding().unwrap(); + first.commit().unwrap(); + first.wait_until_completed_for(WAIT).unwrap(); + assert_eq!(first.error(), None, "the untimed fill"); let before = device.work_counts(); let mut last_end = 0.0; for n in 0..ONE_AFTER_ANOTHER {