Skip to content

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

Merged
Marvisak merged 2 commits into
Marvisak:mainfrom
BastienRodz:gpu/busy-alias-stays-changed
Nov 25, 2026
Merged

Marvisak merged 2 commits into
Marvisak:mainfrom
BastienRodz:gpu/busy-alias-stays-changed

Conversation

@BastienRodz

Copy link
Copy Markdown
Contributor

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

@DenRakEiw DenRakEiw left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified against origin/main (940d32f):

  • Keeping a page marked as changed (and preserving its saved bytes) when an alias cannot be guarded cleanly prevents missed writes.
  • cargo test -p victory-gpu watch::tests: 7/7 passed (including a_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).

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@oni-swr

oni-swr commented Nov 25, 2026

Copy link
Copy Markdown

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.

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.

@kotekompotek

Copy link
Copy Markdown

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.

@BastienRodz

Copy link
Copy Markdown
Contributor Author

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.

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 <noreply@google.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@BastienRodz
BastienRodz force-pushed the gpu/busy-alias-stays-changed branch from 0a741d6 to a96d12f Compare November 25, 2026 16:03

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

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

@fyernald fyernald left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested on real hardware: RTX 3080 (617.42), Windows 10 (19045), main 67e8ae1. 193 passed, 3 failed (victory-gpu --lib, the 3 also fail on main here). a_busy_alias_leaves_the_page_changed_and_keeps_saved_bytes passes.

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 with changed(..., save = true), #2561 with save = 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, while save = false keeps what was saved earlier. If you agree, switching that one argument would make the two equivalent, and the maintainers can take either.

…out saving

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 <noreply@anthropic.com>
@BastienRodz

Copy link
Copy Markdown
Contributor Author

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.

@fyernald fyernald left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Retested a86706c on the RTX 3080 (617.42), Windows 10 (19045), main 67e8ae1: cargo test -p victory-gpu --lib --locked -- --test-threads=1 gives 193 passed, 3 failed. The 3 also fail on main here: the heap cap (FIND-9) and the Windows 10 castable test (#1999). title_memory_aliased now marks with save = false, so this and #2561 are equivalent, and either can land.

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026
@Marvisak
Marvisak merged commit 136e39d into Marvisak:main Nov 25, 2026
1 check passed
Bebrik229 pushed a commit to Bebrik229/VIctory that referenced this pull request Nov 26, 2026
…RAM small buffers & bitmask changed_runs, water texback fence (Marvisak#999), dynamic sky ambient, screen-probe skip, watch alias/refresh fixes (Marvisak#2455/Marvisak#2377), and xgamesave fix
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GPU: taking a page while another mapping of it is busy drops it from the changed pages and its saved bytes

7 participants