GPU: copy title writes under ranges a submission's shaders write #1322

Merged
KevinPratap merged 1 commit from upstream-pr/1322 into main 2026-11-25 00:23:43 +00:00
KevinPratap commented 2026-11-24 17:24:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by KevinPratap on 2026-11-24T17:24:56Z.


Problem

Shadow::update copies only the gaps around pending ranges: ranges that lists earlier in the same submission declared as written by shaders. The world binds unordered-access views of its whole 174 MB heap, so once one is declared, nothing the title writes anywhere in that heap reaches the host copy for the rest of the submission.

Constants the title writes into that heap are then read stale. Seen on an RTX 4050 Laptop (32-lane waves): a depth-downsample compute dispatch read its sizes (1024, 512, 2560, 1440 in title memory) as zeros from the host copy. 1/0 made its loop bounds about 4 billion, and the GPU ran until the device was removed as hung (DRED: the list stopped in that dispatch; the bytes were read from both sides when the device was removed).

Fix

A submission waits for the one before it (ExecuteCommandLists, then a fence wait), so when a submission refreshes, none of its own shaders have run. Under a pending range, the pages the title wrote are now copied as they are anywhere else (update_busy). The same bytes go into the snapshot writing took, so copy_back does not take them for a shader's write and does not undo the title's later writes with them.

Verified

  • New test shadow::tests::title_writes_under_a_busy_range_are_copied (write-watched memory, synthetic data): fails on main (shadow.update(...) > 0 is false, the constant never reaches the copy) and passes with this change. It also checks that a shader's byte still goes back and that a title write made after the refresh is not undone.
  • cargo test -p victory-gpu --release --lib: 52 passed, 1 ignored; cargo clippy -p victory-gpu --all-targets: no new warnings.
  • In the game, on an integration branch of open PRs (RTX 4050, diagnostics build, VICTORY_D3D12_DRED=1): the submission holding that dispatch completes instead of removing the device. The device is still removed later at other dispatches on that card; those are separate.

Only crates/victory-gpu/src/shadow.rs changes.

AI-assisted.

🤖 Generated with Claude Code

<!-- greyfinch-sync:Marvisak/VIctory:issue:6587550841 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1322). Originally posted by [KevinPratap](https://github.com/KevinPratap) on 2026-11-24T17:24:56Z. --- ## Problem `Shadow::update` copies only the gaps around `pending` ranges: ranges that lists earlier in the same submission declared as written by shaders. The world binds unordered-access views of its whole 174 MB heap, so once one is declared, nothing the title writes anywhere in that heap reaches the host copy for the rest of the submission. Constants the title writes into that heap are then read stale. Seen on an RTX 4050 Laptop (32-lane waves): a depth-downsample compute dispatch read its sizes (1024, 512, 2560, 1440 in title memory) as zeros from the host copy. 1/0 made its loop bounds about 4 billion, and the GPU ran until the device was removed as hung (DRED: the list stopped in that dispatch; the bytes were read from both sides when the device was removed). ## Fix A submission waits for the one before it (`ExecuteCommandLists`, then a fence wait), so when a submission refreshes, none of its own shaders have run. Under a pending range, the pages the title wrote are now copied as they are anywhere else (`update_busy`). The same bytes go into the snapshot `writing` took, so `copy_back` does not take them for a shader's write and does not undo the title's later writes with them. ## Verified - New test `shadow::tests::title_writes_under_a_busy_range_are_copied` (write-watched memory, synthetic data): fails on `main` (`shadow.update(...) > 0` is false, the constant never reaches the copy) and passes with this change. It also checks that a shader's byte still goes back and that a title write made after the refresh is not undone. - `cargo test -p victory-gpu --release --lib`: 52 passed, 1 ignored; `cargo clippy -p victory-gpu --all-targets`: no new warnings. - In the game, on an integration branch of open PRs (RTX 4050, diagnostics build, `VICTORY_D3D12_DRED=1`): the submission holding that dispatch completes instead of removing the device. The device is still removed later at other dispatches on that card; those are separate. Only `crates/victory-gpu/src/shadow.rs` changes. AI-assisted. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
crosettiremi commented 2026-11-24 18:05:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by crosettiremi on 2026-11-24T17:34:54Z.


Your depth-downsample investigation led to a reproducible neighboring-byte problem in XCL's sparse memory path. The mechanisms differ: XCL records a hash per 64-byte line. A four-byte GPU counter readback used to record the whole line as synchronized, including a CPU-written constant at byte 24 that had never been uploaded. The next dirty scan returned an empty list.

In an isolated local XCL patch, a partial readback updates the hash only if that line was clean beforehand. The native D3D12 regression now queues the expected 64-byte upload. A second fixture covers a readback spanning a dirty first line, a full line and a clean trailing line. The sparse test module passed 17 tests, with one timing test ignored. This verifies the lost-upload mechanism in XCL; the identity of its stalled game dispatch is still open.

Retail follow-up with only this XCL readback fix added to the previously tested integration build: Player1 input arrived at 47.017 s, assets streamed, and the last positive present sample was 228.288 s. The last captured frame remained dark. No device removal logged; the guest ended with an access violation writing zero at RVA 0x23cf683 after the 258 s sample. The last translated-pipeline counters had 22,659 skipped dispatches. Those counters do not identify the missing producer or a depth-downsample shader. One run on each build, with different account-selection timing.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7139406773 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1322#issuecomment-7139406773). Originally posted by [crosettiremi](https://github.com/crosettiremi) on 2026-11-24T17:34:54Z. --- Your depth-downsample investigation led to a reproducible neighboring-byte problem in XCL's sparse memory path. The mechanisms differ: XCL records a hash per 64-byte line. A four-byte GPU counter readback used to record the whole line as synchronized, including a CPU-written constant at byte 24 that had never been uploaded. The next dirty scan returned an empty list. In an isolated local XCL patch, a partial readback updates the hash only if that line was clean beforehand. The native D3D12 regression now queues the expected 64-byte upload. A second fixture covers a readback spanning a dirty first line, a full line and a clean trailing line. The sparse test module passed 17 tests, with one timing test ignored. This verifies the lost-upload mechanism in XCL; the identity of its stalled game dispatch is still open. Retail follow-up with only this XCL readback fix added to the previously tested integration build: Player1 input arrived at 47.017 s, assets streamed, and the last positive present sample was 228.288 s. The last captured frame remained dark. No device removal logged; the guest ended with an access violation writing zero at RVA 0x23cf683 after the 258 s sample. The last translated-pipeline counters had 22,659 skipped dispatches. Those counters do not identify the missing producer or a depth-downsample shader. One run on each build, with different account-selection timing.
aycow commented 2026-11-24 19:04:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by aycow on 2026-11-24T18:13:31Z.


Thanks @KevinPratap for the exact repro and patch. I verified the corresponding stale-constant failure on exact #185 and #387, including when the CPU update lands after command recording. Their synchronous branches now defer baseline snapshots until CPU refreshes complete (f173d36 and 709647f). The fixed variants preserve both the real GPU write and an independent later CPU write on AMD, NVIDIA and WARP with full GBV. #595 has a distinct lifetime issue because an earlier native submission may still be active during the refresh. The synthetic passes do not yet attribute the title material failure.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7140337883 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1322#issuecomment-7140337883). Originally posted by [aycow](https://github.com/aycow) on 2026-11-24T18:13:31Z. --- Thanks @KevinPratap for the exact repro and patch. I verified the corresponding stale-constant failure on exact #185 and #387, including when the CPU update lands after command recording. Their synchronous branches now defer baseline snapshots until CPU refreshes complete (f173d36 and 709647f). The fixed variants preserve both the real GPU write and an independent later CPU write on AMD, NVIDIA and WARP with full GBV. #595 has a distinct lifetime issue because an earlier native submission may still be active during the refresh. The synthetic passes do not yet attribute the title material failure.
catminou4 commented 2026-11-24 21:02:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T20:09:06Z.

Review: COMMENTED


Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; this is source review plus the PR's own Windows tests.

Title writes landing inside a range this submission's shaders will write are now copied into the shadow and its snapshot (update_busy), so copy_back neither mistakes them for shader writes nor overwrites the title's later writes with stale snapshot bytes. The comment explains the GTA VI 174 MB heap case (depth-downsample reading zero sizes → device removed as hung). The test uses a real MEM_WRITE_WATCH VirtualAlloc range and asserts the title's constant reaches the host copy, the shader's write goes back, and the title's later write survives copy-back. Exactly the right regression coverage. Windows-only.

<!-- greyfinch-sync:Marvisak/VIctory:review:6046546692 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1322#pullrequestreview-6046546692). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T20:09:06Z. **Review:** COMMENTED --- Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; this is source review plus the PR's own Windows tests. Title writes landing inside a range this submission's shaders will write are now copied into the shadow and its snapshot (update_busy), so copy_back neither mistakes them for shader writes nor overwrites the title's later writes with stale snapshot bytes. The comment explains the GTA VI 174 MB heap case (depth-downsample reading zero sizes → device removed as hung). The test uses a real MEM_WRITE_WATCH VirtualAlloc range and asserts the title's constant reaches the host copy, the shader's write goes back, and the title's later write survives copy-back. Exactly the right regression coverage. Windows-only.
KevinPratap commented 2026-11-24 23:05:56 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by KevinPratap on 2026-11-24T22:32:31Z.


Rebased onto today's main (70564ae0), which rewrote shadow.rs around Tracked and snapshot segments. The bug is still there: update skips the pending ranges entirely. The fix is now update_busy: under a pending range it copies the pages Tracked::take reports, and writes the same bytes into the snapshot segments writing took.

  • The new test shadow::tests::title_writes_under_a_busy_range_are_copied uses the tracked pool, like the existing shadow test. It fails on main ("the title's write is copied") and passes with this.
  • cargo clippy -p victory-gpu --all-targets -- -D warnings is clean.
  • cargo test -p victory-gpu --lib: the 3 failures are also there on main, on an RTX 4050 Laptop (dynamic_slots_are_held_until_released, a_texture_written_in_one_format_reads_in_another_through_a_placed_view, lists_share_a_table_and_copies_keep_their_views).

AI-assisted.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7146353607 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1322#issuecomment-7146353607). Originally posted by [KevinPratap](https://github.com/KevinPratap) on 2026-11-24T22:32:31Z. --- Rebased onto today's `main` (70564ae0), which rewrote `shadow.rs` around `Tracked` and snapshot segments. The bug is still there: `update` skips the pending ranges entirely. The fix is now `update_busy`: under a pending range it copies the pages `Tracked::take` reports, and writes the same bytes into the snapshot segments `writing` took. - The new test `shadow::tests::title_writes_under_a_busy_range_are_copied` uses the tracked pool, like the existing shadow test. It fails on `main` ("the title's write is copied") and passes with this. - `cargo clippy -p victory-gpu --all-targets -- -D warnings` is clean. - `cargo test -p victory-gpu --lib`: the 3 failures are also there on `main`, on an RTX 4050 Laptop (`dynamic_slots_are_held_until_released`, `a_texture_written_in_one_format_reads_in_another_through_a_placed_view`, `lists_share_a_table_and_copies_keep_their_views`). AI-assisted.
upstream-sync closed this pull request 2026-11-25 01:06:14 +00:00
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!1322
No description provided.