perf(shader): add DXIL folds, pure LICM, local/shared reuse, and barrier dedup #42

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

@⁠Vladimir-Human on GitHub · 2026-11-27 12:51 UTC · original
Vladimir-Human:perf/dxil-opt-licm-barriers → main · +4700 −94 · 2 files · 1 commits · open

Summary

Extends victory-shader's bitcode::opt DXIL clean-up pipeline with four exact optimization improvements:

  1. Algebraic, bitwise, compare, and select folds (FOLD, bit 2) — canonicalizes and folds additional integer/boolean/compare/select identities while keeping float semantics exact.
  2. Pure loop-invariant code motion (LICM, bit 128) — hoists pure, non-trapping loop-invariant instructions out of natural loops into their dominating preheader (splitting conditional preheaders lazily when needed).
  3. Pointer-root load/store tracking (LOADS, bit 16) — separates thread-private (space 0), groupshared (space 3), constant tables, and DXIL resource memory so non-aliasing writes preserve unrelated reads, forwards space 0 stores to loads, reuses consecutive space 3 reads across non-aliasing resource writes, and eliminates overwritten dead stores within a block.
    • Soundness guard: space 3 (groupshared) store-to-load forwarding is intentionally omitted (const stores invalidate the slot; dynamic stores clear cached space 3 loads without inserting) so barrierless wave-ordered LDS exchange patterns (lds[bucket] = lane; if (lds[bucket] == lane)) remain exact.
  4. Adjacent & bounded read-after-read barrier deduplication (BARRIERS, bit 256) — eliminates redundant dx.op.barrier(mode) calls covered by an earlier barrier across pure ALU or bounded non-escaping LDS read phases.

DEFAULT is updated from 63 to 447 (all passes except opt-in WIDE = 64; ALL = 511). Disk shader cache invalidation is automatic via victory-shader/build.rs (VICTORY_SHADER_SOURCE_HASH), victory-gpu/build.rs (VICTORY_TRANSLATOR), and shader_opt() in shader_cache.rs.

Verification

  • cargo clippy -p victory-shader -p xtask --all-targets --locked -- -D warnings (default & --all-features): 0 warnings
  • cargo test -p xtask --locked: 6 passed; 0 failed (repository_passes_policy green)
  • Hardware D3D12 (VICTORY_D3D12_DEBUG=1, VICTORY_REQUIRE_HW_GPU=1): cargo test -p victory-shader --locked -- --test-threads=1 — 300 passed; 0 failed; 5 ignored
  • WARP (VICTORY_D3D12_DEBUG=1): opt::tests::hw_tests 2 passed; 0 failed; 1 ignored
  • Wide-load parity (VICTORY_SHADER_OPT=511): scalar_buffer_loads_read_the_same_dwords_one_call_or_four 1/1, opt::tests::hw_tests 2/2
**@⁠Vladimir-Human** on GitHub · 2026-11-27 12:51 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/42) `Vladimir-Human:perf/dxil-opt-licm-barriers` → `main` · +4700 −94 · 2 files · 1 commits · open ## Summary Extends `victory-shader`'s `bitcode::opt` DXIL clean-up pipeline with four exact optimization improvements: 1. **Algebraic, bitwise, compare, and select folds (`FOLD`, bit `2`)** — canonicalizes and folds additional integer/boolean/compare/select identities while keeping float semantics exact. 2. **Pure loop-invariant code motion (`LICM`, bit `128`)** — hoists pure, non-trapping loop-invariant instructions out of natural loops into their dominating preheader (splitting conditional preheaders lazily when needed). 3. **Pointer-root load/store tracking (`LOADS`, bit `16`)** — separates thread-private (`space 0`), groupshared (`space 3`), constant tables, and DXIL resource memory so non-aliasing writes preserve unrelated reads, forwards `space 0` stores to loads, reuses consecutive `space 3` reads across non-aliasing resource writes, and eliminates overwritten dead stores within a block. - **Soundness guard:** `space 3` (groupshared) store-to-load forwarding is intentionally omitted (const stores invalidate the slot; dynamic stores clear cached `space 3` loads without inserting) so barrierless wave-ordered LDS exchange patterns (`lds[bucket] = lane; if (lds[bucket] == lane)`) remain exact. 4. **Adjacent & bounded read-after-read barrier deduplication (`BARRIERS`, bit `256`)** — eliminates redundant `dx.op.barrier(mode)` calls covered by an earlier barrier across pure ALU or bounded non-escaping LDS read phases. `DEFAULT` is updated from `63` to `447` (all passes except opt-in `WIDE = 64`; `ALL = 511`). Disk shader cache invalidation is automatic via `victory-shader/build.rs` (`VICTORY_SHADER_SOURCE_HASH`), `victory-gpu/build.rs` (`VICTORY_TRANSLATOR`), and `shader_opt()` in `shader_cache.rs`. ## Verification - `cargo clippy -p victory-shader -p xtask --all-targets --locked -- -D warnings` (default & `--all-features`): **0 warnings** - `cargo test -p xtask --locked`: **6 passed; 0 failed** (`repository_passes_policy` green) - Hardware D3D12 (`VICTORY_D3D12_DEBUG=1`, `VICTORY_REQUIRE_HW_GPU=1`): `cargo test -p victory-shader --locked -- --test-threads=1` — **300 passed; 0 failed; 5 ignored** - WARP (`VICTORY_D3D12_DEBUG=1`): `opt::tests::hw_tests` **2 passed; 0 failed; 1 ignored** - Wide-load parity (`VICTORY_SHADER_OPT=511`): `scalar_buffer_loads_read_the_same_dwords_one_call_or_four` **1/1**, `opt::tests::hw_tests` **2/2**
Extend bitcode::opt with algebraic/bitwise/compare/select folds, pure
loop-invariant code motion (LICM, bit 128), pointer-root load/store
tracking (thread-private space-0 store-to-load forwarding, non-aliasing
space-3 load-to-load reuse, overwritten dead store elimination), and
adjacent plus bounded read-after-read redundant barrier elimination
(BARRIERS, bit 256).

Space-3 (groupshared) store-to-load forwarding is intentionally omitted
(const stores invalidate the slot; dynamic stores clear space-3 cached
loads without inserting) so barrierless wave-ordered LDS exchange
patterns (`lds[bucket] = lane; if (lds[bucket] == lane)`) remain exact.

DEFAULT becomes 447 (all passes except opt-in WIDE=64; ALL=511).
Shader cache invalidation is automatic via VICTORY_TRANSLATOR /
VICTORY_SHADER_SOURCE_HASH and shader_opt() in shader_cache.rs.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 13:02:05 +00:00
Author
Owner

@⁠jptorres96 on GitHub · 2026-11-27 15:33 UTC · original

Independent run on Ada: RTX 4080 SUPER 16 GB, driver 621.01, Ryzen 5 5600X, Windows build 26300, PR head 00d5623, toolchain 1.98.1, DXIL validator from DXC 1.9.2609.5, VICTORY_REQUIRE_HW_GPU=1, nothing else using the GPU.

  • dxil_opt_hw_gpu_bit_exact_parity_and_validation: passed
  • cargo test -p victory-shader --lib -- --test-threads=1: 300 passed, 0 failed, 5 ignored

bench_dxil_opt_hw_gpu (release, GPU median, one run):

opt=0 old_bits DEFAULT (new)
1. Loop + LICM + FOLD 74.75 us 74.75 us 60.42 us
2. LDS forwarding + barriers 114.69 us 113.66 us 78.85 us
3. Real GFX10 loop 69.63 us 57.34 us 57.34 us
4. Real GFX10 waterfall 4.10 us 4.10 us 4.10 us

On this card the synthetic cases gain −19% (1) and −31% (2) over old_bits; in case 1 old_bits gains nothing over opt=0, so the driver does not hoist these itself. The two real translated programs show no change between old_bits and the new default, so the in-game gain is still open. I have no game dump to measure it.

**@⁠jptorres96** on GitHub · 2026-11-27 15:33 UTC · [original](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/42#issuecomment-7222210067) Independent run on Ada: RTX 4080 SUPER 16 GB, driver 621.01, Ryzen 5 5600X, Windows build 26300, PR head `00d5623`, toolchain 1.98.1, DXIL validator from DXC 1.9.2609.5, `VICTORY_REQUIRE_HW_GPU=1`, nothing else using the GPU. - `dxil_opt_hw_gpu_bit_exact_parity_and_validation`: passed - `cargo test -p victory-shader --lib -- --test-threads=1`: 300 passed, 0 failed, 5 ignored `bench_dxil_opt_hw_gpu` (release, GPU median, one run): | | opt=0 | old_bits | DEFAULT (new) | |---|---:|---:|---:| | 1. Loop + LICM + FOLD | 74.75 us | 74.75 us | 60.42 us | | 2. LDS forwarding + barriers | 114.69 us | 113.66 us | 78.85 us | | 3. Real GFX10 loop | 69.63 us | 57.34 us | 57.34 us | | 4. Real GFX10 waterfall | 4.10 us | 4.10 us | 4.10 us | On this card the synthetic cases gain −19% (1) and −31% (2) over `old_bits`; in case 1 `old_bits` gains nothing over opt=0, so the driver does not hoist these itself. The two real translated programs show no change between `old_bits` and the new default, so the in-game gain is still open. I have no game dump to measure it.
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/42/head:github-bot/gh-42'
git switch 'github-bot/gh-42'

Merge

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