perf(gpu): parallel nested refresh fan-out, lock-free scoped_active bitmask, and lock-free ahead epoch walk #3108
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3108"
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-29T20:03:29Z.
Summary
Reduces CPU time in buffer refreshes (
Batch::refresh_front,Batch::flush_all,Shadow::copy_stale,Shadow::take_landed) and watch-epoch lookups:wide_each_scoped(MAX_SCOPED_SLOTS = 16) with lock-freescoped_active: AtomicU16bitmask andscoped_waiters: AtomicUsize: supports nested parallel fan-out (e.g.Shadow::take_allinsiderefresh_front) with zero per-chunk global atomic writes, zero helper exit mutex locks whenscoped_waiters == 0, single exit lock on the fast path, and respectswait_spin()(VICTORY_WAIT_SPIN).AheadSnapshot+EpochLeafSeqLockprev_and_mask+ahead_walk_epochs+ahead_all_within+OWNED_NONEMPTY): allowsShadow::copy_stale_from_aheadto walk page write epochs and sub-page masks without takingJOURNALper buffer.Arcrefresh_front+partition_large_first+Batch::update_wide+copy_mapped_plain: eliminates per-spanArccloning inrefresh_front, places large refreshes first to eliminate tail stragglers, skipscopy_mappedwatched-range checks whenwatched == 1, and optimizesShadow::take_landed(self.landingreset, 16 KiBnotedchunks, unsplit!noted, batchedcard_changed_runs/ECHO).Verification
cargo +1.98.1-x86_64-pc-windows-msvc clippy -p victory-gpu --lib --tests --no-deps --locked: 0 new warnings.cargo +1.98.1-x86_64-pc-windows-msvc test -p victory-gpu --lib --locked -- --test-threads=1(watch::,shadow::,host::,wide_each_scoped):346/346passed.0 WARNs / 0 ERRORs):refreshesmedian/mean:12.20 / 12.43 ms->11.30 / 11.38 ms(Native),11.85 -> 10.70 ms(FG v1 -> v2).Submit: all:36.35 ms->29.35 ms(-7.00 ms,-19.3%), GPU busy81% -> 97%.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by qlfu on 2026-11-30T00:12:46Z.
Rebased cleanly onto
main(41adb551), dropping hunks already landed in#2530/#2604/#2971while preservingahead_all_within,copy_stale_from_ahead,wide_each_scoped, and theGUARDEDstate preservation fix. Verifiedwatch::tests::(41 passed) and--features diagnostics.Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by upipibi on 2026-11-30T04:58:50Z.
Test report for #3108 (head
9df1a472), merged onto main41adb551, on RTX 30. Synthetic tests only: no title run, no game files, so nothing here measures the frame-time gain.Setup: RTX 3070 8 GB, driver 621.40, Ryzen 9 5950X (16 cores), Windows 11 (10.0.26100), rustc 1.98.1.
The new test
watch::epoch_meta_tests::epoch_leaf_meta_matches_journal_parts_since: ok.Negative control: in
PageEpochs::set_with_parts, the same-epoch branch storespartsin place ofold_mask | parts(a write forgets the parts written before it in the same epoch). The test fails atwatch.rs:7245:page=100 taken=1 prev=0, left 32770, right 33287. So it does check the lock-free leaf against the journal for the same-epoch merge.Stability against main, since this is concurrency code. Each tree ran in turn, on the card:
41adb551cargo test -p victory-gpu --lib --locked, 5 runs... -- watch:: shadow::, 10 runsFailures by test, over the 5 suite runs:
shader_cache::tests::every_switch_of_the_translator_is_in_the_keyhost::card_steps::tests::places_written_after_sending_are_learnedhost::uav_pool::tests::host_list_uav_pool_lifecycle_retire_trim_and_info_queueSo the PR adds no failing test and none of main's three gets more frequent with it; the first fails on main every time (
VICTORY_SCALAR_SPLITS is not read by the translator any more), the other two come and go on both trees. No run hung, and thewatch::andshadow::tests, which cover the files this PR changes most, never failed in 20 runs.Not tested: the refresh fan-out under a title's load (the unit tests do not drive
wide_each_scopedwith nested callers at scale), and timing.Tested with the help of Claude Code (Claude Fable 5.2).
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by DoubleD17 on 2026-11-30T07:58:16Z.
We ran a test of this PR on current main (
41adb551with this PR merged), on a CPU-bound machine.We compare only the seconds where the idle camera shows the same lighter views (about 7,500 draws a frame). Its heavier view (about 15,000 draws, half the frame rate) takes 10 to 60 s of each 150 s run, and it moved whole-run means by several ms.
No difference we can measure. The five main runs of the session agreed within 1.3 ms on these seconds. But we also ran main again, built in another folder, eight times: it ranged from 57.5 to 65.5 ms. Its first four runs were 2.4 ms slower than main on average, and the last four 4.2 ms faster. All nine PRs we tested in this session came out 0.4 to 3.9 ms slower than main, and fps moved with it. So we read the difference as a newly built executable, not as this PR.
Picture: in round 1, one frame (of 160) had the island trees and the potted plants missing. They were back in the next frame. We now see it on main too (1 frame in 3,160 tonight, against 7 in 4,240 on PR builds), so it is not this PR alone; it looks like the one-frame gap in #1165.
Setup:
41adb551(only its own commits on top), against41adb551itself;Picture check: a burst of 10 captures a second at the end of each run (80 frames), looked at frame by frame.
AI Assisted
Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by POMXARK on 2026-11-30T10:39:58Z.
Hi @qlfu — sharing two orthogonal
git am-ready patches rebased ontov2026.11.29.05(41adb55) in #3556 (https://github.com/trustno1-coder/VIctory-NVIDIA/discussions/3556#discussioncomment-20023964) that pair cleanly with your parallel refresh & watch-epoch work:xmem.rs(VICTORY_LOW_PRIVATE_WATCH): moves the185 MiB32-bit graphics reservation offSEC_RESERVEMEM_MAPPEDontoMEM_PRIVATE | MEM_WRITE_WATCH(-86.6%VirtualProtect,-71.3%VEH,-43.7%GUARDSlock wait).watch.rs(VICTORY_WIDE_WATCH): parallelizesask_ahead/ask_onceGetWriteWatchruns viawide_each_scoped.Not opening separate PRs — feel free to reuse or adapt directly.
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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.