gpu: sparse copy_stale fast-path, Batch/card_steps hot caches, RT reserve settle-decay, and depth-plane twin UAV barrier #2049

Open
Rixnei wants to merge 4 commits from upstream-pr/2049 into main
Rixnei commented 2026-11-29 08:28:14 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Rixnei on 2026-11-29T08:28:14Z.


What it changes

Four focused, self-contained improvements to victory-gpu (split into 4 atomic commits) from profiling 1440p Series X gameplay on a 12 GB NVIDIA GPU:

  1. Sparse O(written.len()) fast-path in Shadow::copy_stale when ranged > 0 (shadow.rs)

    • When ranged > 0, every page in [from, to) already has taken >= ranged > 0, so taken == 0 is impossible and only pages present in the sorted written slice can satisfy write > taken.
    • Extracted Shadow::collect_stale_runs so ranged > 0 iterates only over written instead of walking 16k–131k pages of multi-hundred-MB buffers on every refresh, and skips take_all when runs is empty.
    • Added unit test collect_stale_runs_sparse_ranged_matches_dense_scan verifying bit-for-bit identical (runs, again_at, copied_pages) against the dense scan (including partial edge pages, adjacent/gapped dirty runs, stale vs. fresh entries, and empty written).
  2. 1-entry hot caches in Batch::add and card_steps span coalescing (host.rs, host/card_steps.rs)

    • Batch::copy_spans already relies on consecutive Step::Refresh entries hitting the same shadow copy; Batch::add and card_steps span coalescing still probed ByCopy hash maps on every step.
    • Added last_add / last_ahead 1-entry caches to Batch (invalidated on give_back, flush_one, flush, title_written, refresh_front, refresh_ahead) and last_span to card_steps.
  3. Settle-decay for peak-based render-target VRAM reserve (resource.rs)

    • targets_kept_from_peak previously ignored still_ms and settle, permanently keeping ~700–970 MiB reserved at 1440p (peak / 2) even after render targets stopped growing, causing "no room" texture upload stalls on 12 GB GPUs.
    • Once render targets stop growing by 64 MiB for settle ms (default 20 s), caps the peak-based reserve to 128 MiB (targets >= 1 GiB) or 256 MiB (>= 256 MiB), returning ~730 MiB to textures while immediately restoring the full reserve if targets grow by 64 MiB again (settle == 0 keeps the previous uncapped behavior).
    • Expanded room_for_targets_follows_their_peak unit test to cover pre-settle, settled 1440p decay, and settle == 0.
  4. Mirror UAV barriers onto twin_plane_resource (list.rs)

    • barrier() mirrored title UAV barriers (kind == 2) onto twin_resource(b.first) (the stencil/colour twin) but did not emit a matching UAV barrier on twin_plane_resource(b.first) (the separate depth-plane twin on depth-stencil formats).
    • Now emits the matching UAV barrier on twin_plane_resource when present so compute writes to a depth-plane twin are synchronized across explicit UAV barriers.
    • (Note for #1541 / depth-twin work: we also tested running mid-list pass_plane on SRV/copy/clear reads, which dropped PLANES[2] to 0, but caused distant-object flickering because u.behind[0] is shared between twin.colour and twin.plane while record_twin_copy does not copy depth back to twin.plane (PLANES[1]), causing stencil-only UAV writes to overwrite live depth with stale twin.plane data. That change is intentionally omitted from this PR.)

How it was tested

  • GPU and profile: RTX 5070 12 GB, Ryzen 7 9800X3D, 32 GB RAM, Windows 11; Series X profile, 1440p, DLSS Quality, tested in both Native and DLSS Frame Generation 2x, ray tracing off (ambient stand-in on).
  • Before (baseline logs on RTX 5070 12 GB, 1440p DLSS Quality + FG 2x):
    • Peak-based RT reserve stayed ~860 MiB throughout steady 1440p gameplay, leaving textures frequently hitting no room stalls.
    • Submitting-thread refresh pass: median frametime 45.5 ms, 17.5% of frames >50 ms, GPU idle behind submitting thread 5.30 ms/frame.
  • After (measured in live 1440p gameplay logs):
    • Settled 1440p RT reserve drops 860 MiB -> 128 MiB (+732 MiB VRAM reclaimed for textures once targets stabilize).
    • With the sparse copy_stale fast-path + Batch::add hot caches: median frametime improved 45.5 ms -> 42.8 ms (+6.3% base FPS, ~2x under FG), frames >50 ms dropped nearly in half (17.5% -> 9.1%), and GPU idle behind CPU dropped 5.30 ms -> 4.40 ms (-17%).
    • Depth-plane twin UAV barriers clean with zero visual regressions or distant-object flickering.
  • For shader changes, the wave sizes tested: N/A (no shader changes).
  • cargo test passed for the crates it touches: yes (cargo test -p victory-gpu --locked -- --test-threads=1: 590 passed, 0 failed; cargo check -p victory-gpu --all-targets --all-features --locked clean; clippy reports 0 warnings on all touched code; xtask asset-policy clean on all touched files).

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: #1541, #1785, #1676, #1442 (checked: #1541 addresses depth-plane publication rather than list.rs UAV barrier mirroring; #1785 / #1676 / #1442 target nothing_new / ask_once / Journal::ahead rather than copy_stale's ranged > 0 scan, Batch::add / card_steps 1-entry caches, or targets_kept_from_peak settle-decay).
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5549012039 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2049). Originally posted by [Rixnei](https://github.com/Rixnei) on 2026-11-29T08:28:14Z. --- ## What it changes Four focused, self-contained improvements to `victory-gpu` (split into 4 atomic commits) from profiling 1440p Series X gameplay on a 12 GB NVIDIA GPU: 1. **Sparse `O(written.len())` fast-path in `Shadow::copy_stale` when `ranged > 0` (`shadow.rs`)** - When `ranged > 0`, every page in `[from, to)` already has `taken >= ranged > 0`, so `taken == 0` is impossible and only pages present in the sorted `written` slice can satisfy `write > taken`. - Extracted `Shadow::collect_stale_runs` so `ranged > 0` iterates only over `written` instead of walking 16k–131k pages of multi-hundred-MB buffers on every refresh, and skips `take_all` when `runs` is empty. - Added unit test `collect_stale_runs_sparse_ranged_matches_dense_scan` verifying bit-for-bit identical `(runs, again_at, copied_pages)` against the dense scan (including partial edge pages, adjacent/gapped dirty runs, stale vs. fresh entries, and empty `written`). 2. **1-entry hot caches in `Batch::add` and `card_steps` span coalescing (`host.rs`, `host/card_steps.rs`)** - `Batch::copy_spans` already relies on consecutive `Step::Refresh` entries hitting the same shadow copy; `Batch::add` and `card_steps` span coalescing still probed `ByCopy` hash maps on every step. - Added `last_add` / `last_ahead` 1-entry caches to `Batch` (invalidated on `give_back`, `flush_one`, `flush`, `title_written`, `refresh_front`, `refresh_ahead`) and `last_span` to `card_steps`. 3. **Settle-decay for peak-based render-target VRAM reserve (`resource.rs`)** - `targets_kept_from_peak` previously ignored `still_ms` and `settle`, permanently keeping ~700–970 MiB reserved at 1440p (`peak / 2`) even after render targets stopped growing, causing `"no room"` texture upload stalls on 12 GB GPUs. - Once render targets stop growing by 64 MiB for `settle` ms (default 20 s), caps the peak-based reserve to 128 MiB (`targets >= 1 GiB`) or 256 MiB (`>= 256 MiB`), returning ~730 MiB to textures while immediately restoring the full reserve if targets grow by 64 MiB again (`settle == 0` keeps the previous uncapped behavior). - Expanded `room_for_targets_follows_their_peak` unit test to cover pre-settle, settled 1440p decay, and `settle == 0`. 4. **Mirror UAV barriers onto `twin_plane_resource` (`list.rs`)** - `barrier()` mirrored title UAV barriers (`kind == 2`) onto `twin_resource(b.first)` (the stencil/colour twin) but did not emit a matching UAV barrier on `twin_plane_resource(b.first)` (the separate depth-plane twin on depth-stencil formats). - Now emits the matching UAV barrier on `twin_plane_resource` when present so compute writes to a depth-plane twin are synchronized across explicit UAV barriers. - *(Note for #1541 / depth-twin work: we also tested running mid-list `pass_plane` on SRV/copy/clear reads, which dropped `PLANES[2]` to 0, but caused distant-object flickering because `u.behind[0]` is shared between `twin.colour` and `twin.plane` while `record_twin_copy` does not copy depth back to `twin.plane` (`PLANES[1]`), causing stencil-only UAV writes to overwrite live depth with stale `twin.plane` data. That change is intentionally omitted from this PR.)* ## How it was tested - **GPU and profile:** RTX 5070 12 GB, Ryzen 7 9800X3D, 32 GB RAM, Windows 11; Series X profile, 1440p, DLSS Quality, tested in both Native and DLSS Frame Generation 2x, ray tracing off (ambient stand-in on). - **Before (baseline logs on RTX 5070 12 GB, 1440p DLSS Quality + FG 2x):** - Peak-based RT reserve stayed ~860 MiB throughout steady 1440p gameplay, leaving textures frequently hitting `no room` stalls. - Submitting-thread refresh pass: median frametime `45.5 ms`, `17.5%` of frames `>50 ms`, GPU idle behind submitting thread `5.30 ms/frame`. - **After (measured in live 1440p gameplay logs):** - Settled 1440p RT reserve drops `860 MiB -> 128 MiB` (`+732 MiB` VRAM reclaimed for textures once targets stabilize). - With the sparse `copy_stale` fast-path + `Batch::add` hot caches: median frametime improved `45.5 ms -> 42.8 ms` (`+6.3%` base FPS, `~2x` under FG), frames `>50 ms` dropped nearly in half (`17.5% -> 9.1%`), and GPU idle behind CPU dropped `5.30 ms -> 4.40 ms` (`-17%`). - Depth-plane twin UAV barriers clean with zero visual regressions or distant-object flickering. - **For shader changes, the wave sizes tested:** N/A (no shader changes). - **`cargo test` passed for the crates it touches:** yes (`cargo test -p victory-gpu --locked -- --test-threads=1`: **590 passed, 0 failed**; `cargo check -p victory-gpu --all-targets --all-features --locked` clean; `clippy` reports 0 warnings on all touched code; `xtask` asset-policy clean on all touched files). ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #1541, #1785, #1676, #1442 (checked: #1541 addresses depth-plane publication rather than `list.rs` UAV barrier mirroring; #1785 / #1676 / #1442 target `nothing_new` / `ask_once` / `Journal::ahead` rather than `copy_stale`'s `ranged > 0` scan, `Batch::add` / `card_steps` 1-entry caches, or `targets_kept_from_peak` settle-decay).
meonline42 commented 2026-11-29 09:18:05 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by meonline42 on 2026-11-29T09:18:05Z.


Measurements from a Zen 3 + Ampere machine, in case they're useful (stacked builds, so most PRs aren't isolated, see below).

Machine: Ryzen 9 5900X (thermally limited: ~3.7 GHz average, Tctl 80-87 °C), RTX 3090 at 350 W, 64 GB DDR4-3200, Windows 11. Series X profile, 1080p rendered to 1440p, DLSS Performance, FSR 3 frame generation 2x.
Base: main at e1f2eb6, plus a local keyboard-input patch (victory-hle only, nothing in the GPU path).
Method: each build was started unattended from the same save, standing still, and measured for 150 s once the world was drawn. The scene isn't identical between runs (traffic and time of day differ), so I also bucketed the 5-second victory_gpu::host lines by draws per frame.

Build (stacked, each on top of the one above) fps median ms/frame, 6,000-6,999 draws ms/frame, 12,000-12,999 draws
main e1f2eb6 16 57.9 (n=3) -
+ #1403 #1279 #2049 #1937 17 56.8 (n=22) 77.6 (n=4)
+ #1988 with VICTORY_PRESENT_QUEUE=1 18 55.9 (n=24) 75.5 (n=10)
#1403 #1279 #2049 #1937 + #128 (fat LTO), no present queue 18 55.0 (n=26) 74.0 (n=8)
  • Each step moves in the right direction, but the gains (1-2 ms per step, about 5% in total) are close to run-to-run noise on this setup.
  • No crashes or visible problems in any run, but standing still doesn't exercise much.
  • #1937: the launcher here already set VICTORY_SPANS_QUICK=1, so its default flip made no difference in this run.
  • #128: a full release build took 4 min 23 s on the 5900X.
  • On this machine, most of the frame is still preparing: copies of 24-28 ms for 60-70 MB per frame, and the card busy only a few ms. Copy-back dropped from ~13 ms to ~6.5 ms between 923e38c and e1f2eb6.

Posted by Claude Code on behalf of the machine's owner.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7253671508 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2049#issuecomment-7253671508). Originally posted by [meonline42](https://github.com/meonline42) on 2026-11-29T09:18:05Z. --- Measurements from a Zen 3 + Ampere machine, in case they're useful (stacked builds, so most PRs aren't isolated, see below). **Machine:** Ryzen 9 5900X (thermally limited: ~3.7 GHz average, Tctl 80-87 °C), RTX 3090 at 350 W, 64 GB DDR4-3200, Windows 11. Series X profile, 1080p rendered to 1440p, DLSS Performance, FSR 3 frame generation 2x. **Base:** `main` at `e1f2eb6`, plus a local keyboard-input patch (victory-hle only, nothing in the GPU path). **Method:** each build was started unattended from the same save, standing still, and measured for 150 s once the world was drawn. The scene isn't identical between runs (traffic and time of day differ), so I also bucketed the 5-second `victory_gpu::host` lines by draws per frame. | Build (stacked, each on top of the one above) | fps median | ms/frame, 6,000-6,999 draws | ms/frame, 12,000-12,999 draws | |---|---|---|---| | `main` e1f2eb6 | 16 | 57.9 (n=3) | - | | + #1403 #1279 #2049 #1937 | 17 | 56.8 (n=22) | 77.6 (n=4) | | + #1988 with `VICTORY_PRESENT_QUEUE=1` | 18 | 55.9 (n=24) | 75.5 (n=10) | | #1403 #1279 #2049 #1937 + #128 (fat LTO), no present queue | 18 | 55.0 (n=26) | 74.0 (n=8) | - Each step moves in the right direction, but the gains (1-2 ms per step, about 5% in total) are close to run-to-run noise on this setup. - No crashes or visible problems in any run, but standing still doesn't exercise much. - #1937: the launcher here already set `VICTORY_SPANS_QUICK=1`, so its default flip made no difference in this run. - #128: a full release build took 4 min 23 s on the 5900X. - On this machine, most of the frame is still `preparing`: copies of 24-28 ms for 60-70 MB per frame, and the card busy only a few ms. Copy-back dropped from ~13 ms to ~6.5 ms between `923e38c` and `e1f2eb6`. Posted by Claude Code on behalf of the machine's owner.
nick0451 commented 2026-11-29 16:25:43 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by nick0451 on 2026-11-29T16:25:43Z.


Tested on an RTX 3090 24 GB, i9-14900K, Windows 11, this PR merged onto main 829188e9 (+ a local 2-line start fix from #1625), Series S, DLSS performance, no FG, the same city-street save throughout.

Speed (city street, card ~75% busy so partly CPU-bound, 2 rounds alternating after a warm-up): 21.5 fps (21.9, 21.2) against main's 21.5 (21.3, 21.6). No change here beyond noise.

The RT reserve (relevant to #191): with VICTORY_VRAM_BUDGET_MB=6800 to stand in for an 8 GB card, standing 12 min:

kept for render targets textures in use the card's own in use / budget
main 829188e9 ~415-477 MB 6.5 → 6.7 GB 6,693 / 6,800 at 12 min (7,872 at 20 min)
this PR 256 MB throughout 6.3 → 6.9 GB 6,863 / 6,800 at 12 min
14e5deda^1 (before #76), for comparison ~2,090 MB held ~4.8 GB within budget

So with this PR the reserve on an 8 GB-sized budget is smaller still, and the card goes past its budget a little sooner than on main (details of that overshoot in #191). It doesn't fix the 8 GB problem, though it isn't aimed at it. If the settle-decay is meant to hand room back to textures, on small cards that's the room render targets need later.

🤖 Generated with Claude Code

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7258895146 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/2049#issuecomment-7258895146). Originally posted by [nick0451](https://github.com/nick0451) on 2026-11-29T16:25:43Z. --- Tested on an RTX 3090 24 GB, i9-14900K, Windows 11, this PR merged onto main `829188e9` (+ a local 2-line start fix from #1625), Series S, DLSS performance, no FG, the same city-street save throughout. **Speed (city street, card ~75% busy so partly CPU-bound, 2 rounds alternating after a warm-up):** 21.5 fps (21.9, 21.2) against main's 21.5 (21.3, 21.6). No change here beyond noise. **The RT reserve (relevant to #191):** with `VICTORY_VRAM_BUDGET_MB=6800` to stand in for an 8 GB card, standing 12 min: | | kept for render targets | textures in use | the card's own in use / budget | |---|---|---|---| | main `829188e9` | ~415-477 MB | 6.5 → 6.7 GB | 6,693 / 6,800 at 12 min (7,872 at 20 min) | | this PR | **256 MB** throughout | 6.3 → 6.9 GB | **6,863 / 6,800** at 12 min | | `14e5deda^1` (before #76), for comparison | ~2,090 MB held | ~4.8 GB | within budget | So with this PR the reserve on an 8 GB-sized budget is smaller still, and the card goes past its budget a little sooner than on main (details of that overshoot in #191). It doesn't fix the 8 GB problem, though it isn't aimed at it. If the settle-decay is meant to hand room back to textures, on small cards that's the room render targets need later. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
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/2049:upstream-pr/2049'
git switch 'upstream-pr/2049'

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