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

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

@⁠gomeaw on GitHub · 2026-11-24 23:01 UTC · original
gomeaw:perf/shadow-copy-back-span → main · +45 −29 · 1 files · 1 commits · open

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.

**@⁠gomeaw** on GitHub · 2026-11-24 23:01 UTC · [original](https://github.com/fxceless/victory-fork/pull/255) `gomeaw:perf/shadow-copy-back-span` → `main` · +45 −29 · 1 files · 1 commits · open ## 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://git.gtahub.st/github/fxceless--victory-fork/pulls/255) [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.
Use fixed-size comparisons to skip equal bytes and retain byte-level bounds for the merge. Cover unaligned ranges, partial chunks and both directions against the byte-wise search.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:39:18 +00:00
Author
Owner

@⁠ryotdev on GitHub · 2026-11-24 23:20 UTC · original

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.

**@⁠ryotdev** on GitHub · 2026-11-24 23:20 UTC · [original](https://github.com/fxceless/victory-fork/pull/255#issuecomment-7147297392) 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 has changes conflicting with the target branch.
  • crates/victory-gpu/src/shadow.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-255'
git switch 'github-bot/gh-255'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-255'
git switch 'github-bot/gh-255'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-255'
git switch 'main'
git merge --squash 'github-bot/gh-255'
git switch 'main'
git merge --ff-only 'github-bot/gh-255'
git switch 'main'
git merge 'github-bot/gh-255'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.