Skip to content

GPU: a withheld range on a marked page does not hold back valid writes there - #1986

Open
0xkn0wh3r3 wants to merge 2 commits into
Marvisak:mainfrom
0xkn0wh3r3:gpu/withheld-marked-pages-keep-valid-writes
Open

0xkn0wh3r3 wants to merge 2 commits into
Marvisak:mainfrom
0xkn0wh3r3:gpu/withheld-marked-pages-keep-valid-writes

Conversation

@0xkn0wh3r3

@0xkn0wh3r3 0xkn0wh3r3 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1976.

The problem

A list's valid write could be lost because another list's withheld range sat on the same 64 KiB page. In issue 1976, list A's bytes at offset 64 retired as zeros because list B's withheld range sat at offset 256 of the same page.

The mechanism: after a submission, copy_back_marks puts the pages that shaders marked as written through views into title memory. It skipped every page a withheld range touches. A withheld range is one whose writes stay out of title memory: a program using title memory declared it in a list that missed memory. Since a page is 64 KiB, skipping the whole page also dropped any valid list's declared write on it.

The fix

copy_back_marks now takes all of the submission's declared ranges, each with whether it goes back (host.rs passes them all instead of only the withheld ones).

  • On a page a withheld range touches, what the lists that go back declared there goes back, less the withheld ranges (Shadow::copy_back_marked with the new only argument; the ranges are cut with a new subtract helper).
  • Bytes a withheld range covers, and bytes no list declared, stay out of title memory, and the copy keeps them, as before.
  • Such a page is not taken, since the copy differs from title memory there.
  • Pages no withheld range touches go back whole, unchanged.

Marks still do not tell lists apart: a page that a withheld list and another list both wrote through views goes back unless the withheld list declared it (the existing shortcut, left as is).

Testing

  • New test shadow::tests::a_withheld_range_does_not_hold_back_a_valid_write_on_its_page: declares a valid range and a withheld one on the same marked page, plus a valid one on the next page. It fails with the old whole-page skip (the valid write on the shared page reads back [0, 0]) and passes with the change.
  • shadow::tests::subtract_cuts_ranges_and_joins_overlaps covers the range helper.
  • New test shadow::tests::a_page_that_went_back_in_part_takes_the_next_marked_writes_back: after a partial copy-back the page stays changed with no saved bytes; a second marked submission on it, refreshed as a marked view is (whole pages), takes the page, and its shader writes plus a title write made during the run reach title memory. With the refresh left out, the second write is lost, so the test would catch a path that skipped it.
  • cargo test -p victory-gpu on an RTX 5070 Ti (driver 621.24): all pass except descriptor::host::tests::dynamic_slots_are_held_until_released and memory::tests::lists_share_a_table_and_copies_keep_their_views, which fail the same way on main (the NVIDIA 1,000,000-descriptor heap cap, NVIDIA D3D12 (70564ae): stride_tests & synthetic_tests fail due to HEAP_VIEWS (2M > 1M NVIDIA limit) and Stride::Structured with rawBufferLoad #1835).
  • cargo clippy -p victory-gpu --all-targets, with and without --features diagnostics: clean.

Not covered

  • Not run with a title (no game data here).

Rebased onto 13f91ca

  • The branch is now the single marked-page commit. The second commit ("a withheld list's bytes stay out of an overlapping snapshot copy-back") is dropped because upstream 0a5be3c supersedes it: only what programs using title memory write is withheld.
  • With 0a5be3c, a range is withheld because of the program that declared it, not the whole list. The definition above is updated to match. The marked-page fix itself is unchanged: a withheld range still must not hold back the valid writes on its 64 KiB page.
  • host.rs now passes all of back to copy_back_marks. The separate withheld list (and its slot in release_later) is gone.

@DesertGamer

Copy link
Copy Markdown

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.

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor

I found one more case on your exact 1c2c216. The marked-page path subtracts withheld ranges, but the snapshot fallback can still copy the overlap of an allowed range and a withheld range into title memory.

5b6583d is one commit on your head. Its WARP regression submits two actual buffer copies through VIctory. List A writes two 0x5a5a5a5a words, then B writes two 0xa5a5a5a5 words starting at A's second word. With B withheld, the original head retired [0x5a5a5a5a, 0xa5a5a5a5, 0] to title memory. The fix retires [0x5a5a5a5a, 0, 0] and all three GPU-copy words stay intact. When both lists are allowed, all three words retire.

The focused test passed 10/10 after the fix. The full WARP GPU suite passed 149 tests with 2 ignored, including your marked-page regression. Strict GPU Clippy and asset policy passed.

@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 on a marked page doesn't hold back valid writes — part of the withheld-range cluster with #1998 and #2004 (fixes issue #1976): three PRs attacking the same bug; maintainer should pick one. This one looks the most targeted.

@0xkn0wh3r3

Copy link
Copy Markdown
Contributor Author

Thanks @andrewpozdnakov7-jpg, that's a real hole, and thanks for the clear reproduction.

82ef681 fixes it. Your commit was a useful reference, but I wrote my own version so I could test it here. Host::execute now collects, per copy, the ranges withheld lists declared in the submission. Shadow::copy_back leaves those bytes alone in game memory and keeps the GPU's bytes for them in the copy, as keep_writes does. A 64 KiB piece containing withheld bytes is no longer marked current, since the copy and game memory differ there.

The new test a_withheld_lists_bytes_stay_out_of_an_overlapping_copy_back follows your scenario. List A writes three dwords and list B writes two, starting at A's third. With B withheld, game memory gets A's first two dwords and keeps 0 under B's, while the copy holds all four. With both allowed, all four go back. Before the change, B's first dword reached game memory. Tested on an RTX 5070 Ti: the shadow:: tests pass, and the full victory-gpu run has only the two NVIDIA heap-limit failures main has (#1835).

@catminou4: on the #1998 and #2004 cluster, this branch now covers both the marked-page and snapshot paths for #1976.

github-actions Bot added a commit to KevinPratap/VIctory that referenced this pull request Nov 25, 2026

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Needs work: needs the maintainer's decision. Thanks for the test and the explanation. Your argument holds up against main. A marked UAV view is refreshed by whole pages (page_range in draw.rs and bindless.rs), and that reaches Shadow::update. Tracked::take (watch.rs) then takes and guards those pages and removes them from the changed set. So the next copy_back_marked sees either an unchanged page or a saved snapshot, and the saved.is_none() && changed early return isn't reached. a_page_that_went_back_in_part_takes_the_next_marked_writes_back checks this, and it fails when the update step is removed. Leaving the page changed instead of calling taken is the right choice, because the copy and title memory differ outside the ranges that go back.

I no longer see a correctness problem. What remains is that #1998 fixes #1976 in the same functions, and only a maintainer can choose between the two. CI: passing.


Generated by Claude Code

…s there

After a submission, `copy_back_marks` puts the pages shaders marked as
written through views into title memory, but skipped every page a
withheld range touches (a range whose writes stay out of title memory: a
program using title memory declared it in a list that missed memory). A
page is 64 KiB, so another range's declared write on the same page was
lost with it (issue 1976: list A's bytes at offset 64 retired as zeros
because list B's withheld range sat at offset 256).

`copy_back_marks` now takes the submission's declared ranges with whether
each goes back. On a page a withheld range touches, what the ranges that
go back declared there goes back, less the withheld ranges
(`Shadow::copy_back_marked` with `only`). Bytes a withheld range covers,
and bytes no list declared, stay out of title memory and the copy keeps
them, as before; the page is not taken, since the copy differs from title
memory there. Pages no withheld range touches go back whole, unchanged,
and the marks of shaders using title memory are held back as before.

The new test declares a valid range and a withheld one on the same marked
page plus a valid one on the next page: with the whole-page skip, the
valid write on the shared page reads back as zeros.
@0xkn0wh3r3
0xkn0wh3r3 force-pushed the gpu/withheld-marked-pages-keep-valid-writes branch from 01a0007 to b6ae3a0 Compare November 25, 2026 23:51
0xkn0wh3r3 added a commit to 0xkn0wh3r3/VIctory that referenced this pull request Nov 26, 2026
0xkn0wh3r3 added a commit to 0xkn0wh3r3/VIctory that referenced this pull request Nov 26, 2026
A marked page that a withheld range touched goes back in part and stays
changed, with no saved bytes. The new test runs a second marked
submission on that page the way a submission prepares a marked view: its
refresh of the view's whole pages takes the page, so the shaders' writes
and a title write made during the run both go back.
@0xkn0wh3r3

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I added the test you suggested in 487598d: shadow::tests::a_page_that_went_back_in_part_takes_the_next_marked_writes_back. It passes on this branch with no code change. Here's why.

The first half of your description is right. On the partial path, copy_back_marked takes the page's saved bytes (shadow.rs:506) and returns without calling taken (shadow.rs:539). Its own write into title memory also marks the page changed (watch::writing, watch.rs:807). So after a partial copy-back the page is changed and has no snapshot. The test asserts this: !copy.clean() after the first submission.

The second half doesn't happen in a real submission, because the page doesn't stay changed until the next copy-back. Every marked UAV view is refreshed by whole pages before its lists run:

  • page_range at draw.rs:937 (root views), draw.rs:1905 (table views) and bindless.rs:321 (heap hulls).
  • The batch flushes those refreshes before the lists run, and they reach Shadow::update at host.rs:2442.
  • Tracked::take then takes and guards every whole page in the range, which removes it from the changed set (watch.rs:516).

So when the next submission's copy_back_marked runs, the page is either unchanged (title memory equals the copy from before) or the title wrote it during the run, after it was armed again. In the second case the guard saved its bytes, so saved is Some. Either way the early return at shadow.rs:507 is not reached. The test runs this second submission the way a marked view is prepared (page_range, update, writing(.., true)), with a shader write and a title write on the page during the run. Both reach title memory. With the update call removed, the shader write is lost ([0x5a, 0x5a] instead of [0xc3, 0xc3]), so the test does catch the case you describe if a path ever skips the refresh.

I left the page changed on purpose rather than calling taken. Outside the ranges that go back, the copy keeps the withheld bytes and title memory keeps its own, so the page isn't equal to title memory. Calling taken would stop the next refresh from copying title writes made there during the run. The withheld range is retaken afterwards in any case (memory.rs:335-339, called from host.rs:1405), and that marks the page changed too.

The choice between #1986 and #1998 is yours.

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

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

5 participants