From 871c54fc5f3cc122ffb57f4a3fbe3b2fa40ae48d Mon Sep 17 00:00:00 2001 From: Anees Iqbal Date: Wed, 18 Nov 2026 00:43:53 -0800 Subject: [PATCH] rt tests: the pending-upload test counts the allocations in use in the pool, not from the gauges every_device_bounds_the_pending_upload failed now and then on the Iris (ms01 jobs 44922 and 44970; passed in 44962): "copy 0: 4 allocations live, at most 3 expected". Its count of the allocations in use was the Blocks gauge less the idle gauges' allocations. The Blocks gauge rises in allocate() before vkAllocateMemory, and the allocation joins the pool (and the idle gauge) only once make_allocation returns; and it falls in free_allocation after vkFreeMemory, where the idle rule took the allocation out of the pool (and the idle gauge) before. So while the block-maker thread makes or frees an idle allocation, that count is one more than the allocations with a block in use. The test now counts the allocations with a block in use where the pool keeps them (Pool::in_use, test-only), which neither window touches. The bound itself is unchanged. --- crates/metal2vulkan-rt/src/memory.rs | 12 ++++++++++++ crates/metal2vulkan-rt/src/tests/upload.rs | 10 ++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/crates/metal2vulkan-rt/src/memory.rs b/crates/metal2vulkan-rt/src/memory.rs index 88f9db2ab..cf61ced47 100644 --- a/crates/metal2vulkan-rt/src/memory.rs +++ b/crates/metal2vulkan-rt/src/memory.rs @@ -566,6 +566,18 @@ impl Pool { self.lock().free(class) >= MAKE_BELOW } + /// For the device tests: the allocations of both classes with a block in use, counted where + /// the pool keeps them. An allocation the block-maker thread is making or freeing is not + /// among them, where the `Blocks` gauge counts it: the gauge rises before the allocation joins + /// the pool and falls after it left. + #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] + pub(crate) fn in_use(&self) -> usize { + let state = self.lock(); + (state.allocations.iter().flatten()) + .filter(|allocation| allocation.live > 0) + .count() + } + /// For the device tests: the class's blocks given back and kept. #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] pub(crate) fn kept(&self, class: MemoryClass) -> usize { diff --git a/crates/metal2vulkan-rt/src/tests/upload.rs b/crates/metal2vulkan-rt/src/tests/upload.rs index 311984b61..3aa01205b 100644 --- a/crates/metal2vulkan-rt/src/tests/upload.rs +++ b/crates/metal2vulkan-rt/src/tests/upload.rs @@ -80,12 +80,10 @@ mod on_device { }); // The allocations in use: the idle ones are the pool's, kept for its window. A texture // made while earlier ones are still being freed can take a second texture block, which - // goes back to the pool once empty and stays there idle. - let in_use = || { - let gauges = counters.gauges(); - let idle = gauges.private_idle_bytes + gauges.shared_idle_bytes; - gauges.blocks - idle / MemoryClass::Private.block_len() - }; + // goes back to the pool once empty and stays there idle. Counted in the pool, not from + // the gauges, which also count an allocation the block-maker thread is making or + // freeing at the time. + let in_use = || core.pool.in_use() as u64; let base = in_use(); // Textures made and released: nothing holds them, and nothing is submitted.