perf(shader): add DXIL pure LICM, canonical ptr-path LDS forwarding, and barrier dedup #1126

Open
github-bot wants to merge 3 commits from github-bot/gh-1126 into main AGit
Owner

@⁠Vladimir-Human on GitHub · 2026-11-25 20:44 UTC · original
Vladimir-Human:shader/dxil-opt-licm-alloca → main · +4655 −95 · 2 files · 3 commits · open

AI-assisted clean-room contribution (victory-shader, synthetic DXIL bitcode tests + hardware GPU parity only — no title files used).

Summary

Adds four sound DXIL bitcode optimization passes inside crates/victory-shader/src/emit/bitcode/opt.rs (and exposes pass-mask test control in crates/victory-shader/src/emit/mod.rs while keeping translation_fingerprint and translate_plain untouched):

  1. Algebraic / select folds & canonical comparison tracking (FACTS): folds redundant compares/selects along dominating branches without introducing AMD fcmp one.
  2. Pure loop-invariant code motion (LICM = 64): hoists loop-invariant pure value-only DXIL math calls, loads on non-escaping invariant slots, and bounded GEPs across split loop preheaders (split_preheader, keeping dominators/SSA/outer loops coherent), while strictly gating non-guaranteed blocks and tracking per-instruction WriteKind::All / dx.op.discard cutoffs.
  3. Hardened local & LDS forwarding / DSE (LOADS = 16): canonicalizes scalar-leaf GEP paths (trace_ptr with signed indices, per-level bounds, strict leaf types, unbounded SSA hop depth matching escaped_globals) and forwards intra-block stores across disjoint pointers.
  4. Adjacent redundant barrier elimination (BARRIERS = 128): removes provably redundant consecutive barriers without accumulating hazard state across unrelated regions.
  • Disjoint scope: modifies only crates/victory-shader/src/emit/bitcode/opt.rs and crates/victory-shader/src/emit/mod.rs (git merge-tree clean against origin/main).

Verification

  • cargo test -p victory-shader --all-targets: 226 passed, 0 failed (4 ignored in default run), including dxil_opt_hw_gpu_bit_exact_parity_and_validation with VICTORY_REQUIRE_HW_GPU=1 on discrete hardware.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warnings.
  • Measured -13.1% to -32.3% GPU loop shader cost reduction and 2.13x faster translation on the synthetic DXIL benchmark suite (dxil_opt); a fresh uncontested idle-hardware benchmark run will follow in a follow-up comment once queued multi-repo work finishes.
**@⁠Vladimir-Human** on GitHub · 2026-11-25 20:44 UTC · [original](https://github.com/fxceless/victory-fork/pull/1126) `Vladimir-Human:shader/dxil-opt-licm-alloca` → `main` · +4655 −95 · 2 files · 3 commits · open AI-assisted clean-room contribution (`victory-shader`, synthetic DXIL bitcode tests + hardware GPU parity only — no title files used). ### Summary Adds four sound DXIL bitcode optimization passes inside `crates/victory-shader/src/emit/bitcode/opt.rs` (and exposes pass-mask test control in `crates/victory-shader/src/emit/mod.rs` while keeping `translation_fingerprint` and `translate_plain` untouched): 1. **Algebraic / select folds & canonical comparison tracking (`FACTS`)**: folds redundant compares/selects along dominating branches without introducing AMD `fcmp one`. 2. **Pure loop-invariant code motion (`LICM = 64`)**: hoists loop-invariant pure value-only DXIL math calls, loads on non-escaping invariant slots, and bounded GEPs across split loop preheaders (`split_preheader`, keeping dominators/SSA/outer loops coherent), while strictly gating non-guaranteed blocks and tracking per-instruction `WriteKind::All` / `dx.op.discard` cutoffs. 3. **Hardened local & LDS forwarding / DSE (`LOADS = 16`)**: canonicalizes scalar-leaf GEP paths (`trace_ptr` with signed indices, per-level bounds, strict leaf types, unbounded SSA hop depth matching `escaped_globals`) and forwards intra-block stores across disjoint pointers. 4. **Adjacent redundant barrier elimination (`BARRIERS = 128`)**: removes provably redundant consecutive barriers without accumulating hazard state across unrelated regions. - **Disjoint scope**: modifies only `crates/victory-shader/src/emit/bitcode/opt.rs` and `crates/victory-shader/src/emit/mod.rs` (`git merge-tree` clean against `origin/main`). ### Verification - `cargo test -p victory-shader --all-targets`: **226 passed, 0 failed** (4 ignored in default run), including `dxil_opt_hw_gpu_bit_exact_parity_and_validation` with `VICTORY_REQUIRE_HW_GPU=1` on discrete hardware. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: **0 warnings**. - Measured `-13.1%` to `-32.3%` GPU loop shader cost reduction and `2.13x` faster translation on the synthetic DXIL benchmark suite (`dxil_opt`); a fresh uncontested idle-hardware benchmark run will follow in a follow-up comment once queued multi-repo work finishes.
Extend bitcode::opt with exact, bit-preserving DXIL optimization passes:
- Extended FOLD & canonical Cmp/FACTS: integer algebraic/bitwise/shift identities and constant reassociation, power-of-two strength reduction, compare negation (guarding against AMD fcmp one), boolean select/zext/compare-of-select folding, and canonicalized Key::Cmp/FACTS lookups (including IEEE-754 float predicates).
- Pure LICM (bit 64, included in MODULE/ALL): natural loop detection via dominator tree, innermost-first fixed-point hoisting of pure non-trapping instructions to dominating preheaders (splitting conditional entry edges lazily), restricting speculative calls to pure value-only DXIL math intrinsics, tracking guaranteed single-pred Term::Br prefixes with per-instruction WriteKind::All (dx.op.discard) boundaries, and validating constant-global GEPs via trace_ptr.
- Pointer-root & non-aliasing memory forwarding/DSE (enhanced LOADS, bit 16): unbounded GEP-chain canonicalization (signed indices, strict per-level array/struct bounds, exact scalar-leaf types) and escape analysis distinguishing constant tables, thread-private space-0 globals, shared space-3 LDS, and DXIL resource memory; store-to-load forwarding, non-aliasing preservation across unrelated stores/barriers, and intra-block dead overwritten store elimination.
- Adjacent redundant dx.op.barrier(mode) elimination (bit 128, included in MODULE/ALL): drops redundant barriers covered by an earlier barrier's mode bits in the same block with no intervening memory or lane operations.
Resolves bitmask collision with upstream WIDE (bit 64) and DEFAULT=ALL&!WIDE:
- Keeps WIDE = 64 and default-off WIDE behavior (DEFAULT = ALL & !WIDE = 447).
- Renumbers LICM = 128 and BARRIERS = 256 (ALL = 511).
- Preserves upstream wide_loads test and shader_opt() parsing while updating doc/unit assertions.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:57:59 +00:00
Author
Owner

@⁠Vladimir-Human on GitHub · 2026-11-25 21:30 UTC · original

Merged origin/main (c36971b2) cleanly into this PR to resolve the VICTORY_SHADER_OPT bit-64 conflict with upstream WIDE:

  • Kept upstream WIDE = 64 and DEFAULT = ALL & !WIDE verbatim (so wide console loads stay opt-in by default).
  • Renumbered LICM = 128 and BARRIERS = 256 (ALL = 511, DEFAULT = 447).
  • Preserved upstream wide_loads lowering and emit::tests::scalar_buffer_loads_read_the_same_dwords_one_call_or_four.

Re-verified on RTX 4070 SUPER / i5-13400F (--locked):

  • cargo test -p victory-shader --all-targets --locked: 227 passed; 0 failed; 4 ignored
  • VICTORY_SHADER_OPT=511 scalar_buffer_loads_read_the_same_dwords_one_call_or_four: passed
  • VICTORY_REQUIRE_HW_GPU=1 dxil_opt_hw_gpu_bit_exact_parity_and_validation: passed
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings: 0 warnings
**@⁠Vladimir-Human** on GitHub · 2026-11-25 21:30 UTC · [original](https://github.com/fxceless/victory-fork/pull/1126#issuecomment-7175160121) Merged `origin/main` (`c36971b2`) cleanly into this PR to resolve the `VICTORY_SHADER_OPT` bit-64 conflict with upstream `WIDE`: - Kept upstream `WIDE = 64` and `DEFAULT = ALL & !WIDE` verbatim (so wide console loads stay opt-in by default). - Renumbered `LICM = 128` and `BARRIERS = 256` (`ALL = 511`, `DEFAULT = 447`). - Preserved upstream `wide_loads` lowering and `emit::tests::scalar_buffer_loads_read_the_same_dwords_one_call_or_four`. Re-verified on RTX 4070 SUPER / i5-13400F (`--locked`): - `cargo test -p victory-shader --all-targets --locked`: **227 passed; 0 failed; 4 ignored** - `VICTORY_SHADER_OPT=511` `scalar_buffer_loads_read_the_same_dwords_one_call_or_four`: **passed** - `VICTORY_REQUIRE_HW_GPU=1` `dxil_opt_hw_gpu_bit_exact_parity_and_validation`: **passed** - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`: **0 warnings**
Drop intra-block middle dx.op.barrier(80, mode) calls between consecutive non-escaping LDS (addrspace 3) read phases when bounded on the left by a covering group+TGSM barrier and on the right by either a covering group+TGSM barrier or shader return, with no intervening stores, atomics, resource/wave calls, or branches.
Author
Owner

@⁠Vladimir-Human on GitHub · 2026-11-26 09:56 UTC · original

Pushed 6b6d888 adding bounded intra-block read-after-read LDS dx.op.barrier coalescing under BARRIERS (256, included in DEFAULT = 447):

  • Drops middle dx.op.barrier(80, mode) calls between consecutive non-escaping addrspace(3) (LDS) read phases when bounded on the left by a covering group+TGSM barrier ((mode & 9) == 9) and on the right by either a covering group+TGSM barrier or Term::Ret (for group/TGSM-only modes), cutting Wave32 split_lds write -> read -> read -> overwrite -> read barriers 5 -> 4 (BWBRBRBWBR -> BWBRRBWBR) and end-of-shader write -> read -> read -> ret 3 -> 2 (BWBRBR -> BWBRR).
  • Strictly preserves barriers across any intervening store, LDS/UAV atomic, resource read/write call, wave/quad op, fence-only barrier(8), or branch (preventing WAR races across control-flow edges).
  • Re-verified on RTX 4070 SUPER (VICTORY_REQUIRE_HW_GPU=1) + Microsoft D3D12 WARP + Windows SDK dxil.dll validator & dxc -dumpbin:
    • cargo test -p victory-shader --all-targets --locked: 229 passed; 0 failed; 4 ignored (all 192 output dwords matched on both physical Wave32 and WARP)
    • cargo clippy -p victory-shader --all-targets --locked -- -D warnings: 0 warnings
    • cargo run --locked -p xtask -- policy --staged: asset policy: 2 files ok
**@⁠Vladimir-Human** on GitHub · 2026-11-26 09:56 UTC · [original](https://github.com/fxceless/victory-fork/pull/1126#issuecomment-7188689121) Pushed `6b6d888` adding bounded intra-block read-after-read LDS `dx.op.barrier` coalescing under `BARRIERS` (`256`, included in `DEFAULT = 447`): - Drops middle `dx.op.barrier(80, mode)` calls between consecutive non-escaping `addrspace(3)` (LDS) read phases when bounded on the left by a covering group+TGSM barrier (`(mode & 9) == 9`) and on the right by either a covering group+TGSM barrier or `Term::Ret` (for group/TGSM-only modes), cutting Wave32 `split_lds` `write -> read -> read -> overwrite -> read` barriers `5 -> 4` (`BWBRBRBWBR` -> `BWBRRBWBR`) and end-of-shader `write -> read -> read -> ret` `3 -> 2` (`BWBRBR` -> `BWBRR`). - Strictly preserves barriers across any intervening store, LDS/UAV atomic, resource read/write call, wave/quad op, fence-only `barrier(8)`, or branch (preventing WAR races across control-flow edges). - Re-verified on RTX 4070 SUPER (`VICTORY_REQUIRE_HW_GPU=1`) + Microsoft D3D12 WARP + Windows SDK `dxil.dll` validator & `dxc -dumpbin`: - `cargo test -p victory-shader --all-targets --locked`: **229 passed; 0 failed; 4 ignored** (all 192 output dwords matched on both physical Wave32 and WARP) - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`: **0 warnings** - `cargo run --locked -p xtask -- policy --staged`: **asset policy: 2 files ok**
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/bitcode/opt.rs
  • crates/victory-shader/src/emit/mod.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/1126/head:github-bot/gh-1126'
git switch 'github-bot/gh-1126'

Merge

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