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.