Copy-back: look for changed runs a word at a time (same output, 4-6x faster search) #26

Open
github-bot wants to merge 1 commit from github-bot/gh-26 into beta AGit
Owner

@⁠spy0eye-beep on GitHub · 2026-11-25 17:24 UTC · original
spy0eye-beep:klbf-fast-copyback → beta · +102 −1 · 1 files · 1 commits · open

What

A CPU-only speed-up in copy-back (shadow.rs back_piece), with the same result byte for byte: nothing about what is drawn changes.

After the merge, back_piece looks for the runs of changed bytes in each 64 KiB piece's mask, one byte at a time. Where a shader wrote here and there in a piece, the mask is mostly zeros, and that search ran at 2-4 GB/s. It now passes over zero words 8 bytes at a time (mask_runs), then finishes byte by byte as before.

cargo test --release -p victory-gpu --lib mask_runs_speed -- --ignored --nocapture, i7-13620H:

64 KiB piece byte by byte by words
every byte written 4.0 GB/s 4.2 GB/s
every 16th dword written 2.4 GB/s 10.0 GB/s
1 byte per 4 KiB written 4.2 GB/s 27.3 GB/s

Same output

  • New test word_search_finds_the_byte_runs: random masks of every length 0-40 and 63, 64, 65, 4095, 4096, 65536 bytes, at five densities (dense to one byte per 4 KiB), runs touching word edges and the end. The runs equal those of the old byte-by-byte search, kept in the test as the reference.
  • The merge itself is unchanged. (I tried merging 8 bytes at a time too: identical bytes, but slower than the byte loop, which the compiler already vectorises. Left out.)
  • The kernel writes per run (write_mapped) are unchanged, so title bytes between runs are still not written (upstream VIctory #2009).

Testing

  • cargo test -p victory-gpu --all-features on the RTX 4060 Laptop: 163 passed, 0 failed (shadow tests: 29 passed).
  • Clippy: the same two existing errors as beta (draw.rs sort_unstable_by_key, indirect.rs depth_written), none new. rustfmt: no new differences.
  • Not measured in the title. How much of a frame this saves depends on how scattered the shaders' writes are; in fxceless/victory-fork#26 copy-back was 148-198 ms of a ~300 ms frame for 45-73 MB, most of it presumably the kernel writes, which this does not touch.

AI-assisted (Claude).

🤖 Generated with Claude Code

**@⁠spy0eye-beep** on GitHub · 2026-11-25 17:24 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/26) `spy0eye-beep:klbf-fast-copyback` → `beta` · +102 −1 · 1 files · 1 commits · open ## What A CPU-only speed-up in copy-back (`shadow.rs` `back_piece`), with **the same result byte for byte**: nothing about what is drawn changes. After the merge, `back_piece` looks for the runs of changed bytes in each 64 KiB piece's mask, one byte at a time. Where a shader wrote here and there in a piece, the mask is mostly zeros, and that search ran at 2-4 GB/s. It now passes over zero words 8 bytes at a time (`mask_runs`), then finishes byte by byte as before. `cargo test --release -p victory-gpu --lib mask_runs_speed -- --ignored --nocapture`, i7-13620H: | 64 KiB piece | byte by byte | by words | |---|---|---| | every byte written | 4.0 GB/s | 4.2 GB/s | | every 16th dword written | 2.4 GB/s | **10.0 GB/s** | | 1 byte per 4 KiB written | 4.2 GB/s | **27.3 GB/s** | ## Same output - New test `word_search_finds_the_byte_runs`: random masks of every length 0-40 and 63, 64, 65, 4095, 4096, 65536 bytes, at five densities (dense to one byte per 4 KiB), runs touching word edges and the end. The runs equal those of the old byte-by-byte search, kept in the test as the reference. - The merge itself is unchanged. (I tried merging 8 bytes at a time too: identical bytes, but slower than the byte loop, which the compiler already vectorises. Left out.) - The kernel writes per run (`write_mapped`) are unchanged, so title bytes between runs are still not written (upstream VIctory #2009). ## Testing - `cargo test -p victory-gpu --all-features` on the RTX 4060 Laptop: 163 passed, 0 failed (`shadow` tests: 29 passed). - Clippy: the same two existing errors as `beta` (`draw.rs` `sort_unstable_by_key`, `indirect.rs` `depth_written`), none new. rustfmt: no new differences. - Not measured in the title. How much of a frame this saves depends on how scattered the shaders' writes are; in fxceless/victory-fork#26 copy-back was 148-198 ms of a ~300 ms frame for 45-73 MB, most of it presumably the kernel writes, which this does not touch. AI-assisted (Claude). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
back_piece found the runs of changed bytes in a piece's mask one byte at a
time; where a shader wrote here and there in a piece the mask is mostly
zeros, and that search ran at 2-4 GB/s. mask_runs passes over zero words
8 bytes at a time, then finishes byte by byte: 10-27 GB/s on such masks,
the same on dense ones, and the same runs (word_search_finds_the_byte_runs,
against the old search kept as the reference). The merge and the writes
per run are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:52:48 +00:00
Author
Owner

@⁠PastiiJay on GitHub · 2026-11-25 18:38 UTC · original

Thanks a lot @⁠spy0eye-beep! Noted. It goes into tonight's RX 9070 XT test queue and I'll report the result here.

**@⁠PastiiJay** on GitHub · 2026-11-25 18:38 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/26#issuecomment-7171182504) Thanks a lot @⁠spy0eye-beep! Noted. It goes into tonight's RX 9070 XT test queue and I'll report the result here.
Author
Owner

@⁠gmankab on GitHub · 2026-11-25 19:20 UTC · original

I ran word_search_finds_the_byte_runs and mask_runs_speed on the exact PR head. The correctness test passed. On the Xeon E5-2670 v3, the dense mask was 1.69 → 1.68 GB/s, one changed byte per 64 bytes was 1.16 → 4.03 GB/s, and one per 4 KiB was 1.64 → 9.48 GB/s.

I also ported the commit to FX with Rayane’s authorship preserved. All 30 of its shadow tests passed, and the mask scan showed a similar gain on sparse inputs. FX draft PR

Tested-on: Fedora Linux 45 x86_64, Wine in the Victory Flatpak with DRM hidden
Assisted-by: gpt-6.2 sol xhigh

**@⁠gmankab** on GitHub · 2026-11-25 19:20 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/26#issuecomment-7172160924) I ran `word_search_finds_the_byte_runs` and `mask_runs_speed` on the exact PR head. The correctness test passed. On the Xeon E5-2670 v3, the dense mask was 1.69 → 1.68 GB/s, one changed byte per 64 bytes was 1.16 → 4.03 GB/s, and one per 4 KiB was 1.64 → 9.48 GB/s. I also ported the commit to FX with Rayane’s authorship preserved. All 30 of its shadow tests passed, and the mask scan showed a similar gain on sparse inputs. [FX draft PR](https://github.com/fxceless/victory-fork/pull/1094) Tested-on: Fedora Linux 45 x86_64, Wine in the Victory Flatpak with DRM hidden Assisted-by: gpt-6.2 sol xhigh
Author
Owner

@⁠PastiiJay on GitHub · 2026-11-25 19:21 UTC · original

Thanks a lot @⁠gmankab for measuring it, those are great numbers (up to ~6x on sparse changes), and for porting it to fxceless with Rayane's authorship kept. It's already in our next test build, and the results will be posted here.

**@⁠PastiiJay** on GitHub · 2026-11-25 19:21 UTC · [original](https://github.com/PastiiJay/klbf-lab/pull/26#issuecomment-7172193773) Thanks a lot @⁠gmankab for measuring it, those are great numbers (up to ~6x on sparse changes), and for porting it to fxceless with Rayane's authorship kept. It's already in our next test build, and the results will be posted here.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
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/26/head:github-bot/gh-26'
git switch 'github-bot/gh-26'

Merge

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