Skip to content

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

Closed
Calvix2k wants to merge 1 commit into
Marvisak:mainfrom
Calvix2k:codex/gpu-marked-copy-back-snapshot
Closed

Calvix2k wants to merge 1 commit into
Marvisak:mainfrom
Calvix2k:codex/gpu-marked-copy-back-snapshot

Conversation

@Calvix2k

Copy link
Copy Markdown
Contributor

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 (GPU tests: placed R32_UINT -> R9G9B9E5 view does not share its host texture (Windows 10, RX 7800 XT) #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 Marvisak#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).
@oni-swr

oni-swr commented Nov 25, 2026

Copy link
Copy Markdown

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)

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

AI use: Claude Code (Claude Sonnet 5.5).

Copy link
Copy Markdown
Owner

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

@Calvix2k

Copy link
Copy Markdown
Contributor Author

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.

This pull request was closed.
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 declared copy-back after a marked one puts the title's older bytes back

3 participants