GPU: a page whose alias cannot be guarded stays changed #2455

Manually merged
github merged 2 commits from gh-pr/2455/head into gh-pr/2455/base 2026-11-26 05:06:25 +00:00
Owner

@⁠BastienRodz on GitHub · 2026-11-25 13:49 UTC · original
BastienRodz:gpu/busy-alias-stays-changed → main · +63 −9 · 1 files · 2 commits · merged 2026-11-25 21:57 UTC

What's wrong

guard_aliases called protect on a page's other mappings and dropped the result. While one mapping b of a physical page is busy with a write the guards do not see (watch::writing: kernel reads and DirectStorage writes into pool views), protect skips it. Tracked::take/taken through another mapping a still guarded a, removed it from the changed pages and dropped its saved bytes. Writes through the open b then went unseen by the copy. When the write ended (Writing::drop, changed without saving), an armed page was left changed with nothing saved, and copy_back_marked dropped the shaders' writes to it. title_memory_aliased ignored protect's result the same way.

What the fix does

  • guard_aliases returns the pages that still have a mapping it could not guard. It returns an empty set at once when there are no aliases.
  • take and taken leave those pages changed and keep their saved bytes, as protect'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_aliased marks 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:

  • two mappings a/b of one page, a tracked and armed, a write under way through b;
  • take and taken through a must leave the page changed, a write through b must still be seen, and the saved bytes must survive the end of the write;
  • aliasing a busy mapping to the guarded page must mark it changed.

Results:

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

**@⁠BastienRodz** on GitHub · 2026-11-25 13:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/2455) `BastienRodz:gpu/busy-alias-stays-changed` → `main` · +63 −9 · 1 files · 2 commits · merged 2026-11-25 21:57 UTC ### What's wrong `guard_aliases` called `protect` on a page's other mappings and dropped the result. While one mapping `b` of a physical page is busy with a write the guards do not see (`watch::writing`: kernel reads and DirectStorage writes into pool views), `protect` skips it. `Tracked::take`/`taken` through another mapping `a` still guarded `a`, removed it from the changed pages and dropped its saved bytes. Writes through the open `b` then went unseen by the copy. When the write ended (`Writing::drop`, changed without saving), an armed page was left changed with nothing saved, and `copy_back_marked` dropped the shaders' writes to it. `title_memory_aliased` ignored `protect`'s result the same way. ### What the fix does - `guard_aliases` returns the pages that still have a mapping it could not guard. It returns an empty set at once when there are no aliases. - `take` and `taken` leave those pages changed and keep their saved bytes, as `protect`'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_aliased` marks 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`: - two mappings `a`/`b` of one page, `a` tracked and armed, a write under way through `b`; - `take` and `taken` through `a` must leave the page changed, a write through `b` must still be seen, and the saved bytes must survive the end of the write; - aliasing a busy mapping to the guarded page must mark it changed. Results: - On `main` (940d32f) it fails at `take must leave the page changed`. - With the fix, `watch::tests` (7), `shadow::tests` (4) and `victory-hle`'s `modules::xmem::` (10) pass (Wine 10, vkd3d-proton 3.1 on llvmpipe). - windows-latest run on the fork: https://github.com/BastienRodz/VIctory/actions/runs/45627451447 ### 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](https://claude.com/claude-code)
guard_aliases ignored what protect returned. While a write the guards
do not see (watch::writing: a kernel read, a DirectStorage write) is
under way through one mapping of a physical page, that mapping stays
open; taking the page through another mapping still guarded it there,
dropped it from the changed pages and dropped the bytes saved of it.
Writes through the open mapping then went unseen by the copy, and when
the write ended (changed without saving) an armed page was left
changed with nothing saved, so copy_back_marked dropped the shaders'
writes to it.

watch.rs: "taking a page guards every address showing it", and "a page
that is mapped but cannot be guarded is left out (it stays changed)".
guard_aliases now returns the pages with a mapping it could not guard;
take and taken leave those changed. title_memory_aliased marks the page
changed when the new mapping of a guarded page cannot be guarded.

Co-Authored-By: Gemini 4 Neon <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Its bytes may already hold the write under way through it; saved as the
page's old bytes, they would be taken for the GPU's at a marked
copy-back (review by fyernald).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:06:24 +00:00
github manually merged commit a86706cc40 into gh-pr/2455/base 2026-11-26 05:06:25 +00:00
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 14:13 UTC · original

Independent WARP verification of #2455 at 4b92022 (fixes #2454)

Commands (Rust 1.98.1, Windows 11, merged cleanly with origin/main 940d32f per git 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.

  • lib tests: 147 passed, 0 failed, 2 ignored (includes a_busy_alias_leaves_the_page_changed_and_keeps_saved_bytes); clippy clean both ways; policy OK.
  • Negative control: watch.rs reverted to origin/main with the new test kept -> the test FAILS (assertion in the test body), so it exercises the fix.
  • Diff matches #2454: guard_aliases now returns the pages with an unguardable alias, and take/taken leave them changed and keep saved bytes; title_memory_aliased marks the page changed when protect could not guard it.
  • Overlap: #2415 (title_memory_remapped), #2377 (Saved/refreshed), and #2434/#2437 (shadow.rs only) — no textual conflicts with this PR (git merge-tree clean against #2415 and #2377). #2415 and #2455 edit different functions; #2377 adds refreshed over 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.

**@⁠oni-swr** on GitHub · 2026-11-25 14:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/2455#issuecomment-7164934271) **Independent WARP verification of #2455 at `4b92022`** (fixes #2454) Commands (Rust 1.98.1, Windows 11, merged cleanly with `origin/main` `940d32f` per `git 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`. - lib tests: 147 passed, 0 failed, 2 ignored (includes `a_busy_alias_leaves_the_page_changed_and_keeps_saved_bytes`); clippy clean both ways; policy OK. - Negative control: `watch.rs` reverted to `origin/main` with the new test kept -> the test FAILS (assertion in the test body), so it exercises the fix. - Diff matches #2454: `guard_aliases` now returns the pages with an unguardable alias, and `take`/`taken` leave them changed and keep saved bytes; `title_memory_aliased` marks the page changed when `protect` could not guard it. - Overlap: #2415 (`title_memory_remapped`), #2377 (`Saved`/`refreshed`), and #2434/#2437 (`shadow.rs` only) — no textual conflicts with this PR (`git merge-tree` clean against #2415 and #2377). #2415 and #2455 edit different functions; #2377 adds `refreshed` over 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.
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 14:21 UTC · original

Verified on Windows 10 / GTX 1050 at 4b92022: a_busy_alias_leaves_the_page_changed_and_keeps_saved_bytes passes — twin views, real guard pages.

The direction is right: an alias that cannot be guarded (a Writing guard holds it open) must not let take/taken mark the page clean — a write through the unguarded mapping would land unmarked and the copy-back would miss it. Keeping it changed re-copies conservatively, and title_memory_aliased marking changed(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.

**@⁠kotekompotek** on GitHub · 2026-11-25 14:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/2455#issuecomment-7165142253) Verified on Windows 10 / GTX 1050 at `4b92022`: `a_busy_alias_leaves_the_page_changed_and_keeps_saved_bytes` passes — twin views, real guard pages. The direction is right: an alias that cannot be guarded (a `Writing` guard holds it open) must not let `take`/`taken` mark the page clean — a write through the unguarded mapping would land unmarked and the copy-back would miss it. Keeping it `changed` re-copies conservatively, and `title_memory_aliased` marking `changed(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.
Author
Owner

@⁠BastienRodz on GitHub · 2026-11-25 15:49 UTC · original

Rebased onto main da82e44. take is now split into take/take_split; the whole.retain(..) for pages with an unguardable alias moved into take_split just before protect_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.

**@⁠BastienRodz** on GitHub · 2026-11-25 15:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/2455#issuecomment-7167343723) Rebased onto main da82e44. `take` is now split into `take`/`take_split`; the `whole.retain(..)` for pages with an unguardable alias moved into `take_split` just before `protect_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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 16:09 UTC · original · edited 2026-11-25 18:47 UTC

Automated triage for the maintainers.

Merge candidate. In crates/victory-gpu/src/watch.rs, guard_aliases now returns the pages with another mapping that protect could not guard (one kept open by a Writing). Tracked::take_split and Tracked::taken leave those pages changed and keep their saved bytes, as protect's own doc says they should. On main, protect's result was ignored, so such a page was taken while writes through the busy mapping were still going unseen. title_memory_aliased now marks the page changed when the new mapping cannot be guarded. The new test a_busy_alias_leaves_the_page_changed_and_keeps_saved_bytes covers take, taken, survival of the saved bytes and the late-alias path, and independent runs report that it fails without the fix. CI check passes.

On your reply: the switch to changed(.., save = false) in title_memory_aliased is right by my reading. The bytes of a mapping under a write may already hold that write. Without saved bytes, shadow.rs copy_back_marked keeps 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 with title_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

**@⁠Marvisak** on GitHub · 2026-11-25 16:09 UTC · [original](https://github.com/Marvisak/VIctory/pull/2455#issuecomment-7167637774) · edited 2026-11-25 18:47 UTC <!-- victory-triage v1 head=a86706cc403121734d305f0b252ea60db56cb742 verdict=merge-candidate at=2026-11-25T18:47:16Z --> Automated triage for the maintainers. **Merge candidate.** In `crates/victory-gpu/src/watch.rs`, `guard_aliases` now returns the pages with another mapping that `protect` could not guard (one kept open by a `Writing`). `Tracked::take_split` and `Tracked::taken` leave those pages changed and keep their saved bytes, as `protect`'s own doc says they should. On `main`, `protect`'s result was ignored, so such a page was taken while writes through the busy mapping were still going unseen. `title_memory_aliased` now marks the page changed when the new mapping cannot be guarded. The new test `a_busy_alias_leaves_the_page_changed_and_keeps_saved_bytes` covers `take`, `taken`, survival of the saved bytes and the late-alias path, and independent runs report that it fails without the fix. CI `check` passes. On your reply: the switch to `changed(.., save = false)` in `title_memory_aliased` is right by my reading. The bytes of a mapping under a write may already hold that write. Without saved bytes, `shadow.rs` `copy_back_marked` keeps 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 with `title_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](https://claude.ai/code)_
Author
Owner

@⁠BastienRodz on GitHub · 2026-11-25 16:43 UTC · original

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. a86706c makes title_memory_aliased mark the page changed with save = false, with a comment saying why. watch::tests 13/13. That should make this and #2561 equivalent on that point.

**@⁠BastienRodz** on GitHub · 2026-11-25 16:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/2455#issuecomment-7168435836) 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. a86706c makes `title_memory_aliased` mark the page changed with `save = false`, with a comment saying why. `watch::tests` 13/13. That should make this and #2561 equivalent on that point.
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!2455
No description provided.