Repository navigation
GPU: grow the write snapshot in place, and cap idle pool memory - #472
SaymonMaster14 wants to merge 1 commit into
Conversation
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 Marvisak#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.
|
Verified Not covered: the snapshot growth and idle-pool cap under a real world frame (no game data here). |
mercuryVM
left a comment
There was a problem hiding this comment.
Tested f200a2a on Windows 11, RTX 5070, MSVC: cargo test --workspace --no-fail-fast passes (264 passed, 0 failed). I could not measure the memory peaks without a game package.
Shadow::writing: the in-place growth is correct.reserve_exactreserves exactly the new span.splice(0..0, host(start, at).iter().copied())uses an exact-size iterator, so the tail moves once. The upper extend starts atold_end. One note on the comment:reserve_exactcan still be a copying realloc when the heap cannot grow the block in place, and for blocks this size that is likely. The peak can still be old + new for that one step. It no longer goes through the pool, though, which is a clear improvement over before.give_back(nit):keptadds every buffer after the largest, including onesretainrejects. Once one oversized buffer is rejected, smaller ones that would fit inPOOL_BYTESare rejected too. Adding only kept buffers (if n <= 8 && kept + cap <= POOL_BYTES { kept += cap; true } else { false }) would match the doc comment.texture.rs: the sharedSCRATCHserialises the detile path of watched textures. Refreshes run in the submission's prepare loop on one thread, so I see no contention today.dstorage.rs: countingintermediate_sizefor zlib+BCPack matches the extra bufferexecuteallocates.
AI-assisted (Claude Code).
…, and cap idle pool memory Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…llision Rename the thread-local SCRATCH buffer in crates/victory-gpu/src/texture.rs to UNWATCHED_SCRATCH so PR Marvisak#143 composes cleanly with PR Marvisak#472's static SCRATCH mutex without an E0428 duplicate-definition error (flagged by @mercuryVM).
|
Companion test-only PR against your 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. |
|
I tried a Series S WARP comparison with 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). |
|
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:
So about 12% shorter frames, mostly copies (−36%) and copy-back (−18%). One run each, and the three were 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. |
…ures, device, DXGI, objects, primitives, capture) Kept from our side: - watch.rs: the per-submission journal (Journal.round, new_round, covered, cover, writes_once) and the WatchKernelUs/WatchGuardUs/WatchPages counters; the guard timing now wraps the PR's by-allocation fallback, and the per-allocation kernel askings (#515) count into WatchKernelUs and WatchPages too. Both sets of watch tests kept. - texture.rs: our version (CommittedRegions, RUNTIME_WRITES and the last.checked skip, changed-subresource detiling, mip drop, widened packed16) with the PR's footprint fix on top: upload footprints end at the last row's data bytes (GetCopyableFootprints row sizes), detiling goes through detile_plane, title_written_flags, overflow-checked committed() and refresh range, and the PR's tests. #143 was already merged; the SCRATCH -> UNWATCHED_SCRATCH rename is left out (no #472 here). - copystat.rs: our counters and lines, plus the PR's process memory line. - primitive.rs: our position+color fast path, plus the PR's zero and overflowing stride guards in the generic path. - #124, #119, device.rs and object.rs changes were already in our tree. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…le pool memory
…le pool memory
…y unchanged pages current) onto Marvisak#346 + Marvisak#334 + integ/next Taken instead of Marvisak#693 (shadow buffers in DEFAULT VRAM with staging readback): both rewrite how shaders' writes reach title memory, on incompatible models (Marvisak#1024 stores from the CPU-mapped host copy; Marvisak#693 has no CPU mapping and merges from readback snapshots), so only one can land. Marvisak#693 has unfixed in-title regressions on its last head's predecessor and no title run since: about 2x slower frames and 5-7x GPU time on an RX 6700 XT (Marvisak#693 (comment)), GPU page faults inside freed `shadow readback/upload staging` on RX 6950 XT and RX 6700 XT (Marvisak#693 (comment)), and a changes-requested review (mercuryVM). Its last commit (1c94839) fixes the review's failure paths but not the performance loss, and was not run in the title. Marvisak#1024 has no negative report; its tests pass on RTX 4090/Wine, RTX 5070 Ti, RX 7700 XT, RTX 5090/Wine, and a title run with it (and Marvisak#472, Marvisak#322) had shorter frames and less copy-back time (AgneyaK). Conflicts, crates/victory-gpu/src/shadow.rs: 1. `Shadow::copy_back`: the stack (Marvisak#124, TG0000) skips pages already found unchanged against this submission's snapshot (`UnchangedPages`) and allocates the title buffer lazily, by PAGE; Marvisak#1024 writes back only the runs of bytes the GPU changed (`write_runs`) and marks a synced page current only if title memory still equals the copy after the final write-watch query. Independent: both kept. The loop keeps the stack's `unchanged.differs` guard and lazy buffer, with Marvisak#1024's run collection and `write_runs` inside; the final check takes the (by then allocated) lazy buffer for its page re-reads. 2. Tests: the stack's `mod tests` and Marvisak#1024's `mod copy_back_tests` at the same place. The shared text holds the closing `);`, `}` and `}`, so the stack's module is closed in the hunk and Marvisak#1024's module follows as its own `#[cfg(test)]` item (not nested). No other non-textual fix needed (cargo check --all-targets --all-features).
|
Automated triage for the maintainers. Needs rebase. This PR does not merge cleanly into current The content has not been reviewed yet; it will be once the branch is rebased onto Generated by Claude Code |
|
Your commit here now conflicts with Measured in Grand Theft Auto VI's world (RTX 5080, Linux): the snapshot pool held 2,040 MB on |
The idle snapshot pool kept the largest buffers up to 2 GiB in all; in the world that was 2.0 GB in 111 blocks, a sixth of the console's memory. It now keeps the largest buffer (the one whose reuse saves the page faults the pool exists for) and others while they add up to 256 MiB, 8 at most. Measured in the world on an RTX 5080: 111-214 MB in 8 blocks. Each texture's staging also kept a buffer the size of its whole texture for good (137 MB in 24 blocks); one shared, already-touched buffer now serves every refresh. zlib then BCPack inflates into a buffer of its own in `execute`; a request's staging count now includes it. From Marvisak/VIctory#472 by SaymonMaster14, rebased as #2153 by desplmfao (GPL-3.0-or-later); the dstorage part was merged there without conflict. Test for the staging count added here.
Adapt the snapshot-pool part of Marvisak#2153 (also Marvisak#472). Do not import the unrelated texture or storage changes. Cap total idle capacity including the largest buffer, preserve the best-fitting allocation path, and limit idle entries to eight. Active snapshot correctness is unchanged. Portable pool regression and Windows all-feature workspace test source checks passed. Co-authored-by: Davi Andrei <67552001+SaymonMaster14@users.noreply.github.com>
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'sdeclared 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_exactfor exactly the growth (the amortized doublingof 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 whatevertheir 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: everyStagingkept aVecof the whole texture for good, so theresident cost was the sum of every texture that had been refreshed. One shared
SCRATCH, kept and already touched, makes it the largest texture instead. Thehash 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 anintermediate 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 GBmachine: 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 — thesereduce 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 peakwent 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.