perf(gpu): parallel nested refresh fan-out, lock-free scoped_active bitmask, and lock-free ahead epoch walk #3108

Closed
github-bot wants to merge 2 commits from github-bot/gh-3108 into main AGit
Owner

@⁠qlfu on GitHub · 2026-11-29 20:03 UTC · original
qlfu:pr/perf-parallel-refresh-and-lockfree-watch → main · +884 −192 · 4 files · 2 commits · closed without merging

Summary

Reduces CPU time in buffer refreshes (Batch::refresh_front, Batch::flush_all, Shadow::copy_stale, Shadow::take_landed) and watch-epoch lookups:

  • Multi-slot wide_each_scoped (MAX_SCOPED_SLOTS = 16) with lock-free scoped_active: AtomicU16 bitmask and scoped_waiters: AtomicUsize: supports nested parallel fan-out (e.g. Shadow::take_all inside refresh_front) with zero per-chunk global atomic writes, zero helper exit mutex locks when scoped_waiters == 0, single exit lock on the fast path, and respects wait_spin() (VICTORY_WAIT_SPIN).
  • Lock-free ahead epoch walk (AheadSnapshot + EpochLeaf SeqLock prev_and_mask + ahead_walk_epochs + ahead_all_within + OWNED_NONEMPTY): allows Shadow::copy_stale_from_ahead to walk page write epochs and sub-page masks without taking JOURNAL per buffer.
  • Zero-Arc refresh_front + partition_large_first + Batch::update_wide + copy_mapped_plain: eliminates per-span Arc cloning in refresh_front, places large refreshes first to eliminate tail stragglers, skips copy_mapped watched-range checks when watched == 1, and optimizes Shadow::take_landed (self.landing reset, 16 KiB noted chunks, unsplit !noted, batched card_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/346 passed.
  • Live 90s benchmarks on Series X title (1440p DLSS Balanced, 0 WARNs / 0 ERRORs):
    • refreshes median/mean: 12.20 / 12.43 ms -> 11.30 / 11.38 ms (Native), 11.85 -> 10.70 ms (FG v1 -> v2).
    • Combined stack Submit: all: 36.35 ms -> 29.35 ms (-7.00 ms, -19.3%), GPU busy 81% -> 97%.
**@⁠qlfu** on GitHub · 2026-11-29 20:03 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3108) `qlfu:pr/perf-parallel-refresh-and-lockfree-watch` → `main` · +884 −192 · 4 files · 2 commits · closed without merging ## Summary Reduces CPU time in buffer refreshes (`Batch::refresh_front`, `Batch::flush_all`, `Shadow::copy_stale`, `Shadow::take_landed`) and watch-epoch lookups: - **Multi-slot `wide_each_scoped` (`MAX_SCOPED_SLOTS = 16`) with lock-free `scoped_active: AtomicU16` bitmask and `scoped_waiters: AtomicUsize`**: supports nested parallel fan-out (e.g. `Shadow::take_all` inside `refresh_front`) with zero per-chunk global atomic writes, zero helper exit mutex locks when `scoped_waiters == 0`, single exit lock on the fast path, and respects `wait_spin()` (`VICTORY_WAIT_SPIN`). - **Lock-free ahead epoch walk (`AheadSnapshot` + `EpochLeaf` SeqLock `prev_and_mask` + `ahead_walk_epochs` + `ahead_all_within` + `OWNED_NONEMPTY`)**: allows `Shadow::copy_stale_from_ahead` to walk page write epochs and sub-page masks without taking `JOURNAL` per buffer. - **Zero-`Arc` `refresh_front` + `partition_large_first` + `Batch::update_wide` + `copy_mapped_plain`**: eliminates per-span `Arc` cloning in `refresh_front`, places large refreshes first to eliminate tail stragglers, skips `copy_mapped` watched-range checks when `watched == 1`, and optimizes `Shadow::take_landed` (`self.landing` reset, 16 KiB `noted` chunks, unsplit `!noted`, batched `card_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/346` passed. - Live 90s benchmarks on Series X title (1440p DLSS Balanced, `0 WARNs / 0 ERRORs`): - `refreshes` median/mean: `12.20 / 12.43 ms` -> **`11.30 / 11.38 ms`** (Native), `11.85 -> 10.70 ms` (FG v1 -> v2). - Combined stack `Submit: all`: `36.35 ms` -> **`29.35 ms` (`-7.00 ms`, `-19.3%`)**, GPU busy `81% -> 97%`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-29 20:06:54 +00:00
github-bot force-pushed github-bot/gh-3108 from 3cf315e253 to 9df1a472cd 2026-11-30 00:17:28 +00:00 Compare
Author
Owner

@⁠qlfu on GitHub · 2026-11-30 00:12 UTC · original

Rebased cleanly onto main (41adb551), dropping hunks already landed in #2530/#2604/#2971 while preserving ahead_all_within, copy_stale_from_ahead, wide_each_scoped, and the GUARDED state preservation fix. Verified watch::tests:: (41 passed) and --features diagnostics.

**@⁠qlfu** on GitHub · 2026-11-30 00:12 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3108#issuecomment-7265066158) Rebased cleanly onto `main` (`41adb551`), dropping hunks already landed in `#2530`/`#2604`/`#2971` while preserving `ahead_all_within`, `copy_stale_from_ahead`, `wide_each_scoped`, and the `GUARDED` state preservation fix. Verified `watch::tests::` (41 passed) and `--features diagnostics`.
Author
Owner

@⁠upipibi on GitHub · 2026-11-30 04:58 UTC · original

Test report for #3108 (head 9df1a472), merged onto main 41adb551, 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 stores parts in place of old_mask | parts (a write forgets the parts written before it in the same epoch). The test fails at watch.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:

Run PR Main 41adb551
cargo test -p victory-gpu --lib --locked, 5 runs 922 passed/1 failed twice, 921/2 three times 921/1 twice, 920/2 twice, 919/3 once
... -- watch:: shadow::, 10 runs 138 passed, 0 failed, 10/10 137 passed, 0 failed, 10/10

Failures by test, over the 5 suite runs:

Test PR Main
shader_cache::tests::every_switch_of_the_translator_is_in_the_key 5 5
host::card_steps::tests::places_written_after_sending_are_learned 2 2
host::uav_pool::tests::host_list_uav_pool_lifecycle_retire_trim_and_info_queue 1 2

So 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 the watch:: and shadow:: 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_scoped with nested callers at scale), and timing.

Tested with the help of Claude Code (Claude Fable 5.2).

**@⁠upipibi** on GitHub · 2026-11-30 04:58 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3108#issuecomment-7269249629) Test report for #3108 (head 9df1a472), merged onto main 41adb551, 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 stores `parts` in place of `old_mask | parts` (a write forgets the parts written before it in the same epoch). The test **fails** at `watch.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: | Run | PR | Main 41adb551 | |---|---|---| | `cargo test -p victory-gpu --lib --locked`, 5 runs | 922 passed/1 failed twice, 921/2 three times | 921/1 twice, 920/2 twice, 919/3 once | | `... -- watch:: shadow::`, 10 runs | 138 passed, 0 failed, 10/10 | 137 passed, 0 failed, 10/10 | Failures by test, over the 5 suite runs: | Test | PR | Main | |---|---|---| | `shader_cache::tests::every_switch_of_the_translator_is_in_the_key` | 5 | 5 | | `host::card_steps::tests::places_written_after_sending_are_learned` | 2 | 2 | | `host::uav_pool::tests::host_list_uav_pool_lifecycle_retire_trim_and_info_queue` | 1 | 2 | So 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 the `watch::` and `shadow::` 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_scoped` with nested callers at scale), and timing. *Tested with the help of Claude Code (Claude Fable 5.2).*
Author
Owner

@⁠DoubleD17 on GitHub · 2026-11-30 07:58 UTC · original · edited 2026-11-30 09:56 UTC

We ran a test of this PR on current main (41adb551 with 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.

CPU prep (ms/frame) main at that point fps main at that point
round 1 62.7 60.4 14.5 14.3
round 2 60.8 60.3 14.8 15.2
mean difference +1.4 ms −0.6 %

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:

  • Ryzen 7 5800X (8 cores, 16 threads), RTX 5070 12 GB (DXGI budget 11,175 MB), 64 GB RAM, Windows 11;
  • Series X, 1440p with DLAA (DLSS at native resolution; corrected, this line said DLSS Performance at first), frame generation and ray tracing off;
  • the PR merged locally onto main 41adb551 (only its own commits on top), against 41adb551 itself;
  • a warm-up run per build, then 150 s runs in two rounds (the second in reverse order), with five main runs spread through the session;
  • every run starts from the same save, restored before each run;
  • CPU prep is the median of the submitting thread's 5 s lines, fps the median of the host's 5 s lines, on the light-view seconds after the first 20 s; each run is compared with main's runs interpolated in time.

Picture check: a burst of 10 captures a second at the end of each run (80 frames), looked at frame by frame.

AI Assisted

**@⁠DoubleD17** on GitHub · 2026-11-30 07:58 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3108#issuecomment-7272333808) · edited 2026-11-30 09:56 UTC We ran a test of this PR on current main (41adb551 with 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. | | CPU prep (ms/frame) | main at that point | fps | main at that point | |---|---|---|---|---| | round 1 | 62.7 | 60.4 | 14.5 | 14.3 | | round 2 | 60.8 | 60.3 | 14.8 | 15.2 | | **mean difference** | **+1.4 ms** | | **−0.6 %** | | 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:** - Ryzen 7 5800X (8 cores, 16 threads), RTX 5070 12 GB (DXGI budget 11,175 MB), 64 GB RAM, Windows 11; - Series X, 1440p with DLAA (DLSS at native resolution; corrected, this line said DLSS Performance at first), frame generation and ray tracing off; - the PR merged locally onto main 41adb551 (only its own commits on top), against 41adb551 itself; - a warm-up run per build, then 150 s runs in two rounds (the second in reverse order), with five main runs spread through the session; - every run starts from the same save, restored before each run; - CPU prep is the median of the submitting thread's 5 s lines, fps the median of the host's 5 s lines, on the light-view seconds after the first 20 s; each run is compared with main's runs interpolated in time. Picture check: a burst of 10 captures a second at the end of each run (80 frames), looked at frame by frame. AI Assisted
Author
Owner

@⁠POMXARK on GitHub · 2026-11-30 10:39 UTC · original

Hi @⁠qlfu — sharing two orthogonal git am-ready patches rebased onto v2026.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:

  1. xmem.rs (VICTORY_LOW_PRIVATE_WATCH): moves the 185 MiB 32-bit graphics reservation off SEC_RESERVE MEM_MAPPED onto MEM_PRIVATE | MEM_WRITE_WATCH (-86.6% VirtualProtect, -71.3% VEH, -43.7% GUARDS lock wait).
  2. watch.rs (VICTORY_WIDE_WATCH): parallelizes ask_ahead / ask_once GetWriteWatch runs via wide_each_scoped.

Not opening separate PRs — feel free to reuse or adapt directly.

**@⁠POMXARK** on GitHub · 2026-11-30 10:39 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3108#issuecomment-7275910859) Hi @⁠qlfu — sharing two orthogonal `git am`-ready patches rebased onto `v2026.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: 1. **`xmem.rs` (`VICTORY_LOW_PRIVATE_WATCH`):** moves the `185 MiB` 32-bit graphics reservation off `SEC_RESERVE` `MEM_MAPPED` onto `MEM_PRIVATE | MEM_WRITE_WATCH` (`-86.6%` `VirtualProtect`, `-71.3%` VEH, `-43.7%` `GUARDS` lock wait). 2. **`watch.rs` (`VICTORY_WIDE_WATCH`):** parallelizes `ask_ahead` / `ask_once` `GetWriteWatch` runs via `wide_each_scoped`. Not opening separate PRs — feel free to reuse or adapt directly.
github-bot closed this pull request 2026-12-01 18:59:04 +00:00

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/trustno1-coder--VIctory-NVIDIA!3108
No description provided.