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

Closed
Calvix2k wants to merge 1 commit from upstream-pr/2561 into main
Calvix2k commented 2026-11-25 15:49:41 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-25T15:49:41Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5494596563 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2561). Originally posted by [Calvix2k](https://github.com/Calvix2k) on 2026-11-25T15:49:41Z. --- 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.
fyernald commented 2026-11-25 16:41:36 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fyernald on 2026-11-25T16:41:36Z.

Review: APPROVED


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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6061367654 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2561#pullrequestreview-6061367654). Originally posted by [fyernald](https://github.com/fyernald) on 2026-11-25T16:41:36Z. **Review:** APPROVED --- 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.
oni-swr commented 2026-11-25 17:05:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T16:13:43Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7167704532 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2561#issuecomment-7167704532). Originally posted by [oni-swr](https://github.com/oni-swr) on 2026-11-25T16:13:43Z. --- **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.
Marvisak commented 2026-11-25 19:06:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T18:39:57Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7171223574 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2561#issuecomment-7171223574). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T18:39:57Z. --- <!-- victory-triage v1 head=1d5e3b1496aad4ebe02aaf2cf51b532bbab243e6 verdict=proposed-close at=2026-11-25T18:39:44Z --> 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](https://claude.ai/code)_
Calvix2k commented 2026-11-26 18:53:27 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-26T18:53:27Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7200964033 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2561#issuecomment-7200964033). Originally posted by [Calvix2k](https://github.com/Calvix2k) on 2026-11-26T18:53:27Z. --- 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.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!2559
No description provided.