GPU: scan copy-back bounds in 32-byte chunks #255

Open
gomeaw wants to merge 1 commit from upstream-pr/255 into main
gomeaw commented 2026-11-24 23:01:32 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by gomeaw on 2026-11-24T23:01:32Z.


Summary

Copy-back locates the first and last changed byte of each differing piece before replaying GPU writes into title memory. The RTX 5080 report in #107 measured 44–47 ms per frame for the broader copy-back stage in one cutscene.

Use fixed 32-byte equality in both searches and inspect individual bytes only in the unequal chunk or the partial tail. On Windows x64, Rust 1.98.1 emits two SSE comparisons per complete chunk. The synchronous, relay and card-local paths all use these helpers. The byte offsets passed to the merge stay the same.

Related work: #71 changes the GPU compare and readback queue. #240 reduces scratch allocation and still uses both searches. I verified that this patch merges cleanly with #240.

Measurement

Windows x64, GitHub-hosted AMD EPYC 7763, Rust 1.98.1, optimized standalone A/B of the original and patched helpers. Median of three runs, each reporting the median of nine samples over 128 synthetic pieces per iteration.

64 KiB piece Base (µs) Patch (µs)
Equal 5.94 2.70
One changed byte near the middle 6.64 4.54
One changed byte near the beginning 4.95 3.27
One changed byte near the end 5.99 3.50
Two interior changes 3.35 1.78

A 64 KiB piece differing at both ends took 0.6 ns longer. The 64-byte input with a middle change took 3.3 ns longer. The benchmark times the CPU search only. An independent RTX 5070 checkpoint A/B passed the shadow tests and reported similar copy-back time per MB with variation in streaming. The gameplay benefit remains unverified. Independent test report Windows run · Benchmark source

The bytewise regression checks cover unaligned input, equal spans, partial chunks, unequal lengths and changes on either side of chunk boundaries. Both Clippy configurations and cargo test --workspace --locked passed on the Windows x64 runner with 497 passed, 7 ignored and 0 failed. The asset policy also passed. Windows test job

AI-assisted with Codex. All benchmark and test inputs are synthetic.

<!-- greyfinch-sync:fxceless/victory-fork:issue:6593148812 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/255). Originally posted by [gomeaw](https://github.com/gomeaw) on 2026-11-24T23:01:32Z. --- ## Summary Copy-back locates the first and last changed byte of each differing piece before replaying GPU writes into title memory. The RTX 5080 report in #107 measured 44–47 ms per frame for the broader copy-back stage in one cutscene. Use fixed 32-byte equality in both searches and inspect individual bytes only in the unequal chunk or the partial tail. On Windows x64, Rust 1.98.1 emits two SSE comparisons per complete chunk. The synchronous, relay and card-local paths all use these helpers. The byte offsets passed to the merge stay the same. Related work: #71 changes the GPU compare and readback queue. #240 reduces scratch allocation and still uses both searches. I verified that this patch merges cleanly with #240. ## Measurement Windows x64, GitHub-hosted AMD EPYC 7763, Rust 1.98.1, optimized standalone A/B of the original and patched helpers. Median of three runs, each reporting the median of nine samples over 128 synthetic pieces per iteration. | 64 KiB piece | Base (µs) | Patch (µs) | | --- | ---: | ---: | | Equal | 5.94 | 2.70 | | One changed byte near the middle | 6.64 | 4.54 | | One changed byte near the beginning | 4.95 | 3.27 | | One changed byte near the end | 5.99 | 3.50 | | Two interior changes | 3.35 | 1.78 | A 64 KiB piece differing at both ends took 0.6 ns longer. The 64-byte input with a middle change took 3.3 ns longer. The benchmark times the CPU search only. An independent RTX 5070 checkpoint A/B passed the shadow tests and reported similar copy-back time per MB with variation in streaming. The gameplay benefit remains unverified. [Independent test report](https://github.com/fxceless/victory-fork/pull/255#issuecomment-7147297392) [Windows run](https://github.com/gomeaw/victory-fork/actions/runs/45506039177) · [Benchmark source](https://github.com/gomeaw/victory-fork/blob/d906ba3675efd89315b17331ef4ffaba42402408/.github/shadow-copy-back-bench.rs) The bytewise regression checks cover unaligned input, equal spans, partial chunks, unequal lengths and changes on either side of chunk boundaries. Both Clippy configurations and `cargo test --workspace --locked` passed on the Windows x64 runner with 497 passed, 7 ignored and 0 failed. The asset policy also passed. [Windows test job](https://github.com/gomeaw/victory-fork/actions/runs/45506039177/job/138841415063) AI-assisted with Codex. All benchmark and test inputs are synthetic.
ryotdev commented 2026-11-25 00:10:06 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by ryotdev on 2026-11-24T23:20:53Z.


I tested 413bab7 on Windows with an RTX 5070 (driver 610.88) and Ryzen 7 7800X3D. I ran the same 3D checkpoint once per build, with the same release settings, starting cache files and scripted inputs, and capture disabled. The only source change between the two builds was this PR. All 20 native shadow unit tests passed, including both byte-search tests.

In the shared 145–158 seconds after launch, both runs had 12 window-title samples at 4,800–5,100 draws/frame. Median reported frame time was 231.8 ms before and 223.4 ms after. The two host copy-back reports per arm averaged 35.2 ms for 70.05 MB before and 33.5 ms for 66.9 MB after, about 0.50 ms/MB in both. Streaming varied between the runs and the host frame-time reports moved in the opposite direction. This pair does not establish an end-to-end speedup or a regression. The changed byte-search functions represent only part of the copy-back timer.

AI-assisted hardware test. No game data attached.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7147297392 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/255#issuecomment-7147297392). Originally posted by [ryotdev](https://github.com/ryotdev) on 2026-11-24T23:20:53Z. --- I tested 413bab7 on Windows with an RTX 5070 (driver 610.88) and Ryzen 7 7800X3D. I ran the same 3D checkpoint once per build, with the same release settings, starting cache files and scripted inputs, and capture disabled. The only source change between the two builds was this PR. All 20 native shadow unit tests passed, including both byte-search tests. In the shared 145–158 seconds after launch, both runs had 12 window-title samples at 4,800–5,100 draws/frame. Median reported frame time was 231.8 ms before and 223.4 ms after. The two host copy-back reports per arm averaged 35.2 ms for 70.05 MB before and 33.5 ms for 66.9 MB after, about 0.50 ms/MB in both. Streaming varied between the runs and the host frame-time reports moved in the opposite direction. This pair does not establish an end-to-end speedup or a regression. The changed byte-search functions represent only part of the copy-back timer. AI-assisted hardware test. No game data attached.
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/255:upstream-pr/255'
git switch 'upstream-pr/255'

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/255'
git switch 'upstream-pr/255'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/255'
git switch 'upstream-pr/255'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/255'
git switch 'main'
git merge --squash 'upstream-pr/255'
git switch 'main'
git merge --ff-only 'upstream-pr/255'
git switch 'main'
git merge 'upstream-pr/255'
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!255
No description provided.