PLACED_RAW in resource.rs keeps every filler variant forever (synthetic load test: 1M variants = ~100 MB) #34

Closed
opened 2026-11-26 15:46:03 +00:00 by github-bot · 2 comments
Owner

@⁠welisonzika14-jpg on GitHub · 2026-11-26 15:45 UTC · original

Hi, I looked for other places that grow without a limit after #27, using a synthetic load test (no game files). I found one small one and no other.

What I tested (#[ignore] tests, run with --ignored --nocapture, on main fab5286, Windows 11, Rust 1.98.1, no GPU needed)

  1. descriptor::tests::placed_view_shapes_load: 1,000,000 create_placed_srv calls where only padding changes (resource words 1 and 13, SRV word 3, the unused union words 8 and 9).
  2. resource::tests::placed_filler_bookkeeping_load: 1,000,000 texture_at calls where only resource words 1 and 13 change.

Long-lived tables in victory-gpu that use a key taken from title bytes

Table Key Limit / removal Result
descriptor.rs Views.shapes / shape_index shape of a placed view (padding zeroed since #27) up to 4M shapes; ownerless entries capped at 1M 1M padding-only views = 1 shape. Fine.
resource.rs PLACED_TEXTURES (address, resource description without words 1 and 13) none, kept for the run by design key is clean; not leaking from padding
resource.rs PLACED_RAW (address, resource description with words 1 and 13) none grows by one entry per filler variant
resource.rs placed_bytes_from KNOWN (thread local) (description, first level) none key comes from the cleaned shape; not tested alone
shadow.rs EXACT (address, length) pruned when over 256 entries and idle needs the host; not tested
shadow.rs LOOSE, BUFFERS (start, length) windows removed in sweeps needs the host; not tested
texture.rs STAGING, THROUGH, HOST_WRITTEN, HOST_WRITTEN_AT resource pointer / address removed in forget not tested
resource.rs SAID (pairs), texture.rs SAID log counters stop at 64 / 200 fine
pipeline.rs SHADERS, pipeline/known.rs, library.rs USED/SLOW blake3 of shader, pipeline key none, but keyed by content hash not tested

Numbers (debug build, one run each)

  • Descriptor shapes, padding only: 1,000,000 views -> 1 new shape, private memory +4 KiB. Control with 100,000 really different views (SRV word 4): 100,000 shapes, +17,320 KiB.
  • Varying one description word at a time (64 values each): only resource words 1 and 13 and view words 3, 8, 9 do not make new shapes. Every other word does, including view words 12-15 ("the console's own fields", kept as is).
  • PLACED_RAW, 1,000,000 asks at 100,000 addresses with different filler: +1,000,000 entries, private memory +102,196 KiB (about 100 bytes each). Without filler: +0.
  • Same address, more variants (each ask scans all variants of that address): 2,000 -> 130 ms, 4,000 -> 528 ms, 8,000 -> 2.19 s in total, so the cost grows with the square.

PLACED_RAW only feeds the PLACED_TWINS counter, which is read in diagnostics builds. Today the insert and the scan run in every build, inside texture_at, while PLACED_TEXTURES is locked (resource.rs around line 3065 on fab5286).

Patch (below): the bookkeeping only runs with --features diagnostics, and there it restarts at 16,384 entries. The ignored test then shows +0 entries (default build) and +576 entries, +536 KiB (diagnostics build). cargo test -p victory-gpu --lib --locked: 347 passed, 0 failed, 38 ignored.

vt-load.patch
diff --git a/crates/victory-gpu/src/descriptor.rs b/crates/victory-gpu/src/descriptor.rs
index 1d6ac56..c5f3fbb 100644
--- a/crates/victory-gpu/src/descriptor.rs
+++ b/crates/victory-gpu/src/descriptor.rs
@@ -2133,4 +2133,70 @@ mod tests {
         assert_eq!(create(desc, Placement { address, size: 7 }, &mut h), S_OK);
         assert_ne!(slot::<extern "system" fn(This) -> u64>(h, 0x48)(h), address);
     }
+
+    /// Load test (`cargo test -p victory-gpu --lib --locked placed_view_shapes_load -- --ignored --nocapture`).
+    /// A million placed views whose descriptions differ only in padding words
+    /// make one shape; a million that really differ make a million. Then each
+    /// description word is varied alone, to list the words that tell shapes apart.
+    #[cfg(windows)]
+    #[test]
+    #[ignore = "load test: about a million table inserts"]
+    fn placed_view_shapes_load() {
+        use crate::loadprobe::{mix, private_bytes};
+        const N: u64 = 1_000_000;
+        let shapes = || VIEWS.read().unwrap().shapes.len();
+        let mut slot = [0u32; 8];
+        let handle = slot.as_mut_ptr() as u64;
+        let null = std::ptr::null();
+        // A 2D texture SRV (dimension 4): the union's words 4-7 are used; 3, 8 and 9 are padding.
+        let resource = [3, 0, 0, 0, 0x4321, 0, 0x4321, 0x10001, 28, 1, 0, 0, 0, 0];
+        let desc = [28, 4, 0x1688, 0, 0, 1, 0, 0, 0, 0, 0x2000, 0x6, 0, 0, 0, 0];
+        let before = (shapes(), private_bytes());
+        for n in 0..N {
+            let mut r = resource;
+            r[1] = mix(n);
+            r[13] = mix(n + N);
+            let mut d = desc;
+            (d[3], d[8], d[9]) = (mix(n + 2 * N), mix(n + 3 * N), mix(n + 4 * N));
+            let address = 0xd_0000_0000 + n * 0x1_0000;
+            (d[10], d[11]) = (address as u32, (address >> 32) as u32);
+            create_placed_srv(null, &r, &d, handle);
+        }
+        let padding = (shapes() - before.0, private_bytes().saturating_sub(before.1));
+        eprintln!("padding only: {N} views -> {} new shapes, private memory +{} KiB", padding.0, padding.1 >> 10);
+        // Control: the mip level (word 4) really differs.
+        let mid = (shapes(), private_bytes());
+        for n in 0..N / 10 {
+            let mut d = desc;
+            (d[4], d[5]) = (n as u32 + 1, 0);
+            create_placed_srv(null, &resource, &d, handle);
+        }
+        let control = (shapes() - mid.0, private_bytes().saturating_sub(mid.1));
+        eprintln!("control: {} really different views -> {} new shapes, private memory +{} KiB", N / 10, control.0, control.1 >> 10);
+        assert_eq!(control.0 as u64, N / 10, "views that differ are shapes");
+        // One word at a time, 64 values each, from a base the other tests do not use.
+        let mut identity = Vec::new();
+        for (name, count) in [("resource", 14usize), ("view", 16)] {
+            for w in 0..count {
+                if name == "view" && (w == 10 || w == 11) {
+                    continue; // the address
+                }
+                let base = shapes();
+                for v in 0..64u32 {
+                    let mut r = [3, 0, 0, 0, 0x7777, 0, 0x7777, 0x10001, 28, 1, 0, 0, 0, 0];
+                    let mut d = [28, 4, 0x1688, 0, 0, 1, 0, 0, 0, 0, 0x2000, 0x6, 0, 0, 0, 0];
+                    let v = 0x5000_0000 + v * 0x1111;
+                    if name == "resource" { r[w] = v } else { d[w] = v }
+                    create_placed_srv(null, &r, &d, handle);
+                }
+                let grew = shapes() - base;
+                eprintln!("{name} word {w:2}: 64 values -> {grew} shapes");
+                if grew > 2 {
+                    identity.push(format!("{name}[{w}]"));
+                }
+            }
+        }
+        eprintln!("words that tell shapes apart: {identity:?}");
+        assert!(padding.0 <= 4, "padding alone made {} shapes out of {N}", padding.0);
+    }
 }
diff --git a/crates/victory-gpu/src/lib.rs b/crates/victory-gpu/src/lib.rs
index 2843d0c..82eacb1 100644
--- a/crates/victory-gpu/src/lib.rs
+++ b/crates/victory-gpu/src/lib.rs
@@ -45,6 +45,8 @@ mod indirect;
 mod inplace;
 #[cfg(windows)]
 mod land;
+#[cfg(all(test, windows))]
+mod loadprobe;
 pub mod list;
 pub mod object;
 pub mod pipeline;
diff --git a/crates/victory-gpu/src/loadprobe.rs b/crates/victory-gpu/src/loadprobe.rs
new file mode 100644
index 0000000..c1095d5
--- /dev/null
+++ b/crates/victory-gpu/src/loadprobe.rs
@@ -0,0 +1,33 @@
+//! Helpers for the `#[ignore]`d load tests (`cargo test -- --ignored`): the
+//! process's private memory, as the title's memory line reports it.
+
+/// `PrivateUsage` of this process in bytes (0 if the call fails).
+pub(crate) fn private_bytes() -> u64 {
+    use windows_sys::Win32::System::ProcessStatus::{
+        K32GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS_EX,
+    };
+    use windows_sys::Win32::System::Threading::GetCurrentProcess;
+    // SAFETY: the counters are plain integers and `cb` is their size.
+    unsafe {
+        let mut counters: PROCESS_MEMORY_COUNTERS_EX = std::mem::zeroed();
+        counters.cb = size_of::<PROCESS_MEMORY_COUNTERS_EX>() as u32;
+        let ok = K32GetProcessMemoryInfo(
+            GetCurrentProcess(),
+            std::ptr::from_mut(&mut counters).cast(),
+            counters.cb,
+        );
+        if ok == 0 {
+            0
+        } else {
+            counters.PrivateUsage as u64
+        }
+    }
+}
+
+/// A cheap mixing step, so noise in "padding" words is spread over all 32 bits.
+pub(crate) fn mix(n: u64) -> u32 {
+    let mut x = n.wrapping_add(0x9e37_79b9_7f4a_7c15);
+    x = (x ^ (x >> 30)).wrapping_mul(0xbf58_476d_1ce4_e5b9);
+    x = (x ^ (x >> 27)).wrapping_mul(0x94d0_49bb_1331_11eb);
+    (x ^ (x >> 31)) as u32
+}
diff --git a/crates/victory-gpu/src/resource.rs b/crates/victory-gpu/src/resource.rs
index 1b7e47f..99f41b0 100644
--- a/crates/victory-gpu/src/resource.rs
+++ b/crates/victory-gpu/src/resource.rs
@@ -2958,10 +2958,14 @@ static PLACED_TEXTURES: std::sync::Mutex<std::collections::BTreeMap<(u64, [u32;
 
 /// The placed textures asked for with filler words set, as asked
 /// (address and description): for [`PLACED_TWINS`].
-#[cfg(windows)]
+#[cfg(all(windows, any(test, feature = "diagnostics")))]
 static PLACED_RAW: std::sync::Mutex<std::collections::BTreeSet<(u64, [u32; 14])>> =
     std::sync::Mutex::new(std::collections::BTreeSet::new());
 
+/// Most variants [`PLACED_RAW`] keeps; past it the set starts over.
+#[cfg(all(windows, feature = "diagnostics"))]
+const PLACED_RAW_CAP: usize = 1 << 14;
+
 /// Placed textures asked for a second time with other filler words in
 /// their description: each was a second resource and host copy before the
 /// filler was left out of the key ([`texture_at`]).
@@ -3051,6 +3055,7 @@ pub(crate) fn texture_at(address: u64, desc: &[u32; 14]) -> Option<This> {
     // that fills at world entry. They are not part of what a texture is.
     // `VICTORY_PLACED_FILLER=1`: kept in the key, as before.
     static KEPT: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
+    #[cfg(feature = "diagnostics")]
     let raw = *desc;
     let mut key = *desc;
     if !*KEPT.get_or_init(|| std::env::var_os("VICTORY_PLACED_FILLER").is_some_and(|v| v == "1")) {
@@ -3061,8 +3066,15 @@ pub(crate) fn texture_at(address: u64, desc: &[u32; 14]) -> Option<This> {
     let mut map = PLACED_TEXTURES.lock().unwrap_or_else(|e| e.into_inner());
     // How many resources the filler alone would have added (a count for
     // the log: `placed_filler_twins`).
+    // Only a diagnostics build reads the count, so only it keeps the variants,
+    // and not past a cap: every filler variant the title ever passed was a
+    // set entry (about 100 bytes each, 1M of them in a synthetic load test).
+    #[cfg(feature = "diagnostics")]
     if raw != key {
         let mut seen = PLACED_RAW.lock().unwrap_or_else(|e| e.into_inner());
+        if seen.len() >= PLACED_RAW_CAP {
+            seen.clear();
+        }
         if seen.insert((address, raw)) {
             let others = seen.range((address, [0; 14])..=(address, [u32::MAX; 14])).filter(|(_, r)| {
                 let mut blank = *r;
@@ -4567,6 +4579,54 @@ float4 lit() : SV_Target { return 1.0; }
         assert_eq!(sweep_batch(&all, 4, 2).collect::<Vec<_>>(), [1, 3]);
     }
 
+    /// Load test (`cargo test -p victory-gpu --lib --locked placed_filler_bookkeeping_load -- --ignored --nocapture`).
+    /// `texture_at` is asked a million times for placed memory whose resource
+    /// description differs only in the filler words 1 and 13. A buffer
+    /// description is used so that no host resource is needed: `texture_at`
+    /// notes the filler variants before it looks at the dimension.
+    #[cfg(windows)]
+    #[test]
+    #[ignore = "load test: about a million lookups"]
+    fn placed_filler_bookkeeping_load() {
+        use crate::loadprobe::{mix, private_bytes};
+        const N: u64 = 1_000_000;
+        let raw_len = || PLACED_RAW.lock().unwrap().len();
+        let map_len = || PLACED_TEXTURES.lock().unwrap().len();
+        let (r0, m0, p0) = (raw_len(), map_len(), private_bytes());
+        // Control: no filler, a million addresses.
+        for n in 0..N {
+            let desc = [BUFFER, 0, 0, 0, 0x1000, 0, 1, 0x10001, 0, 1, 0, 0, 0, 0];
+            texture_at(0x10_0000_0000 + n * 0x1000, &desc);
+        }
+        let control = (raw_len() - r0, map_len() - m0, private_bytes().saturating_sub(p0));
+        eprintln!("no filler, {N} addresses: PLACED_RAW +{}, PLACED_TEXTURES +{}, private +{} KiB", control.0, control.1, control.2 >> 10);
+        // Filler varies, one entry per address as when many resources are placed.
+        let (r1, p1) = (raw_len(), private_bytes());
+        let t = std::time::Instant::now();
+        for n in 0..N {
+            let desc = [BUFFER, mix(n), 0, 0, 0x1000, 0, 1, 0x10001, 0, 1, 0, 0, 0, mix(n + N)];
+            texture_at(0x20_0000_0000 + (n % 100_000) * 0x1000, &desc);
+        }
+        let filler = (raw_len() - r1, private_bytes().saturating_sub(p1));
+        eprintln!(
+            "filler varies, {N} asks at 100,000 addresses: PLACED_RAW +{}, private +{} KiB, {:?}",
+            filler.0,
+            filler.1 >> 10,
+            t.elapsed()
+        );
+        // One address, ever more filler variants: the cost of one ask.
+        for k in [2_000u64, 4_000, 8_000] {
+            let t = std::time::Instant::now();
+            for n in 0..k {
+                let desc = [BUFFER, mix(n + 9 * N), 0, 0, 0x1000, 0, 1, 0x10001, 0, 1, 0, 0, 0, mix(n + 10 * N)];
+                texture_at(0x30_0000_0000 + k * 0x10_0000, &desc);
+            }
+            eprintln!("one address, {k} variants: {:?}", t.elapsed());
+        }
+        assert_eq!(control.0, 0, "no filler, nothing noted");
+        assert!(filler.0 <= 1 << 16, "{} filler variants kept for a log counter", filler.0);
+    }
+
     #[test]
     fn texture_floor_scales_with_vram_budget() {
         const GIB: u64 = 1 << 30;

Limits

  • Synthetic, no game files; it does not reproduce the 70-minute session.
  • It shows that the table grows by about 100 bytes per distinct (address, filler) pair. How many pairs a real session makes is not measured. Even at tens of millions it would be a few GB, so it may not be the whole 0.4-0.5 GB/min.
  • The host-side tables (shadow.rs, texture.rs) were not exercised; they need the GPU host and real title memory.

Written with AI help (Claude/Kiro); the numbers are from runs on my machine.

**@⁠welisonzika14-jpg** on GitHub · 2026-11-26 15:45 UTC · [original](https://github.com/TaynanGT/Vice-Tay/issues/34) Hi, I looked for other places that grow without a limit after #27, using a synthetic load test (no game files). I found one small one and no other. **What I tested** (`#[ignore]` tests, run with `--ignored --nocapture`, on main fab5286, Windows 11, Rust 1.98.1, no GPU needed) 1. `descriptor::tests::placed_view_shapes_load`: 1,000,000 `create_placed_srv` calls where only padding changes (resource words 1 and 13, SRV word 3, the unused union words 8 and 9). 2. `resource::tests::placed_filler_bookkeeping_load`: 1,000,000 `texture_at` calls where only resource words 1 and 13 change. **Long-lived tables in `victory-gpu` that use a key taken from title bytes** | Table | Key | Limit / removal | Result | |---|---|---|---| | `descriptor.rs` `Views.shapes` / `shape_index` | shape of a placed view (padding zeroed since #27) | up to 4M shapes; ownerless entries capped at 1M | 1M padding-only views = 1 shape. Fine. | | `resource.rs` `PLACED_TEXTURES` | (address, resource description without words 1 and 13) | none, kept for the run by design | key is clean; not leaking from padding | | **`resource.rs` `PLACED_RAW`** | (address, resource description **with** words 1 and 13) | **none** | **grows by one entry per filler variant** | | `resource.rs` `placed_bytes_from` `KNOWN` (thread local) | (description, first level) | none | key comes from the cleaned shape; not tested alone | | `shadow.rs` `EXACT` | (address, length) | pruned when over 256 entries and idle | needs the host; not tested | | `shadow.rs` `LOOSE`, `BUFFERS` | (start, length) windows | removed in sweeps | needs the host; not tested | | `texture.rs` `STAGING`, `THROUGH`, `HOST_WRITTEN`, `HOST_WRITTEN_AT` | resource pointer / address | removed in `forget` | not tested | | `resource.rs` `SAID` (pairs), `texture.rs` `SAID` | log counters | stop at 64 / 200 | fine | | `pipeline.rs` `SHADERS`, `pipeline/known.rs`, `library.rs` `USED`/`SLOW` | blake3 of shader, pipeline key | none, but keyed by content hash | not tested | **Numbers** (debug build, one run each) - Descriptor shapes, padding only: 1,000,000 views -> 1 new shape, private memory +4 KiB. Control with 100,000 really different views (SRV word 4): 100,000 shapes, +17,320 KiB. - Varying one description word at a time (64 values each): only resource words 1 and 13 and view words 3, 8, 9 do not make new shapes. Every other word does, including view words 12-15 ("the console's own fields", kept as is). - `PLACED_RAW`, 1,000,000 asks at 100,000 addresses with different filler: **+1,000,000 entries, private memory +102,196 KiB** (about 100 bytes each). Without filler: +0. - Same address, more variants (each ask scans all variants of that address): 2,000 -> 130 ms, 4,000 -> 528 ms, 8,000 -> 2.19 s in total, so the cost grows with the square. `PLACED_RAW` only feeds the `PLACED_TWINS` counter, which is read in diagnostics builds. Today the insert and the scan run in every build, inside `texture_at`, while `PLACED_TEXTURES` is locked (`resource.rs` around line 3065 on `fab5286`). **Patch** (below): the bookkeeping only runs with `--features diagnostics`, and there it restarts at 16,384 entries. The ignored test then shows +0 entries (default build) and +576 entries, +536 KiB (diagnostics build). `cargo test -p victory-gpu --lib --locked`: 347 passed, 0 failed, 38 ignored. <details><summary>vt-load.patch</summary> ```diff diff --git a/crates/victory-gpu/src/descriptor.rs b/crates/victory-gpu/src/descriptor.rs index 1d6ac56..c5f3fbb 100644 --- a/crates/victory-gpu/src/descriptor.rs +++ b/crates/victory-gpu/src/descriptor.rs @@ -2133,4 +2133,70 @@ mod tests { assert_eq!(create(desc, Placement { address, size: 7 }, &mut h), S_OK); assert_ne!(slot::<extern "system" fn(This) -> u64>(h, 0x48)(h), address); } + + /// Load test (`cargo test -p victory-gpu --lib --locked placed_view_shapes_load -- --ignored --nocapture`). + /// A million placed views whose descriptions differ only in padding words + /// make one shape; a million that really differ make a million. Then each + /// description word is varied alone, to list the words that tell shapes apart. + #[cfg(windows)] + #[test] + #[ignore = "load test: about a million table inserts"] + fn placed_view_shapes_load() { + use crate::loadprobe::{mix, private_bytes}; + const N: u64 = 1_000_000; + let shapes = || VIEWS.read().unwrap().shapes.len(); + let mut slot = [0u32; 8]; + let handle = slot.as_mut_ptr() as u64; + let null = std::ptr::null(); + // A 2D texture SRV (dimension 4): the union's words 4-7 are used; 3, 8 and 9 are padding. + let resource = [3, 0, 0, 0, 0x4321, 0, 0x4321, 0x10001, 28, 1, 0, 0, 0, 0]; + let desc = [28, 4, 0x1688, 0, 0, 1, 0, 0, 0, 0, 0x2000, 0x6, 0, 0, 0, 0]; + let before = (shapes(), private_bytes()); + for n in 0..N { + let mut r = resource; + r[1] = mix(n); + r[13] = mix(n + N); + let mut d = desc; + (d[3], d[8], d[9]) = (mix(n + 2 * N), mix(n + 3 * N), mix(n + 4 * N)); + let address = 0xd_0000_0000 + n * 0x1_0000; + (d[10], d[11]) = (address as u32, (address >> 32) as u32); + create_placed_srv(null, &r, &d, handle); + } + let padding = (shapes() - before.0, private_bytes().saturating_sub(before.1)); + eprintln!("padding only: {N} views -> {} new shapes, private memory +{} KiB", padding.0, padding.1 >> 10); + // Control: the mip level (word 4) really differs. + let mid = (shapes(), private_bytes()); + for n in 0..N / 10 { + let mut d = desc; + (d[4], d[5]) = (n as u32 + 1, 0); + create_placed_srv(null, &resource, &d, handle); + } + let control = (shapes() - mid.0, private_bytes().saturating_sub(mid.1)); + eprintln!("control: {} really different views -> {} new shapes, private memory +{} KiB", N / 10, control.0, control.1 >> 10); + assert_eq!(control.0 as u64, N / 10, "views that differ are shapes"); + // One word at a time, 64 values each, from a base the other tests do not use. + let mut identity = Vec::new(); + for (name, count) in [("resource", 14usize), ("view", 16)] { + for w in 0..count { + if name == "view" && (w == 10 || w == 11) { + continue; // the address + } + let base = shapes(); + for v in 0..64u32 { + let mut r = [3, 0, 0, 0, 0x7777, 0, 0x7777, 0x10001, 28, 1, 0, 0, 0, 0]; + let mut d = [28, 4, 0x1688, 0, 0, 1, 0, 0, 0, 0, 0x2000, 0x6, 0, 0, 0, 0]; + let v = 0x5000_0000 + v * 0x1111; + if name == "resource" { r[w] = v } else { d[w] = v } + create_placed_srv(null, &r, &d, handle); + } + let grew = shapes() - base; + eprintln!("{name} word {w:2}: 64 values -> {grew} shapes"); + if grew > 2 { + identity.push(format!("{name}[{w}]")); + } + } + } + eprintln!("words that tell shapes apart: {identity:?}"); + assert!(padding.0 <= 4, "padding alone made {} shapes out of {N}", padding.0); + } } diff --git a/crates/victory-gpu/src/lib.rs b/crates/victory-gpu/src/lib.rs index 2843d0c..82eacb1 100644 --- a/crates/victory-gpu/src/lib.rs +++ b/crates/victory-gpu/src/lib.rs @@ -45,6 +45,8 @@ mod indirect; mod inplace; #[cfg(windows)] mod land; +#[cfg(all(test, windows))] +mod loadprobe; pub mod list; pub mod object; pub mod pipeline; diff --git a/crates/victory-gpu/src/loadprobe.rs b/crates/victory-gpu/src/loadprobe.rs new file mode 100644 index 0000000..c1095d5 --- /dev/null +++ b/crates/victory-gpu/src/loadprobe.rs @@ -0,0 +1,33 @@ +//! Helpers for the `#[ignore]`d load tests (`cargo test -- --ignored`): the +//! process's private memory, as the title's memory line reports it. + +/// `PrivateUsage` of this process in bytes (0 if the call fails). +pub(crate) fn private_bytes() -> u64 { + use windows_sys::Win32::System::ProcessStatus::{ + K32GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS_EX, + }; + use windows_sys::Win32::System::Threading::GetCurrentProcess; + // SAFETY: the counters are plain integers and `cb` is their size. + unsafe { + let mut counters: PROCESS_MEMORY_COUNTERS_EX = std::mem::zeroed(); + counters.cb = size_of::<PROCESS_MEMORY_COUNTERS_EX>() as u32; + let ok = K32GetProcessMemoryInfo( + GetCurrentProcess(), + std::ptr::from_mut(&mut counters).cast(), + counters.cb, + ); + if ok == 0 { + 0 + } else { + counters.PrivateUsage as u64 + } + } +} + +/// A cheap mixing step, so noise in "padding" words is spread over all 32 bits. +pub(crate) fn mix(n: u64) -> u32 { + let mut x = n.wrapping_add(0x9e37_79b9_7f4a_7c15); + x = (x ^ (x >> 30)).wrapping_mul(0xbf58_476d_1ce4_e5b9); + x = (x ^ (x >> 27)).wrapping_mul(0x94d0_49bb_1331_11eb); + (x ^ (x >> 31)) as u32 +} diff --git a/crates/victory-gpu/src/resource.rs b/crates/victory-gpu/src/resource.rs index 1b7e47f..99f41b0 100644 --- a/crates/victory-gpu/src/resource.rs +++ b/crates/victory-gpu/src/resource.rs @@ -2958,10 +2958,14 @@ static PLACED_TEXTURES: std::sync::Mutex<std::collections::BTreeMap<(u64, [u32; /// The placed textures asked for with filler words set, as asked /// (address and description): for [`PLACED_TWINS`]. -#[cfg(windows)] +#[cfg(all(windows, any(test, feature = "diagnostics")))] static PLACED_RAW: std::sync::Mutex<std::collections::BTreeSet<(u64, [u32; 14])>> = std::sync::Mutex::new(std::collections::BTreeSet::new()); +/// Most variants [`PLACED_RAW`] keeps; past it the set starts over. +#[cfg(all(windows, feature = "diagnostics"))] +const PLACED_RAW_CAP: usize = 1 << 14; + /// Placed textures asked for a second time with other filler words in /// their description: each was a second resource and host copy before the /// filler was left out of the key ([`texture_at`]). @@ -3051,6 +3055,7 @@ pub(crate) fn texture_at(address: u64, desc: &[u32; 14]) -> Option<This> { // that fills at world entry. They are not part of what a texture is. // `VICTORY_PLACED_FILLER=1`: kept in the key, as before. static KEPT: std::sync::OnceLock<bool> = std::sync::OnceLock::new(); + #[cfg(feature = "diagnostics")] let raw = *desc; let mut key = *desc; if !*KEPT.get_or_init(|| std::env::var_os("VICTORY_PLACED_FILLER").is_some_and(|v| v == "1")) { @@ -3061,8 +3066,15 @@ pub(crate) fn texture_at(address: u64, desc: &[u32; 14]) -> Option<This> { let mut map = PLACED_TEXTURES.lock().unwrap_or_else(|e| e.into_inner()); // How many resources the filler alone would have added (a count for // the log: `placed_filler_twins`). + // Only a diagnostics build reads the count, so only it keeps the variants, + // and not past a cap: every filler variant the title ever passed was a + // set entry (about 100 bytes each, 1M of them in a synthetic load test). + #[cfg(feature = "diagnostics")] if raw != key { let mut seen = PLACED_RAW.lock().unwrap_or_else(|e| e.into_inner()); + if seen.len() >= PLACED_RAW_CAP { + seen.clear(); + } if seen.insert((address, raw)) { let others = seen.range((address, [0; 14])..=(address, [u32::MAX; 14])).filter(|(_, r)| { let mut blank = *r; @@ -4567,6 +4579,54 @@ float4 lit() : SV_Target { return 1.0; } assert_eq!(sweep_batch(&all, 4, 2).collect::<Vec<_>>(), [1, 3]); } + /// Load test (`cargo test -p victory-gpu --lib --locked placed_filler_bookkeeping_load -- --ignored --nocapture`). + /// `texture_at` is asked a million times for placed memory whose resource + /// description differs only in the filler words 1 and 13. A buffer + /// description is used so that no host resource is needed: `texture_at` + /// notes the filler variants before it looks at the dimension. + #[cfg(windows)] + #[test] + #[ignore = "load test: about a million lookups"] + fn placed_filler_bookkeeping_load() { + use crate::loadprobe::{mix, private_bytes}; + const N: u64 = 1_000_000; + let raw_len = || PLACED_RAW.lock().unwrap().len(); + let map_len = || PLACED_TEXTURES.lock().unwrap().len(); + let (r0, m0, p0) = (raw_len(), map_len(), private_bytes()); + // Control: no filler, a million addresses. + for n in 0..N { + let desc = [BUFFER, 0, 0, 0, 0x1000, 0, 1, 0x10001, 0, 1, 0, 0, 0, 0]; + texture_at(0x10_0000_0000 + n * 0x1000, &desc); + } + let control = (raw_len() - r0, map_len() - m0, private_bytes().saturating_sub(p0)); + eprintln!("no filler, {N} addresses: PLACED_RAW +{}, PLACED_TEXTURES +{}, private +{} KiB", control.0, control.1, control.2 >> 10); + // Filler varies, one entry per address as when many resources are placed. + let (r1, p1) = (raw_len(), private_bytes()); + let t = std::time::Instant::now(); + for n in 0..N { + let desc = [BUFFER, mix(n), 0, 0, 0x1000, 0, 1, 0x10001, 0, 1, 0, 0, 0, mix(n + N)]; + texture_at(0x20_0000_0000 + (n % 100_000) * 0x1000, &desc); + } + let filler = (raw_len() - r1, private_bytes().saturating_sub(p1)); + eprintln!( + "filler varies, {N} asks at 100,000 addresses: PLACED_RAW +{}, private +{} KiB, {:?}", + filler.0, + filler.1 >> 10, + t.elapsed() + ); + // One address, ever more filler variants: the cost of one ask. + for k in [2_000u64, 4_000, 8_000] { + let t = std::time::Instant::now(); + for n in 0..k { + let desc = [BUFFER, mix(n + 9 * N), 0, 0, 0x1000, 0, 1, 0x10001, 0, 1, 0, 0, 0, mix(n + 10 * N)]; + texture_at(0x30_0000_0000 + k * 0x10_0000, &desc); + } + eprintln!("one address, {k} variants: {:?}", t.elapsed()); + } + assert_eq!(control.0, 0, "no filler, nothing noted"); + assert!(filler.0 <= 1 << 16, "{} filler variants kept for a log counter", filler.0); + } + #[test] fn texture_floor_scales_with_vram_budget() { const GIB: u64 = 1 << 30; ``` </details> **Limits** - Synthetic, no game files; it does not reproduce the 70-minute session. - It shows that the table grows by about 100 bytes per distinct (address, filler) pair. How many pairs a real session makes is not measured. Even at tens of millions it would be a few GB, so it may not be the whole 0.4-0.5 GB/min. - The host-side tables (`shadow.rs`, `texture.rs`) were not exercised; they need the GPU host and real title memory. Written with AI help (Claude/Kiro); the numbers are from runs on my machine.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 15:46:04 +00:00
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-26 19:18 UTC · original

The C01 audit confirmed that PLACED_RAW is still unbounded on main. #35 compiles the bookkeeping out of default builds and caps it at 16,384 variants in diagnostics. The independent synthetic result in the PR confirms bounded growth. I have queued CI for that revision.

**@⁠TaynanGT** on GitHub · 2026-11-26 19:18 UTC · [original](https://github.com/TaynanGT/Vice-Tay/issues/34#issuecomment-7201445253) The C01 audit confirmed that `PLACED_RAW` is still unbounded on main. #35 compiles the bookkeeping out of default builds and caps it at 16,384 variants in diagnostics. The independent synthetic result in the PR confirms bounded growth. I have queued CI for that revision.
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-26 19:29 UTC · original

The fix is on main in #35. Default builds no longer collect raw filler variants. Diagnostic builds retain at most 16,384 entries and start a new sample when the cap is reached. The default and diagnostics suites and Clippy passed.

**@⁠TaynanGT** on GitHub · 2026-11-26 19:29 UTC · [original](https://github.com/TaynanGT/Vice-Tay/issues/34#issuecomment-7201649922) The fix is on `main` in #35. Default builds no longer collect raw filler variants. Diagnostic builds retain at most 16,384 entries and start a new sample when the cap is reached. The default and diagnostics suites and Clippy passed.
This discussion has been locked. Commenting is limited to contributors.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/TaynanGT--Vice-Tay#34
No description provided.