Skip to content

GPU: a page whose other mapping cannot be guarded stays changed - #2561

Closed
Calvix2k wants to merge 1 commit into
Marvisak:mainfrom
Calvix2k:codex/gpu-busy-alias-take
Closed

Calvix2k wants to merge 1 commit into
Marvisak:mainfrom
Calvix2k:codex/gpu-busy-alias-take

Conversation

@Calvix2k

Copy link
Copy Markdown
Contributor

Fixes #2454.

The failure

guard_aliases guarded the other mappings of a taken page and ignored what protect returned. While a write the guards do not see is under way through one of those mappings (watch::writing: a kernel read or a DirectStorage write), protect leaves it out — it stays open and busy. The taken page was still removed from the changed pages and its saved bytes dropped (Changed::taken), although writes through the busy mapping would not mark it until Writing::drop. A marked copy-back then found it changed with nothing saved and kept the title's bytes, dropping the shaders' writes. title_memory_aliased ignored the result the same way for the new mapping of a guarded page.

protect already documents the rule this restores: "a page that is mapped but cannot be guarded is left out (it stays changed)", and watch.rs says "taking a page guards every address showing it".

What the change does

  • guard_aliases returns the taken pages one of whose mappings was not guarded. Tracked::take and Tracked::taken leave those out: they stay changed and keep what they saved until every mapping of them can be guarded. A page is retaken on the next refresh/copy-back once the mapping is out of busy.
  • title_memory_aliased, when the new mapping of a guarded page cannot be guarded, marks the page changed without saving (changed(..., false), which follows the alias links), so the tracked mappings pick the writes up and armed bytes are kept.

A blocked page is copied as usual (the copy is correct for what the title wrote so far); only its "taken" state is kept.

Verification

  • a_page_whose_other_mapping_is_busy_is_not_taken: a tracked page taken and armed, linked to b, then a kernel write through b; a refresh takes the page meanwhile. Before: the page was taken, Changed::taken dropped its saved bytes, and changed became false. Now: it stays changed and keeps what it saved; after the write ends, b can be guarded and the page is taken. Both assertions fail on the old code.
  • linking_an_unguardable_mapping_keeps_the_tracked_page_changed: b is busy when the runtime links it to the tracked page a. Before: a stayed current and writes through b were missed; now it stays changed. Fails without the change.
  • Both tests unlink and open the alias page at the end, so tests that reuse the address do not see a guard set entry for freed memory.

cargo test -p victory-gpu --features diagnostics --lib on Windows 10 19045 / RX 7800 XT: 199 passed, 1 ignored, plus the known placed-view failure on a runtime without ID3D12Device10 (#1999, identical on main); clippy -D warnings clean. Three consecutive runs, same result.

One thing I left alone: a page guarded only through an alias (no tracker holds it) is not opened when the runtime unmaps it, so the guard set can name freed memory. That is a different change (title_memory_remapped/open of unheld pages), and the issue is about the take.

`guard_aliases` guarded the other mappings of a taken page and ignored what
`protect` returned. While a write the guards do not see is under way through
one of those mappings (`watch::writing`, a kernel read or a DirectStorage
write), `protect` leaves the page out — it stays open and busy. The taken
page was still removed from the changed pages and its saved bytes dropped
(`Changed::taken`), although writes through the busy mapping would not mark it
until `Writing::drop`; a marked copy-back then found it changed with nothing
saved and kept the title's bytes, dropping the shaders' writes (Marvisak#2454).

`guard_aliases` now returns the taken pages one of whose mappings was not
guarded, and `Tracked::take` and `Tracked::taken` leave those out: they stay
changed and keep what they saved until every mapping of them can be guarded.
`title_memory_aliased` does the same when the new mapping of a guarded page
cannot be guarded: it marks the page changed without saving, so the tracked
mappings pick the writes up and armed bytes are kept.

Tests: `a_page_whose_other_mapping_is_busy_is_not_taken` (a marked copy-back
across a busy mapping: before, the page was taken and its saved bytes went;
now it stays changed and keeps them) and
`linking_an_unguardable_mapping_keeps_the_tracked_page_changed` (the new
mapping is busier than the guard: before, the tracked page stayed current).
Both fail without the change. Lib suite: 199 passed, 1 ignored, plus the known
placed-view failure on a runtime without `ID3D12Device10` (Marvisak#1999); clippy
`-D warnings` clean.
@Calvix2k
Calvix2k force-pushed the codex/gpu-busy-alias-take branch from c316e0d to 1d5e3b1 Compare November 25, 2026 15:57
@oni-swr

oni-swr commented Nov 25, 2026

Copy link
Copy Markdown

Independent verification (software WARP only)

  • PR head: 1d5e3b1496aad4ebe02aaf2cf51b532bbab243e6 (checked out detached)
  • origin/main: 67e8ae1401df112248aed36d0024483181b718b7; read-only git merge-tree --write-tree origin/main <head> merges cleanly (exit 0); GitHub reports MERGEABLE.
  • Environment: Windows 11 Pro 10.0.26200, rustc 1.98.1, VICTORY_D3D12_WARP=1 with VICTORY_DXIL pointing at the Windows SDK 10.0.26100 dxil.dll. Default features, no extra test flags.
  • Not tested: hardware GPU, the title (no game files used).

Commands and results

  • cargo test --locked -p victory-gpu
  • focused: cargo test --locked -p victory-gpu --lib watch::tests
  • victory-gpu lib: 197 passed, 0 failed, 1 ignored. watch::tests filter: 14 passed, including a_page_whose_other_mapping_is_busy_is_not_taken and linking_an_unguardable_mapping_keeps_the_tracked_page_changed.

Review: Looks correct. guard_aliases now returns the taken pages with an unguarded alias, and take/taken skip them so they stay changed and keep their saved bytes. protect returns already-protected pages as taken, so title_memory_aliased only marks the page changed when the protect really failed or was blocked by a busy write. The page is retaken on the next refresh once the mapping is free (the first test covers that). No regressions in the crate suite.

Review and verification by Claude Code (Claude Sonnet 5.5), AI-assisted; no game files, dumps, shader names or hashes involved.

@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. cargo test -p victory-gpu --lib --locked -- --test-threads=1 gives 194 passed, 3 failed. Both new tests pass. The 3 failures also fail on main here: the heap cap (FIND-9) and the Windows 10 castable test (#1999).

This is the same fix as #2455 for #2454: guard_aliases returns the pages with an unguardable mapping, and take/taken leave those changed. The one real difference is in title_memory_aliased, and I think this PR has it right. Once a busy mapping is linked, the unseen write may already have landed through it, so changed(..., save = true) (#2455) could save post-write bytes as what the page held before. save = false keeps whatever was saved earlier and saves nothing new. This test also cleans up the global guard and alias state before freeing its pools, which matters given the parallel-run flakes in this crate. Only one of #2455 and #2561 should land.

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Proposed close: duplicate of #2455. Both PRs fix issue #2454 with the same code change in crates/victory-gpu/src/watch.rs. guard_aliases returns the pages with a mapping that could not be guarded. Tracked::take_split and Tracked::taken filter those pages out. In title_memory_aliased, the page is marked changed(.., false) when protect returns nothing. The fix itself looks correct to me. #2455 was opened first, by the person who filed the issue, and passes CI. Its test uses two real views of one page (twin_views) and also covers the Tracked::taken path. The cleanup at the end of this PR's tests (unlinking, then opening the alias page) would be a useful suggestion on #2455.

CI: the check run passed on this head.

This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the label.


Generated by Claude Code

@Calvix2k

Copy link
Copy Markdown
Contributor Author

Superseded, closing: current main already carries this fix (the busier-alias case is handled by guard_aliases returning the taken pages that must stay changed, with #2454 as the reference in watch.rs). A rebase of this branch onto main leaves zero commits, which is the clearest way to say the same thing.

Thanks to everyone who reviewed it while it was open — the diagnosis held, upstream just landed it in a different shape.

@Calvix2k Calvix2k closed this Nov 26, 2026
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

4 participants