VICTORY_READ_WATCH: log which title code reads textures the card writes #4676

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

@⁠cadfan on GitHub · 2026-12-01 01:31 UTC · original
cadfan:diag/read-watch → main · +568 −0 · 6 files · 1 commits · closed without merging

Refs #4534

What it changes

Why I needed it. In #4534, rivers and pools pushed the player out like a strong current. The logs said nothing was wrong. On the console the CPU sees what the GPU wrote; here, a texture the card writes stays in its host copy unless its kind is copied back (texback.rs). So the likely cause was the title's CPU reading a texture nobody had copied back. But nothing in the tree could say which texture, or whether the title read it at all.

texback.rs already cites a VICTORY_READ_WATCH=1 run of the upstream trace for the ocean's kinds. docs/unified-memory-audit.md notes the switch was never built in this tree (U0, and in #2960's description). This PR is that switch.

What it does. It is off by default and only turns on with VICTORY_READ_WATCH=1. When off, each hook is one cached switch check.

  1. Each title texture a draw or dispatch writes is registered: by unordered access, as a render target, or as a depth target. Textures over VICTORY_READ_WATCH_MAX_KB (16 MiB by default) are skipped. So are textures whose kind is already copied back after unordered access.
  2. About once a second (VICTORY_READ_WATCH_EVERY frames, 30 by default), the pages of each registered texture's title memory are made no-access.
  3. The first touch of a page faults into a vectored exception handler. The handler gives the page its old protection back and execution goes on. If the touching code is outside our own module, it notes the texture and the code's place as module+offset.
  4. Once per pair, the frame-rate line logs: the texture's kind (as VICTORY_TEXTURE_BACK takes it, so it can be tried there straight away), how the card writes it, the code's place, read or write, and the offset.
  5. For every texture read, the log also summarises its bytes as they are in title memory: distinct values, min, max, mean, the most common values, and the 32 bytes around the read. That shows at once whether the title found real data or memory nothing wrote.

Like land's reads, it leaves alone the pages the guards hold, and the first page of each 64 KiB block. It changes nothing the title sees: every page is given back as it was, on first touch, on release, or on remap.

How it helped (#4534). The fix is the separate PR #4675.

  • First run, wading into Kelly River. The watch named one texture the title's code read and nothing copied back: a 256x256 R8_UNORM render target (256x256f61). It was read from two places in the title (+0x50313d2, +0x203345d) about ten times a second. Copy-back only ever ran for unordered-access writes, so no list of kinds could have reached it.
  • Second run, with render targets copied back. The byte summary showed the target holding 128 (calm water). Walking into the river worked, but it felt as if something was holding the player back. The summary then showed twelve more tables read only while the player entered the river (2048x128f62, 4096x64f62, 4096x64f57), all zeros.
  • Third run, with those added. Swimming, driving into the river and Veteran Hunted's crossing all worked. The watch found nothing else the title read uncopied.

It took three runs from "something in the water is stale" to a fix, and no guessing at kinds.

How it was tested

  • GPU and profile: RTX 5080, Windows 11. Series X profile, 2560x1440 output, DLSS Performance, DLSS frame generation 2x. No ray tracing.
  • Before: no way to see which textures the title's CPU reads.
  • After: the three runs above, on 0b353a75 (main of 2026-11-30 plus #3043 and #3487). Frame rate with the watch on was not measured. It is a diagnostic, and it faults once per page per period while on.
  • Not seen by the watch: reads through another view of the same pages, and reads by the kernel.
  • Wave sizes: no shader changes.
  • cargo test passed for the crates it touches: yes, apart from tests that also fail on main:
    • On this commit (dde18b0f), cargo test -p victory-gpu --lib -- readwatch passes. The tests are a_run_split_at_a_touched_page_keeps_both_sides and an_armed_page_opens_on_its_first_read_and_the_rest_stay_armed. The second arms real pages, reads one through the handler, and checks that the rest stay armed and that disarming restores them.
    • cargo clippy --workspace --all-targets --locked -- -D warnings and the same with --all-features: clean.
    • cargo test --workspace --locked --no-fail-fast: everything passes except victory-hle's xmem::tests::a_read_by_range_waits_only_for_a_remapping_that_meets_it. That test fails the same way on main (7d93ee07) when the crate runs as a whole, and passes alone. Open PR #2439 covers it.
    • On an earlier full run, card_steps::shared_scratch_eliminates_flight_settle_end_to_end (#2741) failed once, then passed 3 times out of 3 alone, on main and on this branch.

Checked for overlap

  • I searched the open pull requests for VICTORY_READ_WATCH, read watch and texback, and for the files this touches. Related: #2960 (VICTORY_BACK_READS, per-buffer diagnostics of the memory bridge, diagnostics builds only). That one counts buffer copy-back, refreshes and waits. It doesn't find title reads of textures, so there's no overlap. #4675 (the fix this found). This PR doesn't depend on it, and the two merge cleanly together.
**@⁠cadfan** on GitHub · 2026-12-01 01:31 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4675) `cadfan:diag/read-watch` → `main` · +568 −0 · 6 files · 1 commits · closed without merging Refs #4534 ## What it changes **Why I needed it.** In #4534, rivers and pools pushed the player out like a strong current. The logs said nothing was wrong. On the console the CPU sees what the GPU wrote; here, a texture the card writes stays in its host copy unless its kind is copied back (`texback.rs`). So the likely cause was the title's CPU reading a texture nobody had copied back. But nothing in the tree could say *which* texture, or whether the title read it at all. `texback.rs` already cites a `VICTORY_READ_WATCH=1` run of the upstream trace for the ocean's kinds. `docs/unified-memory-audit.md` notes the switch was never built in this tree (U0, and in #2960's description). This PR is that switch. **What it does.** It is off by default and only turns on with `VICTORY_READ_WATCH=1`. When off, each hook is one cached switch check. 1. Each title texture a draw or dispatch writes is registered: by unordered access, as a render target, or as a depth target. Textures over `VICTORY_READ_WATCH_MAX_KB` (16 MiB by default) are skipped. So are textures whose kind is already copied back after unordered access. 2. About once a second (`VICTORY_READ_WATCH_EVERY` frames, 30 by default), the pages of each registered texture's title memory are made no-access. 3. The first touch of a page faults into a vectored exception handler. The handler gives the page its old protection back and execution goes on. If the touching code is outside our own module, it notes the texture and the code's place as module+offset. 4. Once per pair, the frame-rate line logs: the texture's kind (as `VICTORY_TEXTURE_BACK` takes it, so it can be tried there straight away), how the card writes it, the code's place, read or write, and the offset. 5. For every texture read, the log also summarises its bytes as they are in title memory: distinct values, min, max, mean, the most common values, and the 32 bytes around the read. That shows at once whether the title found real data or memory nothing wrote. Like `land`'s reads, it leaves alone the pages the guards hold, and the first page of each 64 KiB block. It changes nothing the title sees: every page is given back as it was, on first touch, on release, or on remap. **How it helped (#4534).** The fix is the separate PR #4675. - **First run, wading into Kelly River.** The watch named one texture the title's code read and nothing copied back: a 256x256 R8_UNORM **render target** (`256x256f61`). It was read from two places in the title (`+0x50313d2`, `+0x203345d`) about ten times a second. Copy-back only ever ran for unordered-access writes, so no list of kinds could have reached it. - **Second run, with render targets copied back.** The byte summary showed the target holding 128 (calm water). Walking into the river worked, but it felt as if something was holding the player back. The summary then showed twelve more tables read only while the player entered the river (`2048x128f62`, `4096x64f62`, `4096x64f57`), all zeros. - **Third run, with those added.** Swimming, driving into the river and Veteran Hunted's crossing all worked. The watch found nothing else the title read uncopied. It took three runs from "something in the water is stale" to a fix, and no guessing at kinds. ## How it was tested - **GPU and profile:** RTX 5080, Windows 11. Series X profile, 2560x1440 output, DLSS Performance, DLSS frame generation 2x. No ray tracing. - **Before:** no way to see which textures the title's CPU reads. - **After:** the three runs above, on `0b353a75` (main of 2026-11-30 plus #3043 and #3487). Frame rate with the watch on was not measured. It is a diagnostic, and it faults once per page per period while on. - **Not seen by the watch:** reads through another view of the same pages, and reads by the kernel. - **Wave sizes:** no shader changes. - **`cargo test` passed for the crates it touches:** yes, apart from tests that also fail on `main`: - On this commit (`dde18b0f`), `cargo test -p victory-gpu --lib -- readwatch` passes. The tests are `a_run_split_at_a_touched_page_keeps_both_sides` and `an_armed_page_opens_on_its_first_read_and_the_rest_stay_armed`. The second arms real pages, reads one through the handler, and checks that the rest stay armed and that disarming restores them. - `cargo clippy --workspace --all-targets --locked -- -D warnings` and the same with `--all-features`: clean. - `cargo test --workspace --locked --no-fail-fast`: everything passes except `victory-hle`'s `xmem::tests::a_read_by_range_waits_only_for_a_remapping_that_meets_it`. That test fails the same way on `main` (`7d93ee07`) when the crate runs as a whole, and passes alone. Open PR #2439 covers it. - On an earlier full run, `card_steps::shared_scratch_eliminates_flight_settle_end_to_end` (#2741) failed once, then passed 3 times out of 3 alone, on `main` and on this branch. ## Checked for overlap - [x] I searched the open pull requests for `VICTORY_READ_WATCH`, `read watch` and `texback`, and for the files this touches. Related: #2960 (`VICTORY_BACK_READS`, per-buffer diagnostics of the memory bridge, diagnostics builds only). That one counts buffer copy-back, refreshes and waits. It doesn't find title reads of textures, so there's no overlap. #4675 (the fix this found). This PR doesn't depend on it, and the two merge cleanly together.
A diagnostic, off by default (VICTORY_READ_WATCH=1). Each texture a draw or
dispatch writes (unordered access, render target, depth) has its title memory
made no-access about once a second; the first touch of a page faults into a
vectored handler that gives the page its protection back and notes the
texture's kind (as VICTORY_TEXTURE_BACK takes it) and the touching code's
module and offset. The frame-rate line logs each new pair, and a summary of
the bytes the title found in each texture it read.

texback.rs cites a VICTORY_READ_WATCH=1 run of the upstream trace for the
ocean's kinds, but the switch was never in this tree (the unified-memory
audit, U0). It found the render target and the twelve tables behind #4533.

Refs #4533

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01ASPnbv2evYgtuSvV5azeHT
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 01:35:52 +00:00
github-bot closed this pull request 2026-12-01 18:36:55 +00:00
Author
Owner

@⁠trustno1-coder on GitHub · 2026-12-01 18:35 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:35 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/4675#issuecomment-7321178184) 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!4676
No description provided.