perf(gpu): scope title write invalidations, trim submit steps, and speed up texture refresh #3109

Open
qlfu wants to merge 1 commit from upstream-pr/3109 into main
qlfu commented 2026-11-29 20:03:31 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by qlfu on 2026-11-29T20:03:31Z.


Summary

Cuts CPU overhead in per-submission step execution (steps_oth, HostList::run_deferred, HostList::prelude) and texture refresh checks:

  • Scoped Batch::invalidate_written: evicts only ahead and textures entries overlapping [dst, dst + len) (and physical-page alias blocks via watch::wrote_and_elsewhere / elsewhere_blocks) instead of clearing the entire ahead/textures maps on every Step::Copy / Step::Placed.
  • Step::Host split from Step::Run: host-only bookkeeping callbacks no longer flush batch.fill(), invalidate ahead/textures, or terminate ask_once. Also measures Step::Copy/Step::Placed timing after batch.fill()/batch.flush() so batched fill/flush work is not double-counted in SPLIT[7] (copies_fills).
  • Submit & prelude trims: Taken::has_list, batched port::bounds_snapshot / note_filled_batch, lazy air & place::forwards gated on any_placed, cached HostList::cmd_list, lock trims in HostList::prelude (has_detiles, has_twins, alias_rt::on()), fused refresh_front walk, Batch::last_ahead 1-entry cache.
  • Lock-free texture refresh & AVX2 digest: lock-free PreludeUpload::finish_refresh (uploaded && !dirty), Staging::watch_kind + lock-free watch::guarded_clean_since (PageEpochs::all_at_most), all_there checked under _mapped, and AVX2 128-byte-stripe texture::digest.

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 (texture::, host::, watch::): 288/288 passed.
  • Live 90s benchmarks on Series X title (1440p DLSS Balanced, 0 WARNs / 0 ERRORs):
    • steps_oth: 7.35 -> 4.40 ms (-2.95 ms/frame, -40.1%, Native) / 6.50 -> 4.75 ms (FG).
    • copies_fills: 3.85 -> 2.75 ms (-1.10 ms/frame, -28.6%).
    • texture refreshes (all threads): 11.4 -> 8.5 ms (-25.4%), tex_ask: 1.9 -> 0.2 ms (-89.5%), flush_one: 248–268 -> 3–9 (-97%).
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5554574189 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3109). Originally posted by [qlfu](https://github.com/qlfu) on 2026-11-29T20:03:31Z. --- ## Summary Cuts CPU overhead in per-submission step execution (`steps_oth`, `HostList::run_deferred`, `HostList::prelude`) and texture refresh checks: - **Scoped `Batch::invalidate_written`**: evicts only `ahead` and `textures` entries overlapping `[dst, dst + len)` (and physical-page alias blocks via `watch::wrote_and_elsewhere` / `elsewhere_blocks`) instead of clearing the entire `ahead`/`textures` maps on every `Step::Copy` / `Step::Placed`. - **`Step::Host` split from `Step::Run`**: host-only bookkeeping callbacks no longer flush `batch.fill()`, invalidate `ahead`/`textures`, or terminate `ask_once`. Also measures `Step::Copy`/`Step::Placed` timing after `batch.fill()`/`batch.flush()` so batched fill/flush work is not double-counted in `SPLIT[7]` (`copies_fills`). - **Submit & prelude trims**: `Taken::has_list`, batched `port::bounds_snapshot` / `note_filled_batch`, lazy `air` & `place::forwards` gated on `any_placed`, cached `HostList::cmd_list`, lock trims in `HostList::prelude` (`has_detiles`, `has_twins`, `alias_rt::on()`), fused `refresh_front` walk, `Batch::last_ahead` 1-entry cache. - **Lock-free texture refresh & AVX2 digest**: lock-free `PreludeUpload::finish_refresh` (`uploaded && !dirty`), `Staging::watch_kind` + lock-free `watch::guarded_clean_since` (`PageEpochs::all_at_most`), `all_there` checked under `_mapped`, and AVX2 128-byte-stripe `texture::digest`. ## 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` (`texture::`, `host::`, `watch::`): `288/288` passed. - Live 90s benchmarks on Series X title (1440p DLSS Balanced, `0 WARNs / 0 ERRORs`): - `steps_oth`: `7.35 -> 4.40 ms` (`-2.95 ms/frame`, `-40.1%`, Native) / `6.50 -> 4.75 ms` (FG). - `copies_fills`: `3.85 -> 2.75 ms` (`-1.10 ms/frame`, `-28.6%`). - `texture refreshes (all threads)`: `11.4 -> 8.5 ms` (`-25.4%`), `tex_ask`: `1.9 -> 0.2 ms` (`-89.5%`), `flush_one`: `248–268 -> 3–9` (`-97%`).
qlfu commented 2026-11-30 00:12:42 +00:00 (Migrated from github.com)

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


Rebased cleanly onto main (41adb551), integrating upstream #2795 (watch::writes_since) with watch_kind caching + guarded_clean_since in texture.rs, and keeping #2604's lock-free !is_kept() fast path in watch::wrote / wrote_and_elsewhere. Verified watch::tests:: (41 passed) and --features diagnostics.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7265065391 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3109#issuecomment-7265065391). Originally posted by [qlfu](https://github.com/qlfu) on 2026-11-30T00:12:42Z. --- Rebased cleanly onto `main` (`41adb551`), integrating upstream `#2795` (`watch::writes_since`) with `watch_kind` caching + `guarded_clean_since` in `texture.rs`, and keeping `#2604`'s lock-free `!is_kept()` fast path in `watch::wrote` / `wrote_and_elsewhere`. Verified `watch::tests::` (41 passed) and `--features diagnostics`.
DoubleD17 commented 2026-11-30 07:58:18 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by DoubleD17 on 2026-11-30T07:58:18Z.


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 63.2 60.6 14.0 14.3
round 2 60.8 60.2 14.8 15.2
mean difference +1.6 ms −2.4 %

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: 0 defects in 160 frames.

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

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7272334598 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/3109#issuecomment-7272334598). Originally posted by [DoubleD17](https://github.com/DoubleD17) on 2026-11-30T07:58:18Z. --- 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 | 63.2 | 60.6 | 14.0 | 14.3 | | round 2 | 60.8 | 60.2 | 14.8 | 15.2 | | **mean difference** | **+1.6 ms** | | **−2.4 %** | | 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:** 0 defects in 160 frames. **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
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/3109:upstream-pr/3109'
git switch 'upstream-pr/3109'

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/3109'
git switch 'upstream-pr/3109'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/3109'
git switch 'upstream-pr/3109'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/3109'
git switch 'main'
git merge --squash 'upstream-pr/3109'
git switch 'main'
git merge --ff-only 'upstream-pr/3109'
git switch 'main'
git merge 'upstream-pr/3109'
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!3109
No description provided.