perf(gpu): SEH AVX2 word_diff_copy, scoped WC-burst send::take, and fused copy_spans/refresh_front #3395

Open
qlfu wants to merge 4 commits from upstream-pr/3395 into main
qlfu commented 2026-11-29 22:46:12 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by qlfu on 2026-11-29T22:46:12Z.


Summary

Four verified CPU submitting-thread hot-path improvements measured in clean 90s Series X 1440p DLSS Balanced runs (Ryzen 7 5700X + RTX 4070 Ti 12 GB, 0 WARNs / 0 ERRORs):

  1. Single-pass SEH-protected AVX2 victory_safe_word_diff (safecopy.rs, shadow.rs): eliminates the 64 KiB TITLE bounce-buffer double-copy in Shadow::take (watched == 1) with an 8-byte u64 mask scan (emit_word_diff_masks) and zero-alloc word_runs_and_update_into. Includes unit test word_diff_copy_matches_and_recovers_on_fault covering exact partial progress on PAGE_NOACCESS.
  2. Zero-alloc wide_each_scoped combined scatter + copy in send::take + 512 B WC burst scatter (host/send.rs, host.rs): threads join_now = publish from Host::submit -> card_take -> send::take, avoiding redundant copy_beside heap allocations (Box/Arc/Mutex) when the caller joins immediately, and bursts 64 pairs (512 B = 8 WC cache lines) at a time into PCIe BAR under VICTORY_SEND_BAR=1.
  3. Single-pass fused copy_spans + refresh_front + front_complete fast-skip (host.rs): collects front_spans and front_due during the existing copy_spans walk before ask_once, eliminating the duplicate 25k-step traversal and list.deferred() lock acquisitions in refresh_front, and skips Batch::add lookups in run_deferred while front_complete holds.

Measured Results (90s idle-CPU gameplay, Series X 1440p DLSS Balanced, 0 W / 0 E)

Metric Before (233659.log) After (012643.log) Delta
card_mem (mean) 3.33 ms 1.93 ms (002306) -42% (-1.40 ms)
refreshes (mean) 10.87 ms 10.06 ms (002306) -0.81 ms
steps_oth (med) 4.50 ms (002306) 3.75 ms (012643) -17% (-0.75 ms)
prep (med) 27.70 ms 26.15 ms -1.55 ms
Native FPS (mean / max) 26.09 / 41.8 26.39–26.46 / 44.7 (65s 011424: 27.40 med / 28.55 mean / 44.9 max) +0.37 mean / +2.9 max

Verification

  • git merge-tree --write-tree origin/main pr/perf-safecopy-scoped-send-fused-front: exit 0
  • cargo +1.98.1-x86_64-pc-windows-msvc test -p victory-gpu --lib --locked -- word_diff_copy --test-threads=1: pass
  • cargo +1.98.1-x86_64-pc-windows-msvc xtask policy --staged: pass
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5555968746 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3395). Originally posted by [qlfu](https://github.com/qlfu) on 2026-11-29T22:46:12Z. --- ## Summary Four verified CPU submitting-thread hot-path improvements measured in clean 90s Series X 1440p DLSS Balanced runs (Ryzen 7 5700X + RTX 4070 Ti 12 GB, `0 WARNs / 0 ERRORs`): 1. **Single-pass SEH-protected AVX2 `victory_safe_word_diff` (`safecopy.rs`, `shadow.rs`)**: eliminates the 64 KiB `TITLE` bounce-buffer double-copy in `Shadow::take` (`watched == 1`) with an 8-byte `u64` mask scan (`emit_word_diff_masks`) and zero-alloc `word_runs_and_update_into`. Includes unit test `word_diff_copy_matches_and_recovers_on_fault` covering exact partial progress on `PAGE_NOACCESS`. 2. **Zero-alloc `wide_each_scoped` combined scatter + copy in `send::take` + 512 B WC burst scatter (`host/send.rs`, `host.rs`)**: threads `join_now = publish` from `Host::submit` -> `card_take` -> `send::take`, avoiding redundant `copy_beside` heap allocations (`Box`/`Arc`/`Mutex`) when the caller joins immediately, and bursts 64 pairs (512 B = 8 WC cache lines) at a time into PCIe BAR under `VICTORY_SEND_BAR=1`. 3. **Single-pass fused `copy_spans` + `refresh_front` + `front_complete` fast-skip (`host.rs`)**: collects `front_spans` and `front_due` during the existing `copy_spans` walk before `ask_once`, eliminating the duplicate 25k-step traversal and `list.deferred()` lock acquisitions in `refresh_front`, and skips `Batch::add` lookups in `run_deferred` while `front_complete` holds. ## Measured Results (90s idle-CPU gameplay, Series X 1440p DLSS Balanced, `0 W / 0 E`) | Metric | Before (`233659.log`) | After (`012643.log`) | Delta | |---|---:|---:|---:| | `card_mem` (mean) | `3.33 ms` | `1.93 ms` (`002306`) | **-42% (-1.40 ms)** | | `refreshes` (mean) | `10.87 ms` | `10.06 ms` (`002306`) | **-0.81 ms** | | `steps_oth` (med) | `4.50 ms` (`002306`) | `3.75 ms` (`012643`) | **-17% (-0.75 ms)** | | `prep` (med) | `27.70 ms` | `26.15 ms` | **-1.55 ms** | | Native FPS (mean / max) | `26.09 / 41.8` | `26.39–26.46 / 44.7` (65s `011424`: `27.40 med / 28.55 mean / 44.9 max`) | **+0.37 mean / +2.9 max** | ## Verification - `git merge-tree --write-tree origin/main pr/perf-safecopy-scoped-send-fused-front`: exit `0` - `cargo +1.98.1-x86_64-pc-windows-msvc test -p victory-gpu --lib --locked -- word_diff_copy --test-threads=1`: pass - `cargo +1.98.1-x86_64-pc-windows-msvc xtask policy --staged`: pass
qlfu commented 2026-11-30 00:12:39 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by qlfu on 2026-11-30T00:12:39Z.


Rebased cleanly onto main (41adb551), combining send::take with upstream #2509 (parallel_copy_work) while preserving the BAR 64 KiB parallel threshold and join_now, keeping upstream #2530's self.changed_runs(...) in shadow.rs, and guarding front_spans_into / Touch::Part for zero new warnings. Verified safecopy::tests::word_diff_copy, host::send::tests::, and --features diagnostics.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7265064637 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3395#issuecomment-7265064637). Originally posted by [qlfu](https://github.com/qlfu) on 2026-11-30T00:12:39Z. --- Rebased cleanly onto `main` (`41adb551`), combining `send::take` with upstream `#2509` (`parallel_copy_work`) while preserving the BAR 64 KiB parallel threshold and `join_now`, keeping upstream `#2530`'s `self.changed_runs(...)` in `shadow.rs`, and guarding `front_spans_into` / `Touch::Part` for zero new warnings. Verified `safecopy::tests::word_diff_copy`, `host::send::tests::`, and `--features diagnostics`.
DoubleD17 commented 2026-11-30 01:01:39 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by DoubleD17 on 2026-11-30T01:01:39Z.


We ran a test of this PR on an 8-core Zen 3: picture fine, but slower on this machine.

Setup:

  • Ryzen 7 5800X (8 cores), RTX 5070 12 GB, 64 GB RAM, Windows 11;
  • Series X, 1440p, DLSS Performance, frame generation and ray tracing off;
  • this PR merged locally onto main 41adb551 (the merge only adds this PR's own commits), against 41adb551 itself;
  • a warm-up run per build, then 150 s runs alternating base / PR, two rounds;
  • every run starts from the same save, restored before each run;
  • figures are medians of the 5 s host lines.

We also ran a picture check: a burst of 10 captures a second at the end of each run, looked at frame by frame.

preparing refresh fps (mean) one-frame defects
base 41adb551 62.7 / 62.1 ms 21.2 / 20.9 ms 13.4 / 13.7 0 / 0 of 80
this PR 66.4 / 68.0 ms 22.2 / 23.2 ms 12.9 / 12.6 0 / 0 of 80
  • About +5 ms of preparing a frame (+7 %) and -6 % fps on this machine. Refresh time is slightly up rather than down.
  • Picture unchanged: no defects in either run.

The gain in the description was measured with prep around 27 ms. Here the submitting thread is at about 62 ms, bound elsewhere, so the AVX2 path may simply not be where this machine spends its time. If one of the three parts has a switch, we can split them.

AI Assisted

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7265778361 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3395#issuecomment-7265778361). Originally posted by [DoubleD17](https://github.com/DoubleD17) on 2026-11-30T01:01:39Z. --- We ran a test of this PR on an 8-core Zen 3: picture fine, but slower on this machine. **Setup:** - Ryzen 7 5800X (8 cores), RTX 5070 12 GB, 64 GB RAM, Windows 11; - Series X, 1440p, DLSS Performance, frame generation and ray tracing off; - this PR merged locally onto main 41adb551 (the merge only adds this PR's own commits), against 41adb551 itself; - a warm-up run per build, then 150 s runs alternating base / PR, two rounds; - every run starts from the same save, restored before each run; - figures are medians of the 5 s host lines. We also ran a picture check: a burst of 10 captures a second at the end of each run, looked at frame by frame. | | preparing | refresh | fps (mean) | one-frame defects | |---|---|---|---|---| | base 41adb551 | 62.7 / 62.1 ms | 21.2 / 20.9 ms | 13.4 / 13.7 | 0 / 0 of 80 | | this PR | 66.4 / 68.0 ms | 22.2 / 23.2 ms | 12.9 / 12.6 | 0 / 0 of 80 | - **About +5 ms of preparing a frame (+7 %) and -6 % fps** on this machine. Refresh time is slightly up rather than down. - **Picture unchanged:** no defects in either run. The gain in the description was measured with prep around 27 ms. Here the submitting thread is at about 62 ms, bound elsewhere, so the AVX2 path may simply not be where this machine spends its time. If one of the three parts has a switch, we can split them. AI Assisted
qlfu commented 2026-11-30 10:35:56 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by qlfu on 2026-11-30T10:35:56Z.


@DoubleD17 Thanks a ton for testing this on stock 41adb551 — your telemetry nailed two real regressions on stock defaults that were masked in our stacked testing:

  1. Single-slot wide_each_scoped contention in host/send.rs: send::take was switched from crate::land::each_under (dedicated victory-under pool) to crate::shadow::wide_each_scoped. On stock 41adb551, wide_each_scoped has a single q.scoped slot and falls back inline whenever another thread (such as refresh_front) is already in a scoped pass — serializing send::take on the submitting/sending path. Restored crate::land::each_under for both parallel copy+scatter and scatter-only paths.
  2. Single-threaded shadow.nothing_new walk in host.rs::refresh_front when VICTORY_FRONT_SIFT=0 (stock default): During the rebase onto 41adb551, the default front_sift == false branch fell back to a single-threaded spans.retain(|...| !shadow.nothing_new(...)) loop over ~5,200 spans per frame (taking JOURNAL.read() per span) instead of checking nothing_new_with(&self.ahead_snap, ...) inline in parallel inside the single wide_each_scoped refresh dispatch. Restored the lock-free ahead_snap + parallel inline sift (check_inline).
  3. Also 4×-unrolled victory_safe_word_diff (128 B/iter with one combined vpcmpeqd/vpand fast path + exact SEH fallback to the 32 B tail on mid-128B page faults, covered by an added shifted-page fault test in word_diff_copy_matches_and_recovers_on_fault).

Pushed in the latest commit — if you have a chance to re-test on stock 41adb551, both preparing and refreshes should now be cleanly faster than baseline.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7275820548 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3395#issuecomment-7275820548). Originally posted by [qlfu](https://github.com/qlfu) on 2026-11-30T10:35:56Z. --- @DoubleD17 Thanks a ton for testing this on stock `41adb551` — your telemetry nailed two real regressions on stock defaults that were masked in our stacked testing: 1. **Single-slot `wide_each_scoped` contention in `host/send.rs`:** `send::take` was switched from `crate::land::each_under` (dedicated `victory-under` pool) to `crate::shadow::wide_each_scoped`. On stock `41adb551`, `wide_each_scoped` has a single `q.scoped` slot and falls back inline whenever another thread (such as `refresh_front`) is already in a scoped pass — serializing `send::take` on the submitting/sending path. Restored `crate::land::each_under` for both parallel copy+scatter and scatter-only paths. 2. **Single-threaded `shadow.nothing_new` walk in `host.rs::refresh_front` when `VICTORY_FRONT_SIFT=0` (stock default):** During the rebase onto `41adb551`, the default `front_sift == false` branch fell back to a single-threaded `spans.retain(|...| !shadow.nothing_new(...))` loop over ~5,200 spans per frame (taking `JOURNAL.read()` per span) instead of checking `nothing_new_with(&self.ahead_snap, ...)` inline in parallel inside the single `wide_each_scoped` refresh dispatch. Restored the lock-free `ahead_snap` + parallel inline sift (`check_inline`). 3. Also 4×-unrolled `victory_safe_word_diff` (128 B/iter with one combined `vpcmpeqd`/`vpand` fast path + exact SEH fallback to the 32 B tail on mid-128B page faults, covered by an added shifted-page fault test in `word_diff_copy_matches_and_recovers_on_fault`). Pushed in the latest commit — if you have a chance to re-test on stock `41adb551`, both `preparing` and `refreshes` should now be cleanly faster than baseline.
qlfu commented 2026-11-30 15:05:20 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by qlfu on 2026-11-30T15:05:20Z.


Skipped populating Batch::ahead HashMap (~5,400 inserts/frame) in refresh_front when self.front_complete is true, since Step::Refresh skips batch.add while front_complete holds and title_written clears self.ahead. Verified: cargo check -p victory-gpu --all-targets --all-features --locked + host::tests (91 passed, 0 failed) + clean merge-tree onto 41adb551.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7282410400 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3395#issuecomment-7282410400). Originally posted by [qlfu](https://github.com/qlfu) on 2026-11-30T15:05:20Z. --- Skipped populating `Batch::ahead` HashMap (~5,400 inserts/frame) in `refresh_front` when `self.front_complete` is true, since `Step::Refresh` skips `batch.add` while `front_complete` holds and `title_written` clears `self.ahead`. Verified: `cargo check -p victory-gpu --all-targets --all-features --locked` + `host::tests` (91 passed, 0 failed) + clean `merge-tree` onto `41adb551`.
trustno1-coder commented 2026-12-01 18:52:45 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by trustno1-coder on 2026-12-01T18:52:45Z.


Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7321728615 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3395#issuecomment-7321728615). Originally posted by [trustno1-coder](https://github.com/trustno1-coder) on 2026-12-01T18:52:45Z. --- Closing this as part of moving main to the texture and video-memory rework (v2026.12.01.01-test). A lot of the code changed, and this pull request no longer applies cleanly to it; it would need to be rewritten against the new main rather than rebased. Thank you for the work. If the change is still needed, please open a new pull request based on the current main.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/3395:upstream-pr/3395'
git switch 'upstream-pr/3395'

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.

git switch 'main'
git merge --no-ff 'upstream-pr/3395'
git switch 'upstream-pr/3395'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3395'
git switch 'upstream-pr/3395'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3395'
git switch 'main'
git merge --squash 'upstream-pr/3395'
git switch 'main'
git merge --ff-only 'upstream-pr/3395'
git switch 'main'
git merge 'upstream-pr/3395'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

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