GPU: a marked copy-back keeps a declared range's snapshot in step #2513

Closed
github-bot wants to merge 1 commit from gh-pr/2513/head into gh-pr/2513/base
Owner

@⁠Calvix2k on GitHub · 2026-11-25 15:04 UTC · original
Calvix2k:codex/gpu-marked-copy-back-snapshot → main · +60 −3 · 1 files · 1 commits · closed without merging

Fixes #2436.

The failure, reproduced

copy_back_marked merges the page (the shaders' bytes into title memory, the copy taking the title's others) and marks the page taken — but the snapshot a declared range over that page keeps (Shadow::before, taken before the submission) is left alone. A later copy_back over the page then compares the copy against those older bytes, finds the title's own writes differ, takes them for the GPU's and puts the copy's older values back over them — the failure copy_back's comment warns about.

The test added here is the scenario from the issue: a shader byte at 10, the title's write at 40 during the submission, the marked copy-back, then the title writes both again. Before this change it fails at the first:

assertion `left == right` failed: the title's later write at 10 stays
  left: 170   (0xaa, the shader's byte, written back)
 right: 17    (0x11, what the title wrote after the copy-back)

What the change does

The bytes a marked copy-back writes into title memory go into the overlapping part of every declared range's snapshot as well — the same thing update_busy does for the copy ("the same bytes go into the snapshot, so copy-back neither takes them for the GPU's nor puts them back over a later title write"). The segments hold offsets in the copy, so the overlap is computed in that space.

Verification

  • a_marked_copy_back_keeps_a_declared_ranges_snapshot_in_step fails before, passes after.
  • cargo test -p victory-gpu --features diagnostics --lib on Windows 10 19045 / RX 7800 XT: 146 passed, 2 ignored, plus the known placed-view failure on a runtime without ID3D12Device10 (#1999, identical on main); clippy -D warnings clean.
  • Not run on the title; the failing window here is one submission wide (between copy_back_marks and the declared copy-backs), so a title-side repro is unlikely to be visible — the synthetic test is the check.

The overlapping-declared-ranges case from #261 (a copy-back not advancing its own snapshot) is untouched.

**@⁠Calvix2k** on GitHub · 2026-11-25 15:04 UTC · [original](https://github.com/Marvisak/VIctory/pull/2513) `Calvix2k:codex/gpu-marked-copy-back-snapshot` → `main` · +60 −3 · 1 files · 1 commits · closed without merging Fixes #2436. ### The failure, reproduced `copy_back_marked` merges the page (the shaders' bytes into title memory, the copy taking the title's others) and marks the page taken — but the **snapshot** a declared range over that page keeps (`Shadow::before`, taken before the submission) is left alone. A later `copy_back` over the page then compares the copy against those older bytes, finds the title's own writes differ, takes them for the GPU's and puts the copy's older values back over them — the failure `copy_back`'s comment warns about. The test added here is the scenario from the issue: a shader byte at 10, the title's write at 40 during the submission, the marked copy-back, then the title writes both again. Before this change it fails at the first: ``` assertion `left == right` failed: the title's later write at 10 stays left: 170 (0xaa, the shader's byte, written back) right: 17 (0x11, what the title wrote after the copy-back) ``` ### What the change does The bytes a marked copy-back writes into title memory go into the overlapping part of every declared range's snapshot as well — the same thing `update_busy` does for the copy ("the same bytes go into the snapshot, so copy-back neither takes them for the GPU's nor puts them back over a later title write"). The segments hold offsets in the copy, so the overlap is computed in that space. ### Verification - `a_marked_copy_back_keeps_a_declared_ranges_snapshot_in_step` fails before, passes after. - `cargo test -p victory-gpu --features diagnostics --lib` on Windows 10 19045 / RX 7800 XT: **146 passed**, 2 ignored, plus the known placed-view failure on a runtime without `ID3D12Device10` (#1999, identical on `main`); clippy `-D warnings` clean. - Not run on the title; the failing window here is one submission wide (between `copy_back_marks` and the declared copy-backs), so a title-side repro is unlikely to be visible — the synthetic test is the check. The overlapping-declared-ranges case from #261 (a copy-back not advancing its own snapshot) is untouched.
A marked copy-back puts the shaders' bytes into title memory and lets the
copy take the title's others. A declared range over the same page keeps its
snapshot from before the submission, so a later copy-back compares the copy
against those older bytes, takes the title's own writes for the GPU's and
puts the copy's older values back over them — the failure `copy_back`'s
comment warns about ("putting back the copy's older bytes there broke the
title's own records").

The bytes a marked copy-back writes into title memory now go into the
overlapping part of every declared range's snapshot as well, which is what
`update_busy` does for the copy.

The new test is #2436's scenario: a shader byte, a title write during the
submission, the marked copy-back, then the title writes both bytes again —
they stay. Before the change it fails at the first of the two (the shader's
byte goes back over the title's).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:07:55 +00:00
github-bot closed this pull request 2026-11-26 05:07:55 +00:00
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 15:34 UTC · original

Verification (Windows 11, WARP/CPU only) — head 0b92934e2e1392290330cd295c77d9e10a4921e9, with overlap against #2437

Tested: the PR head = origin/main 940d32f + the PR (merge-base 940d32f, fast-forward). Windows 11 Pro 10.0.26200, rustc/cargo 1.98.1. VICTORY_D3D12_WARP=1 with --features diagnostics (the switch only works with that feature), so the host device is WARP; no physical GPU.

command result
cargo test -p victory-gpu --locked --features diagnostics --lib a_marked_copy_back_keeps -- --test-threads=1 1 passed
same, snapshot-advance loop disabled fails: the title's later write at 10 stays, left: 170, right: 17 (matches the PR text)
cargo test -p victory-gpu --locked --features diagnostics --lib -- --test-threads=1 147 passed, 0 failed, 2 ignored
cargo clippy -p victory-gpu --all-targets [--features diagnostics] --locked -- -D warnings clean
cargo xtask policy asset policy: 182 files ok

Side by side with #2437 (head 13c6aa2e; both fix #2436, both only touch victory-gpu/src/shadow.rs)

  • Same mechanism: advance the declared range's before snapshot segments to the bytes the copy and title now share. #2513 does it inline in copy_back_marked, inside if let Some(bytes) = written; #2437 does it in a new sync_snapshot(from - start, host) called unconditionally at the end of copy_back_marked.
  • The two merge textually clean onto 940d32f (merge commit 7e9e3fb; both would then sync twice). On that merge: the 6 shadow::tests pass (both new tests), full lib 148 passed, 0 failed, 2 ignored; clippy with diagnostics clean; policy ok. With #2513's loop disabled in that merge, both new tests still pass, i.e. #2437 alone covers #2513's test.
  • Difference (tested): when the marked pass writes nothing back to title memory but takes a title-written byte into the copy (written == None), #2513 skips the snapshot advance. A throwaway test (title writes byte 40 = 0x11, no shader write, copy_back_marked -> 0 bytes, title writes 0x22, declared copy_back) fails on #2513's head: declared pass writes 65536 bytes and byte 40 reads 17 (0x11) instead of 34 (0x22). On #2437's head the same test passes (declared pass writes 0 bytes). This is the zero-write case DrDarkDK described on #2437; I did not find a covering test in #2513.
  • Minor on #2513: the new test's doc comment was inserted below the existing title_writes_under_a_busy_range_are_copied doc lines, so the new test carries 5 unrelated doc lines and the old test lost its doc.
  • Net: #2437 is a superset of #2513's behaviour; the only extra in #2513 is no separate helper.

WARP only; the throwaway test was not committed. Synthetic data only.

AI use: Claude Code (Claude Sonnet 5.5).

**@⁠oni-swr** on GitHub · 2026-11-25 15:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/2513#issuecomment-7167043393) **Verification (Windows 11, WARP/CPU only) — head `0b92934e2e1392290330cd295c77d9e10a4921e9`, with overlap against #2437** Tested: the PR head = `origin/main` `940d32f` + the PR (merge-base `940d32f`, fast-forward). Windows 11 Pro 10.0.26200, rustc/cargo 1.98.1. `VICTORY_D3D12_WARP=1` with `--features diagnostics` (the switch only works with that feature), so the host device is WARP; no physical GPU. | command | result | |---|---| | `cargo test -p victory-gpu --locked --features diagnostics --lib a_marked_copy_back_keeps -- --test-threads=1` | 1 passed | | same, snapshot-advance loop disabled | **fails**: `the title's later write at 10 stays`, `left: 170`, `right: 17` (matches the PR text) | | `cargo test -p victory-gpu --locked --features diagnostics --lib -- --test-threads=1` | 147 passed, 0 failed, 2 ignored | | `cargo clippy -p victory-gpu --all-targets [--features diagnostics] --locked -- -D warnings` | clean | | `cargo xtask policy` | `asset policy: 182 files ok` | **Side by side with #2437 (head `13c6aa2e`; both fix #2436, both only touch `victory-gpu/src/shadow.rs`)** - Same mechanism: advance the declared range's `before` snapshot segments to the bytes the copy and title now share. #2513 does it inline in `copy_back_marked`, inside `if let Some(bytes) = written`; #2437 does it in a new `sync_snapshot(from - start, host)` called unconditionally at the end of `copy_back_marked`. - The two merge textually clean onto `940d32f` (merge commit `7e9e3fb`; both would then sync twice). On that merge: the 6 `shadow::tests` pass (both new tests), full lib 148 passed, 0 failed, 2 ignored; clippy with `diagnostics` clean; policy ok. With #2513's loop disabled in that merge, both new tests still pass, i.e. #2437 alone covers #2513's test. - **Difference (tested):** when the marked pass writes nothing back to title memory but takes a title-written byte into the copy (`written == None`), #2513 skips the snapshot advance. A throwaway test (title writes byte 40 = 0x11, no shader write, `copy_back_marked` -> 0 bytes, title writes 0x22, declared `copy_back`) fails on #2513's head: declared pass writes 65536 bytes and byte 40 reads `17` (0x11) instead of `34` (0x22). On #2437's head the same test passes (declared pass writes 0 bytes). This is the zero-write case DrDarkDK described on #2437; I did not find a covering test in #2513. - Minor on #2513: the new test's doc comment was inserted below the existing `title_writes_under_a_busy_range_are_copied` doc lines, so the new test carries 5 unrelated doc lines and the old test lost its doc. - Net: #2437 is a superset of #2513's behaviour; the only extra in #2513 is no separate helper. WARP only; the throwaway test was not committed. Synthetic data only. AI use: Claude Code (Claude Sonnet 5.5).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 15:54 UTC · original

Automated triage for the maintainers. Proposed close as a duplicate of the earlier open #2437, which fixes the same issue (#2436) in the same place, Shadow::copy_back_marked in crates/victory-gpu/src/shadow.rs, and covers more. This PR advances the declared ranges' snapshot only inside if let Some(bytes) = written. When the marked pass writes nothing back but the copy still takes a title-written byte (h = t with changed == false), the snapshot stays old, so the later copy_back still puts that byte back over a newer title write. #2437's sync_snapshot runs whether or not anything was written. Also, the new test's doc comment was inserted under the existing doc lines of title_writes_under_a_busy_range_are_copied, so that test lost its doc. CI (check) passes. This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the label.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 15:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/2513#issuecomment-7167420996) <!-- victory-triage v1 head=0b92934e2e1392290330cd295c77d9e10a4921e9 verdict=proposed-close at=2026-11-25T15:54:18Z --> Automated triage for the maintainers. Proposed close as a duplicate of the earlier open #2437, which fixes the same issue (#2436) in the same place, `Shadow::copy_back_marked` in `crates/victory-gpu/src/shadow.rs`, and covers more. This PR advances the declared ranges' snapshot only inside `if let Some(bytes) = written`. When the marked pass writes nothing back but the copy still takes a title-written byte (`h = t` with `changed == false`), the snapshot stays old, so the later `copy_back` still puts that byte back over a newer title write. #2437's `sync_snapshot` runs whether or not anything was written. Also, the new test's doc comment was inserted under the existing doc lines of `title_writes_under_a_busy_range_are_copied`, so that test lost its doc. CI (`check`) passes. This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the label. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠Calvix2k on GitHub · 2026-11-25 16:03 UTC · original

Closing in favour of #2437, as the triage proposes: it is the earlier PR for the same issue (#2436), and its sync_snapshot runs whether or not the marked pass wrote anything — the case this one leaves stale (h = t with changed == false), so it covers more. The note about the test doc comment is right too; that test keeps its doc from main with this closed.

No objection from me to #2437 going in.

**@⁠Calvix2k** on GitHub · 2026-11-25 16:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/2513#issuecomment-7167553543) Closing in favour of #2437, as the triage proposes: it is the earlier PR for the same issue (#2436), and its `sync_snapshot` runs whether or not the marked pass wrote anything — the case this one leaves stale (`h = t` with `changed == false`), so it covers more. The note about the test doc comment is right too; that test keeps its doc from `main` with this closed. No objection from me to #2437 going in.

Pull request closed

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