Skip to content

GPU: a marked copy-back advances the snapshot of declared ranges over its page - #2437

Open
BastienRodz wants to merge 1 commit into
Marvisak:mainfrom
BastienRodz:gpu/copy-back-advances-snapshot
Open

BastienRodz wants to merge 1 commit into
Marvisak:mainfrom
BastienRodz:gpu/copy-back-advances-snapshot

Conversation

@BastienRodz

Copy link
Copy Markdown
Contributor

What's wrong

copy_back_marks runs before the declared ranges' copy-backs (host.rs). A marked copy-back puts the shaders' bytes back, and the copy takes the title's others. But the snapshot (Shadow::before) of a declared range over the same page keeps the bytes from before the submission. That range's copy_back then sees the title's bytes in the copy as differing from the snapshot, takes them for shader writes, and puts them back over anything the title wrote since the marked copy-back. Since cd94d35, a page can be both marked and inside a declared range (a heap view and a root UAV or a clear on the same buffer), and the title's threads keep writing these buffers during copy-back.

What the fix does

At the end of copy_back_marked, the new sync_snapshot copies the page's resulting bytes into any snapshot segment over it, so a later copy-back finds nothing new there. This is what update_busy already does for refreshes: "The same bytes go into the snapshot writing took, so copy-back neither takes them for the GPU's nor puts them back over a later title write." Nothing changes when no declared range covers the page.

Tests

New shadow::tests::a_declared_copy_back_after_a_marked_one_keeps_newer_title_writes: one page, marked and declared. A shader writes byte 10 and the title writes byte 40 during the submission. After the marked copy-back, the title writes 10 and 40 again, and the declared copy-back must write nothing.

  • On main (940d32f) it fails: the declared copy-back writes the page back (left: 65536, right: 0), restoring the older bytes.
  • With the fix it and the other shadow::tests pass (5), as do watch::tests (6). Run under Wine 10 with vkd3d-proton 3.1 on llvmpipe; without a host device the test returns early.
  • windows-latest run on the fork: https://github.com/BastienRodz/VIctory/actions/runs/45623926434

Not tested

No title run, and no AMD/NVIDIA GPU. How often the title writes a byte again between these two steps is not measured.

#261 has the companion case: two overlapping declared ranges, where copy_back does not advance its own snapshot. That PR predates marked copy-back. This one only touches copy_back_marked, so the two don't overlap.

Fixes #2436

AI-assisted (Gemini 4 Neon found and wrote it, Claude Code reviewed, narrowed and verified it). No game data used.

🤖 Generated with Claude Code

@DrDarkDK DrDarkDK left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified 13c6aa2 on native Windows with an RTX 4070 Ti (driver 621.01) and WARP. I also checked a case where the marked pass writes zero bytes back to title memory but takes a title-written byte into the host copy.

On 940d32f, the title wrote 0x11, the marked pass took it into the copy, and the title then wrote 0x22. The later declared pass wrote 65,536 bytes and restored 0x11. On 13c6aa2, the declared pass wrote zero bytes and preserved 0x22. Both adapters gave the same results.

All six targeted shadow tests, including this temporary fixture, passed on each adapter. The zero-write case confirms why the snapshot update matters even when the marked pass reports no write. Synthetic data only.

AI-assisted with Codex.

@oni-swr

oni-swr commented Nov 25, 2026

Copy link
Copy Markdown

Verification — head 13c6aa2e142178f09a697276b01388201f8349c7

Environment: Windows 11 Pro 10.0.26200, rustc/cargo 1.98.1, DXC/dxil 1.8.2502.11 (Windows Kits 10.0.26100.0 x64). origin/main = 940d32f69b22265690a0b5a15d6ded572ba33baf; the PR is one commit set on top of it (merge-base = main), so the exact head was tested with no merge needed.

  • cargo test -p victory-gpu --lib --features diagnostics -- --test-threads=1: 147 passed, 0 failed, 2 ignored (+1). New shadow::tests::a_declared_copy_back_after_a_marked_one_keeps_newer_title_writes ran and passed.
  • Negative control under WARP: with the sync_snapshot call removed that test fails (left: 65536, right: 0), matching the PR description, so it exercises the fix rather than returning early.
  • clippy with and without diagnostics: clean. cargo xtask policy: ok.
  • GPU tests ran with VICTORY_D3D12_WARP=1 and --features diagnostics (the switch has no effect without that feature), -- --test-threads=1; warp_adapter_accepts_only_software ran and passed (adapter vendor 0x1414, software flag). Baseline origin/main for the same command: 146 passed, 0 failed, 2 ignored.
  • Base is main; it fixes GPU: a declared copy-back after a marked one puts the title's older bytes back #2436.

Overlap with #2434 / #2377:

Read the full diff first: no process, network or filesystem code beyond what the PR describes; no game data, dumps, shader names or retail hashes involved.

Verified by Claude Code (Claude Sonnet 5.5), an AI assistant; this is a test report, not a code review or approval.

@BastienRodz

Copy link
Copy Markdown
Contributor Author

Thanks @oni-swr, the negative control under WARP is useful. On #2434: the two don't contradict each other. That PR splits copy_back_marked into phases, and this one only needs the copy's final bytes for the page to reach the snapshot after the page has been written back. If #2434 lands first, I'll rebase and move the sync_snapshot call into its write-back phase.

@kotekompotek

Copy link
Copy Markdown

Verified on Windows 10 / GTX 1050 at 13c6aa2: cargo test -p victory-gpu --lib shadow::tests — 5/5 pass, including the new a_declared_copy_back_after_a_marked_one_keeps_newer_title_writes on real hardware (host GPU present, so find did not early-return).

The fix matches the issue's analysis: by the time sync_snapshot runs, host already equals what title memory holds (the merge loop leaves *h = *t either way, or written is None because they were already equal), so advancing before segments to host is exactly "the same bytes go into the snapshot" that update_busy documents. Declared copy-backs after it then see before == memory and cannot mistake the title's bytes for the GPU's.

Also checked: the early changed-kept path writes nothing to memory, so skipping the snapshot advance there is consistent; and sync_snapshot locking before cannot deadlock — copy_back_marks and the declared copy_backs run on the same submission thread with separate lock acquisitions.

@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.

Marked copy-back advances the snapshot of declared ranges (+47). Static review only: victory-gpu/victory-hle are Windows-only (D3D12/windows-sys); not compiled or tested on this macOS arm64 host. rustc 1.98.1. Same copy-back cluster as #2434.

@oni-swr

oni-swr commented Nov 25, 2026

Copy link
Copy Markdown

Overlap with #2513, WARP/CPU only (addendum to the existing verification of 13c6aa2e)

Same defect (#2436), same file (victory-gpu/src/shadow.rs). Tested on Windows 11 Pro 10.0.26200, rustc 1.98.1, VICTORY_D3D12_WARP=1 + --features diagnostics (WARP; no physical GPU), origin/main 940d32f.

AI use: Claude Code (Claude Sonnet 5.5).

@BastienRodz
BastienRodz force-pushed the gpu/copy-back-advances-snapshot branch from 13c6aa2 to 6c60b95 Compare November 25, 2026 15:46
@BastienRodz

Copy link
Copy Markdown
Contributor Author

Rebased onto main da82e44. Main added clean/dirty_bit next to where sync_snapshot goes; I kept both, and the call still sits at the end of copy_back_marked. On the new main the test still fails without it (left: 65536, right: 0) and passes with it; shadow:: 9/9.

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Verdict: merge candidate. Rebased at 60d81cf, which merges cleanly into main; the change is the same as the version reviewed before. At the end of Shadow::copy_back_marked (crates/victory-gpu/src/shadow.rs) the new sync_snapshot copies the page's final copy bytes into any declared-range snapshot segment over it. Without that, the declared copy_back that follows takes the title's bytes for shader writes and writes them back over newer title writes (#2436). It uses the same mapping-relative offsets and segment loop as sync_before in update_busy. The test a_declared_copy_back_after_a_marked_one_keeps_newer_title_writes fails without the call (reported by the author and by oni-swr under WARP) and passes on hardware (kotekompotek).

The overlapping #2434 and #2513 have been closed, and #2377 has been merged, so nothing else open competes with this.

CI: passing (check).


Generated by Claude Code

… its page

copy_back_marks runs before the copy-backs of declared ranges. It puts a
marked page's GPU bytes back, and the copy takes the title's others
(`*h = *t`), but the snapshot of a declared range over that page
(Shadow::before) kept the bytes from before the submission. That range's
copy-back then found the title's bytes the copy had taken differing from
the snapshot, took them for the GPU's, and put them back over what the
title had written in between.

copy_back_marked now brings the snapshot over the page to the copy's
bytes (sync_snapshot).

Co-Authored-By: Gemini 4 Neon <noreply@google.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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

6 participants