GPU: grow the write snapshot in place, and cap idle pool memory #472

Open
github-bot wants to merge 1 commit from github-bot/gh-472 into main AGit
Owner

@⁠SaymonMaster14 on GitHub · 2026-11-24 03:49 UTC · original
SaymonMaster14:memory/peak-during-world-load → main · +53 −22 · 3 files · 1 commits · open

Four leaks in the copy bridge, found while measuring #471. Each one is small on
its own; together they cost the peak exactly where commit is tight.

shadow.rs, Shadow::writing: the snapshot grown to span a submission's
declared ranges allocated a second buffer of the new size, copied the old
into it and only then returned the old to the pool. At the largest growth that
holds both, and the world's heap is 174 MB — the peak doubles there. It is now
grown in place: reserve_exact for exactly the growth (the amortized doubling
of a buffer this size would double the capacity, and a copying realloc its
peak), then extend on either side.

shadow.rs, give_back: the pool kept its eight largest buffers whatever
their size, so one world load left eight 174 MB snapshots — about 1.4 GB idle,
never shrunk. The largest is now always kept (its reuse is what saves the
millions of page faults the 64 KiB pages were chosen for) and further buffers
only while they add up to 256 MiB, still at most eight.

texture.rs: every Staging kept a Vec of the whole texture for good, so the
resident cost was the sum of every texture that had been refreshed. One shared
SCRATCH, kept and already touched, makes it the largest texture instead. The
hash path does not use the buffer (it hashes the mapping directly), and the
staging mapping is written only at submission, so the lock costs nothing there.

dstorage.rs, staging_bytes: a zlib-then-BCPack request inflates into an
intermediate buffer that counted against no limit. It now counts against the
32 MiB staging cap, so the cap bounds what is really held. Requests of that
shape serialize more when one is large; no throughput was measured either way.

What is in it: those four, and nothing else. No interface change.

Tested: cargo build --release -p victory, cargo test -p victory-gpu -p victory-hle — 130 passed, 1 ignored, 0 failed. Live, release, world load, 16 GB
machine: the process reached 18.0 GB private and died at memory allocation of 70426816 bytes failed, system commit 48.8 GB of 49.0 GB. It still dies — these
reduce the slope, they do not remove the ceiling.

Not tested: the headroom case. The earlier runs measured the page file, not
PrivateMemorySize64, and there are no per-component counters, so "the peak
went down" cannot be claimed from the two side by side; #471 has the samples
and the counters that would settle it. Also unmeasured: whether the 256 MiB cap
is the right number (it keeps ~1.5 world heap snapshots; 192 MiB or 384 MiB are
as arguable), and the DStorage serialization cost.

Not a #407 fix. This is bridge work, which #407 proposes to delete. It holds
until stage 2 there — xmem asking a GPU-visible arena first — replaces the
copies. Worth merging only as the stopgap it is.

Fixes #471.


AI use: Claude (Sonnet 5.5) in a Maestri terminal drove the code reading, the
edits, the build and the test run; the memory sampling and the reproduction
were set up outside it.

**@⁠SaymonMaster14** on GitHub · 2026-11-24 03:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/472) `SaymonMaster14:memory/peak-during-world-load` → `main` · +53 −22 · 3 files · 1 commits · open Four leaks in the copy bridge, found while measuring #471. Each one is small on its own; together they cost the peak exactly where commit is tight. `shadow.rs`, `Shadow::writing`: the snapshot grown to span a submission's declared ranges allocated a **second** buffer of the new size, copied the old into it and only then returned the old to the pool. At the largest growth that holds both, and the world's heap is 174 MB — the peak doubles there. It is now grown in place: `reserve_exact` for exactly the growth (the amortized doubling of a buffer this size would double the capacity, and a copying realloc its peak), then extend on either side. `shadow.rs`, `give_back`: the pool kept its eight largest buffers whatever their size, so one world load left eight 174 MB snapshots — about 1.4 GB idle, never shrunk. The largest is now always kept (its reuse is what saves the millions of page faults the 64 KiB pages were chosen for) and further buffers only while they add up to 256 MiB, still at most eight. `texture.rs`: every `Staging` kept a `Vec` of the whole texture for good, so the resident cost was the sum of every texture that had been refreshed. One shared `SCRATCH`, kept and already touched, makes it the largest texture instead. The hash path does not use the buffer (it hashes the mapping directly), and the staging mapping is written only at submission, so the lock costs nothing there. `dstorage.rs`, `staging_bytes`: a zlib-then-BCPack request inflates into an intermediate buffer that counted against no limit. It now counts against the 32 MiB staging cap, so the cap bounds what is really held. Requests of that shape serialize more when one is large; no throughput was measured either way. **What is in it:** those four, and nothing else. No interface change. **Tested:** `cargo build --release -p victory`, `cargo test -p victory-gpu -p victory-hle` — 130 passed, 1 ignored, 0 failed. Live, release, world load, 16 GB machine: the process reached 18.0 GB private and died at `memory allocation of 70426816 bytes failed`, system commit 48.8 GB of 49.0 GB. It still dies — these reduce the slope, they do not remove the ceiling. **Not tested:** the headroom case. The earlier runs measured the page file, not `PrivateMemorySize64`, and there are no per-component counters, so "the peak went down" cannot be claimed from the two side by side; #471 has the samples and the counters that would settle it. Also unmeasured: whether the 256 MiB cap is the right number (it keeps ~1.5 world heap snapshots; 192 MiB or 384 MiB are as arguable), and the DStorage serialization cost. **Not a #407 fix.** This is bridge work, which #407 proposes to delete. It holds until stage 2 there — xmem asking a GPU-visible arena first — replaces the copies. Worth merging only as the stopgap it is. Fixes #471. --- AI use: Claude (Sonnet 5.5) in a Maestri terminal drove the code reading, the edits, the build and the test run; the memory sampling and the reproduction were set up outside it.
The snapshot `Shadow::writing` keeps, to tell later what a submission's shaders
wrote, is grown to span every range the submission declares. Growing it
allocated a second buffer of the new size, copied the old one in, and only then
returned it to the pool: at the largest growth that holds twice the buffer, and
the world's heap is 174 MB, so the peak doubles right where commit is already
tight.

Grow the old buffer in place instead (`reserve_exact` for exactly the growth,
then extend on either side). The pool that feeds the snapshot kept its eight
largest buffers whatever their size, so after the world had grown once it could
hold eight 174 MB buffers, about 1.4 GB idle. Keep the largest (its reuse is
what saves the millions of page faults the 64 KiB pages were chosen for) and
further buffers only up to 256 MiB.

Measured on a 16 GB machine, world load, release build: the process reached
18.0 GB private and died at `memory allocation of 70426816 bytes failed` with
the system commit at 48.8 GB of a 49.0 GB limit. It is not a fix for that
limit, and not comparable to earlier runs (those measured the page file, not
`PrivateMemorySize64`) — the counters to compare it against do not exist yet.

Refs #407: this is bridge work, which that issue proposes to delete. It stays
valid until stage 2 there (xmem asks a GPU-visible arena first) replaces the
copies.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:05:10 +00:00
Author
Owner

@⁠DaviTostes on GitHub · 2026-11-24 03:51 UTC · original

Verified f200a2a on Arch Linux x86_64, Windows MSVC release build under Wine 11.22 (victory-gpu, --test-threads=1): 43 passed, 0 failed, 1 ignored (same count as main, no new test in this head).

Not covered: the snapshot growth and idle-pool cap under a real world frame (no game data here).

**@⁠DaviTostes** on GitHub · 2026-11-24 03:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/472#issuecomment-7121481845) Verified `f200a2a` on **Arch Linux x86_64**, Windows MSVC release build under **Wine 11.22** (`victory-gpu`, `--test-threads=1`): **43 passed, 0 failed, 1 ignored** (same count as `main`, no new test in this head). Not covered: the snapshot growth and idle-pool cap under a real world frame (no game data here).
Author
Owner

@⁠erickbobd on GitHub · 2026-11-24 13:08 UTC · original

Companion test-only PR against your memory/peak-during-world-load branch: SaymonMaster14/VIctory#1, based exactly on f200a2a.

Two synthetic tests cover snapshot byte preservation/allocation reuse with spare capacity and intermediate DStorage staging for file and memory inputs. On the pure parent plus these tests: 46 victory-gpu passed / 1 ignored; 87 victory-hle passed, serial. Replacing each function with its real pre-#472 version makes its test fail; restoring both passes the full suites again. Asset policy: 151 files OK.

Tested on RTX 5070 Ti / NVIDIA 617.14, Windows 11 26200.9974, Rust 1.98.1 / MSVC x64. This verifies the regression fixtures, not live-game memory savings. AI-assisted (Codex); synthetic inputs only.

**@⁠erickbobd** on GitHub · 2026-11-24 13:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/472#issuecomment-7132398444) Companion test-only PR against your `memory/peak-during-world-load` branch: [SaymonMaster14/VIctory#1](https://github.com/SaymonMaster14/VIctory/pull/1), based exactly on `f200a2a`. Two synthetic tests cover snapshot byte preservation/allocation reuse with spare capacity and intermediate DStorage staging for file and memory inputs. On the pure parent plus these tests: **46 victory-gpu passed / 1 ignored; 87 victory-hle passed**, serial. Replacing each function with its real pre-#472 version makes its test fail; restoring both passes the full suites again. Asset policy: 151 files OK. Tested on RTX 5070 Ti / NVIDIA 617.14, Windows 11 26200.9974, Rust 1.98.1 / MSVC x64. This verifies the regression fixtures, not live-game memory savings. AI-assisted (Codex); synthetic inputs only.
Author
Owner

@⁠BaggyALPHA on GitHub · 2026-11-24 15:42 UTC · original

I tried a Series S WARP comparison with f200a2a applied on top of the PresentX fix from #211 and the diagnostics from #484 and #602. For the patched build I adjusted the local #602 probe to read the new shared texture scratch buffer. Both runs used copies of the same profile, separate caches, and the same commit guard.

The fresh control stopped at its time limit before opening the story archive. The patched run opened it, then reached the commit guard before a confirmed world frame. An earlier run of the same control binary and profile did open the story archive. Against that earlier control, private commit differed by less than 1% at archive open and at the 10- and 20-second marks after it. The sampled idle snapshot capacity stayed zero, and the cached upload peak was the same in those two runs.

This is a comparison of early loading only. It does not establish whether the patch lowers peak commit during world rendering or whether the snapshot-pool cap was exercised. Neither run logged an out-of-memory error or device removal before stopping.

AI-assisted testing and write-up (OpenAI Codex).

**@⁠BaggyALPHA** on GitHub · 2026-11-24 15:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/472#issuecomment-7136476686) I tried a Series S WARP comparison with `f200a2a` applied on top of the PresentX fix from #211 and the diagnostics from #484 and #602. For the patched build I adjusted the local #602 probe to read the new shared texture scratch buffer. Both runs used copies of the same profile, separate caches, and the same commit guard. The fresh control stopped at its time limit before opening the story archive. The patched run opened it, then reached the commit guard before a confirmed world frame. An earlier run of the same control binary and profile did open the story archive. Against that earlier control, private commit differed by less than 1% at archive open and at the 10- and 20-second marks after it. The sampled idle snapshot capacity stayed zero, and the cached upload peak was the same in those two runs. This is a comparison of early loading only. It does not establish whether the patch lowers peak commit during world rendering or whether the snapshot-pool cap was exercised. Neither run logged an out-of-memory error or device removal before stopping. AI-assisted testing and write-up (OpenAI Codex).
Author
Owner

@⁠AgneyaK on GitHub · 2026-11-24 16:37 UTC · original

Test report on an RTX 3050 6 GB Laptop (i7-13700H, 16 GB RAM, Windows 11 26300), diag build, title 1.0.2.1, Series X profile. Base tree: main ffe310e + #208 + #223 #233 #320 #439 + #452 + #579 (VICTORY_SKIP_WAVE64=mesh), from #1232. #472, #322 and #1024 merge cleanly onto it.

tree world frames frame preparing copies textures GPU copying back
base 35 4,641 ms 2,915 943 242 931 741
+ #472 + #322 + #1024 60 4,101 ms 2,615 607 180 836 604

So about 12% shorter frames, mostly copies (−36%) and copy-back (−18%). One run each, and the three were
not separated.

On this 16 GB machine much of the rest looks like paging: private bytes reach 22.9 GB and the working set is trimmed to 2-5 GB (numbers in #1232).

AI use: Claude Code (Claude Opus 5.5) merged and built the trees, ran the title on my machine and drafted this note; results are from the runs described.

**@⁠AgneyaK** on GitHub · 2026-11-24 16:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/472#issuecomment-7137945086) Test report on an RTX 3050 6 GB Laptop (i7-13700H, 16 GB RAM, Windows 11 26300), diag build, title 1.0.2.1, Series X profile. Base tree: `main` `ffe310e` + #208 + #223 #233 #320 #439 + #452 + #579 (`VICTORY_SKIP_WAVE64=mesh`), from #1232. #472, #322 and #1024 merge cleanly onto it. | tree | world frames | frame | preparing | copies | textures | GPU | copying back | |---|---|---|---|---|---|---|---| | base | 35 | 4,641 ms | 2,915 | 943 | 242 | 931 | 741 | | + #472 + #322 + #1024 | 60 | **4,101 ms** | 2,615 | **607** | 180 | 836 | **604** | So about 12% shorter frames, mostly copies (−36%) and copy-back (−18%). One run each, and the three were not separated. On this 16 GB machine much of the rest looks like paging: private bytes reach 22.9 GB and the working set is trimmed to 2-5 GB (numbers in #1232). AI use: Claude Code (Claude Opus 5.5) merged and built the trees, ran the title on my machine and drafted this note; results are from the runs described.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 00:20 UTC · original

Automated triage for the maintainers.

Needs rebase. This PR does not merge cleanly into current main (ac2525d). Conflicting files: crates/victory-gpu/src/shadow.rs, crates/victory-gpu/src/texture.rs.

The content has not been reviewed yet; it will be once the branch is rebased onto main.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 00:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/472#issuecomment-7148399789) <!-- victory-triage v1 head=f200a2a101e2a61999a8a9f46117231f7fcde71a verdict=needs-rebase at=2026-11-25T00:13:20Z --> Automated triage for the maintainers. **Needs rebase.** This PR does not merge cleanly into current `main` (ac2525d). Conflicting files: `crates/victory-gpu/src/shadow.rs`, `crates/victory-gpu/src/texture.rs`. The content has not been reviewed yet; it will be once the branch is rebased onto `main`. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠desplmfao on GitHub · 2026-11-25 06:21 UTC · original

Your commit here now conflicts with main, so I opened #2153 with it brought up to date. Your commit is kept with you as author, and only the conflicts are resolved. The details are in #2153: main has since split the snapshot into segments, so the in-place growth part no longer applies, but the pool cap and the shared SCRATCH carry over unchanged.

Measured in Grand Theft Auto VI's world (RTX 5080, Linux): the snapshot pool held 2,040 MB on main and 111–214 MB with your change, with no change in frame time. If you rebase this PR yourself, I'll close #2153.

**@⁠desplmfao** on GitHub · 2026-11-25 06:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/472#issuecomment-7154707688) Your commit here now conflicts with `main`, so I opened #2153 with it brought up to date. Your commit is kept with you as author, and only the conflicts are resolved. The details are in #2153: `main` has since split the snapshot into segments, so the in-place growth part no longer applies, but the pool cap and the shared `SCRATCH` carry over unchanged. Measured in Grand Theft Auto VI's world (RTX 5080, Linux): the snapshot pool held 2,040 MB on `main` and 111–214 MB with your change, with no change in frame time. If you rebase this PR yourself, I'll close #2153.
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/shadow.rs
  • crates/victory-gpu/src/texture.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/472/head:github-bot/gh-472'
git switch 'github-bot/gh-472'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-472'
git switch 'github-bot/gh-472'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-472'
git switch 'github-bot/gh-472'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-472'
git switch 'main'
git merge --squash 'github-bot/gh-472'
git switch 'main'
git merge --ff-only 'github-bot/gh-472'
git switch 'main'
git merge 'github-bot/gh-472'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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/Marvisak--VIctory!472
No description provided.