Repository navigation
GPU/shadow: write only GPU-changed byte runs in relay_merge, card_merge, and card_merge_relay - #786
Conversation
…ge, and card_merge_relay `Shadow::copy_back_with` (`back_piece`) was fixed for upstream VIctory #2009 to write back only the maximal contiguous byte runs actually modified by the GPU, leaving untouched bytes between the first and last changed byte alone so concurrent title CPU writes in the gap survive. However, all three default-path merges (`Shadow::relay_merge`, `Shadow::card_merge`, and `Shadow::card_merge_relay`) still wrote back the entire `[first..=last]` stretch (up to 64 KiB) in a single `write_mapped` call. Any concurrent title CPU write landing between `read_into` and `write_mapped` in the untouched gap (or inside `skip` ranges in `card_merge_relay`) was silently overwritten with stale bytes from `read_into`. Record per-byte change masks in `merge_piece` and `merge_card_piece`, extract maximal nonzero byte runs via `collect_mask_runs` using reused per-thread scratch, pass those exact runs to `merge_race` so `VICTORY_MERGE_RACE=1` inspects only written bytes, and write only those runs via `write_changed_runs`. Add unit tests covering run extraction for all merge paths plus deterministic and concurrent CPU writes in the untouched gap of a 64 KiB stretch.
…PU-changed byte runs in relay_merge, card_merge, and card_merge_relay (by AscilCH)
…less#786/fxceless#783 merges Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FLuVRkN9XKxpoYQhz4KNXw
…rite Since upstream PR fxceless#786 every run of bytes the GPU changed is its own kernel write (write_mapped, NtWriteVirtualMemory), and shader output changes bytes here and there in every word. In the game the copy-back went from 42 ms to 630-690 ms a frame (frame 270 -> 1,100 ms while warming up). Runs fewer than 64 bytes apart are now written as one, the bytes between them as the title had them; runs further apart stay apart, so a title write in a real gap is still kept.
|
A cost number that may matter here, from the one path that already writes per run. It is not a review of the correctness part, and I have not run this PR. With
So on this machine per-run writes cost about 0.9 ms per differing piece in this path. If the cost shows up there too, Limits: one machine, one run per row, and the joined runs each differ from the per-run one by one more switch. More Windows rows in my comment on #857. AI-assisted (Claude Code). No game data. |
Our merge of fxceless#783 used its first form (b5dee8d). Its later commits: - Drop the one-write copy-back. It filled the gaps between GPU-changed runs with the title's bytes as read and wrote the whole stretch after the loop, over any title write that landed in between, undoing upstream #2009 and the intent of fxceless#786 (write only GPU-changed runs). The author dropped it after review: it did not move the copying-back time. - Forget a released heap's kept pages, so a new heap at the same address does not skip its first sync. - Walk only the records between a page's first and last changed byte, plus slots never mirrored. Adapted to our registry-held CopiedSlots (Codex #13): the never-mirrored check is CopiedSlots::needs. Upstream measured descriptor sync 18.9 -> 10.5 ms/frame (RTX 3080). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FLuVRkAEvF29hMbrBJw8os
…, bisect plan Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FLuVRkAEvF29hMbrBJw8os
…sion It wrote a host copy back whole and overwrote the title's writes, undoing fxceless#786. The PR's author removed it (b5dee8d -> d695015); this applies that change to shadow.rs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01FLuVRkN9XKxpoYQhz4KNXw
Summary
Fix the write-back race (upstream VIctory #2009) across all three default shadow-buffer merge paths in
crates/victory-gpu/src/shadow.rs:Shadow::copy_back_with(back_piece,VICTORY_RELAY=0) was previously updated to write back only the maximal contiguous byte runs modified by the GPU, leaving untouched bytes between the first and last changed byte alone so concurrent title CPU writes in the gap survive.Shadow::relay_merge,Shadow::card_merge, andShadow::card_merge_relaystill wrote back the entire[first..=last]stretch (up to 64 KiB) in a singlewrite_mappedcall, reverting concurrent title CPU writes landing in untouched gap bytes (or insideskipranges incard_merge_relay) betweenread_intoandwrite_mapped.Changes
merged ^ old_title) inmerge_pieceandmerge_card_piece, extract maximal nonzero byte runs viacollect_mask_runs(reused byback_pieceas well) using per-thread scratch (with_merge_scratch), and write back only those runs viawrite_changed_runs.runsintomerge_racesoVICTORY_MERGE_RACE=1diagnostics measure only bytes actually written back to title memory.card_and_relay_merges_emit_only_gpu_changed_runsandwrite_changed_runs_preserves_concurrent_cpu_writes_in_gap) verifying run extraction and proving that both deterministic and concurrent CPU writes in the untouched middle of a 64 KiB stretch are never clobbered.Verification
cargo test -p victory-gpu --locked -- shadow:::30 passed; 0 failed; 0 ignored.cargo clippy -p victory-gpu --all-targets --all-features --locked: 0 warnings incrates/victory-gpu/src/shadow.rs(only pre-existing9376fd6warnings indraw.rsandindirect.rs).cargo xtask policy:171 files ok.(AI-assisted; synthetic unit tests only, no game data.)