Reuse returned scratch chunks: the spare gives up its oldest instead of refusing the newest (patch against fe7c6e5) #441

Open
opened 2026-11-29 12:38:37 +00:00 by einfachama · 8 comments
einfachama commented 2026-11-29 12:38:37 +00:00 (Migrated from github.com)
Contributor

Imported from TaynanGT/Vice-Tay. Originally posted by einfachama on 2026-11-29T12:38:37Z.


I am not opening a fork, so this hands the change over as a patch: the full diff is at the end, under Patch. It applies with git apply to main at fe7c6e5219. It also applies, with line offsets only, to review/local-integration-20261129 as of today.

Summary

A host list's scratch memory comes in chunks: the first one 256 KiB (SCRATCH_FIRST), the rest 4 MiB (SCRATCH_CHUNK). Chunks a list gives back are kept in a spare for the next list, up to 128 MiB (SPARE_MOST; SPARE_KEPT on PCs with more than 32 GB), and Spare::take hands out a kept chunk of exactly the size asked for.

Spare::give refused a chunk that would take the spare past its bound. Once the spare was full of 4 MiB chunks, which happens within the first minutes, every 256 KiB first chunk a list gave back was refused and freed, and the next list made a new one. On my PC, standing in one place in my retail title, that was about 58,000 new upload buffers a minute, about 1,000 a second. Each was waited for until the memory was resident ("new memory waited for": about 61,000 waits and 20 s a minute, spread over the list translation threads). Meanwhile the spare held about 127 MB in 33 to 35 chunks that nobody asked for.

With this change Spare::give keeps the chunk it is given and frees the chunks it has kept longest, as many as needed to stay within the bound. Spare::take already hands out the chunk given last, so the ones freed are the idle ones. A chunk larger than the bound by itself is still refused. Whatever is not kept goes back to the caller with its size and is freed as before, outside the spare's lock. The bound, the two chunk sizes, SPARE_KEPT and the trim under RAM pressure (trim_spare_chunks) are unchanged. The chunk counters in the memory line count every chunk that leaves the spare.

Related work. The same jam has been found in other forks of this code:

  • fxceless/victory-fork #1367 diagnosed it as the spare sitting at its bound in 4 MiB chunks while exact-size takes missed every first chunk. Its fix lets a 256 KiB request take a kept 4 MiB chunk, which the list then uses and gives back as a 4 MiB chunk, and raises the bound to 512 MiB (VICTORY_SCRATCH_SPARE_MB).
  • aleksesipenko/VIctory-RTX c5e3de3 is a port of that fix.
  • trustno1-coder/VIctory-NVIDIA #700, merged November 29, ports the first part of #1367: a small first chunk may take a kept 4 MiB chunk of the same memory kind. It leaves out the 512 MiB bound.
  • trustno1-coder/VIctory-NVIDIA issue #930, reported by moduz87 on November 28, describes the same flaw in Spare::give: at capacity, returned buffers are discarded while older, unused ones stay kept. Under their test conditions it reports about 415 MB/s of needless allocations, and 7.5 to 14.1 FPS with an eviction policy that removes the oldest kept buffers.
  • trustno1-coder/VIctory-NVIDIA PR #973 by jptorres96, opened November 28 and still open, takes the same approach as this change. A full spare frees the chunks kept longest until the one given back fits, a chunk larger than the bound is still refused, and the bound is kept.
    • It also adds a switch back to the old behaviour (VICTORY_SPARE_EVICT=0).
    • It reworks that tree's periodic trim, after a review there found the trim could free the chunk just given back.
    • It was tested on the CPU, not measured in the game.

This change was written independently of #930 and #973, against this tree, and makes no claim about who was first. No code from any of them is in it.

This change differs from #1367 and its ports in three ways:

  • it keeps the 128 MiB bound and both chunk sizes;
  • it adds no memory: in these runs the scratch memory held went down, from about 200 MB to about 147 MB;
  • a small list never holds a 4 MiB chunk.

It was written for a 32 GB PC with about 3 GB of RAM free in play, where 384 MiB more idle spare and 4 MiB chunks for 256 KiB lists would cost memory that is not there. A fallback to a larger kept chunk only when no chunk of the right size is kept would combine with this. It is not part of this change, so that the runs below measure one thing.

Every other user of Spare<T> was checked:

  • Scratch chunks: the same give_chunks path takes them back from a dropped list's scratch, from a list reset (now on the landing helper thread since #284), and from movie-plane uploads. Plane uploads have sizes no later request matches, so before this they could also fill the spare.
  • ReadbackPool (opt-in, VICTORY_READBACK_POOL=1): at its 256 MiB idle bound it now frees the oldest idle read-back buffers instead of the returning one. With the pool off (bound 0) everything is refused as before.
  • host/send.rs's spare and pool.rs's Pool: separate types, unchanged.
  • Trims: the review remark on #973 does not apply here.
    • This tree's scratch spare has no periodic trim. Nothing frees kept chunks by a count of bytes or by how long they have been idle.
    • The only other thing that empties it is trim_spare_chunks. Under RAM pressure it frees every kept chunk, at most once a second, the chunk just given back included. That is what it did before, and it is unchanged.
    • When the bound drops from SPARE_KEPT to SPARE_MOST because host RAM becomes limited, the next give frees the oldest chunks down to 128 MiB and keeps the one given back.
    • The read-back pool has no trim.
    • The open #263 would add an idle-age Spare::trim. It frees from the front of kept and stops at the first chunk given back too recently. Gives append and takes remove without reordering, so with this change a chunk just given back is still never trimmed, except in that PR's panic-memory mode, which frees past the warm ceiling regardless. Merging both needs a small textual merge in Spare::give, for the extra timestamp field.

The diff is one file, crates/victory-gpu/src/host.rs: 107 lines added, 32 removed, most of them doc comments and tests.

Measurements

Ryzen 7 5800X, RTX 4060 8 GB, 32 GB RAM, Windows 11, Series S (about 1280x720 inside a 1920x1080 window), diagnostics builds of 151b7db without and with this change, built the same way. The shader translator's fingerprint is the same in both builds, so both start from the same shader cache and pipeline library. Same settings for every run: the -Machine 4070 set with the 8 GB card sizes (card buffers 1024 MB, windows 512 MB, texture room 85 %), except run 2, which had pipeline workers 8 and VICTORY_MAP_THREADS=auto. Each run started from the same save and stood in the same place for 15 minutes (run 1: 25 minutes, of which minutes 6 to 15 are used). NVIDIA Smooth Motion was on in runs 1 and 2 and off in runs 3 to 5.

Everything is taken from minute 6 to minute 15:

  • Frame time: the median of the window caption's ms/frame, sampled once a second (samples in brackets), split by the caption's draws a frame.
  • Rates: the change in the cumulative counters per minute.
  • List translation: the median of the per-second "list calls translated by threads of ours" total over all eight threads.
  • Card busy: the median of "the card about N % busy" from the card's clock line.
Run Change Smooth Motion Frame ms, 3,000 to 3,700 draws Frame ms, 3,700 to 4,500 draws Upload buffers made a minute New memory waited for, a minute List translation, ms a frame (all threads) Card busy Scratch memory held Lowest available RAM
1 without on 70.4 (233) 72.4 (32) 35,800 38,900 times, 13.0 s 279 80 % 201 MB 3.25 GB
2 without on 69.9 (222) 72.4 (44) 59,000 62,000 times, 20.8 s 300 79 % 206 MB 3.23 GB
3 without off 69.3 (221) 73.1 (47) 57,600 60,700 times, 20.0 s 295 77 % 196 MB 5.00 GB
4 with off 61.1 (241) 63.5 (22) 7 3,460 times, 1.7 s 248 91 % 146 MB 5.15 GB
5 with off 59.0 (183) 61.8 (78) 8 3,540 times, 1.7 s 240 93 % 148 MB 6.46 GB
  • Frame time: at 3,000 to 3,700 draws a frame it fell from 69.3–70.4 ms to 59.0–61.1 ms, about 13 % shorter.
    • The three runs without the change are within 1.1 ms of each other, and so are the two with it.
    • Smooth Motion on or off made no difference to the caption's frame time here (runs 1 and 2 against run 3).
  • New upload buffers: from tens of thousands a minute to single digits.
  • Waits: fell by about 94 %. What is left is the title's shared buffers and the other upload buffers, which this change does not touch.
  • List translation: the total over all threads fell by about 50 ms a frame.
  • Card busy: the card went from about 79 % to about 92 % busy.
  • The spare's contents: it held 33 to 37 chunks of 124 to 127 MB without the change, and about 85 to 96 chunks of about 85 MB with it. Takes from the spare rose from 13,000–36,000 to about 84,000 a minute.
  • Lowest available RAM: this is for the whole run, and runs 1 and 2 also had Smooth Motion on.

Run 1 made fewer new buffers than runs 2 and 3 (35,800 against about 58,000 a minute) with the same code. How fast the spare fills with 4 MiB chunks differs from run to run. The frame time of run 1 is still in line with runs 2 and 3.

What this does not cover

  • One PC: a Ryzen 7 5800X, RTX 4060 8 GB and 32 GB. PCs with more than 32 GB use the 1 GiB SPARE_KEPT bound, which this change treats the same way but which was not run.
  • One place, standing still, 15-minute runs. There is no dense-town or driving measurement with the change yet. Lists that need more scratch than the spare's newest 128 MiB would still make chunks.
  • Not measured on main. The runs are on 151b7db. This branch is the same change on fe7c6e5, where it applies without conflict. None of the 53 commits between them touch Spare, take_chunk, give_chunks or the scratch call sites. #284 moved the list reset, which gives the chunks back, to the landing helper thread, which takes the same lock.
  • Two runs with the change and three without, one of them with different worker settings (run 2). The gap between the groups is about eight times the spread within each, but it is a small sample.
  • Not covered by this change: the title's shared buffers made each frame (about 3 a frame here) and pooling them (aleksesipenko/VIctory-RTX UPLOAD_POOL).

Visual review

All five runs were played by hand. No recording was made.

I saw no difference in the picture between the runs with and without the change.

Verification

On this branch (fe7c6e5 plus the change), as CI runs it:

  • cargo test -p victory-gpu --locked: 529 passed, 0 failed, 45 ignored.
  • cargo test -p victory-gpu --all-features --locked -- --test-threads=1 spare readback_pool: 9 passed, among them the D3D12 test of the read-back pool.
  • cargo clippy --workspace --all-targets --locked -- -D warnings and the same with --all-features: no warnings.
  • cargo check --workspace --profile diag --all-features --locked: clean.
  • cargo xtask policy: 322 files ok. git diff --check: clean.

New tests in host.rs's spare module:

  • a_full_spare_keeps_a_small_thing_and_gives_up_the_oldest: a spare filled with 32 4 MiB chunks keeps a 256 KiB chunk, gives up the oldest 4 MiB one, and hands the small chunk back on the next take of that size. The byte count matches the kept chunks throughout.
  • the_oldest_go_first_and_the_bytes_stay_right: chunks leave oldest first. A chunk that fills the spare exactly is kept, a chunk larger than the bound is refused, and a bound of 0 keeps nothing.
  • The existing test was adjusted to the new return type.

On 151b7db, the build that was measured: cargo test -p victory-gpu --locked passed (498 passed, 43 ignored), and so did both clippy runs.

AI use

Claude Code (Claude Opus 5.5) found the cause in the run logs and the source, and wrote the change and its tests. It also read the related issues and pull requests above and checked this tree's trims against the #973 review remark. Claude Fable 5.2, in the Claude app, planned the runs and checked the numbers and the patch. I played the runs.

Patch

Against main at fe7c6e5219 (one file, crates/victory-gpu/src/host.rs, 107 lines added, 32 removed). Save it as a file and run git apply on it from the repository root.

diff --git a/crates/victory-gpu/src/host.rs b/crates/victory-gpu/src/host.rs
index f4fb7c9..b329490 100644
--- a/crates/victory-gpu/src/host.rs
+++ b/crates/victory-gpu/src/host.rs
@@ -2772,15 +2772,31 @@ impl<T> Spare<T> {
         Some(self.kept.remove(at).0)
     }
 
-    /// Keeps `thing` (`size` bytes) unless that takes the kept bytes past
-    /// `most`: then it comes back.
-    fn give(&mut self, thing: T, size: u64, most: u64) -> Option<T> {
-        if self.bytes + size > most {
-            return Some(thing);
-        }
+    /// Keeps `thing` (`size` bytes). Where that takes the kept bytes past
+    /// `most`, the things kept longest go first ([`Spare::take`] picks the
+    /// one given last, so those are the idle ones): before, `thing` was
+    /// turned away instead, and a limit filled with 4 MiB chunks nobody
+    /// asked for turned away every 256 KiB first chunk a list gave back,
+    /// to be made anew by the next list (run 20261127-195954: about 70
+    /// upload buffers a frame, each waited for). The same jam was found
+    /// first in fxceless/victory-fork #1367 (also in aleksesipenko/
+    /// VIctory-RTX c5e3de3), which lets a first chunk take a kept 4 MiB one
+    /// and raises the bound to 512 MiB; this keeps the bound and the sizes.
+    /// A thing larger than `most` by itself is not kept. What is not kept
+    /// comes back with its size, for the caller to free.
+    fn give(&mut self, thing: T, size: u64, most: u64) -> Vec<(T, u64)> {
+        if size > most {
+            return vec![(thing, size)];
+        }
+        let mut oldest = 0;
+        while self.bytes + size > most {
+            self.bytes -= self.kept[oldest].1;
+            oldest += 1;
+        }
+        let gone = self.kept.drain(..oldest).collect();
         self.bytes += size;
         self.kept.push((thing, size));
-        None
+        gone
     }
 }
 
@@ -3135,8 +3151,8 @@ fn take_chunk(host: &Host, size: u64) -> Option<Chunk> {
 }
 
 /// A list is done with `chunks` (it was reset after its submissions ran,
-/// or dropped): kept for the next list, or freed past [`SPARE_MOST`] and
-/// without the pool.
+/// or dropped): kept for the next list, while the spare ones kept longest
+/// are freed past [`SPARE_MOST`]; all freed without the pool.
 fn give_chunks(chunks: Vec<(Chunk, u64)>) {
     if chunks.is_empty() {
         return;
@@ -3145,29 +3161,30 @@ fn give_chunks(chunks: Vec<(Chunk, u64)>) {
     {
         let mut spare = SPARE.lock().unwrap_or_else(|e| e.into_inner());
         for (chunk, size) in chunks {
-            let back = if scratch_pool() {
-                let limit = if keep_freed() && !crate::residency::limited_host_ram() {
-                    SPARE_KEPT
-                } else {
-                    SPARE_MOST
-                };
-                spare.give(chunk, size, limit)
+            if !scratch_pool() {
+                freed.push((chunk, size));
+                continue;
+            }
+            let limit = if keep_freed() && !crate::residency::limited_host_ram() {
+                SPARE_KEPT
             } else {
-                Some(chunk)
+                SPARE_MOST
             };
-            match back {
-                None => {
-                    ALIVE[3].fetch_add(1, Ordering::Relaxed);
-                    ALIVE[4].fetch_add(size, Ordering::Relaxed);
-                }
-                Some(chunk) => {
-                    ALIVE[1].fetch_sub(1, Ordering::Relaxed);
-                    ALIVE[2].fetch_sub(size, Ordering::Relaxed);
-                    freed.push(chunk);
-                }
+            // Counted as spare; what comes back (this chunk if refused, or
+            // those kept longest) leaves the spare again.
+            ALIVE[3].fetch_add(1, Ordering::Relaxed);
+            ALIVE[4].fetch_add(size, Ordering::Relaxed);
+            for (gone, gone_size) in spare.give(chunk, size, limit) {
+                ALIVE[3].fetch_sub(1, Ordering::Relaxed);
+                ALIVE[4].fetch_sub(gone_size, Ordering::Relaxed);
+                freed.push((gone, gone_size));
             }
         }
     }
+    for (_, size) in &freed {
+        ALIVE[1].fetch_sub(1, Ordering::Relaxed);
+        ALIVE[2].fetch_sub(*size, Ordering::Relaxed);
+    }
     // Freed outside the lock.
     drop(freed);
 }
@@ -12538,12 +12555,12 @@ mod spare {
     fn kept_things_come_back_by_size_within_the_limit() {
         let mut spare: Spare<u32> = Spare::new();
         assert_eq!(spare.take(4), None);
-        assert_eq!(spare.give(1, 4, 10), None);
-        assert_eq!(spare.give(2, 1, 10), None);
-        assert_eq!(spare.give(3, 4, 10), None);
+        assert!(spare.give(1, 4, 10).is_empty());
+        assert!(spare.give(2, 1, 10).is_empty());
+        assert!(spare.give(3, 4, 10).is_empty());
         assert_eq!(spare.bytes, 9);
-        // Past the limit: handed back, nothing changes.
-        assert_eq!(spare.give(4, 4, 10), Some(4));
+        // Larger than the limit by itself: handed back, nothing changes.
+        assert_eq!(spare.give(4, 11, 10), vec![(4, 11)]);
         assert_eq!(spare.bytes, 9);
         assert_eq!(spare.take(2), None, "no thing of that size");
         assert_eq!(spare.take(4), Some(3));
@@ -12553,6 +12570,64 @@ mod spare {
         assert_eq!(spare.bytes, 0);
         assert!(spare.kept.is_empty());
     }
+
+    /// A spare full of large chunks keeps a small one given to it, giving
+    /// up the ones kept longest, and hands it back on take.
+    #[test]
+    fn a_full_spare_keeps_a_small_thing_and_gives_up_the_oldest() {
+        const BIG: u64 = 4 << 20;
+        const SMALL: u64 = 256 << 10;
+        const MOST: u64 = 128 << 20;
+        let mut spare: Spare<u32> = Spare::new();
+        for n in 0..32 {
+            assert!(spare.give(n, BIG, MOST).is_empty());
+        }
+        assert_eq!(spare.bytes, MOST);
+        // One big one goes for the small one: the first given.
+        assert_eq!(spare.give(100, SMALL, MOST), vec![(0, BIG)]);
+        assert_eq!(spare.bytes, MOST - BIG + SMALL);
+        // The next small ones fit in the room that left.
+        for n in 101..116 {
+            assert!(spare.give(n, SMALL, MOST).is_empty());
+        }
+        assert_eq!(spare.bytes, MOST);
+        // Past it again: the oldest big one goes, for a small one or a big one.
+        assert_eq!(spare.give(116, SMALL, MOST), vec![(1, BIG)]);
+        assert_eq!(spare.bytes, MOST - BIG + SMALL);
+        assert_eq!(spare.give(200, BIG, MOST), vec![(2, BIG)]);
+        assert_eq!(spare.bytes, MOST - BIG + SMALL);
+        assert_eq!(spare.take(SMALL), Some(116));
+        assert_eq!(spare.take(SMALL), Some(115));
+        assert_eq!(spare.take(BIG), Some(200));
+        assert_eq!(spare.bytes, MOST - 2 * BIG - SMALL);
+        assert_eq!(spare.bytes, spare.kept.iter().map(|(_, s)| s).sum::<u64>());
+    }
+
+    /// The oldest go first, as many as it takes, and the byte count
+    /// follows gives, takes and what was given up.
+    #[test]
+    fn the_oldest_go_first_and_the_bytes_stay_right() {
+        let mut spare: Spare<u32> = Spare::new();
+        assert!(spare.give(1, 3, 10).is_empty());
+        assert!(spare.give(2, 2, 10).is_empty());
+        assert!(spare.give(3, 4, 10).is_empty());
+        assert_eq!(spare.bytes, 9);
+        // 9 + 6 > 10: 1 (3 bytes) and 2 (2 bytes) go, 4 + 6 = 10 stays.
+        assert_eq!(spare.give(4, 6, 10), vec![(1, 3), (2, 2)]);
+        assert_eq!(spare.bytes, 10);
+        assert_eq!(spare.take(4), Some(3));
+        assert_eq!(spare.bytes, 6);
+        // Exactly the limit is kept; one more byte than it is refused.
+        assert_eq!(spare.give(5, 10, 10), vec![(4, 6)]);
+        assert_eq!(spare.give(6, 11, 10), vec![(6, 11)]);
+        assert_eq!(spare.bytes, 10);
+        assert_eq!(spare.take(10), Some(5));
+        assert_eq!(spare.bytes, 0);
+        assert!(spare.kept.is_empty());
+        // A limit of nothing keeps nothing (the read-back pool when off).
+        assert_eq!(spare.give(7, 1, 0), vec![(7, 1)]);
+        assert_eq!(spare.bytes, 0);
+    }
 }
 
 #[cfg(test)]
<!-- greyfinch-sync:TaynanGT/Vice-Tay:issue:6678800674 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/issues/441). Originally posted by [einfachama](https://github.com/einfachama) on 2026-11-29T12:38:37Z. --- I am not opening a fork, so this hands the change over as a patch: the full diff is at the end, under **Patch**. It applies with `git apply` to `main` at fe7c6e52198f2070805ffafc4e55a7163291bad0. It also applies, with line offsets only, to `review/local-integration-20261129` as of today. ## Summary A host list's scratch memory comes in chunks: the first one 256 KiB (`SCRATCH_FIRST`), the rest 4 MiB (`SCRATCH_CHUNK`). Chunks a list gives back are kept in a spare for the next list, up to 128 MiB (`SPARE_MOST`; `SPARE_KEPT` on PCs with more than 32 GB), and `Spare::take` hands out a kept chunk of exactly the size asked for. `Spare::give` refused a chunk that would take the spare past its bound. Once the spare was full of 4 MiB chunks, which happens within the first minutes, every 256 KiB first chunk a list gave back was refused and freed, and the next list made a new one. On my PC, standing in one place in my retail title, that was about 58,000 new upload buffers a minute, about 1,000 a second. Each was waited for until the memory was resident ("new memory waited for": about 61,000 waits and 20 s a minute, spread over the list translation threads). Meanwhile the spare held about 127 MB in 33 to 35 chunks that nobody asked for. With this change `Spare::give` keeps the chunk it is given and frees the chunks it has kept longest, as many as needed to stay within the bound. `Spare::take` already hands out the chunk given last, so the ones freed are the idle ones. A chunk larger than the bound by itself is still refused. Whatever is not kept goes back to the caller with its size and is freed as before, outside the spare's lock. The bound, the two chunk sizes, `SPARE_KEPT` and the trim under RAM pressure (`trim_spare_chunks`) are unchanged. The chunk counters in the memory line count every chunk that leaves the spare. **Related work.** The same jam has been found in other forks of this code: - **fxceless/victory-fork #1367** diagnosed it as the spare sitting at its bound in 4 MiB chunks while exact-size takes missed every first chunk. Its fix lets a 256 KiB request take a kept 4 MiB chunk, which the list then uses and gives back as a 4 MiB chunk, and raises the bound to 512 MiB (`VICTORY_SCRATCH_SPARE_MB`). - **aleksesipenko/VIctory-RTX c5e3de3** is a port of that fix. - **trustno1-coder/VIctory-NVIDIA #700,** merged November 29, ports the first part of #1367: a small first chunk may take a kept 4 MiB chunk of the same memory kind. It leaves out the 512 MiB bound. - **trustno1-coder/VIctory-NVIDIA issue #930,** reported by moduz87 on November 28, describes the same flaw in `Spare::give`: at capacity, returned buffers are discarded while older, unused ones stay kept. Under their test conditions it reports about 415 MB/s of needless allocations, and 7.5 to 14.1 FPS with an eviction policy that removes the oldest kept buffers. - **trustno1-coder/VIctory-NVIDIA PR #973** by jptorres96, opened November 28 and still open, takes the same approach as this change. A full spare frees the chunks kept longest until the one given back fits, a chunk larger than the bound is still refused, and the bound is kept. - It also adds a switch back to the old behaviour (`VICTORY_SPARE_EVICT=0`). - It reworks that tree's periodic trim, after a review there found the trim could free the chunk just given back. - It was tested on the CPU, not measured in the game. This change was written independently of #930 and #973, against this tree, and makes no claim about who was first. No code from any of them is in it. This change differs from #1367 and its ports in three ways: - it keeps the 128 MiB bound and both chunk sizes; - it adds no memory: in these runs the scratch memory held went down, from about 200 MB to about 147 MB; - a small list never holds a 4 MiB chunk. It was written for a 32 GB PC with about 3 GB of RAM free in play, where 384 MiB more idle spare and 4 MiB chunks for 256 KiB lists would cost memory that is not there. A fallback to a larger kept chunk only when no chunk of the right size is kept would combine with this. It is not part of this change, so that the runs below measure one thing. Every other user of `Spare<T>` was checked: - **Scratch chunks:** the same `give_chunks` path takes them back from a dropped list's scratch, from a list reset (now on the landing helper thread since #284), and from movie-plane uploads. Plane uploads have sizes no later request matches, so before this they could also fill the spare. - **`ReadbackPool`** (opt-in, `VICTORY_READBACK_POOL=1`): at its 256 MiB idle bound it now frees the oldest idle read-back buffers instead of the returning one. With the pool off (bound 0) everything is refused as before. - **`host/send.rs`'s spare and `pool.rs`'s `Pool`:** separate types, unchanged. - **Trims:** the review remark on #973 does not apply here. - This tree's scratch spare has no periodic trim. Nothing frees kept chunks by a count of bytes or by how long they have been idle. - The only other thing that empties it is `trim_spare_chunks`. Under RAM pressure it frees every kept chunk, at most once a second, the chunk just given back included. That is what it did before, and it is unchanged. - When the bound drops from `SPARE_KEPT` to `SPARE_MOST` because host RAM becomes limited, the next give frees the oldest chunks down to 128 MiB and keeps the one given back. - The read-back pool has no trim. - The open #263 would add an idle-age `Spare::trim`. It frees from the front of `kept` and stops at the first chunk given back too recently. Gives append and takes remove without reordering, so with this change a chunk just given back is still never trimmed, except in that PR's panic-memory mode, which frees past the warm ceiling regardless. Merging both needs a small textual merge in `Spare::give`, for the extra timestamp field. The diff is one file, `crates/victory-gpu/src/host.rs`: 107 lines added, 32 removed, most of them doc comments and tests. ## Measurements Ryzen 7 5800X, RTX 4060 8 GB, 32 GB RAM, Windows 11, Series S (about 1280x720 inside a 1920x1080 window), diagnostics builds of 151b7db without and with this change, built the same way. The shader translator's fingerprint is the same in both builds, so both start from the same shader cache and pipeline library. Same settings for every run: the `-Machine 4070` set with the 8 GB card sizes (card buffers 1024 MB, windows 512 MB, texture room 85 %), except run 2, which had pipeline workers 8 and `VICTORY_MAP_THREADS=auto`. Each run started from the same save and stood in the same place for 15 minutes (run 1: 25 minutes, of which minutes 6 to 15 are used). NVIDIA Smooth Motion was on in runs 1 and 2 and off in runs 3 to 5. Everything is taken from minute 6 to minute 15: - **Frame time:** the median of the window caption's ms/frame, sampled once a second (samples in brackets), split by the caption's draws a frame. - **Rates:** the change in the cumulative counters per minute. - **List translation:** the median of the per-second "list calls translated by threads of ours" total over all eight threads. - **Card busy:** the median of "the card about N % busy" from the card's clock line. | Run | Change | Smooth Motion | Frame ms, 3,000 to 3,700 draws | Frame ms, 3,700 to 4,500 draws | Upload buffers made a minute | New memory waited for, a minute | List translation, ms a frame (all threads) | Card busy | Scratch memory held | Lowest available RAM | |---|---|---|---|---|---|---|---|---|---|---| | 1 | without | on | 70.4 (233) | 72.4 (32) | 35,800 | 38,900 times, 13.0 s | 279 | 80 % | 201 MB | 3.25 GB | | 2 | without | on | 69.9 (222) | 72.4 (44) | 59,000 | 62,000 times, 20.8 s | 300 | 79 % | 206 MB | 3.23 GB | | 3 | without | off | 69.3 (221) | 73.1 (47) | 57,600 | 60,700 times, 20.0 s | 295 | 77 % | 196 MB | 5.00 GB | | 4 | **with** | off | **61.1** (241) | **63.5** (22) | 7 | 3,460 times, 1.7 s | 248 | 91 % | 146 MB | 5.15 GB | | 5 | **with** | off | **59.0** (183) | **61.8** (78) | 8 | 3,540 times, 1.7 s | 240 | 93 % | 148 MB | 6.46 GB | - **Frame time:** at 3,000 to 3,700 draws a frame it fell from 69.3–70.4 ms to 59.0–61.1 ms, about 13 % shorter. - The three runs without the change are within 1.1 ms of each other, and so are the two with it. - Smooth Motion on or off made no difference to the caption's frame time here (runs 1 and 2 against run 3). - **New upload buffers:** from tens of thousands a minute to single digits. - **Waits:** fell by about 94 %. What is left is the title's shared buffers and the other upload buffers, which this change does not touch. - **List translation:** the total over all threads fell by about 50 ms a frame. - **Card busy:** the card went from about 79 % to about 92 % busy. - **The spare's contents:** it held 33 to 37 chunks of 124 to 127 MB without the change, and about 85 to 96 chunks of about 85 MB with it. Takes from the spare rose from 13,000–36,000 to about 84,000 a minute. - **Lowest available RAM:** this is for the whole run, and runs 1 and 2 also had Smooth Motion on. Run 1 made fewer new buffers than runs 2 and 3 (35,800 against about 58,000 a minute) with the same code. How fast the spare fills with 4 MiB chunks differs from run to run. The frame time of run 1 is still in line with runs 2 and 3. ## What this does not cover - **One PC:** a Ryzen 7 5800X, RTX 4060 8 GB and 32 GB. PCs with more than 32 GB use the 1 GiB `SPARE_KEPT` bound, which this change treats the same way but which was not run. - **One place, standing still, 15-minute runs.** There is no dense-town or driving measurement with the change yet. Lists that need more scratch than the spare's newest 128 MiB would still make chunks. - **Not measured on main.** The runs are on 151b7db. This branch is the same change on fe7c6e5, where it applies without conflict. None of the 53 commits between them touch `Spare`, `take_chunk`, `give_chunks` or the scratch call sites. #284 moved the list reset, which gives the chunks back, to the landing helper thread, which takes the same lock. - **Two runs with the change and three without,** one of them with different worker settings (run 2). The gap between the groups is about eight times the spread within each, but it is a small sample. - **Not covered by this change:** the title's shared buffers made each frame (about 3 a frame here) and pooling them (aleksesipenko/VIctory-RTX `UPLOAD_POOL`). ## Visual review All five runs were played by hand. No recording was made. I saw no difference in the picture between the runs with and without the change. ## Verification On this branch (fe7c6e5 plus the change), as CI runs it: - `cargo test -p victory-gpu --locked`: 529 passed, 0 failed, 45 ignored. - `cargo test -p victory-gpu --all-features --locked -- --test-threads=1 spare readback_pool`: 9 passed, among them the D3D12 test of the read-back pool. - `cargo clippy --workspace --all-targets --locked -- -D warnings` and the same with `--all-features`: no warnings. - `cargo check --workspace --profile diag --all-features --locked`: clean. - `cargo xtask policy`: 322 files ok. `git diff --check`: clean. New tests in `host.rs`'s `spare` module: - `a_full_spare_keeps_a_small_thing_and_gives_up_the_oldest`: a spare filled with 32 4 MiB chunks keeps a 256 KiB chunk, gives up the oldest 4 MiB one, and hands the small chunk back on the next take of that size. The byte count matches the kept chunks throughout. - `the_oldest_go_first_and_the_bytes_stay_right`: chunks leave oldest first. A chunk that fills the spare exactly is kept, a chunk larger than the bound is refused, and a bound of 0 keeps nothing. - The existing test was adjusted to the new return type. On 151b7db, the build that was measured: `cargo test -p victory-gpu --locked` passed (498 passed, 43 ignored), and so did both clippy runs. ## AI use Claude Code (Claude Opus 5.5) found the cause in the run logs and the source, and wrote the change and its tests. It also read the related issues and pull requests above and checked this tree's trims against the #973 review remark. Claude Fable 5.2, in the Claude app, planned the runs and checked the numbers and the patch. I played the runs. ## Patch Against `main` at fe7c6e52198f2070805ffafc4e55a7163291bad0 (one file, `crates/victory-gpu/src/host.rs`, 107 lines added, 32 removed). Save it as a file and run `git apply` on it from the repository root. ```diff diff --git a/crates/victory-gpu/src/host.rs b/crates/victory-gpu/src/host.rs index f4fb7c9..b329490 100644 --- a/crates/victory-gpu/src/host.rs +++ b/crates/victory-gpu/src/host.rs @@ -2772,15 +2772,31 @@ impl<T> Spare<T> { Some(self.kept.remove(at).0) } - /// Keeps `thing` (`size` bytes) unless that takes the kept bytes past - /// `most`: then it comes back. - fn give(&mut self, thing: T, size: u64, most: u64) -> Option<T> { - if self.bytes + size > most { - return Some(thing); - } + /// Keeps `thing` (`size` bytes). Where that takes the kept bytes past + /// `most`, the things kept longest go first ([`Spare::take`] picks the + /// one given last, so those are the idle ones): before, `thing` was + /// turned away instead, and a limit filled with 4 MiB chunks nobody + /// asked for turned away every 256 KiB first chunk a list gave back, + /// to be made anew by the next list (run 20261127-195954: about 70 + /// upload buffers a frame, each waited for). The same jam was found + /// first in fxceless/victory-fork #1367 (also in aleksesipenko/ + /// VIctory-RTX c5e3de3), which lets a first chunk take a kept 4 MiB one + /// and raises the bound to 512 MiB; this keeps the bound and the sizes. + /// A thing larger than `most` by itself is not kept. What is not kept + /// comes back with its size, for the caller to free. + fn give(&mut self, thing: T, size: u64, most: u64) -> Vec<(T, u64)> { + if size > most { + return vec![(thing, size)]; + } + let mut oldest = 0; + while self.bytes + size > most { + self.bytes -= self.kept[oldest].1; + oldest += 1; + } + let gone = self.kept.drain(..oldest).collect(); self.bytes += size; self.kept.push((thing, size)); - None + gone } } @@ -3135,8 +3151,8 @@ fn take_chunk(host: &Host, size: u64) -> Option<Chunk> { } /// A list is done with `chunks` (it was reset after its submissions ran, -/// or dropped): kept for the next list, or freed past [`SPARE_MOST`] and -/// without the pool. +/// or dropped): kept for the next list, while the spare ones kept longest +/// are freed past [`SPARE_MOST`]; all freed without the pool. fn give_chunks(chunks: Vec<(Chunk, u64)>) { if chunks.is_empty() { return; @@ -3145,29 +3161,30 @@ fn give_chunks(chunks: Vec<(Chunk, u64)>) { { let mut spare = SPARE.lock().unwrap_or_else(|e| e.into_inner()); for (chunk, size) in chunks { - let back = if scratch_pool() { - let limit = if keep_freed() && !crate::residency::limited_host_ram() { - SPARE_KEPT - } else { - SPARE_MOST - }; - spare.give(chunk, size, limit) + if !scratch_pool() { + freed.push((chunk, size)); + continue; + } + let limit = if keep_freed() && !crate::residency::limited_host_ram() { + SPARE_KEPT } else { - Some(chunk) + SPARE_MOST }; - match back { - None => { - ALIVE[3].fetch_add(1, Ordering::Relaxed); - ALIVE[4].fetch_add(size, Ordering::Relaxed); - } - Some(chunk) => { - ALIVE[1].fetch_sub(1, Ordering::Relaxed); - ALIVE[2].fetch_sub(size, Ordering::Relaxed); - freed.push(chunk); - } + // Counted as spare; what comes back (this chunk if refused, or + // those kept longest) leaves the spare again. + ALIVE[3].fetch_add(1, Ordering::Relaxed); + ALIVE[4].fetch_add(size, Ordering::Relaxed); + for (gone, gone_size) in spare.give(chunk, size, limit) { + ALIVE[3].fetch_sub(1, Ordering::Relaxed); + ALIVE[4].fetch_sub(gone_size, Ordering::Relaxed); + freed.push((gone, gone_size)); } } } + for (_, size) in &freed { + ALIVE[1].fetch_sub(1, Ordering::Relaxed); + ALIVE[2].fetch_sub(*size, Ordering::Relaxed); + } // Freed outside the lock. drop(freed); } @@ -12538,12 +12555,12 @@ mod spare { fn kept_things_come_back_by_size_within_the_limit() { let mut spare: Spare<u32> = Spare::new(); assert_eq!(spare.take(4), None); - assert_eq!(spare.give(1, 4, 10), None); - assert_eq!(spare.give(2, 1, 10), None); - assert_eq!(spare.give(3, 4, 10), None); + assert!(spare.give(1, 4, 10).is_empty()); + assert!(spare.give(2, 1, 10).is_empty()); + assert!(spare.give(3, 4, 10).is_empty()); assert_eq!(spare.bytes, 9); - // Past the limit: handed back, nothing changes. - assert_eq!(spare.give(4, 4, 10), Some(4)); + // Larger than the limit by itself: handed back, nothing changes. + assert_eq!(spare.give(4, 11, 10), vec![(4, 11)]); assert_eq!(spare.bytes, 9); assert_eq!(spare.take(2), None, "no thing of that size"); assert_eq!(spare.take(4), Some(3)); @@ -12553,6 +12570,64 @@ mod spare { assert_eq!(spare.bytes, 0); assert!(spare.kept.is_empty()); } + + /// A spare full of large chunks keeps a small one given to it, giving + /// up the ones kept longest, and hands it back on take. + #[test] + fn a_full_spare_keeps_a_small_thing_and_gives_up_the_oldest() { + const BIG: u64 = 4 << 20; + const SMALL: u64 = 256 << 10; + const MOST: u64 = 128 << 20; + let mut spare: Spare<u32> = Spare::new(); + for n in 0..32 { + assert!(spare.give(n, BIG, MOST).is_empty()); + } + assert_eq!(spare.bytes, MOST); + // One big one goes for the small one: the first given. + assert_eq!(spare.give(100, SMALL, MOST), vec![(0, BIG)]); + assert_eq!(spare.bytes, MOST - BIG + SMALL); + // The next small ones fit in the room that left. + for n in 101..116 { + assert!(spare.give(n, SMALL, MOST).is_empty()); + } + assert_eq!(spare.bytes, MOST); + // Past it again: the oldest big one goes, for a small one or a big one. + assert_eq!(spare.give(116, SMALL, MOST), vec![(1, BIG)]); + assert_eq!(spare.bytes, MOST - BIG + SMALL); + assert_eq!(spare.give(200, BIG, MOST), vec![(2, BIG)]); + assert_eq!(spare.bytes, MOST - BIG + SMALL); + assert_eq!(spare.take(SMALL), Some(116)); + assert_eq!(spare.take(SMALL), Some(115)); + assert_eq!(spare.take(BIG), Some(200)); + assert_eq!(spare.bytes, MOST - 2 * BIG - SMALL); + assert_eq!(spare.bytes, spare.kept.iter().map(|(_, s)| s).sum::<u64>()); + } + + /// The oldest go first, as many as it takes, and the byte count + /// follows gives, takes and what was given up. + #[test] + fn the_oldest_go_first_and_the_bytes_stay_right() { + let mut spare: Spare<u32> = Spare::new(); + assert!(spare.give(1, 3, 10).is_empty()); + assert!(spare.give(2, 2, 10).is_empty()); + assert!(spare.give(3, 4, 10).is_empty()); + assert_eq!(spare.bytes, 9); + // 9 + 6 > 10: 1 (3 bytes) and 2 (2 bytes) go, 4 + 6 = 10 stays. + assert_eq!(spare.give(4, 6, 10), vec![(1, 3), (2, 2)]); + assert_eq!(spare.bytes, 10); + assert_eq!(spare.take(4), Some(3)); + assert_eq!(spare.bytes, 6); + // Exactly the limit is kept; one more byte than it is refused. + assert_eq!(spare.give(5, 10, 10), vec![(4, 6)]); + assert_eq!(spare.give(6, 11, 10), vec![(6, 11)]); + assert_eq!(spare.bytes, 10); + assert_eq!(spare.take(10), Some(5)); + assert_eq!(spare.bytes, 0); + assert!(spare.kept.is_empty()); + // A limit of nothing keeps nothing (the read-back pool when off). + assert_eq!(spare.give(7, 1, 0), vec![(7, 1)]); + assert_eq!(spare.bytes, 0); + } } #[cfg(test)] ```
Kal0s-design commented 2026-11-29 13:03:02 +00:00 (Migrated from github.com)
Author
Contributor

Imported from TaynanGT/Vice-Tay. Originally posted by Kal0s-design on 2026-11-29T13:03:02Z.


Applied the patch to fe7c6e5 on Windows and checked it:

  • cargo test -p victory-gpu --lib: 529 passed, 45 ignored. cargo test -p victory-gpu --lib --all-features -- --test-threads=1 spare readback_pool: 9 passed.
  • cargo clippy --workspace --all-targets --locked -D warnings, with and without --all-features: clean. cargo xtask policy: ok.
  • git apply --check also passes on #439's branch at cfd5ebd.

I read the change too. The eviction loop always ends before running past kept, because size <= most is checked first. The ALIVE counters now add the given chunk to the spare and take back whatever comes out, so they stay balanced. trim_spare_chunks still empties the whole spare, so the "trim frees the chunk just given" problem from the other tree doesn't apply here.

One thing worth stating in the PR text: ReadbackLease::drop uses the same Spare::give, so the read-back pool also switches to keeping the newest idle buffer and dropping the oldest when full. It drops the returned Vec outside the lock just as it dropped the old Option, so that's fine, but it is a behaviour change there too.

If you'd rather not open a fork, I'm happy to carry it as a PR with your authorship kept on the commit, if you and the maintainer want that.

AI-assisted: yes

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7256251319 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/issues/441#issuecomment-7256251319). Originally posted by [Kal0s-design](https://github.com/Kal0s-design) on 2026-11-29T13:03:02Z. --- Applied the patch to fe7c6e5 on Windows and checked it: - `cargo test -p victory-gpu --lib`: 529 passed, 45 ignored. `cargo test -p victory-gpu --lib --all-features -- --test-threads=1 spare readback_pool`: 9 passed. - `cargo clippy --workspace --all-targets --locked -D warnings`, with and without `--all-features`: clean. `cargo xtask policy`: ok. - `git apply --check` also passes on #439's branch at cfd5ebd. I read the change too. The eviction loop always ends before running past `kept`, because `size <= most` is checked first. The ALIVE counters now add the given chunk to the spare and take back whatever comes out, so they stay balanced. `trim_spare_chunks` still empties the whole spare, so the "trim frees the chunk just given" problem from the other tree doesn't apply here. One thing worth stating in the PR text: `ReadbackLease::drop` uses the same `Spare::give`, so the read-back pool also switches to keeping the newest idle buffer and dropping the oldest when full. It drops the returned `Vec` outside the lock just as it dropped the old `Option`, so that's fine, but it is a behaviour change there too. If you'd rather not open a fork, I'm happy to carry it as a PR with your authorship kept on the commit, if you and the maintainer want that. AI-assisted: yes
TaynanGT commented 2026-11-29 13:23:29 +00:00 (Migrated from github.com)
Author
Contributor

Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-29T13:23:29Z.


Thanks for the detailed patch and measurements. The oldest-idle eviction change is now adapted in my local working tree, including an overflow-safe capacity comparison. I am testing it before committing; the readback pool behavior and memory-pressure trim also need validation. Your reported stationary measurements are useful, but I will not treat them as proof of improvement during driving.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7256502470 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/issues/441#issuecomment-7256502470). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-29T13:23:29Z. --- Thanks for the detailed patch and measurements. The oldest-idle eviction change is now adapted in my local working tree, including an overflow-safe capacity comparison. I am testing it before committing; the readback pool behavior and memory-pressure trim also need validation. Your reported stationary measurements are useful, but I will not treat them as proof of improvement during driving.
einfachama commented 2026-11-29 13:26:45 +00:00 (Migrated from github.com)
Author
Contributor

Imported from TaynanGT/Vice-Tay. Originally posted by einfachama on 2026-11-29T13:26:45Z.


Thanks for applying and checking it, and for reading the change.

Yes, please carry it as a PR. I am fine with that if the maintainer is. For the commit's author, please use einfachama <[email protected]>.

On the read-back pool: the issue text has it under "Every other user of Spare<T> was checked", but that is easy to miss. Please state it in the PR's summary as a behaviour change of its own: with VICTORY_READBACK_POOL=1, a full pool now keeps the returning buffer and frees the oldest idle ones. My runs do not cover it, they had the pool off.

The runs in the issue are on 151b7db. If it helps the PR, I can repeat the same place with and without the change on the PR's head.

AI use: drafted with Claude Fable 5.2 in the Claude app. I read it before posting.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7256542909 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/issues/441#issuecomment-7256542909). Originally posted by [einfachama](https://github.com/einfachama) on 2026-11-29T13:26:45Z. --- Thanks for applying and checking it, and for reading the change. Yes, please carry it as a PR. I am fine with that if the maintainer is. For the commit's author, please use `einfachama <70332613+[email protected]>`. On the read-back pool: the issue text has it under "Every other user of `Spare<T>` was checked", but that is easy to miss. Please state it in the PR's summary as a behaviour change of its own: with `VICTORY_READBACK_POOL=1`, a full pool now keeps the returning buffer and frees the oldest idle ones. My runs do not cover it, they had the pool off. The runs in the issue are on 151b7db. If it helps the PR, I can repeat the same place with and without the change on the PR's head. AI use: drafted with Claude Fable 5.2 in the Claude app. I read it before posting.
Kal0s-design commented 2026-11-29 14:21:29 +00:00 (Migrated from github.com)
Author
Contributor

Imported from TaynanGT/Vice-Tay. Originally posted by Kal0s-design on 2026-11-29T14:21:29Z.


Thanks. Since the maintainer has already adapted it in his local tree (with an overflow-safe capacity check), a separate PR from me would only duplicate that, so I'll hold off. If it turns out he'd rather take it as a PR, I'll open one with your authorship as you gave it.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7257240290 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/issues/441#issuecomment-7257240290). Originally posted by [Kal0s-design](https://github.com/Kal0s-design) on 2026-11-29T14:21:29Z. --- Thanks. Since the maintainer has already adapted it in his local tree (with an overflow-safe capacity check), a separate PR from me would only duplicate that, so I'll hold off. If it turns out he'd rather take it as a PR, I'll open one with your authorship as you gave it.
TaynanGT commented 2026-11-29 14:39:00 +00:00 (Migrated from github.com)
Author
Contributor

Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-29T14:39:00Z.


The patch is now in my local history as d5ee68e57, with einfachama as the original author. The commit records 12 passing targeted all-feature tests. The readback pool also keeps the returning buffer and evicts the oldest idle buffers when full with VICTORY_READBACK_POOL=1. No duplicate PR is needed. A matched driving run is still required before claiming a performance improvement.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7257467924 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/issues/441#issuecomment-7257467924). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-29T14:39:00Z. --- The patch is now in my local history as d5ee68e57, with einfachama as the original author. The commit records 12 passing targeted all-feature tests. The readback pool also keeps the returning buffer and evicts the oldest idle buffers when full with VICTORY_READBACK_POOL=1. No duplicate PR is needed. A matched driving run is still required before claiming a performance improvement.
TaynanGT commented 2026-11-30 17:00:04 +00:00 (Migrated from github.com)
Author
Contributor

Imported from TaynanGT/Vice-Tay. Originally posted by TaynanGT on 2026-11-30T17:00:04Z.


main has moved to a new line of the code and everything is now named Vice-Tay: vice-tay.exe play, and VICE_TAY_* switches instead of VICTORY_* (details in #468). Could you check whether this still happens on the current main and say so here, with a log if you can?

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7285561536 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/issues/441#issuecomment-7285561536). Originally posted by [TaynanGT](https://github.com/TaynanGT) on 2026-11-30T17:00:04Z. --- `main` has moved to a new line of the code and everything is now named Vice-Tay: `vice-tay.exe play`, and `VICE_TAY_*` switches instead of `VICTORY_*` (details in #468). Could you check whether this still happens on the current `main` and say so here, with a log if you can?
einfachama commented 2026-11-30 23:49:02 +00:00 (Migrated from github.com)
Author
Contributor

Imported from TaynanGT/Vice-Tay. Originally posted by einfachama on 2026-11-30T23:49:02Z.


Checked on main at 6e7e7873, on the PC from the report (Ryzen 7 5800X, RTX 4060 8 GB, 32 GB RAM, Windows 11 build 26300, driver 621.24).

Short answer: the jam this issue describes does not show on this line, and the patch above does not apply to it and is not what it needs. But the current main does not fit this PC at all, so the run is not comparable to the ones in the report.

The jam. In the 71 memory lines of a 7-minute diagnostics run the spare was never at its bound: it moved between 2 and 115 MB (bound 128 MiB), so Spare::give is not what turns chunks away there. Chunks are still made all the time, for another reason as far as I can tell: the PC has under 8 GiB of memory free for the whole run, so keeps_under_pressure() is false and the 1 Hz sweep trims the spares to the floor (spare_trim_to). Per minute, from second 120 to 420:

  • 1,539 to 1,893 upload buffers made (4.7 to 5.3 GB) and 38 to 587 shared buffers (0.2 to 4.4 GB): 7 to 11 new buffers a frame;
  • "new memory waited for": 2,000 to 4,000 times, 7.7 to 12.8 s (the line comes every 1,000 waits);
  • 16,300 to 22,700 chunks taken from the spare.

With the PC this short of memory I would not read more into those numbers. Evicting at the bound would change nothing here, so I withdraw the patch for this line.

What does not fit. Built from source (--profile diag --features diagnostics), started with run and the settings play picks for this PC (Series X, 1440p, DLSS Balanced), frame generation off, Windows' own Direct3D 12 runtime (no D3D12 folder; the card reports shader model 6.8), Streamline 2.14.16, shaders and pipelines preloaded, nothing else open (25.2 GB of memory available at the start), standing still in one place in my retail title:

  • process commit 27 to 30 GB (peak 30.5); available memory mostly 1.1 to 2.4 GB once the world had loaded (lowest 0.42 GB); memory pressure from second 56;
  • the card's own memory 6.8 to 6.9 GB of a 7.19 GB budget, and 9.3 to 10.5 GB of shared memory in use (peak 11.1);
  • frame time, median per minute: 149 to 280 ms (3.5 to 6.7 fps);
  • the picture is wrong: characters are flat or blocky silhouettes, and textures are missing in blocks on the boat and the shore.

A second run with what machine_settings sets under 24 GB of RAM (VICE_TAY_INPLACE=2, VICE_TAY_WINDOW_KB=64, VICE_TAY_WINDOW_TAILS=1, no VICE_TAY_CARD_BUFFERS_MIN_KB) took 25 to 27 GB of commit at 1.5 to 6.6 fps and lost the device after 274 s (0x887A0005; "when the host device went: the submitting thread was preparing a submission (nothing of ours was running on the card)"). A first try with other programs open (22.6 GB available at the start) had under 1 GB available 67 s in, and my watcher stopped it.

play refuses Series S on this build, so I did not try it. For comparison: one day earlier this PC ran trustno1-coder/VIctory-NVIDIA v2026.11.29.05 in Series S at 720p at the same place at about 18 fps, with 20 to 22 GB of process commit, 6.6 GB on the card and the right picture. So for an 8 GB card with 32 GB of RAM, Series S was the profile that fit.

Four lines of the 7-minute run (seconds 240 and 360)
2026-11-30T23:04:35.491513Z INFO vice_tay_gpu::copystat: memory, what holds it: 1471 host lists alive; their scratch memory: 199 chunks 140 MB, of them 99 chunks 70 MB spare (73922 taken from the spare ones so far); their other upload buffers: 0 alive 0 MB; windows outside buffers (grid 4096 KiB): 2792 MB of their pages ever copied, 605 shown by descriptor slots 3668 MB, 604 held by lists or the pass over the heap 3660 MB, 488 asked for without a length 2928 MB; buffer views of the heap whose slot showed another copy than the one brought up to date: 197; distinct views kept: 8438 (350 free) 12 MB; our own allocations: 1820 MB in 1296351 blocks (under 4 KiB 199 MB in 1273192, to 64 KiB 269 MB in 20645, to 1 MiB 457 MB in 2415, larger 895 MB in 99)
2026-11-30T23:04:35.491231Z INFO vice_tay_gpu::copystat: memory: 29719 MB private (19727 MB of it in memory; the PC has 2154 MB free and 17803 MB left to commit); host copies of title memory: 4385 alive 6272 MB, of them 611 windows outside buffers 3704 MB; snapshot buffers kept: 152 reserving 7 MB; staging of textures: 172 alive 67 MB, 166 kept by their texture; host textures: 25591 alive 4591 MB, 48931 placed in title memory; made so far: 5013 upload buffers 18709 MB, 1910 shared buffers 15206 MB, 9011 card buffers 1556 MB
2026-11-30T23:06:35.820880Z INFO vice_tay_gpu::copystat: memory, what holds it: 1449 host lists alive; their scratch memory: 179 chunks 124 MB, of them 39 chunks 32 MB spare (112573 taken from the spare ones so far); their other upload buffers: 0 alive 0 MB; windows outside buffers (grid 4096 KiB): 2781 MB of their pages ever copied, 620 shown by descriptor slots 3750 MB, 620 held by lists or the pass over the heap 3750 MB, 495 asked for without a length 2970 MB; buffer views of the heap whose slot showed another copy than the one brought up to date: 313; distinct views kept: 8438 (391 free) 12 MB; our own allocations: 1931 MB in 1315797 blocks (under 4 KiB 202 MB in 1291813, to 64 KiB 270 MB in 21215, to 1 MiB 555 MB in 2671, larger 905 MB in 98)
2026-11-30T23:06:35.820439Z INFO vice_tay_gpu::copystat: memory: 30363 MB private (19119 MB of it in memory; the PC has 2158 MB free and 17075 MB left to commit); host copies of title memory: 4143 alive 6455 MB, of them 625 windows outside buffers 3780 MB; snapshot buffers kept: 175 reserving 18 MB; staging of textures: 153 alive 58 MB, 153 kept by their texture; host textures: 29588 alive 4928 MB, 56415 placed in title memory; made so far: 8158 upload buffers 28131 MB, 2192 shared buffers 17172 MB, 10755 card buffers 1648 MB

I can open a separate issue for the memory fit with the issue form, and attach more of the log, if that is more useful than this comment.

AI use: Claude Code (Claude Opus 5.5) cloned and built main, read the scratch code and set up the run. Claude Fable 5.2 in the Claude app planned the runs, read the logs and drafted this comment. I ran the runs and read this before posting.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7295559213 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/issues/441#issuecomment-7295559213). Originally posted by [einfachama](https://github.com/einfachama) on 2026-11-30T23:49:02Z. --- Checked on `main` at 6e7e7873, on the PC from the report (Ryzen 7 5800X, RTX 4060 8 GB, 32 GB RAM, Windows 11 build 26300, driver 621.24). **Short answer:** the jam this issue describes does not show on this line, and the patch above does not apply to it and is not what it needs. But the current `main` does not fit this PC at all, so the run is not comparable to the ones in the report. **The jam.** In the 71 memory lines of a 7-minute diagnostics run the spare was never at its bound: it moved between 2 and 115 MB (bound 128 MiB), so `Spare::give` is not what turns chunks away there. Chunks are still made all the time, for another reason as far as I can tell: the PC has under 8 GiB of memory free for the whole run, so `keeps_under_pressure()` is false and the 1 Hz sweep trims the spares to the floor (`spare_trim_to`). Per minute, from second 120 to 420: - 1,539 to 1,893 upload buffers made (4.7 to 5.3 GB) and 38 to 587 shared buffers (0.2 to 4.4 GB): 7 to 11 new buffers a frame; - "new memory waited for": 2,000 to 4,000 times, 7.7 to 12.8 s (the line comes every 1,000 waits); - 16,300 to 22,700 chunks taken from the spare. With the PC this short of memory I would not read more into those numbers. Evicting at the bound would change nothing here, so I withdraw the patch for this line. **What does not fit.** Built from source (`--profile diag --features diagnostics`), started with `run` and the settings `play` picks for this PC (Series X, 1440p, DLSS Balanced), frame generation off, Windows' own Direct3D 12 runtime (no `D3D12` folder; the card reports shader model 6.8), Streamline 2.14.16, shaders and pipelines preloaded, nothing else open (25.2 GB of memory available at the start), standing still in one place in my retail title: - process commit 27 to 30 GB (peak 30.5); available memory mostly 1.1 to 2.4 GB once the world had loaded (lowest 0.42 GB); memory pressure from second 56; - the card's own memory 6.8 to 6.9 GB of a 7.19 GB budget, and 9.3 to 10.5 GB of shared memory in use (peak 11.1); - frame time, median per minute: 149 to 280 ms (3.5 to 6.7 fps); - the picture is wrong: characters are flat or blocky silhouettes, and textures are missing in blocks on the boat and the shore. A second run with what `machine_settings` sets under 24 GB of RAM (`VICE_TAY_INPLACE=2`, `VICE_TAY_WINDOW_KB=64`, `VICE_TAY_WINDOW_TAILS=1`, no `VICE_TAY_CARD_BUFFERS_MIN_KB`) took 25 to 27 GB of commit at 1.5 to 6.6 fps and lost the device after 274 s (0x887A0005; "when the host device went: the submitting thread was preparing a submission (nothing of ours was running on the card)"). A first try with other programs open (22.6 GB available at the start) had under 1 GB available 67 s in, and my watcher stopped it. `play` refuses Series S on this build, so I did not try it. For comparison: one day earlier this PC ran trustno1-coder/VIctory-NVIDIA v2026.11.29.05 in Series S at 720p at the same place at about 18 fps, with 20 to 22 GB of process commit, 6.6 GB on the card and the right picture. So for an 8 GB card with 32 GB of RAM, Series S was the profile that fit. <details><summary>Four lines of the 7-minute run (seconds 240 and 360)</summary> ``` 2026-11-30T23:04:35.491513Z INFO vice_tay_gpu::copystat: memory, what holds it: 1471 host lists alive; their scratch memory: 199 chunks 140 MB, of them 99 chunks 70 MB spare (73922 taken from the spare ones so far); their other upload buffers: 0 alive 0 MB; windows outside buffers (grid 4096 KiB): 2792 MB of their pages ever copied, 605 shown by descriptor slots 3668 MB, 604 held by lists or the pass over the heap 3660 MB, 488 asked for without a length 2928 MB; buffer views of the heap whose slot showed another copy than the one brought up to date: 197; distinct views kept: 8438 (350 free) 12 MB; our own allocations: 1820 MB in 1296351 blocks (under 4 KiB 199 MB in 1273192, to 64 KiB 269 MB in 20645, to 1 MiB 457 MB in 2415, larger 895 MB in 99) 2026-11-30T23:04:35.491231Z INFO vice_tay_gpu::copystat: memory: 29719 MB private (19727 MB of it in memory; the PC has 2154 MB free and 17803 MB left to commit); host copies of title memory: 4385 alive 6272 MB, of them 611 windows outside buffers 3704 MB; snapshot buffers kept: 152 reserving 7 MB; staging of textures: 172 alive 67 MB, 166 kept by their texture; host textures: 25591 alive 4591 MB, 48931 placed in title memory; made so far: 5013 upload buffers 18709 MB, 1910 shared buffers 15206 MB, 9011 card buffers 1556 MB 2026-11-30T23:06:35.820880Z INFO vice_tay_gpu::copystat: memory, what holds it: 1449 host lists alive; their scratch memory: 179 chunks 124 MB, of them 39 chunks 32 MB spare (112573 taken from the spare ones so far); their other upload buffers: 0 alive 0 MB; windows outside buffers (grid 4096 KiB): 2781 MB of their pages ever copied, 620 shown by descriptor slots 3750 MB, 620 held by lists or the pass over the heap 3750 MB, 495 asked for without a length 2970 MB; buffer views of the heap whose slot showed another copy than the one brought up to date: 313; distinct views kept: 8438 (391 free) 12 MB; our own allocations: 1931 MB in 1315797 blocks (under 4 KiB 202 MB in 1291813, to 64 KiB 270 MB in 21215, to 1 MiB 555 MB in 2671, larger 905 MB in 98) 2026-11-30T23:06:35.820439Z INFO vice_tay_gpu::copystat: memory: 30363 MB private (19119 MB of it in memory; the PC has 2158 MB free and 17075 MB left to commit); host copies of title memory: 4143 alive 6455 MB, of them 625 windows outside buffers 3780 MB; snapshot buffers kept: 175 reserving 18 MB; staging of textures: 153 alive 58 MB, 153 kept by their texture; host textures: 29588 alive 4928 MB, 56415 placed in title memory; made so far: 8158 upload buffers 28131 MB, 2192 shared buffers 17172 MB, 10755 card buffers 1648 MB ``` </details> I can open a separate issue for the memory fit with the issue form, and attach more of the log, if that is more useful than this comment. AI use: Claude Code (Claude Opus 5.5) cloned and built `main`, read the scratch code and set up the run. Claude Fable 5.2 in the Claude app planned the runs, read the logs and drafted this comment. I ran the runs and read this before posting.
einfachama commented 2026-12-01 00:50:00 +00:00 (Migrated from github.com)
Author
Contributor

Imported from TaynanGT/Vice-Tay. Originally posted by einfachama on 2026-12-01T00:50:00Z.


Two things changed on main after my runs, so a correction to my last comment.

  • 6e7e787, the commit I tested, is the merge of #477, which 6855370 has since reverted because the first cutscene lost the device with it. The device loss in my second run (274 s, 0x887A0005) may be that and not the small-RAM switches. I have not rerun without #477. The memory numbers stand as measured, but I cannot say how much of them #477 accounts for.
  • #482 added the Series S build in series-s/, the earlier line as of Nov 27. As I read series-s/crates/victory-gpu/src/host.rs, Spare::give there is the one this issue is about: it hands the chunk back when the kept bytes would pass most. So what I wrote about withdrawing the patch holds for the NVIDIA line only. On the Series S build the jam and the patch should both still apply; I have not built it yet.

#482 lists the boat route on Series S as not covered. That is the place my runs in this issue stand at, and Series S is the profile that fits this PC. I will build series-s/, check that the patch applies there, and run that place with and without it, same save and settings, then post the numbers and the patch against series-s/ here.

AI use: drafted with Claude Fable 5.2 in the Claude app, which read the commits and the file on GitHub. I read it before posting.

<!-- greyfinch-sync:TaynanGT/Vice-Tay:comment:7296792311 --> Imported from [TaynanGT/Vice-Tay](https://github.com/TaynanGT/Vice-Tay/issues/441#issuecomment-7296792311). Originally posted by [einfachama](https://github.com/einfachama) on 2026-12-01T00:50:00Z. --- Two things changed on `main` after my runs, so a correction to my last comment. - `6e7e787`, the commit I tested, is the merge of #477, which `6855370` has since reverted because the first cutscene lost the device with it. The device loss in my second run (274 s, 0x887A0005) may be that and not the small-RAM switches. I have not rerun without #477. The memory numbers stand as measured, but I cannot say how much of them #477 accounts for. - #482 added the Series S build in `series-s/`, the earlier line as of Nov 27. As I read `series-s/crates/victory-gpu/src/host.rs`, `Spare::give` there is the one this issue is about: it hands the chunk back when the kept bytes would pass `most`. So what I wrote about withdrawing the patch holds for the NVIDIA line only. On the Series S build the jam and the patch should both still apply; I have not built it yet. #482 lists the boat route on Series S as not covered. That is the place my runs in this issue stand at, and Series S is the profile that fits this PC. I will build `series-s/`, check that the patch applies there, and run that place with and without it, same save and settings, then post the numbers and the patch against `series-s/` here. AI use: drafted with Claude Fable 5.2 in the Claude app, which read the commits and the file on GitHub. I read it before posting.
Sign in to join this conversation.
No labels
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.

Reference
TaynanGT/Vice-Tay#441
No description provided.