GPU: a marked copy-back advances the snapshot of declared ranges over its page #2437
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2437
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@BastienRodz on GitHub · 2026-11-25 13:28 UTC · original
BastienRodz:gpu/copy-back-advances-snapshot→main· +47 −0 · 1 files · 1 commits · openWhat'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
@oni-swr on GitHub · 2026-11-25 13:50 UTC · original
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.
@BastienRodz on GitHub · 2026-11-25 13:52 UTC · original
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.@kotekompotek on GitHub · 2026-11-25 14:00 UTC · original
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.@oni-swr on GitHub · 2026-11-25 15:34 UTC · original
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).
@BastienRodz on GitHub · 2026-11-25 15:47 UTC · original
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.@Marvisak on GitHub · 2026-11-25 16:38 UTC · original · edited 2026-11-26 03:24 UTC
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
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.