From 75773059e7fe1ffab70407366ba158bf1814ac20 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Sun, 22 Nov 2026 11:00:36 -0800 Subject: [PATCH] Tests: three barrier and instruction counts take their kernels' rates as the test's input On lavapipe the measured rates cut these tests' command buffers into pieces, each cut ending a segment with its barrier and its CPU work (job m3-max-68387): - compute every_device_places_barriers_at_hazards_only: independent 2 barriers against 1; - compute every_device_counts_no_instructions_for_a_stage_in_region_a_kernel_does_not_read: 37,422 instructions a dispatch against 39,033 under a region, the arms cut differently; - surface every_device_carries_each_form_of_surface: the ordered pair 2 barriers against the control's 2 (its control cut too), where one more is asserted. Each sets its kernels' rates to 1 ps a threadgroup before the counted command buffer, so the dispatches share one piece and the counts are the test's own. No assertion changes. --- crates/metal2vulkan-runtime/src/tests/compute.rs | 11 +++++++++-- crates/metal2vulkan-runtime/src/tests/surface.rs | 5 +++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/crates/metal2vulkan-runtime/src/tests/compute.rs b/crates/metal2vulkan-runtime/src/tests/compute.rs index 41ea68da7..f791261e4 100644 --- a/crates/metal2vulkan-runtime/src/tests/compute.rs +++ b/crates/metal2vulkan-runtime/src/tests/compute.rs @@ -191,8 +191,11 @@ pub(crate) mod on_device { size: [4, 5, 6], }; let mut per_dispatch = Vec::new(); - // No region, a region set before each dispatch, and the setter with no dispatch. + // No region, a region set before each dispatch, and the setter with no dispatch. The + // kernel's rate 1 ps a threadgroup, the test's own input, so each arm's dispatches + // share one piece (`crate::piece`): no arm pays for a cut the others do not. for (set, dispatched) in [(false, true), (true, true), (true, false)] { + state.inner.compiled.rate.set_for_test(1); let command_buffer = queue.command_buffer().expect("a command buffer"); let mut encoder = command_buffer .compute_command_encoder(DispatchType::Serial) @@ -361,11 +364,14 @@ pub(crate) mod on_device { let expected: Vec = (0..WORDS as u32).map(chained).collect(); assert_eq!(words(&x), expected, "{name}: dependent"); - // Independent: each dispatch has a buffer of its own. + // Independent: each dispatch has a buffer of its own. The kernel's rate 1 ps a + // threadgroup, the test's own input, so the dispatches share one piece + // (`crate::piece`) and the barriers counted are the hazards' alone; so too below. let buffers: Vec = (0..count).map(|_| arena.buffer()).collect(); for buffer in &buffers { write_words(buffer, |index| index); } + state.inner.compiled.rate.set_for_test(1); let before = device.counters().metrics(); let command_buffer = queue.command_buffer().expect("a command buffer"); let mut encoder = command_buffer @@ -389,6 +395,7 @@ pub(crate) mod on_device { // Concurrent: barriers where asked for, and none at the hazards. write_words(&x, |index| index); + state.inner.compiled.rate.set_for_test(1); let before = device.counters().metrics(); let command_buffer = queue.command_buffer().expect("a command buffer"); let mut encoder = command_buffer diff --git a/crates/metal2vulkan-runtime/src/tests/surface.rs b/crates/metal2vulkan-runtime/src/tests/surface.rs index e30555459..dbf3ea7e0 100644 --- a/crates/metal2vulkan-runtime/src/tests/surface.rs +++ b/crates/metal2vulkan-runtime/src/tests/surface.rs @@ -1106,6 +1106,11 @@ mod on_device { let out = (device.new_texture(&d, Some(first + 1))) .unwrap_or_else(|error| panic!("{label}: the output: {error}")); let pair = |target: &crate::Buffer| -> u64 { + // Each kernel's rate 1 ps a threadgroup, the test's own input, so the two dispatches + // share one piece (`crate::piece`) and the barriers counted are the pair's own. + for state in [add, invert] { + state.inner.compiled.rate.set_for_test(1); + } let before = counters.metrics().barriers; let command_buffer = queue.command_buffer().expect("a command buffer"); let mut encoder =