From b2f6c9559601627e2bccc47bdfffc838fa42fb59 Mon Sep 17 00:00:00 2001 From: Marvis Date: Wed, 25 Nov 2026 08:25:56 +0100 Subject: [PATCH] GPU: upload tests count their own texture's uploads What was wrong: the upload tests read a process-wide count of texture uploads, so another test's uploads between their `before` and their submission landed in it: `a_texture_is_uploaded_once_per_submission_and_only_when_written` failed in a parallel run of the crate's tests and passed alone. What changed: each texture's staging state counts its own uploads; the tests read those of their texture (`texture::uploads`, tests only). The process-wide counter had no other reader and is gone. Evidence: the crate's tests three times in a row with 8 threads, 157 passed each time; clippy clean on both feature sets. Co-Authored-By: Claude Opus 5.5 --- crates/victory-gpu/src/draw.rs | 8 ++++---- crates/victory-gpu/src/texture.rs | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/crates/victory-gpu/src/draw.rs b/crates/victory-gpu/src/draw.rs index e864572..b82900e 100644 --- a/crates/victory-gpu/src/draw.rs +++ b/crates/victory-gpu/src/draw.rs @@ -2384,11 +2384,11 @@ void main(uint3 id : SV_DispatchThreadID) { run(list, &slots, &read, 0, Some(&out), (8, 8)); list.close(); } - let before = crate::texture::UPLOADS.load(Ordering::Relaxed); + let before = crate::texture::uploads(object); host.execute(&[&lists[0], &lists[1]]); // SAFETY: inside the mapped output. let texel = unsafe { (data as *const [f32; 4]).read() }; - (crate::texture::UPLOADS.load(Ordering::Relaxed) - before, texel[0]) + (crate::texture::uploads(object) - before, texel[0]) }; let (n, x) = submit(Some(0x40)); assert_eq!(n, 1, "one upload for two lists"); @@ -2425,9 +2425,9 @@ void main(uint3 id : SV_DispatchThreadID) { readable(&list, &used(ResourceType::Srv), &view, false); run(&list, &slots, &read, 0, Some(&out), (8, 8)); list.close(); - let before = crate::texture::UPLOADS.load(Ordering::Relaxed); + let before = crate::texture::uploads(object); host.execute(&[&list]); - crate::texture::UPLOADS.load(Ordering::Relaxed) - before + crate::texture::uploads(object) - before }; assert_eq!(submit(), 1); assert_eq!(submit(), 1, "its own page written: uploaded"); diff --git a/crates/victory-gpu/src/texture.rs b/crates/victory-gpu/src/texture.rs index 87611de..794077d 100644 --- a/crates/victory-gpu/src/texture.rs +++ b/crates/victory-gpu/src/texture.rs @@ -50,6 +50,8 @@ pub(crate) struct Staging { /// memory, hashed instead). tracked: Option, last: Mutex, + /// Uploads [`record_upload`] recorded. + uploads: std::sync::atomic::AtomicU64, } /// What a texture's staging buffer holds: the hash of the memory detiled. @@ -245,11 +247,17 @@ pub(crate) fn record_upload(list: &HostList, copy: &Arc u64 { + let staging = crate::resource::host_copy(resource).and_then(|c| c.staging.lock().unwrap_or_else(|e| e.into_inner()).clone()); + staging.map_or(0, |s| s.uploads.load(std::sync::atomic::Ordering::Relaxed)) +} /// For textures shaders reach through the heap itself, at submission /// (`crate::bindless::uploads`): brings the staging buffer up to date and @@ -546,6 +554,7 @@ fn staging(resource: This, texture: &ID3D12Resource) -> Option> { memory, tracked: crate::watch::track(memory as usize, layout_size, true), last: Mutex::default(), + uploads: Default::default(), }); *held = Some(s.clone()); Some(s)