diff --git a/crates/xcl/src/gpu/uma.rs b/crates/xcl/src/gpu/uma.rs index e4e34f0166..fb005d157d 100644 --- a/crates/xcl/src/gpu/uma.rs +++ b/crates/xcl/src/gpu/uma.rs @@ -987,6 +987,11 @@ impl Arena { static GLOBAL: OnceLock> = OnceLock::new(); +/// The window, if a caller has already made it: for observers, which must not commit it. +pub fn existing() -> Option<&'static Uma> { + GLOBAL.get().and_then(Option::as_ref) +} + /// A process that holds no title memory (a shader preparation worker): `get` is None from here /// on, and nothing is reserved or committed for it (a run's region commits its coherent window). /// Before any `get`. diff --git a/crates/xcl/src/hle/d3d12x/memory_report.rs b/crates/xcl/src/hle/d3d12x/memory_report.rs index 79ff78e38a..912c38bac0 100644 --- a/crates/xcl/src/hle/d3d12x/memory_report.rs +++ b/crates/xcl/src/hle/d3d12x/memory_report.rs @@ -114,7 +114,7 @@ pub fn snapshot() -> Snapshot { let (pools, mapped, retired, sparse_commit) = super::sparse::memory_bytes_for(device); let (_, committed_textures) = super::title_textures::committed_bytes_for(device); let (local, non_local) = video_memory(raw); - let uma = crate::gpu::uma::get().map_or(0, |u| u64::try_from(u.size()).unwrap_or(u64::MAX)); + let uma = crate::gpu::uma::existing().map_or(0, |u| u64::try_from(u.size()).unwrap_or(u64::MAX)); let b = |n: usize| u64::try_from(n).unwrap_or(u64::MAX); let parts = vec![ Part { owner: "UMA window", kind: Kind::Commit, bytes: uma }, @@ -134,6 +134,24 @@ pub fn snapshot() -> Snapshot { mod tests { use super::*; + /// A sample in a process with no UMA window yet (a fresh child) leaves it unmade. + #[test] + fn snapshot_does_not_initialize_uma() { + const CHILD: &str = "XCL_TEST_MEMORY_SNAPSHOT_CHILD"; + if std::env::var_os(CHILD).is_none() { + let output = std::process::Command::new(std::env::current_exe().unwrap()) + .args(["--exact", "hle::d3d12x::memory_report::tests::snapshot_does_not_initialize_uma", "--nocapture"]) + .env(CHILD, "1") + .output() + .unwrap(); + assert!(output.status.success(), "{}{}", String::from_utf8_lossy(&output.stdout), String::from_utf8_lossy(&output.stderr)); + return; + } + assert!(crate::gpu::uma::existing().is_none()); + let _ = snapshot(); + assert!(crate::gpu::uma::existing().is_none(), "a memory sample made the UMA window"); + } + #[test] fn remainder_and_partial_query_failure_are_explicit() { const M: u64 = 1 << 20;