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 <noreply@anthropic.com>
This commit is contained in:
1 parent
a3b0f36e3c
commit
b2f6c95596
2 files changed
+16
-7
No files matched your search
@@ -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");
|
||||
|
||||
@@ -50,6 +50,8 @@ pub(crate) struct Staging {
|
||||
/// memory, hashed instead).
|
||||
tracked: Option<crate::watch::Tracked>,
|
||||
last: Mutex<Last>,
|
||||
/// 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<crate::resource::HostTex
|
||||
copies(list, ©.texture, staging, String::new);
|
||||
move_to(SHADER_RESOURCE);
|
||||
list.keep(&staging.buffer);
|
||||
UPLOADS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
|
||||
staging.uploads.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
|
||||
}
|
||||
|
||||
/// Uploads [`record_upload`] recorded.
|
||||
pub(crate) static UPLOADS: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
|
||||
/// The uploads [`record_upload`] recorded into `resource`'s host texture
|
||||
/// (tests: counts of their own texture, whatever other tests upload
|
||||
/// meanwhile).
|
||||
#[cfg(test)]
|
||||
pub(crate) fn uploads(resource: This) -> 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<Arc<Staging>> {
|
||||
memory,
|
||||
tracked: crate::watch::track(memory as usize, layout_size, true),
|
||||
last: Mutex::default(),
|
||||
uploads: Default::default(),
|
||||
});
|
||||
*held = Some(s.clone());
|
||||
Some(s)
|
||||
|
||||
Reference in new issue
Block a user