From 8bae0315c71cada6c46b7cb03ec516d16b2de62c Mon Sep 17 00:00:00 2001 From: FredApps <153173854+FredApps@users.noreply.github.com> Date: Wed, 2 Dec 2026 10:12:39 +0100 Subject: [PATCH] gpu: readback pool test counts only reusable staging buffers and holds the device test lock (#4958) --- crates/gpu/src/ctx.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crates/gpu/src/ctx.rs b/crates/gpu/src/ctx.rs index 5135ebaa80..ca4200927c 100644 --- a/crates/gpu/src/ctx.rs +++ b/crates/gpu/src/ctx.rs @@ -1350,6 +1350,8 @@ mod tests { /// Readback staging buffers are pooled and reused, and never handed out as storage buffers. #[test] fn readback_staging_buffers_are_pooled_apart_from_storage() { + // (serialised with the tests that change the pool limit, which would trim the pool under it) + let _serial = crate::DEVICE_TEST_LOCK.lock().unwrap_or_else(std::sync::PoisonError::into_inner); let Some(g) = crate::device() else { lightcraft_testkit::skip!(Gpu, "no GPU device"); return; @@ -1357,9 +1359,11 @@ mod tests { let len = 1_234_567usize; let want = (len * 4) as u64; let mapped = wgpu::BufferUsages::MAP_READ | wgpu::BufferUsages::COPY_DST; + // only the staging buffers this readback could reuse (`take_pooled`'s size band), so another + // test's readback of a different size on the shared device doesn't change the count let count = || { let f = g.free.lock().unwrap_or_else(std::sync::PoisonError::into_inner); - f.iter().filter(|b| b.0.usage() == mapped && b.0.size() >= want).count() + f.iter().filter(|b| b.0.usage() == mapped && b.0.size() >= want && b.0.size() <= want + want / 4).count() }; let data: Vec = (0..len as u32).map(|i| i.wrapping_mul(2_654_435_761)).collect(); let b = g.upload(&data);