GPU: a fast content digest for untracked textures, and their commit check kept per remap epoch #2283
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2283
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2283"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@alessiodeia on GitHub · 2026-11-25 09:40 UTC · original
alessiodeia:perf/texture-digest→main· +226 −14 · 4 files · 2 commits · openCloses #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:title_memory_remappednow 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 throughVirtualQueryevery time, as before.committed()keeps main's overflow andPAGE_NOACCESS/PAGE_GUARDchecks.xmem::unmapnotifies beforeUnmapViewOfFile2, so a refresh between the two could cache the still-mapped view under the new epoch. The newtitle_memory_unmappedadvances 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
mainthe 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)
content_hash_vs_blake3_throughput, ignored by default).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 currentmainon this card, becausemaindoesn'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: walksxmem::unmap's order (notify, stillMapped, unmap,No, notify again). Negative control: withtitle_memory_unmappeda 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_releasedandlists_share_a_table_and_copies_keep_their_views, also fail on cleanmainon this NVIDIA card (capped view heap), so they're unrelated.cargo test -p victory-hle xmem: 10 passed.cargo xtask policy: ok.rustfmt --checkon the touched files shows only the differencesmainalready has.Choosing a non-cryptographic digest for change detection is the maintainers' call, as the triage noted.
🤖 Generated with Claude Code
13f91ca) into perf/texture-digest 6a6dcacd97@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. InStaging::refresh_now(crates/victory-gpu/src/texture.rs), BLAKE3 is replaced bycontent_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. Thecommittedcheck is cached per remap epoch for ranges made only ofMEM_MAPPEDviews.watch::title_memory_remappedadvances the epoch, and the newtitle_memory_unmapped, called inxmem::unmapafterUnmapViewOfFile2, 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. CIcheckpasses and it merges cleanly. The touchedxmemcode is memory mapping, not the guardednet/mediamodules.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 viewPAGE_NOACCESSwithout a remap would not be noticed until the epoch moves.Generated by Claude Code
@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 now6a6dcac.main's rewrite of the texture refresh conflicted with this PR intexture.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:
mainadded 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.rsandxmem.rsmerged cleanly. The epoch bump intitle_memory_remappedandtitle_memory_unmappedafterUnmapViewOfFile2are unchanged.Re-verified on Windows 11 with an RTX 2070 SUPER (driver 621.40):
-D warningsis 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 cleanmainon 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;title_memory_unmappedmade a no-op, and passes with it;rustfmt --checkadds no lines beyond thosemainalready has.@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), includingcontent_hash_detects_single_bit_tail_and_order_changescargo clippy -p victory-gpu -p victory-hle --all-targets— 0 warningscargo 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).
@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.
@fuzeofficlal on GitHub · 2026-11-26 19:44 UTC · original · approved these changes
Reviewed and verified
6a6dcacd974a5d27d0f3229a51f0d7cf2c3f27f0merged ontoorigin/main(63bcca43c6a00a758510398fa43096ce7e4f7df0) on Windows 11 x64 (Ryzen 9 9950X, RTX 5090 + Microsoft WARP,--features diagnosticswithVICTORY_D3D12_DEBUG=1, Rust 1.98.1 MSVC).Code & Memory-Safety Audit
UnmapViewOfFile*,VirtualFree, andVirtualProtectcall acrosscrates/:xmem::unmap(crates/victory-hle/src/modules/xmem.rs:940-952) is the only path that unmaps title-visibleMEM_MAPPEDviews (the otherUnmapViewOfFile*sites inxmem.rsonly unmap private temporary or rolled-back views never exposed to title code). Callingtitle_memory_remappedbeforeUnmapViewOfFile2andtitle_memory_unmapped(crates/victory-gpu/src/watch.rs:729-731) after it closes the window where a concurrent refresh cachesCommitted::Mappedunder the pre-unmap epoch.committed_kind(crates/victory-gpu/src/texture.rs:788-819) preserves overflow,MEM_COMMIT, andPAGE_NOACCESS | PAGE_GUARDchecks, and only caches ranges whose every queried sub-region isMEM_MAPPED; anyCommitted::OtherorCommitted::Norange resetslast.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 mixesbytes.len()at both init and SplitMix64 finalization. (blake3remains used bypipelineandshader_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), includingcontent_hash_detects_single_bit_tail_and_order_changesanda_mapped_range_cached_before_its_unmap_is_asked_again.cargo test --locked -p victory-hle --lib xmem— 14/14 passed.0..=65, every single-bit flip across all 568 bit positions of an unaligned 71-byte buffer, last-byte flips across all1..39chunk/tail boundaries, andcommitted_kind(null, 16) == Committed::No— passed on both RTX 5090 and WARP.content_hash_vs_blake3_throughput, 160 MiB):blake3 13.85 ms (11.55 GB/s)vscontent_hash 5.12 ms (31.22 GB/s)(2.7x speedup).Looks good to merge.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.