Skip to content

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

Closed
Jitheswar wants to merge 1 commit into
Marvisak:mainfrom
Jitheswar:fix/marked-page-withheld-range
Closed

Jitheswar wants to merge 1 commit into
Marvisak:mainfrom
Jitheswar:fix/marked-page-withheld-range

Conversation

@Jitheswar

Copy link
Copy Markdown

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

`copy_back_marks` skipped a whole 64 KiB marked page when any withheld
range (a list whose shaders read memory with no copy) overlapped it, so
another list's valid write on that page never reached title memory:
the later per-range copy-back has no snapshot for marked pages (#1976).
One page bit cannot say whose write a byte is, so the page now goes
back as usual except the bytes inside withheld ranges, which stay as
they are in title memory and in the copy (as `keep_writes` leaves
them). The page is taken as before, so the next submission's marks on
it go back normally. Undeclared (directly indexed) writes on the page
still go back: only withheld bytes are held.

Test: two lists' writes on one marked page, the second withheld: the
first reaches title memory, the second stays in the copy only; then
the same page's next marked write goes back, a withheld range on the
other page leaves this one alone, and with nothing withheld both pages
go back.

Fixes #1976.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Calvix2k

Copy link
Copy Markdown
Contributor

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.)

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@welisonzika14-jpg

Copy link
Copy Markdown

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.

@jeremygold02

jeremygold02 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Triage verdict — Consolidate with #1998 (c14029d)

Evidence

  • The same-page regression is useful. I would keep it when choosing one GPU: a withheld range can suppress a disjoint valid marked write on the same page #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

  • GPU: keep valid marked writes beside withheld ranges #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.

@BaggyALPHA

Copy link
Copy Markdown
Contributor

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).

@Calvix2k

Copy link
Copy Markdown
Contributor

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.

@Jitheswar

Copy link
Copy Markdown
Author

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GPU: a withheld range can suppress a disjoint valid marked write on the same page

6 participants