GPU change detection for copies in the PC's memory (VICTORY_GPU_DIRTY=1, F1 GPU CHANGE DETECTION) #4895

Closed
github-bot wants to merge 1 commit from github-bot/gh-4894 into main AGit
Owner

@⁠NICKNAMErutschovkonikovan on GitHub · 2026-12-01 13:08 UTC · original
NICKNAMErutschovkonikovan:pr/gpu-dirty → main · +1481 −11 · 7 files · 1 commits · closed without merging

Refs #756

What it changes

Adds VICTORY_GPU_DIRTY=1 (off by default, read once through asked_for!) and the F1 row ADVANCED > GPU CHANGE DETECTION (OFF, ON).

The idea comes from the "GPU-side dirty bitmap" RFC in #756. That issue posted no patch, so none of its code is used.

Why: for host copies that have a side in the card's memory, CARD_COMPARE already finds on the card what shaders wrote. A copy that lives only in the PC's memory (no room on the card, below the card floor, or a window outside buffers) works differently. The CPU snapshots every declared range before the submission, then compares the whole range after the flight. The module notes of host/gpu_dirty.rs go through a measured frame and show that none of the refresh time is a byte compare the card could take over: title memory is not readable by the card. What is left for the card is what shaders wrote to copies in the PC's memory.

What: with the switch on, every such copy with at least 1 MiB of declared shader writes in a submission gets two passes of a new GPU_DIRTY compute shader. It uses CARD_COMPARE's hash and is compiled through hlsl::compile_for.

  • The first pass runs in its own queue call, right before the submission's lists (send_pre).
  • The second runs in its own queue call, right after the lists and before the flight's signal (send_post). Neither pass shares an ExecuteCommandLists call with the title's UAV writes, and the flight's fence covers both.
  • Each 64 KiB piece whose hash changed gets one bit.
  • At landing (relay, late and waited paths), the CPU compares only the flagged pieces with the snapshot (shadow::find_where), byte by byte as before. The snapshot stays as the merge's reference.

Falls back to the CPU compare, as before: published submissions (VICTORY_SUBMIT_SPLIT), copies under 1 MiB, missing memory or pipeline, a plan without readable bits, and a bit past the end.

Owed blocks: a block found differing whose merge did not take stays in OWED. It is compared again at every later landing until it is found the same. Its entries go when the copy's snapshot is given back or the copy is dropped.

Stats line: once a second, a line reports plans, MB and pieces hashed on the card, pieces found changed, CPU bytes compared vs. left out, and the added CPU time.

Files: new crates/victory-gpu/src/host/gpu_dirty.rs, plus hooks in host.rs, shadow.rs (find_where, has_snapshot, forget calls) and card_steps.rs (one test struct field). The menu row and about text in host/menu.rs follow the existing items. Also one paragraph in docs/unified-memory-audit.md and one row each in the README's F1 guide and settings list.

How it was tested

  • Commit tested: 44bfa42c (branch pr/gpu-dirty, on main 5fabb46e).
  • cargo test -p victory-gpu --lib --locked: 1106 passed, 0 failed, 68 ignored.
  • The new tests within that run:
    • in host::gpu_dirty::tests: pieces, places, bits, joined ranges, pool, cover, owed blocks, forgetting a copy, and the two passes on WARP;
    • in shadow::find_where_tests: find_where against find_all.
    • All passed.
  • cargo test -p victory-gpu --lib --locked -- hardware_gpu_dirty --ignored: 1 passed on an RTX 5090 (the two passes on hardware set exactly the changed pieces' bits).
  • cargo clippy -p victory-gpu --all-targets --locked -- -D warnings: 5 errors, none in code this branch adds. All of them are in lines main already has: host/font.rs:213 and :260 (too_many_arguments), host/menu.rs (held[i] - REPEAT_DELAY) % REPEAT_EVERY == 0 (manual_is_multiple_of, line 667 on main), and host/panel.rs:602 and :668 (collapsible_if; this branch does not change that file).
  • cargo xtask policy --staged: 7 files ok.
  • Numbers from the reference commits, measured on a combined build of several of the fork's changes, not on this branch (RTX 5090 + Ryzen 7 5800X3D, 2026-11-29):
    • a frame of 54 ms on the submitting thread: 4.4 ms asking the write watch, 5.1 ms merging under flights' writes, 26.5 ms in the lists' steps;
    • of that, 15.5 ms of refreshes (46 flushes, 6,963 refreshes, 5,891 known to copy nothing);
    • the D3D12 debug layer with GPU-based validation reported nothing for the pass order, on WARP or on the RTX 5090.
  • The reference commits state the feature itself was not measured in play.
  • This branch was not run in the game. No frame rate or CPU time with the switch on has been measured.
  • cargo test passed for the crates it touches: yes (victory-gpu --lib)

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches. Related: none found (searched "GPU_DIRTY", "GPU change detection"; the closed #3590 carried an earlier form of this).

🤖 Generated with Claude Code

**@⁠NICKNAMErutschovkonikovan** on GitHub · 2026-12-01 13:08 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4894) `NICKNAMErutschovkonikovan:pr/gpu-dirty` → `main` · +1481 −11 · 7 files · 1 commits · closed without merging <!-- Thanks for the pull request. Please label it (pr-fix, pr-feature, pr-performance, pr-diagnostics, pr-refactor, pr-docs or pr-tests, plus the area labels), or put the label in the title, like [pr-fix]. --> Refs #756 ## What it changes Adds `VICTORY_GPU_DIRTY=1` (off by default, read once through `asked_for!`) and the F1 row ADVANCED > GPU CHANGE DETECTION (OFF, ON). The idea comes from the "GPU-side dirty bitmap" RFC in #756. That issue posted no patch, so none of its code is used. **Why:** for host copies that have a side in the card's memory, `CARD_COMPARE` already finds on the card what shaders wrote. A copy that lives only in the PC's memory (no room on the card, below the card floor, or a window outside buffers) works differently. The CPU snapshots every declared range before the submission, then compares the whole range after the flight. The module notes of `host/gpu_dirty.rs` go through a measured frame and show that none of the refresh time is a byte compare the card could take over: title memory is not readable by the card. What is left for the card is what shaders wrote to copies in the PC's memory. **What:** with the switch on, every such copy with at least 1 MiB of declared shader writes in a submission gets two passes of a new `GPU_DIRTY` compute shader. It uses `CARD_COMPARE`'s hash and is compiled through `hlsl::compile_for`. - The first pass runs in its own queue call, right before the submission's lists (`send_pre`). - The second runs in its own queue call, right after the lists and before the flight's signal (`send_post`). Neither pass shares an `ExecuteCommandLists` call with the title's UAV writes, and the flight's fence covers both. - Each 64 KiB piece whose hash changed gets one bit. - At landing (relay, late and waited paths), the CPU compares only the flagged pieces with the snapshot (`shadow::find_where`), byte by byte as before. The snapshot stays as the merge's reference. **Falls back to the CPU compare, as before:** published submissions (`VICTORY_SUBMIT_SPLIT`), copies under 1 MiB, missing memory or pipeline, a plan without readable bits, and a bit past the end. **Owed blocks:** a block found differing whose merge did not take stays in `OWED`. It is compared again at every later landing until it is found the same. Its entries go when the copy's snapshot is given back or the copy is dropped. **Stats line:** once a second, a line reports plans, MB and pieces hashed on the card, pieces found changed, CPU bytes compared vs. left out, and the added CPU time. Files: new `crates/victory-gpu/src/host/gpu_dirty.rs`, plus hooks in `host.rs`, `shadow.rs` (`find_where`, `has_snapshot`, `forget` calls) and `card_steps.rs` (one test struct field). The menu row and about text in `host/menu.rs` follow the existing items. Also one paragraph in `docs/unified-memory-audit.md` and one row each in the README's F1 guide and settings list. ## How it was tested - Commit tested: `44bfa42c` (branch `pr/gpu-dirty`, on `main` 5fabb46e). - `cargo test -p victory-gpu --lib --locked`: 1106 passed, 0 failed, 68 ignored. - The new tests within that run: - in `host::gpu_dirty::tests`: pieces, places, bits, joined ranges, pool, cover, owed blocks, forgetting a copy, and the two passes on WARP; - in `shadow::find_where_tests`: `find_where` against `find_all`. - All passed. - `cargo test -p victory-gpu --lib --locked -- hardware_gpu_dirty --ignored`: 1 passed on an RTX 5090 (the two passes on hardware set exactly the changed pieces' bits). - `cargo clippy -p victory-gpu --all-targets --locked -- -D warnings`: 5 errors, none in code this branch adds. All of them are in lines `main` already has: `host/font.rs:213` and `:260` (too_many_arguments), `host/menu.rs` `(held[i] - REPEAT_DELAY) % REPEAT_EVERY == 0` (manual_is_multiple_of, line 667 on `main`), and `host/panel.rs:602` and `:668` (collapsible_if; this branch does not change that file). - `cargo xtask policy --staged`: 7 files ok. - Numbers from the reference commits, measured on a combined build of several of the fork's changes, not on this branch (RTX 5090 + Ryzen 7 5800X3D, 2026-11-29): - a frame of 54 ms on the submitting thread: 4.4 ms asking the write watch, 5.1 ms merging under flights' writes, 26.5 ms in the lists' steps; - of that, 15.5 ms of refreshes (46 flushes, 6,963 refreshes, 5,891 known to copy nothing); - the D3D12 debug layer with GPU-based validation reported nothing for the pass order, on WARP or on the RTX 5090. - The reference commits state the feature itself was not measured in play. - **This branch was not run in the game.** No frame rate or CPU time with the switch on has been measured. - `cargo test` passed for the crates it touches: yes (`victory-gpu --lib`) ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. Related: none found (searched "GPU_DIRTY", "GPU change detection"; the closed #3590 carried an earlier form of this). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Off by default (asked_for!, read once). After the "GPU-side dirty bitmap"
idea of issue 756; the issue posted no patch, so no code of it is used.

Why: for a host copy with a side in the card's memory, CARD_COMPARE
already finds on the card what shaders wrote. A copy that lives only in
the PC's memory (no room on the card, under the card floor, a window
outside buffers) has the CPU snapshot every declared range before the
submission and compare all of it after the flight. The module notes of
host/gpu_dirty.rs go through a frame measured on an RTX 5090 + Ryzen 7
5800X3D (combined build, 54 ms submitting thread, 15.5 ms of refreshes)
and show that none of the refresh time is a compare the card could take:
sifting reads the journal's notes, asking is the kernel's dirty bit, the
rest is copying title memory, which the card cannot read. What is left
for the card is what shaders wrote to copies in the PC's memory.

What: with the switch, such a copy (>= 1 MiB declared) gets two passes of
a new GPU_DIRTY compute shader (CARD_COMPARE's hash, compiled like the
other helpers by hlsl::compile_for): one in a queue call of its own right
before the submission's lists (send_pre) and one in a queue call of its
own right after them, before the flight's signal (send_post), so neither
shares an ExecuteCommandLists call with the title's UAV writes and the
fence covers both. Each 64 KiB piece whose hash changed gets a bit. At
landing (relay, late and waited paths) the CPU compares only flagged
pieces with the snapshot (shadow::find_where), byte by byte as before;
pieces of a flight without passes are compared as before. The snapshot
stays as the merge's reference. Published submissions, small copies, and
missing memory or pipeline fall back to the CPU.

Fail-safe: a bit past the end counts as set; a plan without readable bits
vouches for nothing; a block found differing whose merge did not take is
kept in OWED and compared at every later landing until found the same,
tallied per copy over all its ranges; OWED entries go when the snapshot
is given back or the copy is dropped (gpu_dirty::forget). A line per
second gives plans, MB and pieces compared on the card, pieces found
changed, CPU bytes compared vs left out, and the added CPU time.

Ported from three commits of a combined branch (the feature, then two
reviews that moved both passes into queue calls of their own and added
the owed blocks and fail-safe bits). The D3D12 debug layer with GPU-based
validation reported nothing for the pass order on WARP and on an
RTX 5090 there (ignored test debug_layer_on_the_first_pass). Not measured
in play.

README: a row in the F1 guide's ADVANCED table and one in the
settings list.

Tests: pieces, places, bits, joined ranges, pool, cover, owed blocks,
forgetting, find_where against find_all, and the two passes on WARP
(hardware variant ignored).

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

@⁠tikD1337 on GitHub · 2026-12-01 13:28 UTC · original

Tested VICTORY_GPU_DIRTY=1 vs =0 on the exact same --release binary (origin/main 5fabb46e + #4885 THIN_PEEPHOLE=1 + #4877 + #4872 + #3556 01/03/04, VICTORY_PORT_CONSTANTS=0, VICTORY_WC_BAR=0):

  • Unit tests: gpu_dirty 10 passed; 0 failed; 2 ignored.
  • Rig: Ryzen 5 7600 + RTX 4070 Ti SUPER 16 GB (Driver 621.1.0, ReBAR ON) + Win11 26300, DLSS Quality, 105 s steady 3D runs, 0 crashes.
  • A/B (VICTORY_GPU_DIRTY=0 -> 1):
    • Steady 3D FPS (>=200 lists): 27.93 -> 24.70 FPS (35.80 -> 40.48 ms, -3.23 FPS)
    • submit_prep: 31.6 -> 37.0 ms (+5.4 ms; steps 19.6 -> 24.2 ms, refr 10.0 -> 12.4 ms)
    • Matched 5.3k–6.5k draws: 27.60 -> 25.00 FPS (host_prep 29.4 -> 34.9 ms)
    • GPU idle: 8.7 -> 13.8 ms (76% -> 66% busy)
    • Note: the gpu_dirty telemetry line reported 0.0 plans, 0.0 copies, 0.0 MB in 0 pieces under this PORT_CONSTANTS=0 + LOW_L0_DMA=1 stack, yet the added per-frame overhead still regressed submit_prep by +5.4 ms.
**@⁠tikD1337** on GitHub · 2026-12-01 13:28 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4894#issuecomment-7312670818) Tested `VICTORY_GPU_DIRTY=1` vs `=0` on the exact same `--release` binary (`origin/main` `5fabb46e` + `#4885` `THIN_PEEPHOLE=1` + `#4877` + `#4872` + `#3556` `01/03/04`, `VICTORY_PORT_CONSTANTS=0`, `VICTORY_WC_BAR=0`): - **Unit tests:** `gpu_dirty` **10 passed; 0 failed; 2 ignored**. - **Rig:** Ryzen 5 7600 + RTX 4070 Ti SUPER 16 GB (Driver `621.1.0`, ReBAR ON) + Win11 `26300`, DLSS Quality, `105 s` steady 3D runs, `0` crashes. - **A/B (`VICTORY_GPU_DIRTY=0` -> `1`):** - Steady 3D FPS (`>=200` lists): **`27.93 -> 24.70 FPS`** (`35.80 -> 40.48 ms`, **-3.23 FPS**) - `submit_prep`: **`31.6 -> 37.0 ms`** (`+5.4 ms`; `steps 19.6 -> 24.2 ms`, `refr 10.0 -> 12.4 ms`) - Matched `5.3k–6.5k` draws: **`27.60 -> 25.00 FPS`** (`host_prep 29.4 -> 34.9 ms`) - GPU idle: **`8.7 -> 13.8 ms`** (`76% -> 66%` busy) - Note: the `gpu_dirty` telemetry line reported `0.0 plans, 0.0 copies, 0.0 MB in 0 pieces` under this `PORT_CONSTANTS=0` + `LOW_L0_DMA=1` stack, yet the added per-frame overhead still regressed `submit_prep` by `+5.4 ms`.
github-bot closed this pull request 2026-12-01 18:30:37 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-12-01 18:29 UTC · original

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** on GitHub · 2026-12-01 18:29 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4894#issuecomment-7321019091) 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

This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

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