GPU: what shaders write beside a root UAV in its pages goes back to title memory #1963

Open
github-bot wants to merge 2 commits from github-bot/gh-1963 into main AGit
Owner

@⁠oVolkra on GitHub · 2026-11-25 01:47 UTC · original
oVolkra:fix/root-uav-partial-pages → main · +300 −36 · 3 files · 2 commits · open

Problem

In programs that use title memory, shaders mark the 64 KiB pages they write, and each marked page goes back after the submission. Pages that a root UAV's range touches are left out (Map::precise), since the range goes back byte for byte. That loses writes in two cases:

  • Beside the range. The whole page is skipped, but only the range's own bytes are snapshotted. Writes before its first byte or after its last one in those pages never reach title memory (the shortcut: on Map::precise). A bigger root UAV loses the rest of the page its 1 MiB window ends in.
  • Another copy owns the page. shadow::find gives the innermost buffer, but the page table names the copy holding the whole page. For a buffer that holds its page only in part inside a bigger one, what shaders write through the page table is in the bigger copy. The snapshot is of the small one, and the page is skipped: those writes are lost.

Change

  • Map::precise takes the range out to whole pages, cut to the copy, for the refresh, the snapshot and the skip alike. Only bytes the GPU changed go back, as before.
  • At submission, the pages of the range that the page table reads from another copy are declared as written in that copy too (Layout::others, Step::GpuWrites): refreshed, snapshotted, and copied back byte for byte with the existing Shadow::writing and copy_back. So the bytes written through the root UAV and those written through the page table both go back, whether or not the memory is write-watched.
  • A marked page is skipped only for a range of the copy the page table names for it, which now includes those declared pages.

The second point (e841f64) answers the triage of 9d41eb7, which was right. There the bigger copy's page went back through copy_back_page, after the root UAV's bytes. In tracked memory that write-back had marked the page changed, so the page-table writes were lost. In untracked memory the whole page went back over the root UAV's bytes.

Cost: per root UAV, at most two more pages of its own copy are snapshotted and compared (the range is up to 1 MiB), plus a page-table lookup for each page of the range at submission. Pages read from another copy are also snapshotted and compared there.

Tests

Four synthetic tests write through the page table and mark pages as translated shaders do. All pass now on an RTX 3060 (Windows 11) and on WARP.

Test Expected Before
Beside the range [1, 2, 3, 4] [0, 2, 0, 4] (main)
Another copy owns the page, page-table writes only [1, 2] [0, 0] (main)
Root UAV and page table in one page, tracked [1, 2] [1, 0] (9d41eb7)
Root UAV and page table in one page, untracked [1, 2] [0, 2] (9d41eb7)

The last two are new. They also check that the GPU wrote both copies, submit the list again and twice in one submission, and check that a title write beside those bytes is kept. With only the second point of the change turned off they fail as in the table.

On the RTX 3060:

  • cargo test --workspace --locked --no-fail-fast: the same 5 tests fail as on main, all NVIDIA ones reported before (dynamic_slots_are_held_until_released, lists_share_a_table_and_copies_keep_their_views, two stride_tests, gathers_at_a_level_match_the_hardware).
  • cargo test -p victory-gpu --locked with #1751 applied locally: 147 passed, 0 failed, 2 ignored.
  • Both clippy runs and cargo xtask policy pass.

Not verified

  • Not run with the title, and no frame time measured.

Not covered

The same loss happens when the inner copy's write is declared without Map::precise (tested by replacing that call with refresh and gpu_writes, with the same root UAV: [1, 0] tracked, [0, 2] untracked). This PR does not touch that path.

Next to #1869 and #1865, which change the lookup and the bitmap of the same loop, not which bytes go back: a textual conflict is likely, and I can rebase on whichever lands.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

**@⁠oVolkra** on GitHub · 2026-11-25 01:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/1963) `oVolkra:fix/root-uav-partial-pages` → `main` · +300 −36 · 3 files · 2 commits · open ## Problem In programs that use title memory, shaders mark the 64 KiB pages they write, and each marked page goes back after the submission. Pages that a root UAV's range touches are left out (`Map::precise`), since the range goes back byte for byte. That loses writes in two cases: - **Beside the range.** The whole page is skipped, but only the range's own bytes are snapshotted. Writes before its first byte or after its last one in those pages never reach title memory (the `shortcut:` on `Map::precise`). A bigger root UAV loses the rest of the page its 1 MiB window ends in. - **Another copy owns the page.** `shadow::find` gives the innermost buffer, but the page table names the copy holding the whole page. For a buffer that holds its page only in part inside a bigger one, what shaders write through the page table is in the bigger copy. The snapshot is of the small one, and the page is skipped: those writes are lost. ## Change - `Map::precise` takes the range out to whole pages, cut to the copy, for the refresh, the snapshot and the skip alike. Only bytes the GPU changed go back, as before. - At submission, the pages of the range that the page table reads from another copy are declared as written in that copy too (`Layout::others`, `Step::GpuWrites`): refreshed, snapshotted, and copied back byte for byte with the existing `Shadow::writing` and `copy_back`. So the bytes written through the root UAV and those written through the page table both go back, whether or not the memory is write-watched. - A marked page is skipped only for a range of the copy the page table names for it, which now includes those declared pages. The second point (`e841f64`) answers the triage of `9d41eb7`, which was right. There the bigger copy's page went back through `copy_back_page`, after the root UAV's bytes. In tracked memory that write-back had marked the page changed, so the page-table writes were lost. In untracked memory the whole page went back over the root UAV's bytes. Cost: per root UAV, at most two more pages of its own copy are snapshotted and compared (the range is up to 1 MiB), plus a page-table lookup for each page of the range at submission. Pages read from another copy are also snapshotted and compared there. ## Tests Four synthetic tests write through the page table and mark pages as translated shaders do. All pass now on an RTX 3060 (Windows 11) and on WARP. | Test | Expected | Before | |---|---|---| | Beside the range | `[1, 2, 3, 4]` | `[0, 2, 0, 4]` (`main`) | | Another copy owns the page, page-table writes only | `[1, 2]` | `[0, 0]` (`main`) | | Root UAV and page table in one page, tracked | `[1, 2]` | `[1, 0]` (`9d41eb7`) | | Root UAV and page table in one page, untracked | `[1, 2]` | `[0, 2]` (`9d41eb7`) | The last two are new. They also check that the GPU wrote both copies, submit the list again and twice in one submission, and check that a title write beside those bytes is kept. With only the second point of the change turned off they fail as in the table. On the RTX 3060: - `cargo test --workspace --locked --no-fail-fast`: the same 5 tests fail as on `main`, all NVIDIA ones reported before (`dynamic_slots_are_held_until_released`, `lists_share_a_table_and_copies_keep_their_views`, two `stride_tests`, `gathers_at_a_level_match_the_hardware`). - `cargo test -p victory-gpu --locked` with #1751 applied locally: 147 passed, 0 failed, 2 ignored. - Both clippy runs and `cargo xtask policy` pass. ## Not verified - Not run with the title, and no frame time measured. ## Not covered The same loss happens when the inner copy's write is declared without `Map::precise` (tested by replacing that call with `refresh` and `gpu_writes`, with the same root UAV: `[1, 0]` tracked, `[0, 2]` untracked). This PR does not touch that path. Next to #1869 and #1865, which change the lookup and the bitmap of the same loop, not which bytes go back: a textual conflict is likely, and I can rebase on whichever lands. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
A marked page touched by a root UAV's range is left to the range's
byte-for-byte copy-back, which covered only the range's own bytes: what
shaders wrote elsewhere in its first and last page was lost. The range is
taken out to whole pages of its copy. A page another copy is read from
(a buffer holding it in part inside a bigger one) goes back as any other
marked page: the range's snapshot is of a copy the shaders do not write.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A root UAV on a buffer that holds its page in part goes back from that
buffer's copy, the page from the bigger one the page table names. The first
marks the page changed, so the second kept the title's bytes and lost what
shaders wrote through the table; in memory that is not tracked it put its
whole page back over the root UAV's bytes. At submission the pages of the
range read from another copy are now declared as written there too, and go
back by their bytes before and after the run.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:50:15 +00:00
Author
Owner

@⁠DesertGamer on GitHub · 2026-11-25 02:17 UTC · original

VIctory V2: community PRs, merged and tested

Open PRs sitting in the queue? V2 pulls them into one build, screens each one (binaries, build scripts, hooks, new deps) and runs tests after every batch.

Where it stands today: launches, runs the menu at 30 fps, plays the intro video, reaches the start screen and loads the world (~50 s). Entering the world is the current blocker: rendering fails with a GPU "device removed" error (tracked in issue #1).

⚠️ Entering the world on a real GPU can hang it and make Windows reset the driver. Try it at your own risk.

Not playable yet, but every batch of merged fixes moves it closer. If you have a PR that's stuck, or a GPU to test on, I'd love your help:
https://DesertGamer/VIctory-V2

Unofficial community fork of Marvisak/VIctory, GPL-3.0.

**@⁠DesertGamer** on GitHub · 2026-11-25 02:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/1963#issuecomment-7150542458) ### VIctory V2: community PRs, merged and tested Open PRs sitting in the queue? V2 pulls them into one build, screens each one (binaries, build scripts, hooks, new deps) and runs tests after every batch. **Where it stands today:** launches, runs the menu at 30 fps, plays the intro video, reaches the start screen and loads the world (~50 s). Entering the world is the current blocker: rendering fails with a GPU "device removed" error (tracked in issue #1). :warning: Entering the world on a real GPU can hang it and make Windows reset the driver. Try it at your own risk. Not playable yet, but every batch of merged fixes moves it closer. If you have a PR that's stuck, or a GPU to test on, I'd love your help: https://DesertGamer/VIctory-V2 *Unofficial community fork of Marvisak/VIctory, GPL-3.0.*
Author
Owner

@⁠BaggyALPHA on GitHub · 2026-11-25 02:23 UTC · original

Independent synthetic verification on Windows with an RTX 3080 (driver 621.24). I tested this PR at 9d41eb7 on 940d32f with #1751 (4521591) applied to clear the two already-reproduced NVIDIA descriptor-heap failures.

  • cargo test -p victory-gpu --locked -- --test-threads=1: 145 passed, 0 failed, 2 ignored. Both root UAV copy-back regressions passed.
  • As a negative control I kept both tests and temporarily restored the pre-fix range and page-skip logic locally. Both tests failed with the same data loss described in the PR. This confirms the tests exercised the hardware path on this setup.

All inputs were synthetic. No title run or frame timing was performed.

AI-assisted (OpenAI Codex).

**@⁠BaggyALPHA** on GitHub · 2026-11-25 02:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/1963#issuecomment-7150651216) Independent synthetic verification on Windows with an RTX 3080 (driver 621.24). I tested this PR at `9d41eb7` on `940d32f` with #1751 (`4521591`) applied to clear the two already-reproduced NVIDIA descriptor-heap failures. - `cargo test -p victory-gpu --locked -- --test-threads=1`: 145 passed, 0 failed, 2 ignored. Both root UAV copy-back regressions passed. - As a negative control I kept both tests and temporarily restored the pre-fix range and page-skip logic locally. Both tests failed with the same data loss described in the PR. This confirms the tests exercised the hardware path on this setup. All inputs were synthetic. No title run or frame timing was performed. AI-assisted (OpenAI Codex).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 08:21 UTC · original · edited 2026-11-26 01:20 UTC

Automated triage for the maintainers.

Merge candidate. The head is rebased (2a3016a) and merges cleanly into current main. It removes the shortcut: on Map::precise (memory.rs). The root UAV range is now widened to whole 64 KiB pages, cut to the copy, for the refresh, the gpu_writes snapshot and the marked-page skip alike. A new Step::GpuWrites (host.rs) uses Layout::others to find, at submission, the pages of that range that the page table reads from another copy. It declares them written in that copy too, so they go back byte for byte through the existing Shadow::writing/copy_back. The missed-page skip now matches on the copy as well as the address. main's #2172 widened marked refreshes but left this shortcut in place, so the PR does not duplicate it. The four synthetic tests cover the data loss the PR describes, including the same-page tracked and untracked cases from the earlier triage. CI (check) passes on this head.

Nit: the doc comment above none_missed in memory.rs tests is over-indented.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 08:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/1963#issuecomment-7156935884) · edited 2026-11-26 01:20 UTC <!-- victory-triage v1 head=2a3016a423dadcce85eafc2d0b75bfeb1202e36a verdict=merge-candidate at=2026-11-26T01:20:10Z --> Automated triage for the maintainers. **Merge candidate.** The head is rebased (`2a3016a`) and merges cleanly into current `main`. It removes the `shortcut:` on `Map::precise` (`memory.rs`). The root UAV range is now widened to whole 64 KiB pages, cut to the copy, for the refresh, the `gpu_writes` snapshot and the marked-page skip alike. A new `Step::GpuWrites` (`host.rs`) uses `Layout::others` to find, at submission, the pages of that range that the page table reads from another copy. It declares them written in that copy too, so they go back byte for byte through the existing `Shadow::writing`/`copy_back`. The missed-page skip now matches on the copy as well as the address. `main`'s #2172 widened marked refreshes but left this shortcut in place, so the PR does not duplicate it. The four synthetic tests cover the data loss the PR describes, including the same-page tracked and untracked cases from the earlier triage. CI (`check`) passes on this head. Nit: the doc comment above `none_missed` in `memory.rs` tests is over-indented. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠oVolkra on GitHub · 2026-11-25 10:40 UTC · original

Update for the triage of 9d41eb7: it was right about the second case, and e841f64 fixes it.

Reproduced. Two new tests write through the root UAV on the inner copy and through the page table in the same page. Expected [1, 2]; 9d41eb7 gave [1, 0] in tracked memory and [0, 2] in untracked memory, as described.

Fix. At submission, the pages of the root UAV's range that the page table reads from another copy are declared as written in that copy too. They are snapshotted and go back byte for byte, so both writes are kept (the first option suggested).

Tests. The four root UAV tests pass on an RTX 3060 and on WARP. With this fix turned off the two new ones fail again with the values above. cargo test -p victory-gpu --locked with #1751 applied locally: 147 passed, 0 failed, 2 ignored. Without it, only the two NVIDIA descriptor-heap tests fail. Both clippy runs and cargo xtask policy pass, and CI passes on e841f64.

Not run with the title, and no frame time measured. A similar loss remains for writes declared without Map::precise, which this PR does not touch. The description is updated with the details.

AI-assisted (Claude Code).

**@⁠oVolkra** on GitHub · 2026-11-25 10:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/1963#issuecomment-7160011046) Update for the triage of `9d41eb7`: it was right about the second case, and `e841f64` fixes it. **Reproduced.** Two new tests write through the root UAV on the inner copy and through the page table in the same page. Expected `[1, 2]`; `9d41eb7` gave `[1, 0]` in tracked memory and `[0, 2]` in untracked memory, as described. **Fix.** At submission, the pages of the root UAV's range that the page table reads from another copy are declared as written in that copy too. They are snapshotted and go back byte for byte, so both writes are kept (the first option suggested). **Tests.** The four root UAV tests pass on an RTX 3060 and on WARP. With this fix turned off the two new ones fail again with the values above. `cargo test -p victory-gpu --locked` with #1751 applied locally: 147 passed, 0 failed, 2 ignored. Without it, only the two NVIDIA descriptor-heap tests fail. Both clippy runs and `cargo xtask policy` pass, and CI passes on `e841f64`. Not run with the title, and no frame time measured. A similar loss remains for writes declared without `Map::precise`, which this PR does not touch. The description is updated with the details. AI-assisted (Claude Code).
Author
Owner

@⁠oVolkra on GitHub · 2026-11-25 19:21 UTC · original · edited 2026-11-25 22:49 UTC

Rebased onto main (219878a) to resolve the merge conflicts.

The two failing GPU tests (dynamic_slots_are_held_until_released and lists_share_a_table_and_copies_keep_their_views) also fail on main without these changes.

**@⁠oVolkra** on GitHub · 2026-11-25 19:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/1963#issuecomment-7172192733) · edited 2026-11-25 22:49 UTC Rebased onto `main` (219878a) to resolve the merge conflicts. The two failing GPU tests (`dynamic_slots_are_held_until_released` and `lists_share_a_table_and_copies_keep_their_views`) also fail on `main` without these changes.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

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