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

Merged
Vladimir-Human merged 1 commit from upstream-pr/42 into main 2026-11-28 19:01:28 +00:00
Vladimir-Human commented 2026-11-27 12:51:00 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by Vladimir-Human on 2026-11-27T12:51:00Z.


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
<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:issue:5526928780 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/42). Originally posted by [Vladimir-Human](https://github.com/Vladimir-Human) on 2026-11-27T12:51:00Z. --- ## 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**
jptorres96 commented 2026-11-27 15:33:51 +00:00 (Migrated from github.com)

Imported from trustno1-coder/VIctory-NVIDIA. Originally posted by jptorres96 on 2026-11-27T15:33:51Z.


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.

<!-- greyfinch-sync:trustno1-coder/VIctory-NVIDIA:comment:7222210067 --> Imported from [trustno1-coder/VIctory-NVIDIA](https://github.com/trustno1-coder/VIctory-NVIDIA/pull/42#issuecomment-7222210067). Originally posted by [jptorres96](https://github.com/jptorres96) on 2026-11-27T15:33:51Z. --- 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.
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
trustno1-coder/VIctory-NVIDIA!42
No description provided.