From ba0d7625b465177dd9a9a759a8f5ca00c2d0a989 Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Thu, 5 Nov 2026 10:02:22 -0800 Subject: [PATCH] Wait the outrun test's late turn without holding the slot's lock d1ff24ed49's test-only delay of the lowering thread's first turn slept inside `if let Some(late) = lock(&self.state).late.take()`, whose guard lives through the block: the slot's state lock was held for the whole 100 ms, so the program's thread, and the test's own reads of the slot, waited for it, and the thread then took the first batch before the program reached the cap. The delay made no late turn, and the negative control (the old read at the cap alone) passed 3 of 3 on lavapipe at 2ce15a2092. `LoweringSlot::wait_late` takes the delay under the lock and sleeps without it. Test: on lavapipe (msi-laptop, --cfg m2v_cpu_icd) and MoltenVK (M3 Max, --cfg m2v_gpu), the test and its negative control. (cherry picked from commit ec37c03abb0ed8ca81ac89703c39c6989950a1f9) --- crates/metal2vulkan-runtime/src/render/deferral.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/crates/metal2vulkan-runtime/src/render/deferral.rs b/crates/metal2vulkan-runtime/src/render/deferral.rs index 6a04ac45c..fabb190f8 100644 --- a/crates/metal2vulkan-runtime/src/render/deferral.rs +++ b/crates/metal2vulkan-runtime/src/render/deferral.rs @@ -360,9 +360,7 @@ impl LoweringSlot { pub(super) fn lower_handed(&self) { loop { #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] - if let Some(late) = lock(&self.state).late.take() { - std::thread::sleep(late); - } + self.wait_late(); let (turn, ended) = { let Some(_section) = exit_guard::enter() else { // The process exits: the program's thread lowers what is handed. @@ -661,6 +659,16 @@ impl LoweringSlot { pub(crate) fn turn_late(&self, by: std::time::Duration) { lock(&self.state).late = Some(by); } + + /// The lowering thread's wait before its turn at the slot where [`turn_late`](Self::turn_late) + /// asked for one: taken under the slot's lock and waited without it, so the program's calls + /// go on meanwhile. + fn wait_late(&self) { + let late = lock(&self.state).late.take(); + if let Some(late) = late { + std::thread::sleep(late); + } + } } /// A program's encoder's slot, with the calls it logged and their checks (the module docs),