List scratch in card memory the CPU maps (VICTORY_SCRATCH_CARD=1, off by default) #4332

Closed
mstrmoos wants to merge 14 commits from upstream-pr/4332 into main
mstrmoos commented 2026-11-30 18:57:52 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by mstrmoos on 2026-11-30T18:57:52Z.


[pr-performance]

What it changes

On discrete NVIDIA cards, a list's own scratch lies in the PC's memory: scratch_wb (837bae72) puts it in write-back L0 memory. That scratch holds the constants and small data the list's commands read. So every load a shader makes from it crosses the bus.

This adds VICTORY_SCRATCH_CARD=1, off by default. It puts those chunks in card memory the CPU maps (D3D12_HEAP_TYPE_GPU_UPLOAD, a resizable BAR), when the host has it (mapped_card_memory()). It covers the pooled chunks of up to 4 MiB and the one-off chunks over 4 MiB.

Two kinds of chunk stay where they were:

  • shared scratch, which the card's own steps fill;
  • the write-combined chunks of streaming callers, which are copy sources read once.

The CPU only writes scratch and never reads it back, which matters: the CPU reads card memory at 0.09 GB/s.

Why, measured on an RTX 5080 with cargo test -p victory-gpu --release --lib host::bus -- --ignored --nocapture:

Shaders read CPU writes
PC memory 32 GB/s 29 GB/s
Card memory the CPU maps 925 GB/s 32 GB/s

How I found it: an Nsight GPU Trace of a replayed frame showed the card stalled on memory (Long Scoreboard), with 0–3 warps per SM for most of its busy time. I then used victory replay --buffers vram --only-buffers seen=Cached --only-buffers min=65537 --only-buffers max=4194304 to move only the frame's 196 scratch chunks (162 of 256 KiB, 34 of 4 MiB) into the card's memory. The replay's card time went from 27.52 to 25.19 ms.

How it was tested

  • GPU and profile: RTX 5080 16 GB (resizable BAR on), Ryzen 7 9800X3D. Series X profile, the repo's victory-settings.txt, 90 s bench route, same save, game window in front for the whole run. Built from main e1251c31, --profile diag --features diagnostics.
  • The bench scene: the same save every run, with the player standing still on a wooden pier for 90 s. In view are the player up close (skinned, with hair), a restaurant terrace with people moving about, open water with boats, and a far shore with foliage and the city skyline. The game sends about 8,100–9,000 draws a frame, about 7,000 of them single-draw ExecuteIndirect mesh calls and about 2,000 compute dispatches. 330–370 a frame are dropped (pipeline not ready), and about 870 ray-tracing indirect calls are left out on purpose, as ray tracing is off.
  • Before (switch unset): frame 43.0 ms median (23.3 fps), card 90% busy (the card is the limit). The title's lists took 29.4–32.6 ms of card time per frame (card meter).
  • After (VICTORY_SCRATCH_CARD=1): frame 37.0 ms median (27.0 fps), card 90% busy. The title's lists took 27.9–28.7 ms of card time. Our sync lists were 0.7–1.0 ms before and 1.0–1.1 ms after.
  • On a branch where the CPU's preparing is the limit (card 87% busy), the title's lists drop by a similar 2–3 ms of card time, but the frame median doesn't move (32.9 → 32.5 ms). There, the sync lists rose from 0.3 to 1.3 ms; I haven't found why yet. That's one reason I've left the switch off by default.
  • Not tested: AMD cards, cards without resizable BAR (there the switch does nothing, as mapped_card_memory() is false), and integrated GPUs.
  • cargo test passed for the crates it touches: cargo test --locked -p victory-gpu --lib gives the same result as on main (1131 passed). The 2 failures, and the 2 Clippy errors from --all-targets (shadow.rs ranged, host.rs:5116), are on main already; the first two are fixed by #4025.

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: #1392 (hardened write-back scratch), #3723 (tiered memory), #3102 (CBV_CARD, which copies constants the card writes). None moves list scratch into card memory.
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5571753624 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4332). Originally posted by [mstrmoos](https://github.com/mstrmoos) on 2026-11-30T18:57:52Z. --- [pr-performance] ## What it changes On discrete NVIDIA cards, a list's own scratch lies in the PC's memory: `scratch_wb` (837bae72) puts it in write-back `L0` memory. That scratch holds the constants and small data the list's commands read. So every load a shader makes from it crosses the bus. This adds `VICTORY_SCRATCH_CARD=1`, off by default. It puts those chunks in card memory the CPU maps (`D3D12_HEAP_TYPE_GPU_UPLOAD`, a resizable BAR), when the host has it (`mapped_card_memory()`). It covers the pooled chunks of up to 4 MiB and the one-off chunks over 4 MiB. Two kinds of chunk stay where they were: - shared scratch, which the card's own steps fill; - the write-combined chunks of streaming callers, which are copy sources read once. The CPU only writes scratch and never reads it back, which matters: the CPU reads card memory at 0.09 GB/s. Why, measured on an RTX 5080 with `cargo test -p victory-gpu --release --lib host::bus -- --ignored --nocapture`: | | Shaders read | CPU writes | |---|---|---| | PC memory | 32 GB/s | 29 GB/s | | Card memory the CPU maps | 925 GB/s | 32 GB/s | How I found it: an Nsight GPU Trace of a replayed frame showed the card stalled on memory (Long Scoreboard), with 0–3 warps per SM for most of its busy time. I then used `victory replay --buffers vram --only-buffers seen=Cached --only-buffers min=65537 --only-buffers max=4194304` to move only the frame's 196 scratch chunks (162 of 256 KiB, 34 of 4 MiB) into the card's memory. The replay's card time went from 27.52 to 25.19 ms. ## How it was tested - GPU and profile: RTX 5080 16 GB (resizable BAR on), Ryzen 7 9800X3D. Series X profile, the repo's `victory-settings.txt`, 90 s bench route, same save, game window in front for the whole run. Built from main e1251c31, `--profile diag --features diagnostics`. - The bench scene: the same save every run, with the player standing still on a wooden pier for 90 s. In view are the player up close (skinned, with hair), a restaurant terrace with people moving about, open water with boats, and a far shore with foliage and the city skyline. The game sends about 8,100–9,000 draws a frame, about 7,000 of them single-draw ExecuteIndirect mesh calls and about 2,000 compute dispatches. 330–370 a frame are dropped (pipeline not ready), and about 870 ray-tracing indirect calls are left out on purpose, as ray tracing is off. - Before (switch unset): frame 43.0 ms median (23.3 fps), card 90% busy (the card is the limit). The title's lists took 29.4–32.6 ms of card time per frame (card meter). - After (`VICTORY_SCRATCH_CARD=1`): **frame 37.0 ms median (27.0 fps)**, card 90% busy. The title's lists took 27.9–28.7 ms of card time. Our sync lists were 0.7–1.0 ms before and 1.0–1.1 ms after. - On a branch where the CPU's preparing is the limit (card 87% busy), the title's lists drop by a similar 2–3 ms of card time, but the frame median doesn't move (32.9 → 32.5 ms). There, the sync lists rose from 0.3 to 1.3 ms; I haven't found why yet. That's one reason I've left the switch off by default. - Not tested: AMD cards, cards without resizable BAR (there the switch does nothing, as `mapped_card_memory()` is false), and integrated GPUs. - `cargo test` passed for the crates it touches: `cargo test --locked -p victory-gpu --lib` gives the same result as on main (1131 passed). The 2 failures, and the 2 Clippy errors from `--all-targets` (`shadow.rs` `ranged`, `host.rs:5116`), are on main already; the first two are fixed by #4025. ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: #1392 (hardened write-back scratch), #3723 (tiered memory), #3102 (`CBV_CARD`, which copies constants the card writes). None moves list scratch into card memory.
trustno1-coder commented 2026-12-01 18:42:40 +00:00 (Migrated from github.com)

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


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:7321393839 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4332#issuecomment-7321393839). Originally posted by [trustno1-coder](https://github.com/trustno1-coder) on 2026-12-01T18:42:40Z. --- 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.
trustno1-coder commented 2026-12-01 18:44:15 +00:00 (Migrated from github.com)

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


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:7321444984 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4332#issuecomment-7321444984). Originally posted by [trustno1-coder](https://github.com/trustno1-coder) on 2026-12-01T18:44:15Z. --- 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.

Pull request closed

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!4332
No description provided.