GPU: preserve CPU stores across overlapping snapshot writebacks #3412
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!3412
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3412"
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?
@Jineggegg on GitHub · 2026-11-26 23:01 UTC · original
Jineggegg:fix/shadow-snapshot-race→main· +154 −14 · 1 files · 2 commits · openReproduction
Two declarations from one submission can cover the same bytes. In the first regression test the ranges cover offsets 2–5 and 3–7. The shader output changes bytes 2 and 5. A CPU thread writes C1 at byte 4 after the first writeback reads title memory. The original code writes its earlier value, 00, over C1. The test also writes C2 before processing the second declaration and verifies that C2 survives.
The second regression test declares an aligned 64 KiB page followed by its four bytes at offsets 100–103. The full-page writeback publishes A1 A2 A3 A4. The CPU then writes C2 at offset 101. Processing the smaller declaration used to publish A2 again, overwriting the newer CPU store.
Change
The snapshot path compares shader output with the bytes saved before the submission. It writes contiguous runs of changed bytes through the existing checked write API. A CPU store in a gap between two shader changes therefore survives. After restoring write tracking on a completed full page, it reads title memory back into the shadow. It also updates the comparison baseline for a reconciled partial piece so that a later declaration can revisit it safely.
The per-submission set now records a full page after a successful full-page comparison against readable title memory. A later partial declaration now looks up the same aligned page in that set and skips it. Partial pieces do not mark the whole page complete. A failed read spanning a decommitted 4 KiB block leaves the 64 KiB page eligible for retry. A third regression test verifies that a later four-byte declaration beyond the hole still publishes its shader output.
Windows test evidence
The three regression tests in
shadow::testsuse real D3D12 devices and synthetic shadow contents, so the CPU store lands at the same point on every run:overlapping_snapshots_keep_late_cpu_storespartial_snapshot_after_a_full_page_preserves_a_new_cpu_storereadable_partial_snapshot_retries_after_a_full_page_read_failscargo test -p victory-gpu --features diagnostics --lib --locked shadow::tests:: -- --test-threads=1, on the RTX 5090 and again withVICTORY_D3D12_WARP=1(the GPU crate's WARP switch exists only indiagnosticsbuilds).63bcca4read back 00 where the CPU had written C1.b1fb182) read back A1 A2 A3 A4 after the CPU replaced A2 with C2.The decommitted-block test also passed on both devices. The 64 KiB read failed as expected and the four mapped bytes beyond the hole received A1 A2 A3 A4.
On Windows the upstream-based workspace recorded 868 passes, 6 failures and 10 ignored tests. Every failure also reproduced on the preceding snapshot commit,
b1fb182. Two GPU assertions concern the native descriptor heap size and the view beyond the dynamic slots. One shader test (heap_direct_texture_reads_mark_their_heap_index) terminated with Windows status 0xc0000005 (#2571); the remaining shader tests were then run by name. Three other shader tests failed on hardware: the stride used for a structured-buffer read, dispatch when the buffer view is absent, and the gathered values at a specified level. The same outcomes were recorded on both revisions. The adapter-dependent regression tests follow the existing skip convention if no host can be created.Comparison with prior work
The following candidates were each ported onto one local integration tree (not tested at their own heads) and run with the first regression test on an RTX 5090. The comparisons concern the snapshot path, even where a proposal mainly changes another path.
Three open PRs that change the same snapshot code were tested directly at their current heads, on the RTX 5090 and on WARP. The three tests above were added unchanged, with the same read seam in
copy_back_or_not(the title read goes through a closure, as in this PR):overlapping_snapshots_keep_late_cpu_storespartial_snapshot_after_a_full_page_preserves_a_new_cpu_storemain63bcca4(same seam)[A1, 00, 00, A2], the CPU's C1 lost[A1, A2, A3, A4], the CPU's C2 lost8b284ddebd01cd60d81cf31626ecreadable_partial_snapshot_retries_after_a_full_page_read_failspasses on all of them; it guards this PR's own change. #3318 and #3211 rework the same function for speed, and this PR will need rebasing on whichever lands first.Scope
This fix covers declared ranges with saved snapshots. Upstream’s separate marked-page path,
copy_back_marked, can still overwrite a concurrent CPU store when it writes a merged whole page. That issue remains open.RTX 5090, driver 621.14, Windows 11 build 26300, in-box WARP 10.0.26100.9818, Rust 1.98.1.
Synthetic tests only, no game data. AI-assisted (Claude Code); the runs are from my machine.
🤖 Generated with Claude Code
@Dukestar69 on GitHub · 2026-11-26 23:07 UTC · original · approved these changes
LGTM — verified on RTX 5090 (Windows / D3D12) against
origin/main(63bcca4).cargo test -p victory-gpu --lib shadow:: -- --test-threads=1: 13 passed, 0 failed (overlapping_snapshots_keep_late_cpu_stores,partial_snapshot_after_a_full_page_preserves_a_new_cpu_store,readable_partial_snapshot_retries_after_a_full_page_read_fails).cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@Jackster on GitHub · 2026-11-26 23:46 UTC · original
Windows 11,
63bcca4+ this PR, Radeon RX 7900 XTX:cargo test -p victory-gpu --lib: 234 passed / 0 failed / 1 ignored (unpatched63bcca4here: 231 passed; +3).cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.The three added tests are
readable_partial_snapshot_retries_after_a_full_page_read_fails,partial_snapshot_after_a_full_page_preserves_a_new_cpu_storeandoverlapping_snapshots_keep_late_cpu_stores; all pass, and the existing snapshot/withheld tests are unchanged. Synthetic only. AI-assisted.@fuzeofficlal on GitHub · 2026-11-27 00:48 UTC · original · approved these changes
Looks solid. Reviewed
store_snapshot_changesand thecopy_back_or_not_withtracking/re-arm sequence incrates/victory-gpu/src/shadow.rs, and verified on both RTX 5090 and WARP withVICTORY_D3D12_DEBUG=1:cargo xtask policyandcargo clippy --tests -p victory-gpu(default and--features diagnostics,-D warnings) pass cleanly.store_snapshot_changesemits writes only for contiguousgpu != oldruns that still differ fromtitle, avoiding gap overwrites of concurrent CPU stores.comparedon the aligned 64 KiB page and inserting only after a successful full-page read correctly prevents smaller overlapping declarations from replaying completed pages while still allowing readable subranges to retry after a failed full-page read.t.taken(&whole)) before re-reading title memory into the shadow and refreshing the partial-piecebeforebaseline preserves late CPU writes across partial-before-full and overlapping partial snapshots.shadow::testsplus an additional cross-page partial-before-full overlap probe pass on both RTX 5090 and WARP (13/13 passed, 0 D3D12 debug layer messages).@rezioliver-collab on GitHub · 2026-11-27 02:58 UTC · original
I replayed the snapshot writeback on an Apple M1 using a five-byte slice as mapped memory. For each of 7,776 mask combinations, I inserted late CPU stores after the title read, only at offsets the simulated GPU had left untouched. I then checked all five final bytes.
63bcca4331626ecaI also counted mapped-write calls for a 64 KiB piece with 32 KiB changed. One contiguous change took one call on the PR. Changing every other byte took 32,768 calls for the same 32 KiB total. The base issued one 64 KiB write in both cases. These are call counts from the CPU harness. Windows write latency was outside the test.
AI-assisted with Codex.
@upipibi on GitHub · 2026-11-27 18:52 UTC · original
Overlap with #3031 (RVZO6, opened 11-26 03:59Z, triage verdict "merge-candidate"). It fixes the same bug in
Shadow::copy_back_or_not(crates/victory-gpu/src/shadow.rs): two declared ranges of one submission cover the same bytes, the first copy-back merges a CPU store into the host copy but leaves the savedbeforebytes alone, and the second copy-back writes the stale value over a newer CPU store. #3031 advances the saved bytes after the merge, while this PR compares against the saved bytes and writes only changed runs. This PR cites #2437 and others but not #3031.I ran each PR's regression test against the other's fix on Windows 11 with an RTX 3070 (driver 616.56),
cargo test -p victory-gpu --lib shadow::tests::, 3 runs each:main63bcca4partial_snapshot_after_a_full_page_preserves_a_new_cpu_store1de058ca31626ecaoverlapping_copy_backs_do_not_clobber_newer_cpu_writesSo each fix covers the other's case. Your other two tests (
readable_partial_snapshot_retries_after_a_full_page_read_fails,overlapping_snapshots_keep_late_cpu_stores) use thecopy_back_or_not_withhook this PR adds, so I could not run them on #3031. The read-failure retry they cover is something #3031 does not claim. The two PRs conflict inshadow.rs(merging31626ecaonto1de058ca), so only one can go in as is.AI-assisted (Claude Code, Claude Opus 5.5 ran the cross-tests and posted).
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.