perf(gpu): compare big card copies only where written lately #501

Open
github-bot wants to merge 1 commit from github-bot/gh-501 into main AGit
Owner

@⁠ballsimulation on GitHub · 2026-11-27 23:38 UTC · original
ballsimulation:perf/lazy-card-compare → main · +451 −23 · 3 files · 1 commits · open

Summary

Two opt-in switches, both off by default, that cut the cost of the title's 174 MB constants heap:

  • VICTORY_LAZY_COMPARE_MB=64: the GPU compares only the parts of the heap that shaders recently wrote, plus a rotating sweep of the rest.
  • VICTORY_LAZY_NARROW=1: constant reads from the heap stop counting as blocked by in-flight work, except on those recently written parts.

On main, with both on: frames 4–6% faster, and the submitting thread's planning of steps on the card drops from 7.4 to 1.7 ms.

Why

The skinning passes declare the whole heap written in every submission, through one view of it. That has two costs:

  • GPU: the heap's card copy is compared in full after each of ~12 submissions per frame. That is about 2.2 GB of reads per frame to find ~2.6 MB that shaders actually wrote.
  • CPU: while flights are in the air, nearly every constant fill from the heap counts as blocked, so each is planned onto the card (card_steps). That costs 7–12 ms per frame on the submitting thread.

What changes

VICTORY_LAZY_COMPARE_MB=<MiB>

For a card copy at least this large, a submission compares only:

  1. pieces found written in the last VICTORY_LAZY_HOT compares (default 64);
  2. skipped pieces that are about to be sent up. Their rehash is held back, so the compare still sees older shader writes;
  3. the next VICTORY_LAZY_SWEEP skipped pieces in turn (default 128).

These compares store their hashes (mode 2). Anything found is fetched and merged exactly as before. A log line every 5 s shows the counts.

VICTORY_LAZY_NARROW=1 (needs the switch above)

Where submission steps wait for flights, or are done on the card in flight order (late_blocked, card_steps, cut_for, the relay's wait), such a copy counts as written only on its recently written pieces. Refreshes still see every declared write.

Trade-off

A heap piece that shaders write for the first time reaches title memory only when the sweep finds it, about 2 frames later. Until then, CPU steps read the title's own bytes there.

Results

RTX 4070, Ryzen 9 7950X. Series X profile at native 2560x1440, no DLSS, frame rate uncapped. One build of main 64d4931b with this change, the same save and walk, run with the switches off and then on. Median frame time by draws per frame:

Draws per frame Off On
4–6k 53.7 ms 50.4 ms
6–7k 56.8 ms 54.4 ms
7–8k 59.2 ms 57.1 ms
8–9.5k 62.7 ms 58.8 ms
Submitting thread 49.5 ms 45.8 ms
Its planning of steps on the card 7.4 ms 1.7 ms
  • The card was ~90–95% busy in both runs (native 1440p), so only part of the CPU saving shows up in frame time. On an older integration branch with the Series S profile and DLSS Performance, where the card was less busy, the same change brought frames from 46–55 ms down to 39–48 ms.
  • No new warnings or errors in the log. Clippy is clean for the new code.
  • On the integration branch, water and reflections looked the same with the switches on and off.

Caveats

  • Both switches are off by default; nothing changes unless they are set.
  • The two runs on main loaded at slightly different spots in the save, and the samples per bin are small (15–56).

🤖 Generated with Claude Code

**@⁠ballsimulation** on GitHub · 2026-11-27 23:38 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/501) `ballsimulation:perf/lazy-card-compare` → `main` · +451 −23 · 3 files · 1 commits · open ## Summary Two opt-in switches, both off by default, that cut the cost of the title's 174 MB constants heap: - `VICTORY_LAZY_COMPARE_MB=64`: the GPU compares only the parts of the heap that shaders recently wrote, plus a rotating sweep of the rest. - `VICTORY_LAZY_NARROW=1`: constant reads from the heap stop counting as blocked by in-flight work, except on those recently written parts. On main, with both on: **frames 4–6% faster**, and the submitting thread's planning of steps on the card drops from **7.4 to 1.7 ms**. ## Why The skinning passes declare the whole heap written in every submission, through one view of it. That has two costs: - **GPU:** the heap's card copy is compared in full after each of ~12 submissions per frame. That is about 2.2 GB of reads per frame to find ~2.6 MB that shaders actually wrote. - **CPU:** while flights are in the air, nearly every constant fill from the heap counts as blocked, so each is planned onto the card (`card_steps`). That costs 7–12 ms per frame on the submitting thread. ## What changes ### `VICTORY_LAZY_COMPARE_MB=<MiB>` For a card copy at least this large, a submission compares only: 1. pieces found written in the last `VICTORY_LAZY_HOT` compares (default 64); 2. skipped pieces that are about to be sent up. Their rehash is held back, so the compare still sees older shader writes; 3. the next `VICTORY_LAZY_SWEEP` skipped pieces in turn (default 128). These compares store their hashes (mode 2). Anything found is fetched and merged exactly as before. A log line every 5 s shows the counts. ### `VICTORY_LAZY_NARROW=1` (needs the switch above) Where submission steps wait for flights, or are done on the card in flight order (`late_blocked`, `card_steps`, `cut_for`, the relay's wait), such a copy counts as written only on its recently written pieces. Refreshes still see every declared write. ### Trade-off A heap piece that shaders write for the first time reaches title memory only when the sweep finds it, about 2 frames later. Until then, CPU steps read the title's own bytes there. ## Results RTX 4070, Ryzen 9 7950X. Series X profile at native 2560x1440, no DLSS, frame rate uncapped. One build of main `64d4931b` with this change, the same save and walk, run with the switches off and then on. Median frame time by draws per frame: | Draws per frame | Off | On | |---|---|---| | 4–6k | 53.7 ms | **50.4 ms** | | 6–7k | 56.8 ms | **54.4 ms** | | 7–8k | 59.2 ms | **57.1 ms** | | 8–9.5k | 62.7 ms | **58.8 ms** | | Submitting thread | 49.5 ms | **45.8 ms** | | Its planning of steps on the card | 7.4 ms | **1.7 ms** | - The card was ~90–95% busy in both runs (native 1440p), so only part of the CPU saving shows up in frame time. On an older integration branch with the Series S profile and DLSS Performance, where the card was less busy, the same change brought frames from 46–55 ms down to 39–48 ms. - No new warnings or errors in the log. Clippy is clean for the new code. - On the integration branch, water and reflections looked the same with the switches on and off. ## Caveats - Both switches are off by default; nothing changes unless they are set. - The two runs on main loaded at slightly different spots in the save, and the samples per bin are small (15–56). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
The constants heap (174 MB) is declared written by the skinning passes in
every submission, so it was compared whole after each of ~12 submissions a
frame (2.2 GB of the card's reads to find ~2.6 MB written), and every
constant fill from it counted as blocked by flights and was planned onto
the card (`card_steps`, 7-12 ms a frame on the submitting thread).

VICTORY_LAZY_COMPARE_MB=<MiB>: of a card copy at least this large, a
submission compares only the pieces found written lately
(VICTORY_LAZY_HOT compares, 64), the left-out pieces about to be sent up
(their rehash is held back, so the compare still sees older shader
writes), and the next VICTORY_LAZY_SWEEP (128) left-out pieces in turn.
Those compares store their hashes (mode 2). The write-back itself is
unchanged: what is found is fetched and merged as before.

VICTORY_LAZY_NARROW=1 (with the above): where submission steps wait for
flights or are done on the card in their order (late_blocked, card_steps,
cut_for, the relay's wait), such a copy counts as written only on those
pieces. Refreshes still see every declared write.

Accepted: a piece written for the first time reaches title memory, and is
read as the title has it, only once the sweep finds it (~2 frames).

Series S, DLSS Performance, 30 fps cap, RTX 4070, same walk, one build:
frame time by draws per frame, switches off -> on:
4-6k 53.7 -> 50.4 ms, 6-7k 56.8 -> 54.4, 7-8k 59.2 -> 57.1,
8-9.5k 62.7 -> 58.8; submitting thread 49.5 -> 45.8 ms, its planning of
steps on the card 7.4 -> 1.7 ms.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 23:41:41 +00:00
Author
Owner

@⁠POMXARK on GitHub · 2026-11-28 00:29 UTC · original

Testing feedback on RTX 5080 16 GB / AMD Ryzen 7 5700X (8C/16T) / 32 GB RAM, Windows 11, Series X 1440p + DLSS Quality + DLSS MFG 4x, based on v2026.11.27.8 (64d4931) with VICTORY_LAZY_COMPARE_MB=64 and VICTORY_LAZY_NARROW=1:

Hit a guest access violation at 3m44s (Frame: 5348, prison gameplay) that did not occur on prior 12-minute runs without VICTORY_LAZY_*:

  • unhandled exception 0xc0000005 at victory-image-b99f876b74d4a77f.dll+0x4e9b54a (read 0xffffffffffffffff: outside the address space)
  • Registers: rcx 0x31ff84a045495676 (non-canonical pointer), rax 0x0, rbx 0xd0418f3a8, rdi 0xd04189938, r8/r9 0xffffffff00000000
  • Top frames: +0x4e9b54a -> +0x4e9b4bf -> +0x4a4a -> +0x4d9f49c -> +0x2484ac4 -> +0x321c5 -> +0x3346d -> +0x555e921

Full disclosure: this was tested on a custom branch with additional local GPU patches on top of v2026.11.27.8 (also with PR #498 and PR #499 enabled), so it is not yet a clean main-only repro. Sharing the crash trace here since it looks consistent with the documented risk in lazy.rs around delayed/missed first-time shader write-backs into the 174 MB constants heap when VICTORY_LAZY_NARROW=1 is enabled.

**@⁠POMXARK** on GitHub · 2026-11-28 00:29 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/501#issuecomment-7230954850) Testing feedback on RTX 5080 16 GB / AMD Ryzen 7 5700X (8C/16T) / 32 GB RAM, Windows 11, Series X 1440p + DLSS Quality + DLSS MFG 4x, based on `v2026.11.27.8` (`64d4931`) with `VICTORY_LAZY_COMPARE_MB=64` and `VICTORY_LAZY_NARROW=1`: Hit a guest access violation at **3m44s** (`Frame: 5348`, prison gameplay) that did not occur on prior 12-minute runs without `VICTORY_LAZY_*`: - `unhandled exception 0xc0000005 at victory-image-b99f876b74d4a77f.dll+0x4e9b54a (read 0xffffffffffffffff: outside the address space)` - Registers: `rcx 0x31ff84a045495676` (non-canonical pointer), `rax 0x0`, `rbx 0xd0418f3a8`, `rdi 0xd04189938`, `r8/r9 0xffffffff00000000` - Top frames: `+0x4e9b54a -> +0x4e9b4bf -> +0x4a4a -> +0x4d9f49c -> +0x2484ac4 -> +0x321c5 -> +0x3346d -> +0x555e921` Full disclosure: this was tested on a custom branch with additional local GPU patches on top of `v2026.11.27.8` (also with PR #498 and PR #499 enabled), so it is not yet a clean `main`-only repro. Sharing the crash trace here since it looks consistent with the documented risk in `lazy.rs` around delayed/missed first-time shader write-backs into the 174 MB constants heap when `VICTORY_LAZY_NARROW=1` is enabled.
Author
Owner

@⁠Machad3x on GitHub · 2026-11-28 01:19 UTC · original

Tested merged on top of main (RTX 3080 Ti, Ryzen 7 5700X, 1440p DLSS Quality, title ray tracing on). With the switch at its default (off) the run was fine. Review found one bug in host/lazy.rs hot_within:

It joins a hot piece onto out.last_mut() whenever last.1 >= a, without checking last.0 <= a. out already holds unrelated ranges at that point (Line::joined seeds it with textures.to_vec(), and the line rebuild adds other ranges first). A hot piece that lies below an unrelated range above it gets swallowed: last.1 = max(last.1, b) changes nothing, so [a, b) is lost. With VICTORY_LAZY_NARROW=1, the waits (late_blocked, card_steps, cut_for, relay_wait) then do not wait for the flight that writes those bytes, and a later list reads stale data.

Fix we use (callers already sort and join afterwards):

-                Some(last) if last.1 >= a => last.1 = last.1.max(b),
+                // `out` may already hold unrelated ranges; callers sort and join after.
+                Some(last) if last.0 <= a && last.1 >= a => last.1 = last.1.max(b),

plus a test hot_piece_below_an_unrelated_range_stays.

**@⁠Machad3x** on GitHub · 2026-11-28 01:19 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/501#issuecomment-7231586507) Tested merged on top of main (RTX 3080 Ti, Ryzen 7 5700X, 1440p DLSS Quality, title ray tracing on). With the switch at its default (off) the run was fine. Review found one bug in `host/lazy.rs` `hot_within`: It joins a hot piece onto `out.last_mut()` whenever `last.1 >= a`, without checking `last.0 <= a`. `out` already holds unrelated ranges at that point (`Line::joined` seeds it with `textures.to_vec()`, and the line rebuild adds other ranges first). A hot piece that lies below an unrelated range above it gets swallowed: `last.1 = max(last.1, b)` changes nothing, so `[a, b)` is lost. With `VICTORY_LAZY_NARROW=1`, the waits (`late_blocked`, `card_steps`, `cut_for`, `relay_wait`) then do not wait for the flight that writes those bytes, and a later list reads stale data. Fix we use (callers already sort and join afterwards): ```diff - Some(last) if last.1 >= a => last.1 = last.1.max(b), + // `out` may already hold unrelated ranges; callers sort and join after. + Some(last) if last.0 <= a && last.1 >= a => last.1 = last.1.max(b), ``` plus a test `hot_piece_below_an_unrelated_range_stays`.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/501/head:github-bot/gh-501'
git switch 'github-bot/gh-501'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-501'
git switch 'github-bot/gh-501'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-501'
git switch 'github-bot/gh-501'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-501'
git switch 'main'
git merge --squash 'github-bot/gh-501'
git switch 'main'
git merge --ff-only 'github-bot/gh-501'
git switch 'main'
git merge 'github-bot/gh-501'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.