GPU: copy-back reads into scratch sized to the changed stretch, not a zeroed 64 KiB per range #240

Open
fffluffy-dev wants to merge 1 commit from upstream-pr/240 into main
fffluffy-dev commented 2026-11-24 22:58:32 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by fffluffy-dev on 2026-11-24T22:58:32Z.


Shadow::copy_back_with allocated and zeroed a 64 KiB scratch (vec![0u8; PIECE]) on every call, once per joined span, though it only reads the stretch from the first to the last changed byte of each differing piece. The merge moves into back_piece unchanged; the scratch now starts empty and is sized to each stretch, as card_merge already does.

Same bytes compared, read and written back as before; only the scratch changes. Every scratch byte used is first filled by read_into for exactly that stretch, and a failed read returns before the merge, as before.

Model of one submission (8 MiB copy, overlapping and repeated ranges): scratch bytes zeroed 40,763,392 (622 allocations) → 10,912 (171); bytes compared, pieces and bytes written back unchanged. Marvisak/VIctory#1656 found the same allocation before upstream redesigned Shadow.

Validation (cargo-xwin, tests under Wine): cargo test -p victory-gpu 111 passed, 1 ignored, new test a_piece_put_back_reads_only_its_stretch; clippy clean both ways; policy ok. On a real frame: "copying back" ms should fall at the same MB.

AI use: written with Claude Code (Claude Opus 5.5); reviewed and posted with my approval. No game files were used.

<!-- greyfinch-sync:fxceless/victory-fork:issue:6593105246 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/240). Originally posted by [fffluffy-dev](https://github.com/fffluffy-dev) on 2026-11-24T22:58:32Z. --- `Shadow::copy_back_with` allocated and zeroed a 64 KiB scratch (`vec![0u8; PIECE]`) on every call, once per joined span, though it only reads the stretch from the first to the last changed byte of each differing piece. The merge moves into `back_piece` unchanged; the scratch now starts empty and is sized to each stretch, as `card_merge` already does. Same bytes compared, read and written back as before; only the scratch changes. Every scratch byte used is first filled by `read_into` for exactly that stretch, and a failed read returns before the merge, as before. Model of one submission (8 MiB copy, overlapping and repeated ranges): scratch bytes zeroed 40,763,392 (622 allocations) → 10,912 (171); bytes compared, pieces and bytes written back unchanged. Marvisak/VIctory#1656 found the same allocation before upstream redesigned `Shadow`. Validation (cargo-xwin, tests under Wine): `cargo test -p victory-gpu` 111 passed, 1 ignored, new test `a_piece_put_back_reads_only_its_stretch`; clippy clean both ways; policy ok. On a real frame: "copying back" ms should fall at the same MB. **AI use:** written with Claude Code (Claude Opus 5.5); reviewed and posted with my approval. No game files were used.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/240:upstream-pr/240'
git switch 'upstream-pr/240'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/240'
git switch 'upstream-pr/240'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/240'
git switch 'upstream-pr/240'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/240'
git switch 'main'
git merge --squash 'upstream-pr/240'
git switch 'main'
git merge --ff-only 'upstream-pr/240'
git switch 'main'
git merge 'upstream-pr/240'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
fxceless/victory-fork!240
No description provided.