GPU: a fast content digest for untracked textures, and their commit check kept per remap epoch #2283

Open
github-bot wants to merge 2 commits from github-bot/gh-2283 into main AGit
Owner

@⁠alessiodeia on GitHub · 2026-11-25 09:40 UTC · original
alessiodeia:perf/texture-digest → main · +226 −14 · 4 files · 2 commits · open

Closes #916. Opened as the issue triage asked, carried onto current main (940d32f) with the unmap-race fix from that thread.

What it changes

Staging::refresh_now, for sampled textures whose memory is not tracked:

  • Digest. BLAKE3 over the whole tiled memory is replaced by a 128-bit non-cryptographic digest: four 64-bit lanes, 32 bytes per step, and a SplitMix-style finish. Its only job is to tell whether the bytes changed since the last detile.
  • Commit check per remap epoch. title_memory_remapped now advances a remap epoch. A range made only of mapped views of physical pages (MEM_MAPPED) can only change through the runtime, so a texture keeps "committed" for it until the epoch moves. Any other range is asked through VirtualQuery every time, as before. committed() keeps main's overflow and PAGE_NOACCESS/PAGE_GUARD checks.
  • Unmap race (found by @⁠DrDarkDK on #916). xmem::unmap notifies before UnmapViewOfFile2, so a refresh between the two could cache the still-mapped view under the new epoch. The new title_memory_unmapped advances it once more after the view is gone.

The bytes are still digested in full on every refresh. Pages remapped under a stable address still show as a change, which was @⁠pickles976's concern on #916.

On main the tracked/untracked split is already decided per texture (Staging::tracked), so the original issue's "known not watched" cache is no longer needed and is not part of this PR.

Numbers (RTX 2070 SUPER, Windows 11)

  • Benchmark, 160 MiB, release: BLAKE3 70.7 ms (2.26 GB/s), new digest 11.5 ms (13.9 GB/s), 6.1× (content_hash_vs_blake3_throughput, ignored by default).
  • Measured on the issue's base (ffe310e): the world frame hashed about 156 MB of untracked textures with nothing changed, about 383 ms per frame. I haven't measured the world on current main on this card, because main doesn't reach it here (#1753 removes the device first).

Tests

  • content_hash_detects_single_bit_tail_and_order_changes: single-bit flips in the 32-byte blocks, the 8-byte words and the tail, plus a swap and a length change.
  • a_mapped_range_cached_before_its_unmap_is_asked_again: walks xmem::unmap's order (notify, still Mapped, unmap, No, notify again). Negative control: with title_memory_unmapped a no-op, it fails with "a mapping cached between the notification and the unmap must not stay current".
  • cargo clippy --workspace --all-targets -D warnings: clean, with and without --all-features.
  • cargo test -p victory-gpu: 143 passed, 2 failed. Both failures, dynamic_slots_are_held_until_released and lists_share_a_table_and_copies_keep_their_views, also fail on clean main on this NVIDIA card (capped view heap), so they're unrelated.
  • cargo test -p victory-hle xmem: 10 passed.
  • cargo xtask policy: ok.
  • rustfmt --check on the touched files shows only the differences main already has.

Choosing a non-cryptographic digest for change detection is the maintainers' call, as the triage noted.

🤖 Generated with Claude Code

**@⁠alessiodeia** on GitHub · 2026-11-25 09:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/2283) `alessiodeia:perf/texture-digest` → `main` · +226 −14 · 4 files · 2 commits · open Closes #916. Opened as the issue triage asked, carried onto current `main` (`940d32f`) with the unmap-race fix from that thread. ### What it changes `Staging::refresh_now`, for sampled textures whose memory is not tracked: - **Digest.** BLAKE3 over the whole tiled memory is replaced by a 128-bit non-cryptographic digest: four 64-bit lanes, 32 bytes per step, and a SplitMix-style finish. Its only job is to tell whether the bytes changed since the last detile. - **Commit check per remap epoch.** `title_memory_remapped` now advances a remap epoch. A range made only of mapped views of physical pages (`MEM_MAPPED`) can only change through the runtime, so a texture keeps "committed" for it until the epoch moves. Any other range is asked through `VirtualQuery` every time, as before. `committed()` keeps main's overflow and `PAGE_NOACCESS`/`PAGE_GUARD` checks. - **Unmap race (found by @⁠DrDarkDK on #916).** `xmem::unmap` notifies before `UnmapViewOfFile2`, so a refresh between the two could cache the still-mapped view under the new epoch. The new `title_memory_unmapped` advances it once more after the view is gone. The bytes are still digested in full on every refresh. Pages remapped under a stable address still show as a change, which was @⁠pickles976's concern on #916. On `main` the tracked/untracked split is already decided per texture (`Staging::tracked`), so the original issue's "known not watched" cache is no longer needed and is not part of this PR. ### Numbers (RTX 2070 SUPER, Windows 11) - Benchmark, 160 MiB, release: BLAKE3 70.7 ms (2.26 GB/s), new digest 11.5 ms (13.9 GB/s), **6.1×** (`content_hash_vs_blake3_throughput`, ignored by default). - Measured on the issue's base (`ffe310e`): the world frame hashed about 156 MB of untracked textures with nothing changed, about 383 ms per frame. I haven't measured the world on current `main` on this card, because `main` doesn't reach it here (#1753 removes the device first). ### Tests - `content_hash_detects_single_bit_tail_and_order_changes`: single-bit flips in the 32-byte blocks, the 8-byte words and the tail, plus a swap and a length change. - `a_mapped_range_cached_before_its_unmap_is_asked_again`: walks `xmem::unmap`'s order (notify, still `Mapped`, unmap, `No`, notify again). Negative control: with `title_memory_unmapped` a no-op, it fails with "a mapping cached between the notification and the unmap must not stay current". - `cargo clippy --workspace --all-targets -D warnings`: clean, with and without `--all-features`. - `cargo test -p victory-gpu`: 143 passed, 2 failed. Both failures, `dynamic_slots_are_held_until_released` and `lists_share_a_table_and_copies_keep_their_views`, also fail on clean `main` on this NVIDIA card (capped view heap), so they're unrelated. - `cargo test -p victory-hle xmem`: 10 passed. - `cargo xtask policy`: ok. - `rustfmt --check` on the touched files shows only the differences `main` already has. Choosing a non-cryptographic digest for change detection is the maintainers' call, as the triage noted. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
`Staging::refresh_now` hashes the whole tiled memory of every untracked
sampled texture with BLAKE3 on every refresh, and asks VirtualQuery
region by region whether it is committed. In a world frame that was
about 156 MB hashed and ~380 ms per frame on an RTX 2070 SUPER, with
nothing changed.

- The digest is a 128-bit non-cryptographic one (four 64-bit lanes, 32
  bytes a step, a SplitMix-style finish). It only has to tell whether
  the bytes changed. On 160 MiB in release it runs at 13.9 GB/s against
  BLAKE3's 2.3 GB/s here (6.1x).
- A range made only of mapped views of physical pages (MEM_MAPPED) can
  only change through the runtime, which calls title_memory_remapped.
  That now advances a remap epoch, and a texture keeps "committed" for
  such a range until the epoch moves. Other ranges are asked every time,
  as before.
- xmem::unmap notifies before UnmapViewOfFile2. A refresh between the
  two could cache the still-mapped view under the new epoch (found by
  DrDarkDK on #916). title_memory_unmapped advances the epoch once more
  after the view is gone.

The content is still digested in full on every refresh, so pages
remapped under a stable address still show as a change.

Tests: the digest catches single-bit flips in every part of the input,
a swap and a length change. The epoch test walks xmem's order (notify,
still mapped, unmap, notify again) and fails without the second bump.
An ignored benchmark compares the two digests.

Closes #916.

Co-authored-by: BlueKaiman <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
main rewrote texture refresh (per-subresource hashes of tracked textures,
shared staging, zeros for uncommitted memory). The change is re-applied
on top of it: the content digest replaces BLAKE3 at all three hashing
sites (the untracked whole-texture digest, the zero fill's, and the
tracked per-subresource digests), and the untracked path's commit check
is kept per remap epoch for ranges of mapped views.

Co-authored-by: BlueKaiman <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:00:52 +00:00
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 13:32 UTC · original · edited 2026-11-26 00:23 UTC

Automated triage for the maintainers.

Merge candidate (worth a look; the digest choice is the maintainer's call). Updated by merging main. In Staging::refresh_now (crates/victory-gpu/src/texture.rs), BLAKE3 is replaced by content_hash, a 128-bit non-cryptographic digest, at all three change-detection sites. It only decides whether bytes changed since the last detile, so collision resistance against an adversary is not needed. The committed check is cached per remap epoch for ranges made only of MEM_MAPPED views. watch::title_memory_remapped advances the epoch, and the new title_memory_unmapped, called in xmem::unmap after UnmapViewOfFile2, closes the race between the notification and the unmap. Other ranges are queried every time as before. Tests cover bit flips, swaps and length in the digest, and the unmap order, with a negative control. CI check passes and it merges cleanly. The touched xmem code is memory mapping, not the guarded net/media modules.

On your reply: the rebase re-applies the change on main's rewritten refresh, including the new per-subresource digests, and I found no conflict left. One thing for the maintainer to weigh: the cached answer assumes a mapped view's protection changes only through the runtime's remaps; a title call that makes a mapped view PAGE_NOACCESS without a remap would not be noticed until the epoch moves.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 13:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/2283#issuecomment-7163927803) · edited 2026-11-26 00:23 UTC <!-- victory-triage v1 head=6a6dcacd974a5d27d0f3229a51f0d7cf2c3f27f0 verdict=merge-candidate at=2026-11-26T00:23:11Z --> Automated triage for the maintainers. **Merge candidate (worth a look; the digest choice is the maintainer's call).** Updated by merging `main`. In `Staging::refresh_now` (`crates/victory-gpu/src/texture.rs`), BLAKE3 is replaced by `content_hash`, a 128-bit non-cryptographic digest, at all three change-detection sites. It only decides whether bytes changed since the last detile, so collision resistance against an adversary is not needed. The `committed` check is cached per remap epoch for ranges made only of `MEM_MAPPED` views. `watch::title_memory_remapped` advances the epoch, and the new `title_memory_unmapped`, called in `xmem::unmap` after `UnmapViewOfFile2`, closes the race between the notification and the unmap. Other ranges are queried every time as before. Tests cover bit flips, swaps and length in the digest, and the unmap order, with a negative control. CI `check` passes and it merges cleanly. The touched `xmem` code is memory mapping, not the guarded `net`/`media` modules. On your reply: the rebase re-applies the change on `main`'s rewritten refresh, including the new per-subresource digests, and I found no conflict left. One thing for the maintainer to weigh: the cached answer assumes a mapped view's protection changes only through the runtime's remaps; a title call that makes a mapped view `PAGE_NOACCESS` without a remap would not be noticed until the epoch moves. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠alessiodeia on GitHub · 2026-11-25 20:36 UTC · original

Updated for current main (13f91ca) by merging it into the branch, with no force-push. Head is now 6a6dcac.

main's rewrite of the texture refresh conflicted with this PR in texture.rs. I re-applied the change on top of the new code, not on the old one:

  • The digest now replaces BLAKE3 at all three hashing sites:

    • the untracked whole-texture digest, as before;
    • the digest of the zero fill for uncommitted memory;
    • the new per-subresource digests of tracked textures, a spot main added since this PR was opened.

    All three only decide whether bytes changed since the last detile.

  • The untracked path's commit check is kept per remap epoch for ranges made only of mapped views, as before. Uncommitted memory still takes main's new zero-fill path.

  • watch.rs, lib.rs and xmem.rs merged cleanly. The epoch bump in title_memory_remapped and title_memory_unmapped after UnmapViewOfFile2 are unchanged.

Re-verified on Windows 11 with an RTX 2070 SUPER (driver 621.40):

  • workspace clippy -D warnings is clean, with and without --all-features;
  • cargo test -p victory-gpu: 195 passed, including the new texture tests. The same 2 tests that fail on clean main on this NVIDIA card (dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views, capped view heap) fail here too;
  • cargo test -p victory-hle xmem: 11 passed;
  • cargo xtask policy: ok;
  • the race test still fails with title_memory_unmapped made a no-op, and passes with it;
  • rustfmt --check adds no lines beyond those main already has.
**@⁠alessiodeia** on GitHub · 2026-11-25 20:36 UTC · [original](https://github.com/Marvisak/VIctory/pull/2283#issuecomment-7173927595) Updated for current `main` (`13f91ca`) by merging it into the branch, with no force-push. Head is now `6a6dcac`. `main`'s rewrite of the texture refresh conflicted with this PR in `texture.rs`. I re-applied the change on top of the new code, not on the old one: - **The digest now replaces BLAKE3 at all three hashing sites:** - the untracked whole-texture digest, as before; - the digest of the zero fill for uncommitted memory; - the new per-subresource digests of tracked textures, a spot `main` added since this PR was opened. All three only decide whether bytes changed since the last detile. - **The untracked path's commit check** is kept per remap epoch for ranges made only of mapped views, as before. Uncommitted memory still takes `main`'s new zero-fill path. - `watch.rs`, `lib.rs` and `xmem.rs` merged cleanly. The epoch bump in `title_memory_remapped` and `title_memory_unmapped` after `UnmapViewOfFile2` are unchanged. Re-verified on Windows 11 with an RTX 2070 SUPER (driver 621.40): - workspace clippy `-D warnings` is clean, with and without `--all-features`; - `cargo test -p victory-gpu`: 195 passed, including the new texture tests. The same 2 tests that fail on clean `main` on this NVIDIA card (`dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views`, capped view heap) fail here too; - `cargo test -p victory-hle xmem`: 11 passed; - `cargo xtask policy`: ok; - the race test still fails with `title_memory_unmapped` made a no-op, and passes with it; - `rustfmt --check` adds no lines beyond those `main` already has.
Author
Owner

@⁠DenRakEiw on GitHub · 2026-11-25 09:42 UTC · original · approved these changes

Verified locally merged onto origin/main (940d32f, Windows 11 x64, Rust 1.98.1 MSVC):

  • cargo test -p victory-gpu --lib texture:: — 4 passed, 0 failed (1 ignored), including content_hash_detects_single_bit_tail_and_order_changes
  • cargo clippy -p victory-gpu -p victory-hle --all-targets — 0 warnings
  • cargo xtask policy — ok (183 files ok)

Clean fast content digest for untracked textures and per-remap-epoch commit-check caching. Looks good.

AI-assisted (Gemini 4 Neon).

**@⁠DenRakEiw** on GitHub · 2026-11-25 09:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/2283#pullrequestreview-6055166210) · **approved these changes** Verified locally merged onto `origin/main` (`940d32f`, Windows 11 x64, Rust 1.98.1 MSVC): - `cargo test -p victory-gpu --lib texture::` — 4 passed, 0 failed (1 ignored), including `content_hash_detects_single_bit_tail_and_order_changes` - `cargo clippy -p victory-gpu -p victory-hle --all-targets` — 0 warnings - `cargo xtask policy` — ok (`183 files ok`) Clean fast content digest for untracked textures and per-remap-epoch commit-check caching. Looks good. AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠catminou4 on GitHub · 2026-11-25 10:19 UTC · original · reviewed

GPU+HLE: fast content digest (blake3 → [u64;2]) for untracked textures, plus title_memory_unmapped export. Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1.

**@⁠catminou4** on GitHub · 2026-11-25 10:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/2283#pullrequestreview-6055711041) · **reviewed** GPU+HLE: fast content digest (blake3 → [u64;2]) for untracked textures, plus title_memory_unmapped export. Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 19:44 UTC · original · approved these changes

Reviewed and verified 6a6dcacd974a5d27d0f3229a51f0d7cf2c3f27f0 merged onto origin/main (63bcca43c6a00a758510398fa43096ce7e4f7df0) on Windows 11 x64 (Ryzen 9 9950X, RTX 5090 + Microsoft WARP, --features diagnostics with VICTORY_D3D12_DEBUG=1, Rust 1.98.1 MSVC).

Code & Memory-Safety Audit

  • Audited every UnmapViewOfFile*, VirtualFree, and VirtualProtect call across crates/: xmem::unmap (crates/victory-hle/src/modules/xmem.rs:940-952) is the only path that unmaps title-visible MEM_MAPPED views (the other UnmapViewOfFile* sites in xmem.rs only unmap private temporary or rolled-back views never exposed to title code). Calling title_memory_remapped before UnmapViewOfFile2 and title_memory_unmapped (crates/victory-gpu/src/watch.rs:729-731) after it closes the window where a concurrent refresh caches Committed::Mapped under the pre-unmap epoch.
  • committed_kind (crates/victory-gpu/src/texture.rs:788-819) preserves overflow, MEM_COMMIT, and PAGE_NOACCESS | PAGE_GUARD checks, and only caches ranges whose every queried sub-region is MEM_MAPPED; any Committed::Other or Committed::No range resets last.committed_epoch = 0 (L637-652) and is re-queried every time.
  • content_hash (L889-941) uses four odd multipliers (K0..K3), distinct rotations, handles arbitrary tail lengths (0..31), and mixes bytes.len() at both init and SplitMix64 finalization. (blake3 remains used by pipeline and shader_cache, so no unused dependency is left behind.)

Local Verification

  • cargo xtask policy — pass (191 files ok).
  • cargo clippy --locked -p victory-gpu -p victory-hle --all-targets -- -D warnings (default and --all-features) — 0 warnings.
  • cargo test --locked -p victory-gpu --features diagnostics --lib texture::tests:: (RTX 5090 and WARP) — 5/5 passed (1 ignored benchmark), including content_hash_detects_single_bit_tail_and_order_changes and a_mapped_range_cached_before_its_unmap_is_asked_again.
  • cargo test --locked -p victory-hle --lib xmem — 14/14 passed.
  • Additional probe verifying distinct digests for all zero-filled lengths 0..=65, every single-bit flip across all 568 bit positions of an unaligned 71-byte buffer, last-byte flips across all 1..39 chunk/tail boundaries, and committed_kind(null, 16) == Committed::No — passed on both RTX 5090 and WARP.
  • Release throughput benchmark on Ryzen 9 9950X (content_hash_vs_blake3_throughput, 160 MiB): blake3 13.85 ms (11.55 GB/s) vs content_hash 5.12 ms (31.22 GB/s) (2.7x speedup).

Looks good to merge.

**@⁠fuzeofficlal** on GitHub · 2026-11-26 19:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/2283#pullrequestreview-6079708372) · **approved these changes** Reviewed and verified `6a6dcacd974a5d27d0f3229a51f0d7cf2c3f27f0` merged onto `origin/main` (`63bcca43c6a00a758510398fa43096ce7e4f7df0`) on Windows 11 x64 (Ryzen 9 9950X, RTX 5090 + Microsoft WARP, `--features diagnostics` with `VICTORY_D3D12_DEBUG=1`, Rust 1.98.1 MSVC). ### Code & Memory-Safety Audit - Audited every `UnmapViewOfFile*`, `VirtualFree`, and `VirtualProtect` call across `crates/`: `xmem::unmap` (`crates/victory-hle/src/modules/xmem.rs:940-952`) is the only path that unmaps title-visible `MEM_MAPPED` views (the other `UnmapViewOfFile*` sites in `xmem.rs` only unmap private temporary or rolled-back views never exposed to title code). Calling `title_memory_remapped` before `UnmapViewOfFile2` and `title_memory_unmapped` (`crates/victory-gpu/src/watch.rs:729-731`) after it closes the window where a concurrent refresh caches `Committed::Mapped` under the pre-unmap epoch. - `committed_kind` (`crates/victory-gpu/src/texture.rs:788-819`) preserves overflow, `MEM_COMMIT`, and `PAGE_NOACCESS | PAGE_GUARD` checks, and only caches ranges whose every queried sub-region is `MEM_MAPPED`; any `Committed::Other` or `Committed::No` range resets `last.committed_epoch = 0` (`L637-652`) and is re-queried every time. - `content_hash` (`L889-941`) uses four odd multipliers (`K0..K3`), distinct rotations, handles arbitrary tail lengths (`0..31`), and mixes `bytes.len()` at both init and SplitMix64 finalization. (`blake3` remains used by `pipeline` and `shader_cache`, so no unused dependency is left behind.) ### Local Verification - `cargo xtask policy` — pass (`191 files ok`). - `cargo clippy --locked -p victory-gpu -p victory-hle --all-targets -- -D warnings` (default and `--all-features`) — 0 warnings. - `cargo test --locked -p victory-gpu --features diagnostics --lib texture::tests::` (RTX 5090 and WARP) — 5/5 passed (1 ignored benchmark), including `content_hash_detects_single_bit_tail_and_order_changes` and `a_mapped_range_cached_before_its_unmap_is_asked_again`. - `cargo test --locked -p victory-hle --lib xmem` — 14/14 passed. - Additional probe verifying distinct digests for all zero-filled lengths `0..=65`, every single-bit flip across all 568 bit positions of an unaligned 71-byte buffer, last-byte flips across all `1..39` chunk/tail boundaries, and `committed_kind(null, 16) == Committed::No` — passed on both RTX 5090 and WARP. - Release throughput benchmark on Ryzen 9 9950X (`content_hash_vs_blake3_throughput`, 160 MiB): `blake3 13.85 ms (11.55 GB/s)` vs `content_hash 5.12 ms (31.22 GB/s)` (**2.7x** speedup). Looks good to merge.
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/2283/head:github-bot/gh-2283'
git switch 'github-bot/gh-2283'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2283'
git switch 'github-bot/gh-2283'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2283'
git switch 'github-bot/gh-2283'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2283'
git switch 'main'
git merge --squash 'github-bot/gh-2283'
git switch 'main'
git merge --ff-only 'github-bot/gh-2283'
git switch 'main'
git merge 'github-bot/gh-2283'
git push origin 'main'
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!2283
No description provided.