perf(shadow): lock-free pending check, merge ranged under copied lock, chunk wide_each #1243
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1243"
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?
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by qlfu on 2026-11-28T16:16:01Z.
Summary
Reduces lock acquisitions, cross-thread scheduling overhead, and atomic contention in
crates/victory-gpu/src/shadow.rs:rangedunderShadow::copied(CopiedState):copied: Mutex<Vec<u64>>andranged: Mutex<[(usize, usize, u64); 2]>into a singleMutex<CopiedState>, eliminating the extra lock acquisitions pernothing_new()andcopy_stale()call while preserving the same lock ordering.has_pending: AtomicBoolmirror:Shadow::pendingon read/refresh paths (writes_pending,writes_pending_in,stale_under_writes,merge_under_writes,update,nothing_new,send_copied) in the common case when no shader writes are pending (Releasestore insidependingmutex onwriting/copy_back_done,Acquireload before locking).wide()&wide_each()overhead reduction:Arc<(Mutex<usize>, Condvar)>completion decrement with anAtomicUsizecounter (notifying theCondvaronly whenfetch_sub(1, AcqRel) == 1).n <= 1fast-path (noArc/Box/pool wakeups for 0 or 1 item) and adaptive index chunking (1..=32whenn > max_threads * 4) inwide_each().wide_each_covers_every_index_once_across_chunk_boundariescopied_state_ranged_selects_latest_containing_intervalVerification
cargo clippy -p victory-gpu --all-targets --lockedand--all-features --locked: 0 warnings/errors in modified lines (only pre-existing upstreamshadow.rs:1720turns % 16 == 0present onmain).cargo test -p victory-gpu --lib --locked -- --test-threads=1: 456 passed, 0 failed, 36 ignored.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Bj0rnis on 2026-11-28T17:11:15Z.
Verified
9f53f3aaon RTX 5070 Ti 16 GB (Blackwell, driver621.24) + Ryzen 7 9800X3D, 32 GB RAM, Windows 11 (Rust 1.98.1).Automated checks & code audit
git merge-treevsorigin/main(9ce3cf9): clean.shadow.rs): verified theAtomicUsize+Condvarcompletion gate inwide()acquiresdone.wait.0beforenotify_all()(no lost-wakeup deadlock), and allpendingmutation paths updatehas_pendingwithRelease/Acquireinside thependinglock.cargo test --locked -p victory-gpu --features diagnostics --lib(RTX 5070 Ti): 509 passed, 0 failed, 36 ignored (including both newwide_each_covers_every_index_once_across_chunk_boundariesandcopied_state_ranged_selects_latest_containing_intervaltests).cargo clippy --locked -p victory-gpu --tests: 0 new warnings (only pre-existingshadow.rs:1720manual_is_multiple_of).cargo build --release --locked -p victory: succeeded cleanly.Live gameplay (
--release, Series X,2560×1440, DLSS Quality, FG off, RT off, ~5 min)wide()/wide_each()across intro + heavy indoor room (~10.1k draws).draws >= 3000, warm cache):~5.5kmedian draws): 26.9 fps median (34.2peak); settled break room F3 (10,096draws): 29.5 fps (33.9 ms,longest 36 ms,SUBMIT BUSY 28.3 ms,GPU IDLE BEHIND US 7.6 ms,COPY BACK 5.7 ms).landingmerge median:1.69 ms(vs1.78–1.82 msin earlier non-RT runs on this rig); submit-threadpreparing34.1 ms/refreshes8.8 ms; frame times34.3 msmed /50.2 msp95 /82.7 msp99 (61frames>100 ms). Overall FPS/CPU delta vs earliermainruns was within normal run-to-run variance on a 9800X3D, though pacing felt smooth with noticeably fewer big hitches.Not tested
main9ce3cf9(compared against earlierv2026.11.28.01runs), RT-on (VICTORY_BVH_BUILDER=1), or WARP / lower-core-count CPUs where lock contention may show a larger win. (cargo xtask policyhit the pre-existingbindings.inifailure onmain.)AI-assisted test run and summary.
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-11-28T19:23:02Z.
Thanks for this. I'm closing it without merging because it conflicts with the current main in several places (main has moved a lot since it was opened, with about 100 pull requests merged today), and I can't resolve that safely on your behalf. If you'd still like it in, please rebase it on the current main and open a new pull request.
Pull request closed