GPU: remember which title memory is view memory until it is remapped #1277
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!1277
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1277/head"
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?
@TG0000 on GitHub · 2026-11-24 17:02 UTC · original
TG0000:perf/view-memory-cache→main· +159 −22 · 3 files · 1 commits · closed without mergingWhy
The write guards ask
VirtualQuerywhether a range is view memory at each check, about 900 times in a world frame. In the title's big heap each call walks the page tables.What
Measured
Time of a looped world frame's submissions (preparation, GPU, copy-back), all ways in one launch, RX 6800 on Windows; 8 frames, each repeated with every way. This is not frame time, and nothing here is an fps claim. One launch, one area, in a build of
mainwith measuring tools and other local changes, the same in every row.Medians of the paired differences with the range over the 8 frames; a control (same switches, another order) differed by 9 ms. A build that also asked each time found no wrong answer in 23,140 checks in the world.
Tests
remapped_memory_is_asked_about_again,a_check_during_the_unmapping_leaves_nothing_behind(fails when the report comes before the unmapping).cargo test --workspace --locked(344 passed), clippy with-D warningswith and without--all-featureson Windows, clippy on macOS: pass at6739366.Overlap and conflicts
kernel_will_writeandwatch.rs, #1122 the guards of all views of physical pages and the unmapping inxmem.rs: both conflict here. If either goes in first I rebase.Not verified
AI-assisted (Claude Code).
🤖 Generated with Claude Code
@adamdotpy on GitHub · 2026-11-24 20:09 UTC · original
Reviewed at head
6739366(worktree on the PR head, isolated target dir, Windows 11 / Rust 1.98.1). Findings, ranked:1. The caching is correct about invalidation.
guard()now remembers, per block, that the memory is a mapped view (Guards.views), so the world heap's ~900 checks per frame skip theVirtualQuery(the 60–130 ms you measured). The cache is dropped for a range ontitle_memory_remapped, and aremapscounter handles the check-in-flight race:guard()drops the lock for the query, re-locks, and only records the answer ifremapsis unchanged — so a remap that happened during the query discards the stale answer instead of caching it for good.2. The unmap path fixes a real ordering bug.
xmem::unmappreviously calledtitle_memory_remappedbeforeUnmapViewOfFile2, so aguard()racing inside that window would query the still-mapped view, guard the blocks, and remember them — for good, since the later clearing had already run. The newunmap_title_view(exported fromvictory-gpu) unmaps first and then forgets viatitle_memory_remapped, and themapfailure path uses it too. The newa_check_during_the_unmapping_leaves_nothing_behindtest pins exactly that interleaving (guard during unmap → after,views/protected/cleanare empty for the range, the nextguardreturnsNone, and fresh private memory at the same addresses is not guarded).remapped_memory_is_asked_about_againpins the cache-and-invalidate behavior. Both pass here, plus the pre-existing watch tests:cargo test -p victory-gpu --lib watch5 passed.3. Full checks on
6739366:cargo test -p victory-gpu52 passed / 0 failed / 1 ignored;cargo test -p victory-hle94 passed + 1 integration suite, 0 failed;cargo clippy -p victory-gpu -p victory-hle --all-targets --all-features --locked -- -D warningsclean;cargo build --release -p victorybuilds.rustfmt --check:xmem.rsclean,watch.rshas 8 hunks vs main's 2 pre-existing — about 6 are in the new code (cosmetic; CI has no fmt job).4. One residual race, noted not blocking: if a remap lands between
guard()'s query and its re-lock, the query answer is discarded for theviewscache but the block loop still guards based on the stale (pre-remap)MEM_MAPPEDanswer. The fault handler re-queries at write time and unguards non-view memory, so it self-heals on first touch; makingguard()re-query whenremapschanged would close it fully if you want zero window.Nothing found that would block this.
@Marvisak on GitHub · 2026-11-25 00:36 UTC · original
Automated triage for the maintainers. Closing because this change is already in
main, ormainhas since replaced the code it patches.Caches the per-check view query of the old guard; main has no per-check query (trackers ask once when made) and remapping is reported by the runtime.
If this is mistaken, reply here with what was missed (or push a change and say so) and it will be looked at again. Thank you for the contribution.
Pull request closed