GPU: fix marked copy-back across shared 64 KiB pages and sub-page copies #2434
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!2434
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2434/head"
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?
@fuzeofficlal on GitHub · 2026-11-25 13:27 UTC · original
fuzeofficlal:fix/gpu-marked-copyback-shared-and-subpage→main· +210 −49 · 1 files · 1 commits · closed without mergingSummary
copy_back_marks/Shadow::copy_back_marked(introduced incd94d35/940d32f) had two coupled page-tracking bugs affecting sub-allocated buffers that share a 64 KiB title page or do not span a full 64 KiB page:Cross-copy
watch::writingself-sabotage on shared 64 KiB pages:When two
Shadowcopies share a 64 KiB pagepage(e.g. sub-allocated buffers[page, page + 4096)and[page + 4096, page + 8192)) and shaders write both in the same submission via heap-indexed UAVs (where lists do not declare ranges, so neitherTrackedisarmed),copy_back_marksprocessed them sequentially:watch::writingopenedpage / PAGEand markedpage / PAGEaschangedin every holder ing.holders[page / PAGE], including the second copy.saved.is_none() && t.changed(page / PAGE)and dropped its GPU writes (MarkedKept), mistaking the first copy's write-back for a concurrent title CPU write.watch::writingimmediately re-openedpage / PAGEand marked the first copychangedagain.Sub-64-KiB / unaligned-end copies never re-taking their page after
copy_back_marked:copy_back_markedgatedt.taken(&[page / PAGE])onfrom == page && to == page + PAGE, even though[from, to)(page.max(start)..(page + PAGE).min(end)) is already 100% ofself's tracked range withinpage(matchingTracked::takeandShadow::copy_back_page). Every placed buffer withlen < 64 KiBorlen % 64 KiB != 0therefore left its page unguarded and markedchangedin its ownTrackedafter every marked write-back, causing redundant CPU->GPU re-uploads and dropping a subsequent marked write when only a sub-slice view was refreshed.Changes
copy_back_marksincrates/victory-gpu/src/shadow.rsinto three phases:Shadow::prepare_marked: unarmspage / PAGE, skips unarmed pages already changed before any write-back (MarkedKept), and snapshots each slice's baseline[from, to)(savedslice when present, else current title memory) before anywatch::writingopens shared pages.MarkedSlice::commit: fast-paths unchanged unsaved slices (*host == self.before[..]), otherwise merges GPU changes againstbeforeinto current title memory and writes back underwatch::writing.Writingguards drop, callst.taken(&[page / PAGE])for every synced slice (including sub-page copies), unless a later write in the batch overlapped its byte range.shared_page_marked_copies_do_not_drop_or_dirty_each_otherandsubpage_marked_copy_retakes_its_page_across_rounds.Verification
cargo test -p victory-gpu --lib --locked -- shadow(6 passed)cargo clippy -p victory-gpu --all-targets --no-default-features --locked -- -D warningscargo clippy -p victory-gpu --all-targets --all-features --locked -- -D warningscargo xtask policy@oni-swr on GitHub · 2026-11-25 13:50 UTC · original
Verification — head
794ab08e5a3a50660e40a71d39d6d316cdcc5861Environment: 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: 148 passed, 0 failed, 2 ignored (+2). Newshared_page_marked_copies_do_not_drop_or_dirty_each_otherandsubpage_marked_copy_retakes_its_page_across_roundsran and passed. (Both return early when no host device exists; under WARP one exists. I did not run them againstmainas a negative control.)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.Overlap with #2437 / #2377 (all based on
940d32f):Shadow::copy_back_marked(replaced byprepare_marked+MarkedSlice::commit). #2437 adds async_snapshotcall inside that function and its test callscopy_back_marked; #2377's test calls it too.git mergeof #2437 or #2377 onto #2434 conflicts inshadow.rs(production hunk, not only tests), and the tests would no longer compile even after resolving.Shadow::beforesnapshot, so the declared-range scenario of #2437 (#2436) does not look addressed by it (reasoned from the diff, not run); #2437's fix would need re-porting intocommit/prepare_marked.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.
@kotekompotek on GitHub · 2026-11-25 14:01 UTC · original
Reviewed at current head — the prepare/commit split is the right shape for both bugs:
prepare_markeds run before anywatch::writing/write_mapped, so a copy sharing a 64 KiB page no longer sees another copy's write-back as achangedtitle write. Thesaved/changedgate moved to prepare exactly where it must.commitreproduces both old branches:was_saved→ per-byte GPU-wins merge against the watch baseline;!was_saved→beforeis title memory, soh != bare precisely the GPU bytes and the loop writes them over — same as the old wholesalewrite_mapped(host).was_saved || wrote_on_page) && !overlapped_latercorrectly drops the full-page requirement —[from,to)is already the copy's whole tracked slice insidepage— and stays conservative where a later batch entry overlapped the slice.Interplay note for triage: this does not subsume #2437 —
commitdoes not advancebefore(declared-range snapshot) segments after writing, so the #2436 race remains. Whichever lands second will need thesync_snapshotcall carried intocommit(after the merge loop, same invariant:hostequals title memory there).@Marvisak on GitHub · 2026-11-25 16:06 UTC · original · edited 2026-11-25 16:45 UTC
Automated triage for the maintainers.
Merge candidate, with a merge-order note.
Both bugs are real on
main. First,watch::writingin one copy's marked write-back marks the page changed in every holder. A second copy on the same 64 KiB page then hitssaved.is_none() && changedand drops its GPU writes. Second,copy_back_markedre-takes only whole pages, butTracked::takealready counts a copy's whole slice of a page as whole. Incopy_back_marks,prepare_markednow runs for every page before any write-back,MarkedSlice::commitdoes the merge, and the re-take comes after allWritingguards drop, skipping slices a later entry overlapped. The merge incommitmatches both old branches. The two tests cover these cases.Relation to #2437 (merge candidate): this PR removes
Shadow::copy_back_marked, which is where #2437 addssync_snapshot, so the two conflict in production code. This PR does not fix #2437's case (#2436), becausecommitdoes not advanceShadow::before. Whichever lands second must callsync_snapshot(from - start, host)at the end ofcommitand adapt #2437's test tocopy_back_marks. #2377's test also callscopy_back_marked.Nit: the doc on
gpu_writes(shadow.rs ~line 270) still linksShadow::copy_back_marked.CI:
checkpassing.Generated by Claude Code
@Marvisak on GitHub · 2026-11-25 22:09 UTC · original
Automated triage for the maintainers, second look (a review against current
main, with builds and tests where they could change the verdict).Closing because the new code leaves copies stale, although both bugs are real (the two tests fail on
main). Incommit, a slice with no saved bytes whose copy equals its baseline returns early without reading title memory, and is then re-taken whenever an earlier entry wrote the same page, even if that write landed under it: with an outer copy writing a byte inside an inner copy that was marked but unchanged, the inner copy's refresh copies 0 bytes and keeps the old value. Re-taking pages only after every commit also widens the window in which a title write is lost, and holding a 64 KiB buffer per marked page costs about 100 MB a world frame. It also removes the function #2437 fixes. A narrower fix for the two cases would be welcome.If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.
Pull request closed