GPU: merge shadow write-back bytes in AVX2 vectors with scalar fallback #1867

Open
github-bot wants to merge 4 commits from github-bot/gh-1867 into main AGit
Owner

@⁠VlREX on GitHub · 2026-11-24 23:49 UTC · original
VlREX:perf/avx2-shadow-merge → main · +118 −8 · 2 files · 4 commits · open

Vectorize CPU-side GPU shadow write-back merging with AVX2, processing 32 bytes per iteration with runtime CPU detection and scalar fallback. Native C AVX2 equivalent verified against all 16,777,216 possible byte triples and 4,416 alignment/length cases, zero mismatches. Three Rust regression tests included. Native Rust integration and GPU performance benchmarks pending. No new dependencies or game assets. AI-assisted (ChatGPT).

**@⁠VlREX** on GitHub · 2026-11-24 23:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/1867) `VlREX:perf/avx2-shadow-merge` → `main` · +118 −8 · 2 files · 4 commits · open Vectorize CPU-side GPU shadow write-back merging with AVX2, processing 32 bytes per iteration with runtime CPU detection and scalar fallback. Native C AVX2 equivalent verified against all 16,777,216 possible byte triples and 4,416 alignment/length cases, zero mismatches. Three Rust regression tests included. Native Rust integration and GPU performance benchmarks pending. No new dependencies or game assets. AI-assisted (ChatGPT).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:47:05 +00:00
Author
Owner

@⁠upipibi on GitHub · 2026-11-25 00:10 UTC · original

Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at eabd870: cargo test -p victory-gpu --locked gives 79 passed, 2 failed, 1 ignored. The two failures are the NVIDIA heap-cap ones main also has (descriptor::host::tests::dynamic_slots_are_held_until_released and memory::tests::lists_share_a_table_and_copies_keep_their_views, #1744), so there is nothing new on this hardware. Not run: a title.

AI-assisted (Claude Code).

**@⁠upipibi** on GitHub · 2026-11-25 00:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/1867#issuecomment-7148235385) Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at `eabd870`: `cargo test -p victory-gpu --locked` gives 79 passed, 2 failed, 1 ignored. The two failures are the NVIDIA heap-cap ones `main` also has (`descriptor::host::tests::dynamic_slots_are_held_until_released` and `memory::tests::lists_share_a_table_and_copies_keep_their_views`, #1744), so there is nothing new on this hardware. Not run: a title. AI-assisted (Claude Code).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 07:18 UTC · original · edited 2026-11-25 22:18 UTC

Automated triage for the maintainers.

Needs rebase. This PR no longer merges cleanly into main (conflict in crates/victory-gpu/src/shadow.rs). It will be reviewed again once it is rebased.

From the earlier needs-work note, still open: post before/after copy-back timings from a release build, and update the title, description and test name, which still describe AVX2 vectors.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 07:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/1867#issuecomment-7155720106) · edited 2026-11-25 22:18 UTC <!-- victory-triage v1 head=ea57fd91c0fb76bdf4b6017ba5d8bf16be2d526c verdict=needs-rebase at=2026-11-25T22:22:40Z --> Automated triage for the maintainers. **Needs rebase.** This PR no longer merges cleanly into `main` (conflict in `crates/victory-gpu/src/shadow.rs`). It will be reviewed again once it is rebased. From the earlier needs-work note, still open: post before/after copy-back timings from a release build, and update the title, description and test name, which still describe AVX2 vectors. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠catminou4 on GitHub · 2026-11-25 00:32 UTC · original · reviewed

Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

Shadow write-back bytes merged in AVX2 (docs+gpu): SIMD merge of shadow ranges — pairs with #1382's batched barriers.

**@⁠catminou4** on GitHub · 2026-11-25 00:32 UTC · [original](https://github.com/Marvisak/VIctory/pull/1867#pullrequestreview-6049696360) · **reviewed** Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff. Shadow write-back bytes merged in AVX2 (docs+gpu): SIMD merge of shadow ranges — pairs with #1382's batched barriers.
Author
Owner

@⁠upipibi on GitHub · 2026-11-26 17:46 UTC · original

Release-build copy-back timings: std-only bench, bodies copied verbatim, workspace [profile.release]. Ns per call net of a memcpy baseline, median of 41 interleaved samples. Scalar = the loop this PR replaces (70564ae0), PR = merge at ea57fd91.

case (aligned / misaligned) scalar PR speedup
4 KiB 0 % 1197 / 1200 145 / 285 8.3x / 4.2x
4 KiB 1 % 1383 / 1357 146 / 282 9.5x / 4.8x
4 KiB 50 % 2095 / 2085 146 / 287 14x / 7.3x
64 KiB 1 % 23943 / 32050 2502 / 5641 9.6x / 5.7x
64 KiB 50 % 158875 / 146669 3311 / 4624 48x / 32x
1 MiB 0 % 304511 / 303017 47577 / 78692 6.4x / 3.9x
1 MiB 1 % 396556 / 399141 47758 / 78950 8.3x / 5.1x
1 MiB 50 % 2705576 / 2825431 47733 / 80571 57x / 35x

Asm (baseline SSE2): the old loop is only partly vectorized. LLVM does the compares 16 bytes at a time, but it scalarizes the conditional *t = *h into 16 test/branch/byte-store sequences per block. merge compiles to a branch-free pcmpeqb/pand/pandn/por loop.

However, main already has a branch-free merge_writeback (#2054). It runs 2-8 % faster than this PR's merge in 35 of 36 session-case pairs, so after a rebase this PR adds no speed.

A second session kept the ratios, but its absolute times ran up to 64 % higher (loaded machine).

Ryzen 9 5950X with AVX2, rustc 1.98.1, high priority, pinned to one core. Inputs are synthetic.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠upipibi** on GitHub · 2026-11-26 17:46 UTC · [original](https://github.com/Marvisak/VIctory/pull/1867#issuecomment-7199622295) Release-build copy-back timings: std-only bench, bodies copied verbatim, workspace `[profile.release]`. Ns per call net of a memcpy baseline, median of 41 interleaved samples. Scalar = the loop this PR replaces (70564ae0), PR = `merge` at ea57fd91. | case (aligned / misaligned) | scalar | PR | speedup | |---|---|---|---| | 4 KiB 0 % | 1197 / 1200 | 145 / 285 | 8.3x / 4.2x | | 4 KiB 1 % | 1383 / 1357 | 146 / 282 | 9.5x / 4.8x | | 4 KiB 50 % | 2095 / 2085 | 146 / 287 | 14x / 7.3x | | 64 KiB 1 % | 23943 / 32050 | 2502 / 5641 | 9.6x / 5.7x | | 64 KiB 50 % | 158875 / 146669 | 3311 / 4624 | 48x / 32x | | 1 MiB 0 % | 304511 / 303017 | 47577 / 78692 | 6.4x / 3.9x | | 1 MiB 1 % | 396556 / 399141 | 47758 / 78950 | 8.3x / 5.1x | | 1 MiB 50 % | 2705576 / 2825431 | 47733 / 80571 | 57x / 35x | Asm (baseline SSE2): the old loop is only partly vectorized. LLVM does the compares 16 bytes at a time, but it scalarizes the conditional `*t = *h` into 16 test/branch/byte-store sequences per block. `merge` compiles to a branch-free pcmpeqb/pand/pandn/por loop. However, `main` already has a branch-free `merge_writeback` (#2054). It runs 2-8 % faster than this PR's `merge` in 35 of 36 session-case pairs, so after a rebase this PR adds no speed. A second session kept the ratios, but its absolute times ran up to 64 % higher (loaded machine). Ryzen 9 5950X with AVX2, rustc 1.98.1, high priority, pinned to one core. Inputs are synthetic. AI-assisted (Claude Code, Claude Opus 5.5).
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/1867/head:github-bot/gh-1867'
git switch 'github-bot/gh-1867'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1867'
git switch 'github-bot/gh-1867'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1867'
git switch 'github-bot/gh-1867'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1867'
git switch 'main'
git merge --squash 'github-bot/gh-1867'
git switch 'main'
git merge --ff-only 'github-bot/gh-1867'
git switch 'main'
git merge 'github-bot/gh-1867'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!1867
No description provided.