GPU: hash and detile unwatched textures from a kernel-read copy #143

Closed
github-bot wants to merge 3 commits from gh-pr/143/head into gh-pr/143/base
Owner

@⁠AndyLatimer on GitHub · 2026-11-24 00:57 UTC · original
AndyLatimer:fix/gpu-texture-hash-unmapped → main · +21 −2 · 1 files · 3 commits · closed without merging

Staging::refresh_now (crates/victory-gpu/src/texture.rs) has two paths for a sampled texture's memory:

  • Watched path: reads it through copy_mapped (ReadProcessMemory), which reports unmapped pages instead of faulting.
  • Unwatched path: the physical-page views of the texture pool. It checked committed() and then read the memory directly, twice: once for blake3::hash and once for detile.

If the title unmaps those pages between the check and the reads, the read faults. That happens, for example, when it evicts a texture that a big descriptor table still lists, because the GPU would never sample it. The vectored handler in watch.rs takes only write faults, so the process dies.

The unwatched path now reads through copy_mapped as well. Unmapped pages come back as zeros. The copy goes into a per-thread scratch buffer that is reused between textures, so no CPU copy is kept per texture (keeping one in Last::read, as the watched path does, would hold a copy of every sampled texture in the pool). The committed() early-out stays. The hash and detile code moved unchanged into Staging::changed.

Cost: one extra copy of each hashed texture per refresh, on top of the hash's own read. I have not measured it in game. The diagnostics copy statistics (MoveUs, TexHashed) show it.

Testing

  • cargo test -p victory-gpu: 43 passed, 1 ignored, with this commit rebased onto d2a4bae. That commit includes #129, which fixed the duplicate mod tests in host.rs that kept victory-gpu's tests from building on the branch's base 9aef3d9.
  • cargo test --workspace --exclude victory-gpu on the branch: 221 passed, 3 ignored (need external files).
  • cargo clippy -p victory-gpu --all-targets and cargo clippy -p victory --features diagnostics: no new warnings. The ones in host.rs:267 (test code) and xmem.rs are on main.
  • cargo xtask policy: pass. rustfmt --check on texture.rs: clean.
  • No new test: the race needs pages unmapped by another thread mid-read. Not run against a title.

🤖 Generated with Claude Code

**@⁠AndyLatimer** on GitHub · 2026-11-24 00:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/143) `AndyLatimer:fix/gpu-texture-hash-unmapped` → `main` · +21 −2 · 1 files · 3 commits · closed without merging `Staging::refresh_now` (`crates/victory-gpu/src/texture.rs`) has two paths for a sampled texture's memory: - **Watched path:** reads it through `copy_mapped` (`ReadProcessMemory`), which reports unmapped pages instead of faulting. - **Unwatched path:** the physical-page views of the texture pool. It checked `committed()` and then read the memory directly, twice: once for `blake3::hash` and once for `detile`. If the title unmaps those pages between the check and the reads, the read faults. That happens, for example, when it evicts a texture that a big descriptor table still lists, because the GPU would never sample it. The vectored handler in `watch.rs` takes only write faults, so the process dies. The unwatched path now reads through `copy_mapped` as well. Unmapped pages come back as zeros. The copy goes into a per-thread scratch buffer that is reused between textures, so no CPU copy is kept per texture (keeping one in `Last::read`, as the watched path does, would hold a copy of every sampled texture in the pool). The `committed()` early-out stays. The hash and detile code moved unchanged into `Staging::changed`. Cost: one extra copy of each hashed texture per refresh, on top of the hash's own read. I have not measured it in game. The `diagnostics` copy statistics (`MoveUs`, `TexHashed`) show it. ## Testing - `cargo test -p victory-gpu`: 43 passed, 1 ignored, with this commit rebased onto `d2a4bae`. That commit includes #129, which fixed the duplicate `mod tests` in `host.rs` that kept `victory-gpu`'s tests from building on the branch's base `9aef3d9`. - `cargo test --workspace --exclude victory-gpu` on the branch: 221 passed, 3 ignored (need external files). - `cargo clippy -p victory-gpu --all-targets` and `cargo clippy -p victory --features diagnostics`: no new warnings. The ones in `host.rs:267` (test code) and `xmem.rs` are on `main`. - `cargo xtask policy`: pass. `rustfmt --check` on `texture.rs`: clean. - No new test: the race needs pages unmapped by another thread mid-read. Not run against a title. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Textures in memory with no write watch (the physical-page views of the
texture pool) were checked with committed() and then read directly,
twice (hash, detile). A title unmapping those pages in between, for
example evicting a texture a big descriptor table still lists, faulted
on the read, and the vectored handler takes only writes. The memory is
now read through copy_mapped (ReadProcessMemory, zeros for unmapped
pages), as the watched path already does, into a per-thread scratch
buffer reused between textures.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Rename the thread-local SCRATCH buffer in crates/victory-gpu/src/texture.rs to UNWATCHED_SCRATCH so PR #143 composes cleanly with PR #472's static SCRATCH mutex without an E0428 duplicate-definition error (flagged by @mercuryVM).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:52:05 +00:00
github-bot closed this pull request 2026-11-26 03:52:05 +00:00
Author
Owner

@⁠jeremygold02 on GitHub · 2026-11-24 04:36 UTC · original

Tested head 652f06057d13bb183ff64d48806205d25f9debd2:

  • cargo test -p victory-gpu --lib texture -- --test-threads=1 was blocked before running tests by E0428: crates/victory-gpu/src/host.rs defines mod tests twice (lines 252 and 1974; PR head).
  • cargo check -p victory-gpu passed.

#143 changes only crates/victory-gpu/src/texture.rs; host.rs is unchanged from this branch's base. The duplicate is not present on current upstream d2a4bae1 (main host.rs, which has one test module). Texture unit tests could not run until the branch is updated to a base without that duplicate.

**@⁠jeremygold02** on GitHub · 2026-11-24 04:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/143#issuecomment-7122168764) Tested head `652f06057d13bb183ff64d48806205d25f9debd2`: - `cargo test -p victory-gpu --lib texture -- --test-threads=1` was blocked before running tests by `E0428`: `crates/victory-gpu/src/host.rs` defines `mod tests` twice (lines 252 and 1974; [PR head](https://github.com/Marvisak/VIctory/blob/652f06057d13bb183ff64d48806205d25f9debd2/crates/victory-gpu/src/host.rs)). - `cargo check -p victory-gpu` passed. #143 changes only `crates/victory-gpu/src/texture.rs`; `host.rs` is unchanged from this branch's base. The duplicate is not present on current upstream `d2a4bae1` ([main `host.rs`](https://github.com/Marvisak/VIctory/blob/d2a4bae1f49533ef5cb512fd1b1ba1513f2e1989/crates/victory-gpu/src/host.rs), which has one test module). Texture unit tests could not run until the branch is updated to a base without that duplicate.
Author
Owner

@⁠AndyLatimer on GitHub · 2026-11-24 07:47 UTC · original

Thanks @⁠jeremygold02. The duplicate mod tests came from this branch's old base (9aef3d9); upstream fixed it in #129. I merged main (d2a4bae) into the branch, new head 8d9e40f, without changing the fix. cargo test -p victory-gpu --lib now builds and passes here: 43 passed, 1 ignored.

**@⁠AndyLatimer** on GitHub · 2026-11-24 07:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/143#issuecomment-7125366096) Thanks @⁠jeremygold02. The duplicate `mod tests` came from this branch's old base (`9aef3d9`); upstream fixed it in #129. I merged `main` (`d2a4bae`) into the branch, new head `8d9e40f`, without changing the fix. `cargo test -p victory-gpu --lib` now builds and passes here: 43 passed, 1 ignored.
Author
Owner

@⁠AndyLatimer on GitHub · 2026-11-24 11:20 UTC · original

Thanks @⁠mercuryVM for the review and the heads-up about the SCRATCH name collision with #472!

Renamed the thread-local buffer in crates/victory-gpu/src/texture.rs to UNWATCHED_SCRATCH in 525a713 so both branches compose cleanly without an E0428 duplicate definition.

Verified on Windows 11 (rustc 1.98.1):

  • cargo test -p victory-gpu: 43 passed, 0 failed, 1 ignored
  • cargo test -p victory-gpu --features diagnostics: 45 passed, 0 failed, 1 ignored
  • cargo clippy -p victory-gpu --lib -- -D warnings (default and --features diagnostics), rustfmt --edition 2024 --check crates/victory-gpu/src/texture.rs, cargo xtask policy: clean
**@⁠AndyLatimer** on GitHub · 2026-11-24 11:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/143#issuecomment-7129967744) Thanks @⁠mercuryVM for the review and the heads-up about the `SCRATCH` name collision with #472! Renamed the thread-local buffer in `crates/victory-gpu/src/texture.rs` to `UNWATCHED_SCRATCH` in `525a713` so both branches compose cleanly without an `E0428` duplicate definition. Verified on Windows 11 (`rustc 1.98.1`): - `cargo test -p victory-gpu`: 43 passed, 0 failed, 1 ignored - `cargo test -p victory-gpu --features diagnostics`: 45 passed, 0 failed, 1 ignored - `cargo clippy -p victory-gpu --lib -- -D warnings` (default and `--features diagnostics`), `rustfmt --edition 2024 --check crates/victory-gpu/src/texture.rs`, `cargo xtask policy`: clean

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/Marvisak--VIctory!143
No description provided.