GPU: add opt-in LRU eviction for unreferenced shadow buffer copies (VICTORY_SHADOW_BUDGET_MB) #3457
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!3457
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3457"
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?
@Luislariosss on GitHub · 2026-11-27 03:26 UTC · original
Luislariosss:feat/shadow-budget-evict→main· +296 −2 · 3 files · 2 commits · openSummary
Adds opt-in LRU eviction (
VICTORY_SHADOW_BUDGET_MB, off by default) for large unreferencedShadowbuffer copies inshadow::BUFFERS:Shadowwith a monotoniclast_usedsequence on creation and on everyshadow::find()hit.Host::execute, right besideresource::evict_unused(), after the previous submission has finished),shadow::evict_unused()evicts least-recently-used buffer copies when total live shadow bytes exceedVICTORY_SHADOW_BUDGET_MB.Arc::strong_count == 1and emptypending/beforewriteback state — guaranteeing no active command list, descriptor heap slot, or pending GPU writeback is ever disturbed.changed()somemory.rspage tables refresh on next use, and drops all evictedArc<Shadow>s outsideBUFFERS.lock().Validation
cargo test -p victory-gpu --lib shadow::: all shadow tests passed (including newshadow_budget_evicts_lru_unreferenced_copies_and_keeps_held_ones).cargo clippy -p victory-gpu --all-targets -- -D warnings(default and--features diagnostics): clean.cargo xtask policy: 191 files ok.@Luislariosss on GitHub · 2026-11-27 03:37 UTC · original
Live verification of the 11-PR stack with this PR merged (60 s release runs, Windows 11, AMD RX 9060 XT 16 GB, 32 GB RAM, same cache and boot; every run reached frame 1024 with 0 errors):
VICTORY_SHADOW_BUDGET_MB=256VICTORY_SHADOW_BUDGET_MB=1024main.shadow::tests: 12/12 pass post-merge on the integration branch (the new eviction test plus the pre-existing loose-window suite).@oni-swr on GitHub · 2026-11-27 04:10 UTC · original
WARP test report for #3457 (AI-assisted (Claude), claimed on #1633 comment 7209455899; I did not repeat the RX 9060 XT live numbers above)
VICTORY_WARP=1 VICTORY_D3D12_WARP=1), rustc 1.98.1 / cargo 1.98.1, Windows SDK 10.0.26100dxil.dllviaVICTORY_DXIL,cargo test -j 4 -p <crate> --lib --locked -- --test-threads=1. No GPU hardware used. No game files involved.63bcca43c6a00a758510398fa43096ce7e4f7df0; head6b442f527447b9b4e1f320be020a51f08a294340. The head already contains this main, so the merge is a fast-forward and the tested tree equals the head.victory-gpulib: main 231 passed / 0 failed / 1 ignored -> head 232 passed / 0 failed / 1 ignored. The extra test isshadow::tests::shadow_budget_evicts_lru_unreferenced_copies_and_keeps_held_ones. I confirmed it really ran on the WARP host (it does not take its "no host GPU" early return): it evicts the unreferenced copy and keeps the one a caller still holds. No regressions.VICTORY_SHADOW_BUDGET_MBunset (or0/garbage)evict_unused()returns before touching any map, so the only default-path cost is oneAtomicU64stamp perfind().Arc::strong_count == 1, emptypendingand emptybefore, so a copy held by an in-flight command list, descriptor or snapshot is skipped, and the drop happens after theBUFFERSlock is released. That looks right, provided every in-flight user keeps anArc<Shadow>rather than only a raw address; the author should confirm this.cfg!(test)forces the budget toNone, so the once-per-frame throttle inevict_unused()and the env parsing path are not exercised by tests. The new test callsevict_unused_with_budget(0), which evicts every unreferenced shadow in the process-global map, so it could disturb other shadow tests if run in parallel (I ran--test-threads=1).@Luislariosss on GitHub · 2026-11-27 04:22 UTC · original
Follow-up to the WARP report: an independent audit found one blocking gap this PR's tests did not cover. Bytes shaders write through a heap's unordered access views never go back to title memory (bindless
refresh's shortcut): once the slots viewing a copy were all rebound, its refcount could drop to one, the budget pass could evict it, andfind()would rebuild it from stale title memory, silently losing the GPU's bytes. Fixed ina070759:Shadow::uav_ranges: added with the first range, removed with the last or when the heap goes); the eviction pass skips copies with any, and re-checks before the take.VICTORY_SHADOW_BUDGET_MBthat does not parse warns once instead of silently turning off.Verified: 12/12
shadow::, 233/233victory-gpu --lib, clippy-D warningsclean; 60 s and 300 s live runs with the knob at 256 MiB show 0 errors (the 300 s run reaches the 3D world).View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.