GPU: a marked copy-back advances the snapshot of declared ranges over its page #2435
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2437"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by BastienRodz on 2026-11-25T13:28:52Z.
What's wrong
copy_back_marksruns 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'scopy_backthen 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. Sincecd94d35, 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 newsync_snapshotcopies the page's resulting bytes into any snapshot segment over it, so a later copy-back finds nothing new there. This is whatupdate_busyalready does for refreshes: "The same bytes go into the snapshotwritingtook, 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.main(940d32f) it fails: the declared copy-back writes the page back (left: 65536,right: 0), restoring the older bytes.shadow::testspass (5), as dowatch::tests(6). Run under Wine 10 with vkd3d-proton 3.1 on llvmpipe; without a host device the test returns early.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_backdoes not advance its own snapshot. That PR predates marked copy-back. This one only touchescopy_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
Imported from Marvisak/VIctory. Originally posted by DrDarkDK on 2026-11-25T13:43:43Z.
Review: APPROVED
Verified
13c6aa2on 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 wrote0x11, the marked pass took it into the copy, and the title then wrote0x22. The later declared pass wrote 65,536 bytes and restored0x11. On13c6aa2, the declared pass wrote zero bytes and preserved0x22. 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.
Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T13:50:14Z.
Verification — head
13c6aa2e142178f09a697276b01388201f8349c7Environment: 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). Newshadow::tests::a_declared_copy_back_after_a_marked_one_keeps_newer_title_writesran and passed.sync_snapshotcall removed that test fails (left: 65536, right: 0), matching the PR description, so it exercises the fix rather than returning early.diagnostics: clean.cargo xtask policy: ok.VICTORY_D3D12_WARP=1and--features diagnostics(the switch has no effect without that feature),-- --test-threads=1;warp_adapter_accepts_only_softwareran and passed (adapter vendor 0x1414, software flag). Baselineorigin/mainfor the same command: 146 passed, 0 failed, 2 ignored.main; it fixes #2436.Overlap with #2434 / #2377:
copy_back_marked, where this PR adds its call; see my note there). Not combined-tested for that reason.shadow.rs; code hunks (copy_back_markedtail vscopy_back_page+watch.rs) merge cleanly.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.
Imported from Marvisak/VIctory. Originally posted by BastienRodz on 2026-11-25T13:52:08Z.
Thanks @oni-swr, the negative control under WARP is useful. On #2434: the two don't contradict each other. That PR splits
copy_back_markedinto 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 thesync_snapshotcall into its write-back phase.Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T14:00:43Z.
Verified on Windows 10 / GTX 1050 at
13c6aa2:cargo test -p victory-gpu --lib shadow::tests— 5/5 pass, including the newa_declared_copy_back_after_a_marked_one_keeps_newer_title_writeson real hardware (host GPU present, sofinddid not early-return).The fix matches the issue's analysis: by the time
sync_snapshotruns,hostalready equals what title memory holds (the merge loop leaves*h = *teither way, orwrittenisNonebecause they were already equal), so advancingbeforesegments tohostis exactly "the same bytes go into the snapshot" thatupdate_busydocuments. Declared copy-backs after it then seebefore == memoryand 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; andsync_snapshotlockingbeforecannot deadlock —copy_back_marksand the declaredcopy_backs run on the same submission thread with separate lock acquisitions.Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T14:11:16Z.
Review: COMMENTED
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.
Imported from Marvisak/VIctory. Originally posted by oni-swr on 2026-11-25T15:34:09Z.
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/main940d32f.0b92934e) advances the declared range's snapshot inline insideif let Some(bytes) = written; this PR callssync_snapshotunconditionally. The two merge textually clean onto940d32f(merge commit7e9e3fb); there: 6shadow::testspass, full lib 148 passed, 0 failed, 2 ignored; clippy and policy clean. With #2513's loop disabled in that merge, both PRs' tests still pass, so this PR alone covers #2513's test.copy_back_markedreturns 0, title writes 0x22, declaredcopy_back) fails (declared pass writes 65536 bytes, byte reads 0x11). On this PR's head it passes (declared pass writes 0 bytes).AI use: Claude Code (Claude Sonnet 5.5).
Imported from Marvisak/VIctory. Originally posted by BastienRodz on 2026-11-25T15:47:42Z.
Rebased onto main
da82e44. Main addedclean/dirty_bitnext to wheresync_snapshotgoes; I kept both, and the call still sits at the end ofcopy_back_marked. On the new main the test still fails without it (left: 65536,right: 0) and passes with it;shadow::9/9.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T16:38:15Z.
Automated triage for the maintainers.
Verdict: merge candidate. Rebased at
60d81cf, which merges cleanly intomain; the change is the same as the version reviewed before. At the end ofShadow::copy_back_marked(crates/victory-gpu/src/shadow.rs) the newsync_snapshotcopies the page's final copy bytes into any declared-range snapshot segment over it. Without that, the declaredcopy_backthat 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 assync_beforeinupdate_busy. The testa_declared_copy_back_after_a_marked_one_keeps_newer_title_writesfails 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
Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T15:04:46Z.
Review: APPROVED
Reviewed
crates/victory-gpu/src/shadow.rsat60d81cfbmerged ontoorigin/main(63bcca43) and verified on RTX 5090 and WARP (VICTORY_D3D12_WARP=1) withVICTORY_D3D12_DEBUG=1.Code & edge-case audit
self.sync_snapshot(from - start, host)(shadow.rs:534,shadow.rs:553-562) unconditionally at the end ofcopy_back_markedmirrorssync_beforeinupdate_tracked: it advances only the overlapping bytes ofself.before.0inside[from - start, to - start)to the post-marked-copy-backhostslice.merge_writebackabsorbed title writes intohost, preventing a later declaredcopy_backfrom treating those bytes as GPU writes and clobbering newer title writes.MarkedKeptearly-return path unchanged (neitherhostnor title memory was modified) and introduces no lock-ordering issues.Verification
cargo run -p xtask -- policy: 191 files ok.cargo clippy -p victory-gpu --all-targets -- -D warnings(default and--all-features): clean.shadow:: watch::withVICTORY_D3D12_DEBUG=1: 26/26 passed on RTX 5090 and 26/26 passed on WARP (--features diagnostics), includinga_declared_copy_back_after_a_marked_one_keeps_newer_title_writes(shadow.rs:1666).copy_backpreserves newer title writes on page 0 and writes backPAGEbytes on page 1), (2) a zero-write marked pass absorbing title writes before a newer title write, (3) a sub-page declared range[128..256)inside a marked page, and (4) an empty snapshot no-op passed cleanly on both RTX 5090 + Debug Layer and WARP + Debug Layer.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.