perf(shader): per-barrier UAV fence elision, aligned 16-bit buffer fast path, and exact integer peepholes #29

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

@⁠jarvixaiassistant-glitch on GitHub · 2026-11-30 15:09 UTC · original
jarvixaiassistant-glitch:perf/shader-barrier-uav-aligned16-peepholes → main · +535 −9 · 3 files · 1 commits · open

Summary

Three self-contained, exact victory-shader compiler optimizations (zero floating-point behavior changes, zero runtime coupling, minimal diff in lower.rs):

  1. Per-barrier UAV memory-fence reachability (emit/barrier_uav.rs)

    • Previously, s_barrier emitted dx.op.barrier bit 2 (UAVMemoryFence) on every s_barrier whenever whole-shader writes_uavs was true.
    • Adds a forward CFG reachability fixed-point pass (barrier_needs_uav_fence) computing the exact (block, inst) s_barrier sites reachable from any UAV store/atomic (Image/Buffer/Smem store/atomic, global_* non-load, flat_* store/atomic) without crossing an intervening emitted s_barrier.
    • Pure-LDS reduction barriers before a final UAV store (or consecutive barriers with no intervening UAV write) emit 1 | 8 (GroupSync | TGSMFence) instead of 1 | 2 | 8, while preserving bit 2 across loops, branch joins, and suppressed no_barrier blocks.
  2. Single-dword fast path for 2-byte aligned 16-bit buffer loads/stores (lower.rs, bitcode/opt.rs)

    • Adds Module::maybe_set(v, depth) conservative known-bits analysis (preserving guaranteed trailing zero bits through Add, Sub, and Mul even across modular wrap-around, e.g. (idx << 1) + 4, (idx * 6) + 2).
    • When bits == 16 and maybe_set(byte, 6) & 1 == 0, within = byte & 3 is guaranteed 0 or 2 (never 3), so a 16-bit access cannot straddle a 4-byte boundary: buffer_load_ushort/sshort omits the second rawBufferLoad + select, and buffer_store_short omits the second guarded atomicBinOp pair.
  3. Exact bit-level unpack-of-pack & equality-compare peepholes (bitcode/opt.rs)

    • Unpack-of-pack folding via maybe_set: drops dead sides of (x | y) / (x ^ y) under And, LShr, Shl, and Trunc (e.g. ((x & 0xFFFF) | (y << 16)) & 0xFFFF -> x & 0xFFFF, >> 16 -> y & 0xFFFF, trunc(x | (y << 16), i16) -> trunc(x, i16)).
    • Exact Cmp(EQ|NE) folding over Xor/Sub/Add: (x ^ y) ==/!= 0 -> x ==/!= y, (x - y) ==/!= 0 -> x ==/!= y, (x ^ k1) ==/!= k2 -> x ==/!= (k1 ^ k2), (x + k1) ==/!= k2 -> x ==/!= (k2 - k1).

Verification (Windows 11, VICTORY_WARP=1)

  • cargo clippy -p victory-shader --lib: 0 warnings.
  • VICTORY_WARP=1 cargo test -p victory-shader --lib -- barrier_uav maybe_set_alignment_and_unpack_cmp_peepholes opt::tests: 16/16 passed (including all 4 barrier_uav CFG unit tests, maybe_set_alignment_and_unpack_cmp_peepholes, and every_pass_leaves_what_random_programs_store randomized parity fuzzing).
  • Clean-room GPL-3.0-or-later, zero game data / zero RVAs.
  • AI-assisted: yes
**@⁠jarvixaiassistant-glitch** on GitHub · 2026-11-30 15:09 UTC · [original](https://github.com/vix0e0e/VIctory-LITE/pull/29) `jarvixaiassistant-glitch:perf/shader-barrier-uav-aligned16-peepholes` → `main` · +535 −9 · 3 files · 1 commits · open ## Summary Three self-contained, exact `victory-shader` compiler optimizations (zero floating-point behavior changes, zero runtime coupling, minimal diff in `lower.rs`): 1. **Per-barrier UAV memory-fence reachability (`emit/barrier_uav.rs`)** - Previously, `s_barrier` emitted `dx.op.barrier` bit `2` (`UAVMemoryFence`) on *every* `s_barrier` whenever whole-shader `writes_uavs` was true. - Adds a forward CFG reachability fixed-point pass (`barrier_needs_uav_fence`) computing the exact `(block, inst)` `s_barrier` sites reachable from any UAV store/atomic (`Image`/`Buffer`/`Smem` store/atomic, `global_*` non-load, `flat_*` store/atomic) without crossing an intervening emitted `s_barrier`. - Pure-LDS reduction barriers before a final UAV store (or consecutive barriers with no intervening UAV write) emit `1 | 8` (`GroupSync | TGSMFence`) instead of `1 | 2 | 8`, while preserving bit `2` across loops, branch joins, and suppressed `no_barrier` blocks. 2. **Single-dword fast path for 2-byte aligned 16-bit buffer loads/stores (`lower.rs`, `bitcode/opt.rs`)** - Adds `Module::maybe_set(v, depth)` conservative known-bits analysis (preserving guaranteed trailing zero bits through `Add`, `Sub`, and `Mul` even across modular wrap-around, e.g. `(idx << 1) + 4`, `(idx * 6) + 2`). - When `bits == 16` and `maybe_set(byte, 6) & 1 == 0`, `within = byte & 3` is guaranteed `0` or `2` (never `3`), so a 16-bit access cannot straddle a 4-byte boundary: `buffer_load_ushort`/`sshort` omits the second `rawBufferLoad` + select, and `buffer_store_short` omits the second guarded `atomicBinOp` pair. 3. **Exact bit-level unpack-of-pack & equality-compare peepholes (`bitcode/opt.rs`)** - Unpack-of-pack folding via `maybe_set`: drops dead sides of `(x | y)` / `(x ^ y)` under `And`, `LShr`, `Shl`, and `Trunc` (e.g. `((x & 0xFFFF) | (y << 16)) & 0xFFFF -> x & 0xFFFF`, `>> 16 -> y & 0xFFFF`, `trunc(x | (y << 16), i16) -> trunc(x, i16)`). - Exact `Cmp(EQ|NE)` folding over `Xor`/`Sub`/`Add`: `(x ^ y) ==/!= 0 -> x ==/!= y`, `(x - y) ==/!= 0 -> x ==/!= y`, `(x ^ k1) ==/!= k2 -> x ==/!= (k1 ^ k2)`, `(x + k1) ==/!= k2 -> x ==/!= (k2 - k1)`. ## Verification (Windows 11, `VICTORY_WARP=1`) - `cargo clippy -p victory-shader --lib`: **0 warnings**. - `VICTORY_WARP=1 cargo test -p victory-shader --lib -- barrier_uav maybe_set_alignment_and_unpack_cmp_peepholes opt::tests`: **16/16 passed** (including all 4 `barrier_uav` CFG unit tests, `maybe_set_alignment_and_unpack_cmp_peepholes`, and `every_pass_leaves_what_random_programs_store` randomized parity fuzzing). - Clean-room `GPL-3.0-or-later`, zero game data / zero RVAs. - `AI-assisted: yes`
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 12:38:39 +00:00
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/29/head:github-bot/gh-29'
git switch 'github-bot/gh-29'

Merge

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