gpu: readback pool test counts only reusable staging buffers and holds the device test lock (#4958)

This commit is contained in:
FredApps committed 2026-12-02 10:12:39 +01:00
1 parent c5bd44a1f7
commit 8bae0315c7
1 file changed
+5 -1
+5 -1
View File
@@ -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<u32> = (0..len as u32).map(|i| i.wrapping_mul(2_654_435_761)).collect();
let b = g.upload(&data);