Repository navigation
GPU: a copy-back keeps the snapshot in step, so a later range takes no older bytes - #214
Conversation
…o older bytes A copy-back puts what the shaders wrote into title memory and lets the copy take the title's own bytes. The snapshot it compares against (the copy's bytes before the submission) kept only the GPU's bytes, so the bytes the copy had just taken from title memory looked like the GPU's to a later copy-back of a range that overlaps: it put the copy's older bytes back over a title write made after the first copy-back. Now the bytes a copy-back merges into the copy go into the snapshot too (`merge_back`, one pass over the differing span, no second copy of it): a later range finds them unchanged, takes the title's current bytes and writes nothing back. `merge_back` is `merge_piece`'s rule with the copy stored into as well; `merge_piece` keeps not storing into its source (the card may be writing it for a later flight). The same shape is already right on the card-merge path and in `relay_merge`, which update the snapshot they hold. What is not changed: `relay_merge`'s own snapshot still follows only the GPU's bytes (relay is off by default and its merge reads the copy without writing it). Tests: shadow::merge_tests::a_copy_back_keeps_its_snapshot_in_step — the upstream #2436 shape in one piece (a shader byte, a title write beside it, the copy-back, then the title writing both again: both stay), and the same piece with the snapshot left behind, which puts the older byte back. Gates: clippy clean (workspace, all targets); victory-gpu 207 passed, 2 ignored (the existing benchmark and watch benchmarks), 0 "no device" skips on the RADV card; victory-shader 187 passed, 2 ignored. Behaviour only on the CPU copy-back path, no switch. Not tested in a game run. Co-authored-by: Calvix2k <calvinhebben1@gmail.com> (cherry picked from commit 69ca2a8)
…itten The merge wrote the snapshot through a slice while a shared slice of the same bytes (the whole declared range) was still live, which Rust's aliasing rules forbid even though the mutex keeps other threads out. Now the range-wide shared slice lives only for the comparison that finds the differing pieces, and each piece's bytes are read in a scope of their own that ends before `merge_back` writes them: no borrow of the snapshot is kept across the merge. Found by CodeRabbit on #198. Gates: clippy clean; victory-gpu 207 passed, 2 ignored, 0 "no device" skips on the RADV card; cargo xtask policy 244 files ok. Co-authored-by: Calvix2k <calvinhebben1@gmail.com> (cherry picked from commit 98d563d)
|
No actionable comments were generated in the recent review. Walkthrough
Change: Bug fix Merge Risk:
|
Supersedes #198 (that branch had a same-worktree mistake in it: it carried the DirectStorage commit too; this one is
the copy-back change alone, on today's
main).What
A copy-back puts what the shaders wrote into title memory and lets the copy take the title's own bytes
(
Shadow::copy_back_with). The snapshot it compares against — the copy's bytes before the submission — kept onlythe GPU's bytes, so the bytes the copy had just taken from title memory looked like the GPU's to a later copy-back
of a range that overlaps the first one (the world declares overlapping views of its big heap dozens of times a
frame): it wrote the copy's older bytes back over a title write made after the first copy-back. Same family as the
stale-bytes-over-live-data failures we chase in streaming and geometry.
Now the bytes a copy-back merges into the copy go into the snapshot too:
merge_back, one pass over the differingspan (no second copy of it — this runs over the differing bytes of every declared range). A later range finds them
unchanged, takes the title's current bytes and writes nothing back.
merge_backismerge_piece's rule with thecopy stored into as well;
merge_piecekeeps not storing into its source (the card may be writing it for a laterflight).
The same shape is already right on the card-merge path (
Shadow::card_merge) and inrelay_merge, which update thesnapshot they hold — this brings the plain CPU path in line.
Not changed:
relay_mergestill lets its snapshot follow only the GPU's bytes (relay is off by default and its mergereads the copy without writing it).
Credit: Marvisak/VIctory #2513 (Calvix2k, GPL-3.0). Reimplemented
— theirs changes
copy_back_marked, which this tree has no equivalent of — withCo-authored-by:trailers and oneCREDITS.md line.
Tests
shadow::merge_tests::a_copy_back_keeps_its_snapshot_in_step: upstream #2436's shape in one piece — a shaderbyte, a title write beside it, the copy-back, then the title writing both again: both stay. Plus the same piece
with the snapshot left behind, which puts the older byte back.
slice stays live across
merge_back's write.Gates
cargo xwin clippy --target x86_64-pc-windows-msvc --workspace --all-targets -- -D warnings: clean.victory-gpuon the RADV card (VICTORY_TEST_ADAPTER=hw, native dxgi): 211 passed, 2 ignored (the existingbenchmarks), 0
skipped: no device.cargo test -p victory-shader(Linux): 194 passed, 2 ignored.cargo xtask policy: 255 files ok; the game-name grep is empty.Off switch
None: this only stops a wrong write on the CPU copy-back path.
Not tested in a game run.
Summary by CodeRabbit