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

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

@⁠0xkn0wh3r3 on GitHub · 2026-11-25 02:21 UTC · original
0xkn0wh3r3:gpu/withheld-marked-pages-keep-valid-writes → main · +213 −21 · 2 files · 2 commits · open

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, #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.
**@⁠0xkn0wh3r3** on GitHub · 2026-11-25 02:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/1986) `0xkn0wh3r3:gpu/withheld-marked-pages-keep-valid-writes` → `main` · +213 −21 · 2 files · 2 commits · open 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, #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.
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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:50:44 +00:00
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.
Author
Owner

@⁠DesertGamer on GitHub · 2026-11-25 02:28 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:28 UTC · [original](https://github.com/Marvisak/VIctory/pull/1986#issuecomment-7150763329) ### 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

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-25 02:37 UTC · original

I found one more case on your exact 1c2c21603602b4e02140db51b23653112da78140. 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.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-25 02:37 UTC · [original](https://github.com/Marvisak/VIctory/pull/1986#issuecomment-7150969385) I found one more case on your exact 1c2c21603602b4e02140db51b23653112da78140. 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](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/5b6583d0daea0253b0870305ab1580c9d99aefce) 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.
Author
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-25 06:11 UTC · original

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.

**@⁠0xkn0wh3r3** on GitHub · 2026-11-25 06:11 UTC · [original](https://github.com/Marvisak/VIctory/pull/1986#issuecomment-7154543478) 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.
Author
Owner

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

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

**@⁠Marvisak** on GitHub · 2026-11-25 08:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/1986#issuecomment-7157008735) · edited 2026-11-26 07:21 UTC <!-- victory-triage v1 head=487598d6b54da697746a260240225b18d81509db verdict=needs-work at=2026-11-26T07:21:45Z --> 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](https://claude.ai/code)_
Author
Owner

@⁠0xkn0wh3r3 on GitHub · 2026-11-26 06:47 UTC · original

Thanks for the review. I added the test you suggested in 487598d6: 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.

**@⁠0xkn0wh3r3** on GitHub · 2026-11-26 06:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/1986#issuecomment-7184792574) Thanks for the review. I added the test you suggested in 487598d6: `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.
This pull request can be merged automatically.
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/1986/head:github-bot/gh-1986'
git switch 'github-bot/gh-1986'

Merge

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