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

Open
github-bot wants to merge 1 commit from github-bot/gh-2561 into main AGit
Owner

@⁠Calvix2k on GitHub · 2026-11-25 15:49 UTC · original
Calvix2k:codex/gpu-busy-alias-take → main · +80 −9 · 1 files · 1 commits · open

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.

**@⁠Calvix2k** on GitHub · 2026-11-25 15:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/2561) `Calvix2k:codex/gpu-busy-alias-take` → `main` · +80 −9 · 1 files · 1 commits · open 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 (#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` (#1999); clippy
`-D warnings` clean.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:09:17 +00:00
Author
Owner

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

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.

**@⁠oni-swr** on GitHub · 2026-11-25 16:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/2561#issuecomment-7167704532) **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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 18:39 UTC · original

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

**@⁠Marvisak** on GitHub · 2026-11-25 18:39 UTC · [original](https://github.com/Marvisak/VIctory/pull/2561#issuecomment-7171223574) <!-- 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)_
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/watch.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2561/head:github-bot/gh-2561'
git switch 'github-bot/gh-2561'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2561'
git switch 'github-bot/gh-2561'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2561'
git switch 'github-bot/gh-2561'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2561'
git switch 'main'
git merge --squash 'github-bot/gh-2561'
git switch 'main'
git merge --ff-only 'github-bot/gh-2561'
git switch 'main'
git merge 'github-bot/gh-2561'
git push origin 'main'
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!2561
No description provided.