GPU: a page whose alias cannot be guarded stays changed #2453
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2455"
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?
Imported from Marvisak/VIctory. Originally posted by BastienRodz on 2026-11-25T13:49:41Z.
What's wrong
guard_aliasescalledprotecton a page's other mappings and dropped the result. While one mappingbof a physical page is busy with a write the guards do not see (watch::writing: kernel reads and DirectStorage writes into pool views),protectskips it.Tracked::take/takenthrough another mappingastill guardeda, removed it from the changed pages and dropped its saved bytes. Writes through the openbthen went unseen by the copy. When the write ended (Writing::drop, changed without saving), an armed page was left changed with nothing saved, andcopy_back_markeddropped the shaders' writes to it.title_memory_aliasedignoredprotect's result the same way.What the fix does
guard_aliasesreturns the pages that still have a mapping it could not guard. It returns an empty set at once when there are no aliases.takeandtakenleave those pages changed and keep their saved bytes, asprotect's own doc says for a page it cannot guard ("it stays changed"). They are taken at a later refresh, once every mapping can be guarded.title_memory_aliasedmarks the page changed (saving armed pages) when the new mapping of a guarded page cannot be guarded.Tests
New
watch::tests::a_busy_alias_leaves_the_page_changed_and_keeps_saved_bytes:a/bof one page,atracked and armed, a write under way throughb;takeandtakenthroughamust leave the page changed, a write throughbmust still be seen, and the saved bytes must survive the end of the write;Results:
main(940d32f) it fails attake must leave the page changed.watch::tests(7),shadow::tests(4) andvictory-hle'smodules::xmem::(10) pass (Wine 10, vkd3d-proton 3.1 on llvmpipe).Not tested
No title run, and no AMD/NVIDIA GPU. How often the title streams into a pool view while a copy of another mapping of the same pages is taken is not measured.
Fixes #2454
AI-assisted (Gemini 4 Neon found and wrote it, Claude Code reviewed and verified it). No game data used.
🤖 Generated with Claude Code
Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T13:54:28Z.
Review: APPROVED
Verified against
origin/main(940d32f):cargo test -p victory-gpu watch::tests: 7/7 passed (includinga_busy_alias_leaves_the_page_changed_and_keeps_saved_bytes).cargo clippy -p victory-gpu --all-targets -- -D warnings: 0 warnings.cargo xtask policy: 183 files ok.AI-assisted (Gemini 4 Neon).
Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T14:11:25Z.
Review: COMMENTED
A page whose alias cannot be guarded stays changed. 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.
Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T14:13:00Z.
Independent WARP verification of #2455 at
4b92022(fixes #2454)Commands (Rust 1.98.1, Windows 11, merged cleanly with
origin/main940d32fpergit merge-tree):cargo test -p victory-gpu --features diagnostics --lib -- --test-threads=1,cargo clippy -p victory-gpu --all-targets -- -D warnings(with and without--features diagnostics),cargo xtask policy.a_busy_alias_leaves_the_page_changed_and_keeps_saved_bytes); clippy clean both ways; policy OK.watch.rsreverted toorigin/mainwith the new test kept -> the test FAILS (assertion in the test body), so it exercises the fix.guard_aliasesnow returns the pages with an unguardable alias, andtake/takenleave them changed and keep saved bytes;title_memory_aliasedmarks the page changed whenprotectcould not guard it.title_memory_remapped), #2377 (Saved/refreshed), and #2434/#2437 (shadow.rsonly) — no textual conflicts with this PR (git merge-treeclean against #2415 and #2377). #2415 and #2455 edit different functions; #2377 addsrefreshedover the same saved bytes this PR keeps, so they are complementary. I did not run the combined stack.AI-assisted verification by Claude Code (Claude Sonnet 5.5). Software-only: Microsoft Basic Render Driver (WARP, vendor 0x1414, forced by
VICTORY_D3D12_WARP=1+--features diagnostics;warp_adapter()refuses a non-software adapter), no physical GPU, no game files, dumps or hashes.Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T14:21:05Z.
Verified on Windows 10 / GTX 1050 at
4b92022:a_busy_alias_leaves_the_page_changed_and_keeps_saved_bytespasses — twin views, real guard pages.The direction is right: an alias that cannot be guarded (a
Writingguard holds it open) must not lettake/takenmark the page clean — a write through the unguarded mapping would land unmarked and the copy-back would miss it. Keeping itchangedre-copies conservatively, andtitle_memory_aliasedmarkingchanged(save=true)when the new alias cannot be guarded is the same conservative move at registration. The test covers take, taken, saved-bytes survival, and the late-alias path.Imported from Marvisak/VIctory. Originally posted by BastienRodz on 2026-11-25T15:49:22Z.
Rebased onto main
da82e44.takeis now split intotake/take_split; thewhole.retain(..)for pages with an unguardable alias moved intotake_splitjust beforeprotect_noting. On the new main the test still fails without the fix (take must leave the page changed) and passes with it;watch::13/13,shadow::8/8.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T16:09:06Z.
Automated triage for the maintainers.
Merge candidate. In
crates/victory-gpu/src/watch.rs,guard_aliasesnow returns the pages with another mapping thatprotectcould not guard (one kept open by aWriting).Tracked::take_splitandTracked::takenleave those pages changed and keep their saved bytes, asprotect's own doc says they should. Onmain,protect's result was ignored, so such a page was taken while writes through the busy mapping were still going unseen.title_memory_aliasednow marks the page changed when the new mapping cannot be guarded. The new testa_busy_alias_leaves_the_page_changed_and_keeps_saved_bytescoverstake,taken, survival of the saved bytes and the late-alias path, and independent runs report that it fails without the fix. CIcheckpasses.On your reply: the switch to
changed(.., save = false)intitle_memory_aliasedis right by my reading. The bytes of a mapping under a write may already hold that write. Without saved bytes,shadow.rscopy_back_markedkeeps the title's bytes (its documented shortcut) rather than taking the write for the GPU's. Two notes for the maintainer: #2561 fixes the same issue (#2454) the same way and was opened later, so only one of the two should land. Unlike #2561's tests, this test does not undo the alias link it makes withtitle_memory_aliased(c, &[a]), which could leave guard state behind for later tests that reuse the address. Unlinking at the end of the test would tidy that.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by fyernald on 2026-11-25T16:41:41Z.
Review: COMMENTED
Tested on real hardware: RTX 3080 (617.42), Windows 10 (19045),
main67e8ae1. 193 passed, 3 failed (victory-gpu --lib, the 3 also fail onmainhere).a_busy_alias_leaves_the_page_changed_and_keeps_saved_bytespasses.Heads-up: #2561 is the same fix for #2454. The one difference that matters is in
title_memory_aliased: this PR marks the newly linked page withchanged(..., save = true), #2561 withsave = false. When the new mapping is busy, the write the guards can't see may already have landed through it. Saving at that point can store post-write bytes as the page's "before" copy, whilesave = falsekeeps what was saved earlier. If you agree, switching that one argument would make the two equivalent, and the maintainers can take either.Imported from Marvisak/VIctory. Originally posted by BastienRodz on 2026-11-25T16:43:34Z.
Thanks @fyernald, agreed. If the new mapping can't be guarded because a write the guards don't see is under way through it, its bytes may already hold that write, and saving them as the page's old bytes would get them taken for the GPU's at a marked copy-back.
a86706cmakestitle_memory_aliasedmark the page changed withsave = false, with a comment saying why.watch::tests13/13. That should make this and #2561 equivalent on that point.Imported from Marvisak/VIctory. Originally posted by fyernald on 2026-11-25T17:38:53Z.
Review: APPROVED
Thanks. Retested
a86706con the RTX 3080 (617.42), Windows 10 (19045),main67e8ae1:cargo test -p victory-gpu --lib --locked -- --test-threads=1gives 193 passed, 3 failed. The 3 also fail onmainhere: the heap cap (FIND-9) and the Windows 10 castable test (#1999).title_memory_aliasednow marks withsave = false, so this and #2561 are equivalent, and either can land.