GPU: pool and recycle shadow::exact() buffers with GPU quarantine (#346) #451
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Belobug--VIctory-Belobug-AMD!451
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-451"
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?
@BE29ZZ on GitHub · 2026-11-27 02:27 UTC · original
BE29ZZ:feat/issue-346-exact-buffer-pool→a-publier· +642 −50 · 2 files · 1 commits · openAddresses #346 (item 1: \shadow::exact()\ lock-free allocation + quarantined recycled buffer pool), independently confirmed in #368.
Problem
In \crates/victory-gpu/src/shadow.rs, \shadow::exact()\ held a single global \Mutex\ across lookups, ran an \O(N)\ \map.retain(...)\ sweep on every miss once \map.len() >= 256, and called \host()?.shared_buffer(...)\ (\CreateCommittedResource) while holding the mutex. Under heavy ring-buffer turnover (#346 reported ~716 misses/frame), list threads serialized on D3D12 buffer creation and constantly created/destroyed committed buffers.
What changed
ow_frame >= last_frame + 2, \Arc::strong_count == 1, and \host::references == 1.
esidency::limited_host_ram()\ is set, else 320 MiB; configurable via \VICTORY_EXACT_POOL_MB=\ (\ disables pooling while keeping shared read locks and out-of-lock allocation).
esidency::pressured()\ or \RamBand::High).
Relation to #443
#443 also moves \exact()\ allocation out of its lock (and covers \loose()\ / \xmem::change()), without buffer pooling. This PR focuses strictly on \shadow::exact()\ and combines shared read locks + out-of-lock allocation with the power-of-two GPU-quarantined recycling pool described in #346.
Verification (Windows 11 x64, NVIDIA GeForce RTX 3060, Rust 1.98.1)
Credit to @ToolxMaster (#346) for profiling, designing, and measuring the quarantined pool, and to @Miquella135 (#368) for independently validating it.
Not tested in the title itself (no game files on this machine); ready for in-game validation.
AI-assisted; no game data.
@MamaLeVrai on GitHub · 2026-11-27 03:55 UTC · original
Tested on an RX 6950 XT (RDNA 2), driver 32.0.21045.29003, Windows 11 build 26300, Rust 1.98.1, release. At
d03efab:cargo test --release -p victory-gpu --lib402 passed, 0 failed, 34 ignored.AI-assisted (Claude Code); no game data.
@adrianmjim on GitHub · 2026-11-27 06:50 UTC · original
Tested on RX 7900 XT (RDNA3), driver 32.0.32029.2010, Windows 11 26300, Rust 1.98.1. Head
d03efabvs base a-publier4eb6cfd. Release and debug builds.cargo test -p victory-gpu --lib, release, 3 runs each, base and head interleaved: base 396/0/34 and head 402/0/34 on every run.--test-threads=1: base 396/0/34, head 402/0/34.shadow::filter, 10 runs each side: base 35/0 and head 41/0 on all 10 runs.views_off_their_elements_get_a_copy_of_their_bytespassed 10/10 on both base and head.exact_recycles_quarantined_gpu_buffer_and_zeroes_stale_bytes10/10,exact_concurrent_misses_return_the_same_shadow_and_pool_losers10/10.shadow::exact_testswith 1 thread: 10/10.VICTORY_EXACT_POOL_MB=0, the views test passed 3/3. Theshadow::exact_testsset their own pool limit, so this variable reachesexact()only through that test.Reading notes:
VICTORY_EXACT_POOL_MB=0does not restore base behaviour for an A/B.exact_bucketrounding still applies, so a view just over 64 KiB commits 128 KiB, and 33 MiB commits 64 MiB.host::retireinstead of being dropped.ExactClock::now()at the start ofexact(), before the write lock and the reference checks.host::retiresamples it when called. A submission begun in that window that reaches the buffer only through a descriptor is covered only by the 2-frame wait.OWN_MADE(the "copies made" count in the frame line) now counts new allocations only, not buffers taken from the pool. The shared-buffer bytes in the memory line now count bucket sizes.Not tested: in the title; memory use or map size under load; timing.
@pr0vId3nce on GitHub · 2026-11-27 07:23 UTC · original
A data point for this approach from NVIDIA. An RTX 4080 has 32-lane waves and no raw descriptor twins, so every off-element view goes through
shadow::exact(). On avatarmanz main, pooling the own-bytes copies and making them outside the lock took Series X from 276 to 142 ms a frame, with the picture unchanged. The patch and numbers are here: https://github.com/avatarmanz/VIctory-7900XTX/issues/221#issuecomment-7200700579Two pieces we added on top of plain pooling:
🤖 Generated with Claude Code
@Robotniq on GitHub · 2026-11-27 10:14 UTC · original
Tested in the title on an 8 GB NVIDIA card: RTX 3070 Ti (8 GB, 32-lane waves, no raw twins, driver 32.0.16.2140), i7-13700F, 32 GB RAM, Windows 11 26200. Diagnostics builds on
a-publier4eb6cfd,--console series-s, thescripts\play.ps1settings (not-Safe),VICTORY_PORT_CONSTANTS/DESCRIPTORS/CBV/GUARD/JOURNAL=1,VICTORY_D3D12_DRED=faults,VICTORY_UPSCALER=6, ray tracing off. Same save, four to seven minutes in the prologue's first area per run, warm pipeline library.What was compared: #443 alone against this PR with #443's
looseandxmemhunks on top (itsexacthunks left out, since the two rewrite the same function). So the difference between the two columns is this PR'sexactagainst #443's.Frame rate by draws a frame (median of the frame lines in each band):
loose/xmem)List calls (
VICTORY_THIN, median over the frame lines at 20,000 calls or more): 14.2 µs a call with #443, 4.9 µs with this PR.The frame line with this PR: about 1,770 asked for a frame, 0.0 new + 261 recycled copies a frame, 4,100-4,750 kept, up to 1,560 quarantined, 135-175 MiB pooled. With #443 it read about 500 copies made a frame and 5,200 kept. The card went from about 70% busy to about 91% by the card's clock line, so it is the limit again here.
No device loss and nothing in
crashes.login three runs with the PR (about 15 minutes in the world). Private memory about 24 GB in both.On the picture: the person playing thought there were slightly more black patches with the PR, then fewer in a later, slower run of the same build. I could not settle it:
VICTORY_CAPTURE_WORLDruns of the two builds do not line up (the save opens in a cutscene and the slower build is at an earlier shot at the same frame count), and the share of near-black pixels over about 100 captured world frames each was no higher with the PR. So no regression shown, and none ruled out.AI-assisted (Claude Code): the runs, the reading of the logs and this text.
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.