GPU: copy-back can mark a page up to date after the title wrote it, so the GPU keeps reading old data #722
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#722
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@Dufftwt on GitHub · 2026-11-24 08:26 UTC · original
What's wrong
At the end of
Shadow::copy_back(crates/victory-gpu/src/shadow.rs:237-247), every page it synced is marked up to date in the host copy (copied[page] = now). Thenowcomes from one write-watch query (watch::writes(.., reset)) made after all pieces are done.That query also clears any title write that happened after a page was read and before the query. The kernel can't tell our own
write_mappedfrom a title write, so both are reset together. The page is then marked current, later refreshes skip it, and the GPU keeps reading the old bytes until the title happens to write that page again.copy_staledoes this in the safe order (ask first, then copy).copy_backreads first and asks afterwards.Example
copy_backtakes milliseconds.Evidence
The test
a_title_write_during_copy_back_reaches_the_copyreplays it deterministically:copy_backhas written page 1, so page 0 is fully done.copy_backstill has 62 pages to go.copy_back, a refresh of page 0 should bring the 7 into the host copy.On
main(dd54de2), on GitHub'swindows-latest:The write reached title memory but never reached the copy. The test's code is in the
race_testsmodule posted in #721.Suggested fix
After the final query, mark a synced page current only if title memory, read again with
read_into, still matches the host copy:Related
@Yorivel on GitHub · 2026-11-24 09:25 UTC · original
A fix as suggested here, with the test from #721's
race_testsmodule (credited in the code): https://github.com/Yorivel/VIctory/tree/fix/copy-back-current-pages (on8e79c80).After the final asking,
copy_backreads each synced page again and marks it current only if it still matches the copy. A title write cleared by that asking leaves the page as written atnow, after its last copy, so the next refresh copies it. A write after the asking shows at the next one as before. Cost: one 64 KiB read per synced page.Tested (Windows 11 26300, MSVC, Rust 1.98.1,
--test-threads=1):a_title_write_during_copy_back_reaches_the_copyon unchangedmain: 3 of 3 runs fail (left: 0, right: 7, "in the copy"); with the fix: 3 of 3 pass.cargo test -p victory-gpu --lib: 51 passed, 1 ignored. Clippy (-D warnings) clean,cargo xtask policyok.The #721 test is not included, as this branch does not change the whole-piece write-back; the fix doesn't touch the lines xstraok's #721 branch changes, but I haven't tested the two together.
Written with Claude Code.
@flaxdmin199 on GitHub · 2026-11-24 09:32 UTC · original
Implemented and verified along the suggested fix:
In \crates/victory-gpu/src/shadow.rs, \Shadow::copy_back\ now checks whether title memory still matches the host copy before marking \copied[page - base] = now. If a concurrent title write happened between its piece merge and the write-watch reset, title memory differs, so the page remains stale and the subsequent \update\ refreshes it into the host copy.
Verification
Tested on Windows 11 (MSVC, Rust 1.98.1), synthetic tests only, no game data. External PR creation is collaborator-only, so the branch is available on the fork for cherry-picking:
github.com/flaxdmin199/VIctory@b17490a6e3@Machad3x on GitHub · 2026-11-24 14:12 UTC · original
Fix, with your test (failed 3/3 before, passes 3/3 after):
github.com/Machad3x/VIctory@3800387a5c. The watch is now asked (watch::writes, reset) before the first piece is read, and synced pages are marked current with that asking instead of one taken after the whole copy-back, so a title write made while pieces are copied back is newer than the mark and shows at the next refresh. Our own write-backs come after the asking, so the next refresh copies those bytes once more (equal bytes, only some cost). Fork branch claude/gta6-shader-translation-crashes-705550.@Dufftwt on GitHub · 2026-11-24 15:10 UTC · original
Fixed in #1024, together with #721: a synced page is marked current only if title memory, read again after the final write-watch query, still matches the copy.
@Marvisak on GitHub · 2026-11-25 01:48 UTC · original
Automated triage for the maintainers.
The mechanism the report names is gone from
main. There's no write-watch query orcopied[page] = nowany more: sincec75fdba, changes are tracked per 64 KiB page with read-only guards incrates/victory-gpu/src/watch.rs. The defect itself is still there in the new form:Shadow::copy_back_or_not(crates/victory-gpu/src/shadow.rs) collects the pieces it synced and callsTracked::takenon them once, after all pieces are done.takenre-guards those pages and clears their "changed" mark without looking at title memory again.watch::writing, and dropping that left its pages open (unguarded). A title write to such a page while later pieces are still processed doesn't fault, so nothing records it.takenthen marks the page current, and later refreshes skip it, so the host copy keeps the older bytes.copy_back_markedandcopy_back_page, the per-page paths (the first added incd94d35), calltakenright after their own write. That leaves a shorter window of the same kind.The two newest commits (
cd94d35,940d32f) don't close this. They change which pages are compared and stop the marked path's own write from saving the page, but they don't re-check title memory beforetaken.The fix is in an open pull request: #1024 (also fixes #721). It re-reads title memory and marks a page current only if it still matches the copy. It was written against the write-watch version (
ffe310e) and needs a rebase onto the guard-basedtaken. The fork branches in the comments (Yorivel, flaxdmin199, Machad3x) target the old code too.Generated by Claude Code