Skip to content

GPU: remapping one mapping of aliased pages leaves the others guarded - #2415

Open
BastienRodz wants to merge 1 commit into
Marvisak:mainfrom
BastienRodz:gpu/remap-keeps-alias-guards
Open

BastienRodz wants to merge 1 commit into
Marvisak:mainfrom
BastienRodz:gpu/remap-keeps-alias-guards

Conversation

@BastienRodz

Copy link
Copy Markdown
Contributor

What's wrong

title_memory_remapped(at, len) marks [at, at + len) changed with changed, which also walks alias_of. So remapping or unmapping one address of aliased physical pages opens every other address that shows them, and marks their trackers changed without saving, while those addresses still show the same bytes. A copy over such an address that is armed for marked writes then loses the shaders' writes: copy_back_marked sees a changed page with nothing saved and keeps the title's bytes. A later title write there doesn't fault, so nothing is saved either.

What the fix does

  • title_memory_remapped marks only [first, last) itself (changed_here).
  • When the remapped pages' alias links are removed, a formerly linked page is opened only if no tracker holds it, directly or through an alias it still has. Without that it could stay guarded with no one tracking it.

Pages that do have a tracker stay guarded and unchanged, as they are when nothing is remapped.

Tests

New shadow::tests::remapping_an_alias_does_not_drop_marked_writes_on_the_surviving_copy: two pages mapped at a and b, a copy over a armed for marked writes, a shader-side byte written in each page, then b is remapped and the title writes page 1 through a. Both shader writes must go back, and so must the title's write.

  • On main (940d32f) it fails at the first check (page 0's shader write goes back).
  • With the fix it passes, and so do the other shadow::tests (5), watch::tests (6) and victory-hle's modules::xmem:: (10). Run under Wine 10 with vkd3d-proton 3.1 on llvmpipe: the copy needs a host device, and the test returns early without one.
  • windows-latest run on the fork: https://github.com/BastienRodz/VIctory/actions/runs/45620387821

Not tested

No title run, and no AMD/NVIDIA GPU. Whether the title unmaps one view of pages while a submission writes them through another is not measured. #2021 adds an early return for len == 0 at the top of the same function; the two combine without overlapping lines.

Fixes #2414

AI-assisted (Gemini 4 Neon found and wrote it, Claude Code reviewed and verified it). No game data used.

🤖 Generated with Claude Code

@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.

Remapping one mapping of aliased pages leaves the others guarded (twin_views regression test). 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.

@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) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP:

  • Leaving surviving mappings guarded when remapping one mapping of aliased pages cleanly prevents dropped marked writes.
  • cargo test -p victory-gpu shadow::: 5/5 passed on RTX 5090, 5/5 passed on WARP (including remapping_an_alias_does_not_drop_marked_writes_on_the_surviving_copy).
  • cargo test -p victory-gpu watch::tests: 6/6 passed.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 183 files ok.

AI-assisted (Gemini 4 Neon).

@kotekompotek

Copy link
Copy Markdown

Verified on Windows 10 / GTX 1050 at 487f6b4: remapping_an_alias_does_not_drop_marked_writes_on_the_surviving_copy passes — real twin mappings, real guard faults.

Mechanics check out:

  • changed → changed_here is the core fix: an unmap changes only what [first, last) shows; the physical pages still exist through other mappings, so marking the aliases "changed" was wrong — and its side effect (opening the survivors' guards) let the next title write through the surviving mapping land unguarded, no saved baseline, copy_back_marked then dropping the shaders' bytes.
  • The open(g, other) fallback is the right stale-guard cleanup: unguard a surviving mapping only when nothing holds it directly or through a remaining alias — a guard kept while any alias is held is still doing its job.
  • The test covers the whole chain: alias unmap → surviving guard still armed → title write saves pre-write bytes → marked merge keeps both writers' bytes on both pages.

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate. title_memory_remapped (crates/victory-gpu/src/watch.rs) now marks changed and opens only the remapped range (mark_changed + open_guarded), instead of going through changed, which also opened and marked every alias. A page that loses its alias links is opened only when no tracker holds it, directly or through a remaining alias. The new shadow::tests::remapping_an_alias_does_not_drop_marked_writes_on_the_surviving_copy covers the lost-write case.

On your reply: the rebase applies exactly the change the second look asked for after #2239 split changed_here. It matches what changed on main does for the range itself, without the alias walk. CI: passing.


Generated by Claude Code

@BastienRodz

Copy link
Copy Markdown
Contributor Author

Rebased onto main da82e44 (conflict only in the shadow tests block). On the new main the test still fails without the fix (page 0's shader write goes back) and passes with it; shadow:: 9/9, watch:: 12/12.

@Marvisak

Copy link
Copy Markdown
Owner

Automated triage for the maintainers, second look (a review against main, with the PR built and tested).

This is right as reviewed. It no longer builds on main, though: #2239, merged today, split changed_here in two. In crates/victory-gpu/src/watch.rs title_memory_remapped, changed_here(&mut g, first, last, false); becomes mark_changed(&mut g, first, last, false); open_guarded(&mut g, first, last);. With that change it was built and tested together with the rest.

Push the change and it will be reviewed again. Thank you for the contribution.

title_memory_remapped marked [first, last) changed through `changed`,
which follows alias links: every other address showing the same
physical pages was opened and its trackers marked changed, without
saving. Those addresses still show the same bytes. If a copy there was
armed for marked writes, copy_back_marked then found the page changed
with nothing saved and kept the title's bytes, dropping the shaders'
writes; and a later title write there no longer faulted to save the
page.

Mark only [first, last) (changed_here), and when its alias links go,
open a page that was guarded for them only, one no tracker holds itself
or through a remaining alias.

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/remap-keeps-alias-guards branch from 16438f4 to 5661933 Compare November 25, 2026 22:22
@BastienRodz

Copy link
Copy Markdown
Contributor Author

Rebased on main (f3578e3) as 5661933, with the change you describe: changed_here(&mut g, first, last, false) becomes mark_changed(&mut g, first, last, false); open_guarded(&mut g, first, last); in title_memory_remapped.

The shadow::tests (10, including remapping_an_alias_does_not_drop_marked_writes_on_the_surviving_copy) and watch::tests (15) pass under Wine with vkd3d-proton, and cargo clippy --workspace --all-targets --locked -- -D warnings is clean. The test conflict with #2377's partial_refresh_under_marked_range_updates_saved_bytes was positional: both tests are kept.

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: remapping one mapping of aliased pages marks the others changed, dropping marked shader writes there

5 participants