GPU: a withheld range holds back only its own bytes of a marked page (#1976) #2002

Closed
Jitheswar wants to merge 1 commit from upstream-pr/2004 into main
Jitheswar commented 2026-11-25 02:44:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Jitheswar on 2026-11-25T02:44:31Z.


Fixes #1976. Claimed on #1633 at 02:21:19 UTC.

Bug: copy_back_marks skips a whole 64 KiB marked page when any withheld range (a list whose shaders read memory with no copy) overlaps it. So another list's valid write on that page never reaches title memory, because the later per-range copy_back has no snapshot for marked pages. This is exactly @yualk's fixture: same-page marked + miss retires 00 00 00 00 for both ranges.

Fix: one page bit can't say whose write a byte is, so copy_back_marked now takes the page's withheld byte ranges as holes:

  • Bytes outside the holes go back exactly as before: by the bytes the GPU changed, with or without the title's saved bytes.
  • Hole bytes stay as they are, in title memory and in the copy, as keep_writes leaves them and as the whole skipped page used to be.
  • The page is still marked taken, so its next submission's marks go back normally.
  • Undeclared (directly indexed) writes on the page still go back. Only withheld bytes are held, which is the narrow invariant the issue asks for.

Test: shadow::tests::a_withheld_range_holds_only_its_own_bytes_of_a_marked_page (synthetic, no game data):

  1. List A writes at +64 (valid) and list B at +256 (withheld) on one marked page. A reaches title memory; B doesn't, and stays in the copy.
  2. Then that page's next marked write goes back, a withheld range on the other page leaves this page alone, and with nothing withheld both pages go back.

Without the fix it fails at step 1 ([0,0,0,0] instead of [5a,5a,5a,5a]), the issue's symptom.

Compared with the two other open PRs for this issue. I ran the same test against each one's head on the same machine:

case #1986 #1998 this PR
valid A declared, B withheld, same page passes passes passes
valid A undeclared (directly indexed), B withheld A lost (0 vs 5a) passes passes
the page's next marked write, next submission lost (0 vs 3c) lost (0 vs 3c) passes
the PR's own new test on this host passes fails (withheld_ranges_are_cut_out_without_losing_the_gaps: (131122, 131152) vs (131122, 131172)) passes

The "next marked write" row is the case I got wrong first myself: leaving the page not taken keeps it marked as changed, and its next marked copy-back is then kept back as a title-changed page. Happy to have this folded into whichever PR the maintainers prefer.

Checked on an RTX 3050 6 GB Laptop (Linux, Proton 11, vkd3d-proton, real device):

  • victory-gpu tests: 130 passed / 14 failed. The 14 are identical to plain 940d32f on this host (the view heap is capped at 1,000,000, plus vkd3d root-signature refusals).
  • All 5 shadow tests pass.
  • Windows-target clippy -D warnings is clean, with and without diagnostics. cargo xtask policy passes. rustfmt adds no new differences.
  • Game: Grand Theft Auto VI, Xbox Series 1.0.2.1 (my own dump), diagnostics build. Boot and menus run at 30 fps with no panics. This card can't reach the world on main (VRAM), so the world's marked pages weren't exercised in-game.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:6595994214 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2004). Originally posted by [Jitheswar](https://github.com/Jitheswar) on 2026-11-25T02:44:31Z. --- Fixes #1976. Claimed on #1633 at 02:21:19 UTC. **Bug:** `copy_back_marks` skips a whole 64 KiB marked page when any withheld range (a list whose shaders read memory with no copy) overlaps it. So another list's valid write on that page never reaches title memory, because the later per-range `copy_back` has no snapshot for marked pages. This is exactly @yualk's fixture: same-page marked + miss retires `00 00 00 00` for both ranges. **Fix:** one page bit can't say whose write a byte is, so `copy_back_marked` now takes the page's withheld byte ranges as holes: - Bytes outside the holes go back exactly as before: by the bytes the GPU changed, with or without the title's saved bytes. - Hole bytes stay as they are, in title memory and in the copy, as `keep_writes` leaves them and as the whole skipped page used to be. - The page is still marked taken, so its next submission's marks go back normally. - Undeclared (directly indexed) writes on the page still go back. Only withheld bytes are held, which is the narrow invariant the issue asks for. **Test:** `shadow::tests::a_withheld_range_holds_only_its_own_bytes_of_a_marked_page` (synthetic, no game data): 1. List A writes at +64 (valid) and list B at +256 (withheld) on one marked page. A reaches title memory; B doesn't, and stays in the copy. 2. Then that page's next marked write goes back, a withheld range on the other page leaves this page alone, and with nothing withheld both pages go back. Without the fix it fails at step 1 (`[0,0,0,0]` instead of `[5a,5a,5a,5a]`), the issue's symptom. **Compared with the two other open PRs for this issue.** I ran the same test against each one's head on the same machine: | case | #1986 | #1998 | this PR | |---|---|---|---| | valid A declared, B withheld, same page | passes | passes | passes | | valid A **undeclared** (directly indexed), B withheld | A lost (`0` vs `5a`) | passes | passes | | the page's next marked write, next submission | lost (`0` vs `3c`) | lost (`0` vs `3c`) | passes | | the PR's own new test on this host | passes | fails (`withheld_ranges_are_cut_out_without_losing_the_gaps`: `(131122, 131152)` vs `(131122, 131172)`) | passes | The "next marked write" row is the case I got wrong first myself: leaving the page *not taken* keeps it marked as changed, and its next marked copy-back is then kept back as a title-changed page. Happy to have this folded into whichever PR the maintainers prefer. **Checked on** an RTX 3050 6 GB Laptop (Linux, Proton 11, vkd3d-proton, real device): - `victory-gpu` tests: 130 passed / 14 failed. The 14 are identical to plain `940d32f` on this host (the view heap is capped at 1,000,000, plus vkd3d root-signature refusals). - All 5 shadow tests pass. - Windows-target clippy `-D warnings` is clean, with and without `diagnostics`. `cargo xtask policy` passes. rustfmt adds no new differences. - **Game:** Grand Theft Auto VI, Xbox Series 1.0.2.1 (my own dump), diagnostics build. Boot and menus run at 30 fps with no panics. This card can't reach the world on `main` (VRAM), so the world's marked pages weren't exercised in-game. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
catminou4 commented 2026-11-25 03:03:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T02:48:44Z.

Review: COMMENTED


Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

Withheld range holds back only its own bytes of a marked page (fixes #1976) — third PR in the cluster (#1986, #1998, #2004); all three should be compared and one chosen.

<!-- greyfinch-sync:Marvisak/VIctory:review:6051087828 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2004#pullrequestreview-6051087828). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T02:48:44Z. **Review:** COMMENTED --- Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff. Withheld range holds back only its own bytes of a marked page (fixes #1976) — third PR in the cluster (#1986, #1998, #2004); all three should be compared and one chosen.
Calvix2k commented 2026-11-25 03:03:38 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-25T02:47:03Z.


Independent run on Windows 10 19045 with an RX 7800 XT (RDNA3), your head at the time of writing:

  • shadow::tests::a_withheld_range_holds_only_its_own_bytes_of_a_marked_page — ok.
  • all shadow::tests — 5 passed, 0 failed.

So the same-page case behaves the same on AMD as in yualk's NVIDIA/WARP fixture: the valid write at 64 and 128 reaches title memory, the withheld 4 bytes stay in the copy and out of title memory, and the no-withhold case publishes both pages.

On the code: clipping holes per page (a.max(page)/(a+n).min(page+PAGE)) and testing them per byte is the only thing that can be right with one page bit, and the None (no snapshot) branch keeps the “what differs is the shaders’” rule while skipping held bytes. Nothing I would change.

(The one failing test in victory-gpu --features diagnostics on this host is unrelated: the placed-view sharing test needs ID3D12Device10, absent on the Windows 10 system runtime — tracked in #1999/#2005.)

<!-- greyfinch-sync:Marvisak/VIctory:comment:7151182437 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2004#issuecomment-7151182437). Originally posted by [Calvix2k](https://github.com/Calvix2k) on 2026-11-25T02:47:03Z. --- Independent run on Windows 10 19045 with an **RX 7800 XT (RDNA3)**, your head at the time of writing: - `shadow::tests::a_withheld_range_holds_only_its_own_bytes_of_a_marked_page` — **ok**. - all `shadow::tests` — **5 passed, 0 failed**. So the same-page case behaves the same on AMD as in yualk's NVIDIA/WARP fixture: the valid write at 64 and 128 reaches title memory, the withheld 4 bytes stay in the copy and out of title memory, and the no-withhold case publishes both pages. On the code: clipping `holes` per page (`a.max(page)`/`(a+n).min(page+PAGE)`) and testing them per byte is the only thing that can be right with one page bit, and the `None` (no snapshot) branch keeps the “what differs is the shaders’” rule while skipping held bytes. Nothing I would change. (The one failing test in `victory-gpu --features diagnostics` on this host is unrelated: the placed-view sharing test needs `ID3D12Device10`, absent on the Windows 10 system runtime — tracked in #1999/#2005.)
welisonzika14-jpg commented 2026-11-25 03:03:43 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by welisonzika14-jpg on 2026-11-25T03:01:29Z.


RTX 5070 (Blackwell, driver 621.24), Ryzen 7 5700X, Windows 11, Rust 1.98.1 MSVC. No game files, unit tests only. Head c14029d (base 940d32f), cargo test -p victory-gpu --lib, run twice: 142 ok, 2 fail both times. The 2 are the view heap cap tests that main already fails on NVIDIA (#1744). The new shadow tests pass.

One note: in one earlier combined run (-p victory-gpu -p victory-shader) bindless::tests::heap_views_are_current failed once (round 0, dword 0, left: 0, right: 1064). It passed 3 times alone and in the 2 runs above, so it looks intermittent. I cannot say if this PR is involved.

#1998 covers the same issue (#1976); it also passes here.

Written with AI help (Claude/Kiro); the numbers are from runs on my machine.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7151514008 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2004#issuecomment-7151514008). Originally posted by [welisonzika14-jpg](https://github.com/welisonzika14-jpg) on 2026-11-25T03:01:29Z. --- RTX 5070 (Blackwell, driver 621.24), Ryzen 7 5700X, Windows 11, Rust 1.98.1 MSVC. No game files, unit tests only. Head `c14029d` (base `940d32f`), `cargo test -p victory-gpu --lib`, run twice: 142 ok, 2 fail both times. The 2 are the view heap cap tests that `main` already fails on NVIDIA (#1744). The new `shadow` tests pass. One note: in one earlier combined run (`-p victory-gpu -p victory-shader`) `bindless::tests::heap_views_are_current` failed once (`round 0, dword 0`, `left: 0`, `right: 1064`). It passed 3 times alone and in the 2 runs above, so it looks intermittent. I cannot say if this PR is involved. #1998 covers the same issue (#1976); it also passes here. Written with AI help (Claude/Kiro); the numbers are from runs on my machine.
BaggyALPHA commented 2026-11-25 04:06:45 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by BaggyALPHA on 2026-11-25T03:13:31Z.


I tested the next-refresh concern raised above on Windows/RTX 3080 with the same synthetic fixture on 940d32f + this PR (c14029d) and separately on 940d32f + #1998 (3385794).

  1. Mark two disjoint GPU-copy writes on the same page, withholding one range. While the page is armed, write a different value to that withheld range from the title side.
  2. Retire the first submission. Both PRs commit the allowed write and preserve the title-side value in the withheld range at this point.
  3. Refresh the page before a second submission, then mark a third, disjoint write with no withholding.

This PR failed 3/3: the refresh copied zero bytes and the second copy-back overwrote the title-side value with the previously withheld bytes. #1998 passed 3/3 and all seven shadow tests passed with the added probe.

As a causal check, I locally prevented this PR from calling taken when a page has holes. The new test passed, but the existing fixture's second write then failed in its sequence without an intervening refresh. So the guard is diagnostic evidence, not a complete patch by itself. This fixture tests the next-submission issue specifically. All inputs were synthetic, with no game files used.

AI-assisted (OpenAI Codex).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7151711003 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2004#issuecomment-7151711003). Originally posted by [BaggyALPHA](https://github.com/BaggyALPHA) on 2026-11-25T03:13:31Z. --- I tested the next-refresh concern raised above on Windows/RTX 3080 with the same synthetic fixture on `940d32f` + this PR (`c14029d`) and separately on `940d32f` + #1998 (`3385794`). 1. Mark two disjoint GPU-copy writes on the same page, withholding one range. While the page is armed, write a different value to that withheld range from the title side. 2. Retire the first submission. Both PRs commit the allowed write and preserve the title-side value in the withheld range at this point. 3. Refresh the page before a second submission, then mark a third, disjoint write with no withholding. This PR failed 3/3: the refresh copied zero bytes and the second copy-back overwrote the title-side value with the previously withheld bytes. #1998 passed 3/3 and all seven shadow tests passed with the added probe. As a causal check, I locally prevented this PR from calling `taken` when a page has holes. The new test passed, but the existing fixture's second write then failed in its sequence without an intervening refresh. So the guard is diagnostic evidence, not a complete patch by itself. This fixture tests the next-submission issue specifically. All inputs were synthetic, with no game files used. AI-assisted (OpenAI Codex).
jeremygold02 commented 2026-11-25 04:06:50 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-25T03:08:40Z.


Triage verdict — Consolidate with #1998 (c14029d)

Evidence

  • The same-page regression is useful. I would keep it when choosing one #1976 implementation. At c14029d, copy_back_marked leaves the withheld bytes different in the shadow, then still calls t.taken for a full page. It also writes the entire page span from a title snapshot, including the holes. A title write into a hole after that snapshot could be overwritten even though the GPU bytes there were withheld.

Checks and limits

  • These are source-level gaps; the existing disjoint-range test does not schedule either case.

Next step

  • #1998 gives a useful model for this part: write only the allowed spans and leave pages with withheld ranges dirty. The acceptance test I’d carry forward should check the next refresh after partial copy-back as well as byte preservation inside a hole. Also keep the different-page and no-miss controls from this PR. That would let maintainers choose one implementation without losing the stronger fixture.

This verification was AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7151632447 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2004#issuecomment-7151632447). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-25T03:08:40Z. --- **Triage verdict — Consolidate with #1998** (`c14029d`) **Evidence** - The same-page regression is useful. I would keep it when choosing one #1976 implementation. At `c14029d`, `copy_back_marked` leaves the withheld bytes different in the shadow, then still calls `t.taken` for a full page. It also writes the entire page span from a title snapshot, including the holes. A title write into a hole after that snapshot could be overwritten even though the GPU bytes there were withheld. **Checks and limits** - These are source-level gaps; the existing disjoint-range test does not schedule either case. **Next step** - #1998 gives a useful model for this part: write only the allowed spans and leave pages with withheld ranges dirty. The acceptance test I’d carry forward should check the next refresh after partial copy-back as well as byte preservation inside a hole. Also keep the different-page and no-miss controls from this PR. That would let maintainers choose one implementation without losing the stronger fixture. This verification was AI-assisted.
Calvix2k commented 2026-11-25 04:06:58 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-25T03:34:54Z.


Correction to my verification above: I only checked the first submission and the full-page/no-withhold cases, which pass. @jeremygold02's next-refresh fixture (a title-side write into a withheld range, then a refresh and a second copy-back) fails 3/3 here — the unconditional t.taken for a page with holes lets the withheld bytes come back later. So "nothing I would change" was too strong.

@Halfect's #1998 keeps the same regression and only marks a page taken when no withheld range was left different; it passes that fixture on an RTX 3080 (jeremygold02) and its six shadow tests pass on my AMD host. That is the one I would land for #1976.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7152047401 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2004#issuecomment-7152047401). Originally posted by [Calvix2k](https://github.com/Calvix2k) on 2026-11-25T03:34:54Z. --- Correction to my verification above: I only checked the first submission and the full-page/no-withhold cases, which pass. @jeremygold02's next-refresh fixture (a title-side write into a withheld range, then a refresh and a second copy-back) fails 3/3 here — the unconditional `t.taken` for a page with holes lets the withheld bytes come back later. So "nothing I would change" was too strong. @Halfect's #1998 keeps the same regression and only marks a page taken when no withheld range was left different; it passes that fixture on an RTX 3080 (jeremygold02) and its six shadow tests pass on my AMD host. That is the one I would land for #1976.
upstream-sync closed this pull request 2026-11-25 07:02:33 +00:00
Jitheswar commented 2026-11-25 07:03:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Jitheswar on 2026-11-25T06:51:56Z.


Thanks @BaggyALPHA, @jeremygold02 and @Calvix2k. You're right: calling t.taken on a page with holes lets the withheld bytes come back after a refresh and overwrite the title's write. The comparison table in my description is also out of date: #1998's current head handles the "next marked write" row I listed as lost.

I checked #1998 at b49aa3f on my machine (RTX 3050 6 GB Laptop, Linux, Proton 11, vkd3d-proton): all 7 shadow::tests pass, 3 runs out of 3, including a_title_write_does_not_suppress_the_next_marked_submission and a_withheld_range_does_not_suppress_the_pages_other_writes (the same-page fixture this PR added).

So #1998 covers everything this PR does and the case it gets wrong. I'm closing this in its favour for #1976.

AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7155239309 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2004#issuecomment-7155239309). Originally posted by [Jitheswar](https://github.com/Jitheswar) on 2026-11-25T06:51:56Z. --- Thanks @BaggyALPHA, @jeremygold02 and @Calvix2k. You're right: calling `t.taken` on a page with holes lets the withheld bytes come back after a refresh and overwrite the title's write. The comparison table in my description is also out of date: #1998's current head handles the "next marked write" row I listed as lost. I checked #1998 at `b49aa3f` on my machine (RTX 3050 6 GB Laptop, Linux, Proton 11, vkd3d-proton): all 7 `shadow::tests` pass, 3 runs out of 3, including `a_title_write_does_not_suppress_the_next_marked_submission` and `a_withheld_range_does_not_suppress_the_pages_other_writes` (the same-page fixture this PR added). So #1998 covers everything this PR does and the case it gets wrong. I'm closing this in its favour for #1976. AI-assisted (Claude Code).

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!2002
No description provided.