GPU/Shadow: advance saved before snapshot after merge_writeback in copy_back_or_not #3031

Open
github-bot wants to merge 1 commit from github-bot/gh-3031 into main AGit
Owner

@⁠RVZO6 on GitHub · 2026-11-26 03:59 UTC · original
RVZO6:rvzo/shadow-copyback-stale-before → main · +61 −3 · 1 files · 1 commits · open

In Shadow::copy_back_or_not() (crates/victory-gpu/src/shadow.rs:414-454), compared deduplicates only whole 64 KiB PIECE chunks (if n == PIECE && !compared.insert(...)). When two overlapping ranges in the same submission include a partial range (< 64 KiB) — e.g. [0, 0x1000) followed by [0, 0x2000) or [0x1000, 0x2000) followed by [0, PAGE) — the second copy_back() re-compares those bytes against the saved before snapshot segment.

Because merge_writeback(title, host, old) copies concurrent CPU writes from title into host without updating old (before), a subsequent overlapping copy_back() in the same submission sees host[i] != old[i] on those CPU-written bytes, mistakes the earlier CPU write for a GPU write, and clobbers newer CPU writes in title memory back to the stale value.

Update old.copy_from_slice(host) immediately after merge_writeback so already-merged bytes match the snapshot on subsequent overlapping copy-backs. Disjoint from #2914 (copy_back_marks) and #2848 (Back buffer pooling).

Verification

  • Added overlapping_copy_backs_do_not_clobber_newer_cpu_writes covering both partial_then_wider ([0, 0x1000) -> [0, 0x2000)) and partial_then_whole_page ([0x1000, 0x2000) -> [0, PAGE)) on D3D12 WARP SM 6.6.
  • Official Windows MSVC + WARP SM 6.6 CI (Rust 1.98.1, default + --tests + --features diagnostics clippy, xtask policy, full workspace tests): RVZO6/VIctory CI run #45748741503 (green, combined Wave 10 check on 63bcca4).
  • Not run: the title; any hardware GPU.

AI-assisted: T3 Code (Antigravity, gemini-4-neon).

**@⁠RVZO6** on GitHub · 2026-11-26 03:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/3031) `RVZO6:rvzo/shadow-copyback-stale-before` → `main` · +61 −3 · 1 files · 1 commits · open In `Shadow::copy_back_or_not()` (`crates/victory-gpu/src/shadow.rs:414-454`), `compared` deduplicates only whole 64 KiB `PIECE` chunks (`if n == PIECE && !compared.insert(...)`). When two overlapping ranges in the same submission include a partial range (`< 64 KiB`) — e.g. `[0, 0x1000)` followed by `[0, 0x2000)` or `[0x1000, 0x2000)` followed by `[0, PAGE)` — the second `copy_back()` re-compares those bytes against the saved `before` snapshot segment. Because `merge_writeback(title, host, old)` copies concurrent CPU writes from `title` into `host` without updating `old` (`before`), a subsequent overlapping `copy_back()` in the same submission sees `host[i] != old[i]` on those CPU-written bytes, mistakes the earlier CPU write for a GPU write, and clobbers newer CPU writes in title memory back to the stale value. Update `old.copy_from_slice(host)` immediately after `merge_writeback` so already-merged bytes match the snapshot on subsequent overlapping copy-backs. Disjoint from #2914 (`copy_back_marks`) and #2848 (`Back` buffer pooling). ### Verification - Added `overlapping_copy_backs_do_not_clobber_newer_cpu_writes` covering both `partial_then_wider` (`[0, 0x1000)` -> `[0, 0x2000)`) and `partial_then_whole_page` (`[0x1000, 0x2000)` -> `[0, PAGE)`) on D3D12 WARP SM 6.6. - Official Windows MSVC + WARP SM 6.6 CI (Rust 1.98.1, default + `--tests` + `--features diagnostics` clippy, `xtask policy`, full workspace tests): [RVZO6/VIctory CI run #45748741503](https://github.com/RVZO6/VIctory/actions/runs/45748741503) (green, combined Wave 10 check on `63bcca4`). - **Not run:** the title; any hardware GPU. AI-assisted: T3 Code (Antigravity, gemini-4-neon).
In Shadow::copy_back_or_not(), `compared` deduplicates only whole 64 KiB
PIECE chunks; partial ranges (< 64 KiB) or a partial range followed by an
overlapping wider or full-page range in the same submission re-inspect
bytes against the saved `before` snapshot segment.

Because `merge_writeback(title, host, old)` copies CPU writes from `title`
into `host` without updating `old` (`before`), a subsequent overlapping
`copy_back()` in the same submission sees `host[i] != old[i]` on those
CPU-written bytes, mistakes the earlier CPU write for a GPU write, and
overwrites newer CPU writes in title memory back to the stale value.

Update `old.copy_from_slice(host)` immediately after `merge_writeback`
so already-merged bytes match the snapshot on subsequent overlapping
copy-backs. Disjoint from #2914 and #2848.

Assisted-by: T3 Code (Antigravity, gemini-4-neon)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:26:59 +00:00
Author
Owner

@⁠pickles976 on GitHub · 2026-11-26 04:05 UTC · original

Independent hardware verification at exact clean head 1de058caa2f34b407766df930f7ef49793cf68f1: Windows-MSVC victory-gpu regression shadow::tests::overlapping_copy_backs_do_not_clobber_newer_cpu_writes 1/1 PASS (0.79 s) under Wine 11.0/vkd3d-proton 3.2.0 on an NVIDIA RTX 4060 Laptop GPU (8 GiB), 16 GiB RAM. DXVK explicitly enumerated the laptop GPU and vkd3d initialized a hardware D3D12 device; this test reached the live Shadow path rather than the find() == None early-return branch. It exercises both partial-then-wider and partial-then-whole-page overlapping ranges and verifies the first GPU byte remains while the newer CPU byte survives the second copy-back.

I ran it inside the 9 GiB cgroup / 512 MiB swap safety scope with global available RAM >=2 GiB, GPU used <=6 GiB, disk >=10 GiB; no guard stop. Local log .compat-runtime/logs/verify-pr3031-wine-rtx4060-shadow-copyback.log. No retail title was launched; this is a synthetic GPU-shadow correctness check, not evidence the 16 GiB loader bottleneck is fixed. No objections from the focused Wine/NVIDIA fixture.

**@⁠pickles976** on GitHub · 2026-11-26 04:05 UTC · [original](https://github.com/Marvisak/VIctory/pull/3031#issuecomment-7182282253) Independent hardware verification at exact clean head `1de058caa2f34b407766df930f7ef49793cf68f1`: Windows-MSVC `victory-gpu` regression `shadow::tests::overlapping_copy_backs_do_not_clobber_newer_cpu_writes` **1/1 PASS** (0.79 s) under Wine 11.0/vkd3d-proton 3.2.0 on an **NVIDIA RTX 4060 Laptop GPU (8 GiB), 16 GiB RAM**. DXVK explicitly enumerated the laptop GPU and vkd3d initialized a hardware D3D12 device; this test reached the live `Shadow` path rather than the `find() == None` early-return branch. It exercises both partial-then-wider and partial-then-whole-page overlapping ranges and verifies the first GPU byte remains while the *newer* CPU byte survives the second copy-back. I ran it inside the 9 GiB cgroup / 512 MiB swap safety scope with global available RAM >=2 GiB, GPU used <=6 GiB, disk >=10 GiB; no guard stop. Local log `.compat-runtime/logs/verify-pr3031-wine-rtx4060-shadow-copyback.log`. No retail title was launched; this is a synthetic GPU-shadow correctness check, not evidence the 16 GiB loader bottleneck is fixed. No objections from the focused Wine/NVIDIA fixture.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 06:17 UTC · original

Automated triage for the maintainers.

This fixes a real bug in crates/victory-gpu/src/shadow.rs::copy_back_or_not. merge_writeback sets host to the merged title bytes but leaves the before snapshot unchanged. compared only skips whole 64 KiB pieces, so a second, overlapping partial range in the same submission compares host with the stale before again. It then treats the CPU's earlier bytes as GPU writes and puts them back over newer CPU writes. The one-line fix, old.copy_from_slice(host) after the merge, matches what update_tracked's sync_before already does for the snapshot. The new test covers both overlap shapes.

CI: check is failing, but only in descriptor::host::tests::views_bound_while_another_slot_gets_its_texture_do_not_wait ("both made"). That test does not touch shadow.rs, and #3035 reports it as intermittently failing on unmodified main, so a re-run is probably enough. Please confirm before merging.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 06:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/3031#issuecomment-7184288304) <!-- victory-triage v1 head=1de058caa2f34b407766df930f7ef49793cf68f1 verdict=merge-candidate at=2026-11-26T06:22:00Z --> Automated triage for the maintainers. This fixes a real bug in `crates/victory-gpu/src/shadow.rs::copy_back_or_not`. `merge_writeback` sets `host` to the merged title bytes but leaves the `before` snapshot unchanged. `compared` only skips whole 64 KiB pieces, so a second, overlapping partial range in the same submission compares `host` with the stale `before` again. It then treats the CPU's earlier bytes as GPU writes and puts them back over newer CPU writes. The one-line fix, `old.copy_from_slice(host)` after the merge, matches what `update_tracked`'s `sync_before` already does for the snapshot. The new test covers both overlap shapes. CI: `check` is **failing**, but only in `descriptor::host::tests::views_bound_while_another_slot_gets_its_texture_do_not_wait` ("both made"). That test does not touch `shadow.rs`, and #3035 reports it as intermittently failing on unmodified `main`, so a re-run is probably enough. Please confirm before merging. --- _Generated by [Claude Code](https://claude.ai/code)_
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/3031/head:github-bot/gh-3031'
git switch 'github-bot/gh-3031'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3031'
git switch 'github-bot/gh-3031'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3031'
git switch 'github-bot/gh-3031'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3031'
git switch 'main'
git merge --squash 'github-bot/gh-3031'
git switch 'main'
git merge --ff-only 'github-bot/gh-3031'
git switch 'main'
git merge 'github-bot/gh-3031'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3031
No description provided.