Skip to content

fix(gpu): preserve newer game writes across partial copy-back overlaps - #438

Merged
pragyaangaur merged 3 commits into
pragyaangaur:mainfrom
mikebuckets171:contrib/mac-declared-copyback-baseline
Nov 27, 2026
Merged

pragyaangaur merged 3 commits into
pragyaangaur:mainfrom
mikebuckets171:contrib/mac-declared-copyback-baseline

Conversation

@mikebuckets171

Copy link
Copy Markdown
Contributor

Port of @RVZO6's Marvisak/VIctory#3031, commit 1de058ca, onto macOS bf99e728.

The remaining stale-write case

When two declared write ranges overlap within a submission, a partial-page copy-back can be followed by another copy-back of the same bytes. The whole-page comparison set does not cover that overlap. The first pass merges the game’s CPU writes into the host buffer, but leaves the saved comparison bytes unchanged. The next pass then mistakes those merged values for new GPU writes and restores them over newer game writes.

The saved bytes now advance after a successful read and merge, whether or not a write back was necessary. The existing widened-view refresh, whole-page shortcut and pending-range retirement stay in the same order.

Mac regression

The test exercises four layouts, each both with a write-back and with the GPU bytes already present in game memory (a merge that writes nothing):

  • Partial range, then a wider partial range.
  • Partial range, then the whole page.
  • Whole page, then a partial range.
  • Two partial ranges crossing a 64 KiB page boundary.

It changes two game-side bytes between the passes and verifies that a GPU byte outside the first range still goes back with the second. On clean bf99e728 plus the test, all eight cases fail: the three checked bytes are AA 22 BB instead of 66 33 BB. This reproduces the error in the real mapped-buffer path under Wine/D3DMetal.

This addresses overlapping declared ranges. #437 addresses marked pages followed by declared ranges. Neither establishes that a particular in-game visual fault or crash came from this error.

Validation

On M5 Pro / 48 GB, macOS 27.2.1, Wine 11.0 and D3DMetal 4.0b3:

  • The exact release regression failed with all eight wrong results on base + test only; it passes on this branch and prints checked 8 overlapping copy-back cases, confirming it reached the host path.
  • Native workspace, base and head: 555 passed, 0 failed, 17 ignored. Windows-target workspace under Wine/D3DMetal (serial): base 1,124/0/28, head 1,125/0/28 (passed/failed/ignored).
  • Native Clippy and strict Windows-target workspace Clippy (default and all features) passed. Whole-tree and staged asset policy, plus git diff --check, passed.
  • Workspace rustfmt still flags the same 81 files as unmodified main. No unrelated formatting changes included.

Integration with #436 and #437

The three changes were combined locally and the release diagnostics Wine suite passed 36 shadow tests, 0 failed, 4 ignored, including the eight cases here and #437's regression. The ignored mapped capture benchmark passed explicitly and retained a 1.370 ms growing-range median. All-features Windows Clippy also passed.

There is a small source conflict with #436's different snapshot storage. On that layout, keep its snapshot.covers / changed_piece path and use snapshot.refresh(at, host) at the same point as this PR's old.copy_from_slice(host). The local combined test used that resolution, including fragmented captures. #437's production change is independent; both tests need keeping at the shared insertion point.

Prepared and tested with GPT-6.2 Astra. Synthetic test data only.

Port RVZO6’s Marvisak/VIctory#3031 (1de058ca) to macOS. Whole-page deduplication does not cover partial overlaps. Advance the saved bytes after merging even if no title write is needed. Eight M5 Pro D3DMetal cases failed on bf99e72 and pass here, preserving newer CPU bytes and still publishing the GPU writes outside the first range.

Co-authored-by: RVZO6 <66844656+RVZO6@users.noreply.github.com>
…copyback-baseline

# Conflicts:
#	crates/victory-gpu/src/shadow.rs
@pragyaangaur

Copy link
Copy Markdown
Owner

Thanks for this. Many pull requests landed today, and this one now conflicts with main. Could you merge or rebase main into it, rerun the checks and ping here? I will review and merge it as soon as CI is green.

@pragyaangaur
pragyaangaur merged commit efba834 into pragyaangaur:main Nov 27, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants