Shadow: snapshot per 64 KiB piece instead of the full copy (fixes #4520) #4927
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
good first issue
help wanted
input
INTEL
invalid
lighting
linux-proton
memory
needs-info
needs-logs
needs-rebase
NVIDIA
performance
pr-diagnostics
pr-docs
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
rendering
report
series-s
shaders
spam
startup
upstream
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/trustno1-coder--VIctory-NVIDIA!4927
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-4926"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Raesdf on GitHub · 2026-12-01 14:15 UTC · original
Raesdf:fix/snapshot-commit-4520→main· +661 −254 · 2 files · 7 commits · closed without mergingFixes #4521
Problem
Shadow::writingcommitted the snapshot at the full copy length: a 1 MiB declared range on a 256 MiB copy committed ~256 MiB.Fix
Shadow::beforeis now a sparseSnapshot: one 64 KiB buffer per piece a declared range touches; pieces nothing declared are never allocated.copy_back,differing,relay_merge,find_all,merge_under_writes,placed_copy,land_back,copy_back_done) walk piece by piece.POOL,SnapshotPool,pooled,give_back,snapshots_kept,trim_snapshot_pool+ its tests) is removed.memory()keeps its[u64; 6]shape; the last two numbers (pool stats) are now 0.Measurement (test from #4515, cherry-picked)
Before: first range committed +256.8 MiB, second +0.0 MiB.
After: first range committed +1.4 MiB, second +1.0 MiB.
Testing
cargo check -p victory-gpu: clean (only the 11 pre-existingfetch_updatedeprecation warnings).cargo test -p victory-gpu --lib snapshot_tests: 5 passed.cargo test -p victory-gpu --lib: 0 failed.cargo test -p victory-gpu --lib snapshot_commit -- --ignored: 1 passed.VICTORY_KEEP_SNAPSHOTS=1 VICTORY_KEEP_SNAPSHOTS_MB=1 cargo test -p victory-gpu --lib kept_snapshot_growth -- --ignored --test-threads=1: 1 passed.cargo test -p victory-gpu --lib snapshot_tests5 passed, 1 ignored;cargo test -p victory-gpu --lib dropped_pieces -- --ignored --test-threads=11 passed; measurement test first range +0.6 MiB, second +1.0 MiB (first range better than +1.4: the pool reused pieces from the other test in the same run).Overlap
snapshot_commit_per_declared_byte, commit359ef8bd, cherry-picked as4d8a86a0). If #4515 merges first, the cherry-pick can be dropped in a rebase.@gut0to on GitHub · 2026-12-01 14:23 UTC · original · reviewed
AI-assisted review; I used an AI assistant to inspect this diff.
@ -2335,3 +2251,1 @@assert!(pool.critical);assert!(pool.sweep(2_000, false, false).is_empty());assert!(!pool.critical);fn unaligned_range_allocates_only_the_pieces_it_touches() {@gut0to on GitHub · 2026-12-01 14:23 UTC · original
Could this exercise
Shadow::pieceswith aShadowwhose title-memory start is not 64 KiB aligned?touch_rangeindexes offsets from zero, while the production mapping also depends onstart; the current test therefore does not cover the unaligned-start mapping used bywriting,find_all, andland_back. A range crossing an actual title-memory boundary would catch piece-index or offset errors in those paths. AI-assisted review; I used an AI assistant to inspect the diff and trace the piece-offset paths.@gut0to on GitHub · 2026-12-01 14:34 UTC · original · reviewed
AI-assisted review; I used an AI assistant to inspect this diff.
@ -6623,0 +6705,4 @@} else if kept.1 != 0 && kept.1 != bytes {// A later submission added pieces to the kept snapshot.if bytes > kept.1 {KEPT_BYTES.fetch_add(bytes - kept.1, Ordering::Relaxed);@gut0to on GitHub · 2026-12-01 14:34 UTC · original
When a snapshot is already counted, this branch adds newly allocated piece bytes without checking
kept_most(). Since later writes can touch additional pieces,KEPT_BYTEScan exceed the configured global cap (for example, a snapshot admitted at 1 MiB can later grow by hundreds of MiB). Could you apply the cap check to this delta and stop retaining the snapshot if it no longer fits? A regression test could admit a snapshot below the cap, grow it, and assert the total stays within the limit. AI-assisted review; I traced the accounting fromwritingthroughcopy_back_done.@ -6623,0 +6705,4 @@} else if kept.1 != 0 && kept.1 != bytes {// A later submission added pieces to the kept snapshot.if bytes > kept.1 {KEPT_BYTES.fetch_add(bytes - kept.1, Ordering::Relaxed);@tyr0nsur on GitHub · 2026-12-01 14:36 UTC · original
I reproduced this on Windows at
9adc3b86with a CPU-only test ofShadow::writingandcopy_back_done. WithVICTORY_KEEP_SNAPSHOTS=1,VICTORY_KEEP_SNAPSHOTS_MB=1and relay off, I declared 512 KiB on a 2 MiB unbacked copy, completed that submission, then declared the next 1 MiB and completed a second submission.The same focused test fails on the PR head and passes when the growth branch checks the total after charging the delta. On refusal, subtract the entire new snapshot size from
KEPT_BYTESand clearkept.1, so the existing cleanup frees the snapshot. The reservation at that point includes both the old charge and the delta.Claude Opus 5.5 helped review the accounting. The numbers are from the local Rust test.
@ -2335,3 +2251,1 @@assert!(pool.critical);assert!(pool.sweep(2_000, false, false).is_empty());assert!(!pool.critical);fn unaligned_range_allocates_only_the_pieces_it_touches() {@Raesdf on GitHub · 2026-12-01 14:47 UTC · original
Thanks — good catch. The
snapshot_testshelpers did assume an aligned start; the mapping itself was already covered bypiece_tests::pieces_cover_the_copy_as_the_compare_cuts_it(which loops over unaligned starts), but nothing round-tripped bytes through aSnapshotvia the production mapping with an unaligned start. Addedunaligned_start_round_trips_through_the_production_mappingin the latest commit: it usespieces_of/piece_atwith start5 * PIECE + 12345and checks the bytes land at the right offsets and only the touched pieces are allocated.@Raesdf on GitHub · 2026-12-01 14:58 UTC · original
On
crates/victory-gpu/src/shadow.rsline 6708 (outdated):Thanks, both — you're right, and tyr0nsur's repro nails it. The growth branch in
copy_back_donecharged the delta without checking the cap. Fixed in the latest commit: the delta is only charged if the total still fitskept_most(); otherwise the whole reservation for the snapshot is undone (KEPT_BYTES -= bytes),kept.1is cleared, and the existing cleanup drops the snapshot. Addedkept_snapshot_growth_past_the_cap_is_dropped(ignored, needsVICTORY_KEEP_SNAPSHOTS=1 VICTORY_KEEP_SNAPSHOTS_MB=1): it admits 512 KiB on a 2 MiB copy, grows it by 1 MiB, and assertsKEPT_BYTESis 0 afterwards. It fails on the old head (1,572,864 bytes) and passes with the fix.@mstrmoos on GitHub · 2026-12-01 17:39 UTC · original
I tried this in the game on an RTX 5080, and on my scene it costs frame time without saving commit.
Setup. RTX 5080 16 GB, Ryzen 7 9800X3D, 32 GB. Series X, 2560x1440, DLSS Balanced, frame generation off. Standing on a pier for 120 s after a warm-up, about 5,200-5,300 draws a frame. Diagnostics build of my branch (#4836's code). This PR picked cleanly on top. Same session and switches for both runs:
A second build with this PR and #4984 (switched off with
VICTORY_VIEW_START_REMAINDER=0) gave 30.6 ms on the same scene earlier, against 25.9 without either. So it's two runs pointing the same way, though one of each isn't proof. With it on, the submitting thread was also waiting for the card 4.2 ms a frame, against 0.My guess is that walking the snapshot piece by piece costs more on the merge and copy-back paths than the full copy did, and that the full-length snapshots #4521 describes aren't where this scene's commit goes. The
memory()pool numbers are 0 now, so I can't see snapshot bytes directly. If you have a scene where #4521's growth shows, I'd be glad to rerun there. And if there's a cheap way to log the snapshot bytes held, the two runs above would show whether it saves anything here.@Raesdf on GitHub · 2026-12-01 18:25 UTC · original
Thanks for the in-game numbers — that measurement is exactly what I can't do myself (16 GB RAM, RTX 2070).
You're right: on your scene the trade-off is bad, +4.3 ms median with no commit saved. The most likely cost is one I introduced: every piece is a fresh
Box::new([0u8; PIECE])— a 64 KiB zeroed allocation per piece, every submission — because step 3 removed the snapshot pool entirely. On main the snapshot was one uninitialized pooled Vec, reused; my change made it N fresh zeroed boxes a frame with no reuse at all. On a scene whose ranges cover most of a copy, that's pure overhead with almost nothing saved.Latest commit adds two things:
memory()now reports live snapshots (count) and the bytes their pieces hold, in thesnapshotsrows of the memory line — so the two runs can show whether the snapshot bytes actually drop anywhere on your scene.Could you rerun the same pier scene with the new build and report the same table plus the snapshots numbers from the memory line? If the frame time is back near 25.0 ms, the pool was the cost. If it's still ~29 ms, the cost is in the merge/copy-back walking, and the next step is a fast path for snapshots that cover the whole copy — the bytes number will tell us whether there's any saving worth protecting there.
@trustno1-coder on GitHub · 2026-12-01 18:28 UTC · original
Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.
Pull request closed