GPU: speed up unwatched texture refresh with fast 128-bit digest and remap-epoch caching (fix on fork) #916
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#916
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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-24 14:05 UTC · original
Problem
In world frames (measured on Windows 11 + RTX 2070 SUPER, retail 1.0.2.1, diagnostics build),
Staging::refresh_now()spends 308–416 ms/frame (average ~380 ms/frame) checking 150–156.5 MB/frame of unwatched textures in physical-page views where 0.0 MB/frame actually changed:ext 3814.5 preparing: copies 3359.1 ms 173.0 MB, textures 383.2 ms 156.5 MB textures 0.0 MB watched and changed, 156.5 MB hashed, 0.0 MB of them changedThree avoidable costs compound on every submission (~19 submissions/frame):
GetWriteWatchcalls: unlikeShadow,Stagingdid not cacheNOT_WATCHED, so every submission acquired the globalJOURNALmutex and issued a failingGetWriteWatchsyscall for every physical-page-view texture.VirtualQuerywalks:committed()walked every 64 KiB mapped view region on every submission, even when no physical-page views had been mapped or unmapped since the previous check.blake3::hash(tiled)ran over ~156 MB/frame of tiled texture bytes (~2.24 GB/s) solely for change detection.Fix
Branch:
alessiodeia/VIctory@perf/fast-texture-content-hash(commit8cb0222, cleanly based onmainffe310e)https://github.com/alessiodeia/VIctory/tree/perf/fast-texture-content-hash
crates/victory-gpu/src/watch.rs:REMAP_EPOCH: AtomicU64incremented intitle_memory_remapped()and exposed viapub(crate) fn remap_epoch() -> u64.crates/victory-gpu/src/texture.rs:watched: AtomicU8(NOT_WATCHED) toStaging, only cached aftercommitted_kind()confirms the range is committed (so initially-unmapped write-watched textures are never misclassified).committed_kind()returningCommitted::{No, Mapped, Other}. OnlyMEM_MAPPEDranges cachecommitted_epoch(since all physical-page view unmaps go throughtitle_memory_remapped());MEM_PRIVATEranges continue to callVirtualQuery. Bothcommitted_epochandwatchedinvalidate immediately whenremap_epoch()advances.blake3::hashwith a zero-dependency 4-laneu64128-bit non-cryptographic digest (as_chunks::<32>()+ SplitMix64 finalizer). Every byte is still checked on every submission, preserving identical correctness forwrite_physical/ DirectStorage writes.texture::tests::content_hash_detects_single_bit_tail_and_order_changestexture::tests::committed_kind_distinguishes_mapped_and_private_and_remap_advances_epochtexture::tests::content_hash_vs_blake3_throughput(#[ignore = "benchmark"])Verification (Windows 11)
blake3 = 71.43 ms (2.24 GB/s)->content_hash = 11.62 ms (13.77 GB/s)(6.1x faster on hashing alone, plus elimination of per-submissionGetWriteWatch+VirtualQueryoverhead onMEM_MAPPEDviews)cargo test -p victory-gpu --locked --offline -- --test-threads=1: 52 passed, 0 failed (2 ignored benchmarks)cargo clippy -p victory-gpu --all-targets -- -D warnings(default &--features diagnostics): 0 warningscargo --offline xtask policy: 154 files ok@pickles976 on GitHub · 2026-11-24 14:07 UTC · original
Two cross-project data points from the sibling runtime (ivall/xcl), where the same pipeline is open bugs and open benchmarks today — worth a look before this lands, because our #504 is precisely the trap this design can step on:\n\n1. The epoch/hash must not skip remaps. Our content-hash cache (#504, open) has three defects from the same instinct: it skips textures whose pages were remapped (data moves under a stable VA — a pure epoch cache keyed on the VAs content misses exactly this, since nobody wrote through the VA you are digesting), double-reads changed ones (hash pass + read pass over a multi-GB subresource), and caches failures (a failed upload never retries). If the "remap-epoch" is bumped only by your commit/remap paths, check the case where the title maps over a range your epoch did not observe.\n2. Digest speed is measurable and build-sensitive. Our thread (#175) has today: a release cross-build hashing at ~13 GB/s vs 2.65 GB/s on another box traced to a debug-profile build, and a same-speed repro on ntfs3 vs ntfs-3g storage — so before crediting the 128-bit digest, pin (a) release profile, (b) where the source pages live, (c) huge-page state. And a partial-detile design (#915) composes with yours: detile-per-changed-page only pays off if the changed-set is exact, which is the same correctness bar as (1) — false negatives there are corrupted textures, a much worse failure than slow loads.\n\nPosted per the shared-ledger practice; our measurements are in #175 if useful.
@alessiodeia on GitHub · 2026-11-24 14:23 UTC · original
Thanks @pickles976, both points checked against
8cb0222:1. Remaps under a stable VA. The epoch caches only two facts, never content: that a
MEM_MAPPEDrange is committed, and that it is not write-watched. The digest itself still runs over the full texture range through the VA on every refresh that reaches the hash path, so pages remapped under an unchanged VA produce a new digest and a re-detile. On your three #504 defects:VirtualQueryandwatch::writes. Every title mapping change goes throughxmem::map/xmem::unmap, and both calltitle_memory_remapped, which bumps the epoch. Ranges that are not allMEM_MAPPED(Committed::Other) never cache their commit state and are re-queried on every refresh.main. One digest pass, then a detile read only when the digest differs.committed_epochorhash, so the next refresh retries.2. Build sensitivity. Re-run pinned on Windows 11, RTX 2070 SUPER host,
--release(opt-level 3), source: a 160 MiB private heap buffer (not huge pages, not a file view):blake387.5 ms (1.83 GB/s), new digest 11.4 ms (14.0 GB/s), 7.7×. The earlier 6.1× was the same benchmark under the default test profile. In the title, the gain is bounded by the 156.5 MB/frame we digest, so it is about 383 ms → ~50 ms/frame on this box.Agreed that a false negative in the changed set would be far worse than slowness, which is why this change keeps the full-range digest instead of a page-granular skip. A per-page scheme like #915 would need the exact-changed-set guarantee you describe.
@DrDarkDK on GitHub · 2026-11-24 14:27 UTC · original
The stable-address replacement worked in my test on
8cb0222too. The staging texel picked up the new value on both WARP and RTX 4070 Ti.I found a separate issue with the cached mapping check.
xmem::unmapadvances the epoch before Windows removes the view. If a texture refresh runs between those steps, it can cache the still-mapped view under the new epoch. After the unmap, Windows reports the address as unmapped while staging still treats the cached mapping as current. I confirmed that mismatch on both adapters. In the control, a notification after the unmap made the next refresh skip the range.AI-assisted. Synthetic Windows test only, with no world-frame measurements.
@alessiodeia on GitHub · 2026-11-24 16:52 UTC · original
Thanks @DrDarkDK, you're right, and thanks for the control run.
xmem::unmapnotifies beforeUnmapViewOfFile2, so a refresh in between caches the still-mapped view under the new epoch.Fixed in
alessiodeia/VIctory@e2fba46onperf/fast-texture-content-hash. A newtitle_memory_unmappedadvances the epoch once more after the view is gone, andxmem::unmapcalls it right afterUnmapViewOfFile2. The existing call before the unmap stays because it also clears guards. A mapping cached in that window no longer matches the epoch, so the next refresh asksVirtualQueryagain and skips the range.committed_kind_distinguishes_mapped_and_private_and_remap_advances_epochnow walks your order: notify, stillMapped, unmap,No, notify again, epoch differs from the cached one.One window remains, and it is not new: a refresh that has already passed the check while another thread unmaps.
main'scommitted()followed by the read has the same gap. Closing it would take the unmap and the refresh under one lock, which seems out of scope here.Verified on Windows 11 with an RTX 2070 SUPER:
cargo test -p victory-gpu52 passed, 2 ignored;cargo test -p victory-hle xmem10 passed; workspace clippy-D warningsclean, default and--all-features;cargo xtask policyok.@Marvisak on GitHub · 2026-11-25 06:56 UTC · original · edited 2026-11-25 09:56 UTC
Automated triage for the maintainers.
The change is now open as PR #2283, carried onto current
main(940d32f) with @DrDarkDK's unmap fix (title_memory_unmappedadvances the epoch afterUnmapViewOfFile2) and a test for it. Review continues there.On
main,Staging::refresh_nowincrates/victory-gpu/src/texture.rsstill callscommittedand hashes an untracked texture's bytes withblake3::hashon every refresh. So the faster digest and the per-epoch commit check from this issue still apply. Whether a non-cryptographic digest is acceptable for change detection is for the maintainers to decide.Generated by Claude Code
@alessiodeia on GitHub · 2026-11-25 09:40 UTC · original
Opened as #2283, carried onto current
main(940d32f). It includes @DrDarkDK's unmap fix (title_memory_unmappedafterUnmapViewOfFile2) with a test that fails without it. Onmainthe tracked/untracked choice is already made per texture, so only the digest and the per-epoch commit check are left from this issue.