perf(shader): add DXIL folds, pure LICM, local/LDS forwarding, and barrier dedup #193

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

@⁠Vladimir-Human on GitHub · 2026-11-27 07:47 UTC · original
Vladimir-Human:perf/dxil-opt-licm-lds-barriers → main · +5330 −105 · 2 files · 1 commits · open

Summary

Extends crates/victory-shader/src/emit/bitcode/opt.rs with five independent, opt-in, semantics-preserving DXIL IR optimisation passes behind separate VICTORY_SHADER_OPT bits while keeping DEFAULT = 63 100% bit-identical to main and leaving TRANSLATOR_VERSION = 9 (crates/victory-shader/src/lib.rs) untouched so warm shader caches stay valid on the baseline control:

Bit Mask Pass Default Description
0..5 63 DEFAULT (DEAD|FOLD|REUSE|FACTS|LOADS|FIRST) ON Exact main control (bit-identical DXIL output; warm cache unchanged).
6 64 WIDE OFF Existing 4-dword wide console load lowering (main).
7 128 EXT_FOLD OFF (opt-in) Extended integer algebraic/bitwise/shift identities, constant reassociation, power-of-two mul/udiv/urem strength reduction, IEEE-754 NaN-safe compare negation (avoiding AMD fcmp one), undef-safe boolean select/zext folds, and canonical Key::Cmp/FACTS reuse.
8 256 MEM_FWD OFF (opt-in) Unbounded canonical GEP-path + escape analysis separating constant tables, thread-private addrspace(0) globals, shared addrspace(3) LDS, and DXIL resource memory for private-global forwarding, non-aliasing LDS load-to-load reuse, and intra-block overwritten-store DSE. Groupshared (addrspace(3)) store-to-load forwarding is disabled to preserve barrierless wave-ordered LDS exchange.
9 512 LICM OFF (opt-in) Conservative natural-loop LICM (guaranteed dominating blocks only): pure non-trapping hoisting to dominating preheaders (lazily splitting conditional entry edges), WriteKind::All (dx.op.discard) prefix guards, and explicit blocking of deriv*, wave*, quad*, and getDimensions calls.
10 1024 BARRIERS OFF (opt-in) Drops adjacent covered dx.op.barrier(80, mode) calls and coalesces bounded intra-block read-after-read barriers between non-escaping LDS read phases bounded by covering group+TGSM barriers (or Term::Ret when no UAV fence bits are set).
11 2048 SPEC_LICM OFF (opt-in) Opt-in speculative ALU, pure math allowlist, and provably in-bounds constant-table hoisting from conditional loop blocks (requires LICM; still blocks deriv*, wave*, quad*, getDimensions, traps, and resource reads).
  • Combined masks: VICTORY_SHADER_OPT=63 (or unset) = baseline main control; 63 + bit isolates any single pass (e.g. 191 = DEFAULT|EXT_FOLD, 319 = DEFAULT|MEM_FWD, 575 = DEFAULT|LICM, 1087 = DEFAULT|BARRIERS, 2623 = DEFAULT|LICM|SPEC_LICM); 4031 = ALL & !WIDE; 4095 = ALL.
  • Cache separation: victory-gpu's shader cache already hashes victory_shader::emit::shader_opt().to_le_bytes(), so DEFAULT = 63 stays warm on main's cache while every opt-in bitmask caches independently.
  • Switch & test harness (crates/victory-shader/src/emit/mod.rs): updates VICTORY_SHADER_OPT docs/tests and adds a test-only with_shader_opt thread-local override (translation_fingerprint() / VICTORY_SHADER_SWITCHES unchanged).

Visual impact

Zero visual change. DEFAULT = 63 emits bit-identical DXIL to main, and every opt-in pass is strictly semantics-preserving at the DXIL IR level (no fast-math flags, no float arithmetic reassociation, IEEE-754 NaN and undef semantics preserved, groupshared store-to-load forwarding disabled). Verified with dxil.dll validation, random-program interpreter equivalence across 400 seeds (including SPEC_LICM and LICM | SPEC_LICM), and bit-exact D3D12 hardware GPU + WARP parity.

Verification

  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings (default and --all-features): 0 warnings
  • cargo run -p xtask --locked -- policy: asset policy: 313 files ok (opt.rs 321,857 B, emit/mod.rs 146,437 B)
  • cargo test -p xtask --locked: 11 passed; 0 failed
  • HW (VICTORY_D3D12_DEBUG=1, --test-threads=1, 0 D3D12 debug errors):
    • emit::bitcode::opt::tests (default and --all-features): 29 passed; 0 failed; 1 ignored (bench)
    • the_clean_up_switch_parses_or_runs_every_pass: 1 passed; 0 failed
    • VICTORY_SHADER_OPT=4031 (hw_tests, emit::tests, emit::wave64_tests, emit::size_tests, emit::waterfall_tests): 66 passed; 0 failed; 1 ignored
  • WARP (VICTORY_WARP=1, both with VICTORY_D3D12_DEBUG=1 and CI mode without it, default and --all-features):
    • emit::bitcode::opt::tests::hw_tests: 3 passed; 0 failed; 1 ignored (0 skips)
**@⁠Vladimir-Human** on GitHub · 2026-11-27 07:47 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/193) `Vladimir-Human:perf/dxil-opt-licm-lds-barriers` → `main` · +5330 −105 · 2 files · 1 commits · open ## Summary Extends `crates/victory-shader/src/emit/bitcode/opt.rs` with five independent, opt-in, semantics-preserving DXIL IR optimisation passes behind separate `VICTORY_SHADER_OPT` bits while keeping `DEFAULT = 63` **100% bit-identical to `main`** and leaving `TRANSLATOR_VERSION = 9` (`crates/victory-shader/src/lib.rs`) untouched so warm shader caches stay valid on the baseline control: | Bit | Mask | Pass | Default | Description | | --- | ---: | --- | --- | --- | | `0..5` | `63` | `DEFAULT` (`DEAD\|FOLD\|REUSE\|FACTS\|LOADS\|FIRST`) | **ON** | Exact `main` control (bit-identical DXIL output; warm cache unchanged). | | `6` | `64` | `WIDE` | OFF | Existing 4-dword wide console load lowering (`main`). | | `7` | `128` | `EXT_FOLD` | OFF (opt-in) | Extended integer algebraic/bitwise/shift identities, constant reassociation, power-of-two `mul`/`udiv`/`urem` strength reduction, IEEE-754 NaN-safe compare negation (avoiding AMD `fcmp one`), `undef`-safe boolean `select`/`zext` folds, and canonical `Key::Cmp`/`FACTS` reuse. | | `8` | `256` | `MEM_FWD` | OFF (opt-in) | Unbounded canonical GEP-path + escape analysis separating constant tables, thread-private `addrspace(0)` globals, shared `addrspace(3)` LDS, and DXIL resource memory for private-global forwarding, non-aliasing LDS load-to-load reuse, and intra-block overwritten-store DSE. **Groupshared (`addrspace(3)`) store-to-load forwarding is disabled** to preserve barrierless wave-ordered LDS exchange. | | `9` | `512` | `LICM` | OFF (opt-in) | Conservative natural-loop LICM (guaranteed dominating blocks only): pure non-trapping hoisting to dominating preheaders (lazily splitting conditional entry edges), `WriteKind::All` (`dx.op.discard`) prefix guards, and explicit blocking of `deriv*`, `wave*`, `quad*`, and `getDimensions` calls. | | `10` | `1024` | `BARRIERS` | OFF (opt-in) | Drops adjacent covered `dx.op.barrier(80, mode)` calls and coalesces bounded intra-block read-after-read barriers between non-escaping LDS read phases bounded by covering group+TGSM barriers (or `Term::Ret` when no UAV fence bits are set). | | `11` | `2048` | `SPEC_LICM` | OFF (opt-in) | Opt-in speculative ALU, pure math allowlist, and provably in-bounds constant-table hoisting from conditional loop blocks (requires `LICM`; still blocks `deriv*`, `wave*`, `quad*`, `getDimensions`, traps, and resource reads). | - **Combined masks:** `VICTORY_SHADER_OPT=63` (or unset) = baseline `main` control; `63 + bit` isolates any single pass (e.g. `191` = `DEFAULT|EXT_FOLD`, `319` = `DEFAULT|MEM_FWD`, `575` = `DEFAULT|LICM`, `1087` = `DEFAULT|BARRIERS`, `2623` = `DEFAULT|LICM|SPEC_LICM`); `4031` = `ALL & !WIDE`; `4095` = `ALL`. - **Cache separation:** `victory-gpu`'s shader cache already hashes `victory_shader::emit::shader_opt().to_le_bytes()`, so `DEFAULT = 63` stays warm on `main`'s cache while every opt-in bitmask caches independently. - **Switch & test harness (`crates/victory-shader/src/emit/mod.rs`):** updates `VICTORY_SHADER_OPT` docs/tests and adds a test-only `with_shader_opt` thread-local override (`translation_fingerprint()` / `VICTORY_SHADER_SWITCHES` unchanged). ## Visual impact **Zero visual change.** `DEFAULT = 63` emits bit-identical DXIL to `main`, and every opt-in pass is strictly semantics-preserving at the DXIL IR level (no fast-math flags, no float arithmetic reassociation, IEEE-754 NaN and `undef` semantics preserved, groupshared store-to-load forwarding disabled). Verified with `dxil.dll` validation, random-program interpreter equivalence across 400 seeds (including `SPEC_LICM` and `LICM | SPEC_LICM`), and bit-exact D3D12 hardware GPU + WARP parity. ## Verification - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings` (default and `--all-features`): **0 warnings** - `cargo run -p xtask --locked -- policy`: **asset policy: 313 files ok** (`opt.rs` `321,857 B`, `emit/mod.rs` `146,437 B`) - `cargo test -p xtask --locked`: **11 passed; 0 failed** - HW (`VICTORY_D3D12_DEBUG=1`, `--test-threads=1`, `0` D3D12 debug errors): - `emit::bitcode::opt::tests` (default and `--all-features`): **29 passed; 0 failed; 1 ignored** (bench) - `the_clean_up_switch_parses_or_runs_every_pass`: **1 passed; 0 failed** - `VICTORY_SHADER_OPT=4031` (`hw_tests`, `emit::tests`, `emit::wave64_tests`, `emit::size_tests`, `emit::waterfall_tests`): **66 passed; 0 failed; 1 ignored** - WARP (`VICTORY_WARP=1`, both with `VICTORY_D3D12_DEBUG=1` and CI mode without it, default and `--all-features`): - `emit::bitcode::opt::tests::hw_tests`: **3 passed; 0 failed; 1 ignored** (`0` skips)
Extend bitcode::opt with semantics-preserving, bit-exact DXIL IR optimizations
(zero visual change) while preserving all existing pass flags, defaults
(WIDE=64 off by default), ROV usage tracking, and float bound helpers:

- Extended FOLD & canonical Cmp/FACTS: integer algebraic/bitwise/shift
  identities and constant reassociation, power-of-two strength reduction,
  compare negation (avoiding AMD fcmp one), boolean select/zext/compare-of-
  select folding, and canonicalized Key::Cmp/FACTS lookups preserving IEEE-754
  NaN semantics.
- Pure LICM (bit 128, in MODULE/DEFAULT/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 math intrinsics,
  tracking unconditional single-pred Term::Br prefixes with WriteKind::All
  (dx.op.discard) boundaries, and validating constant-global GEPs via trace_ptr.
- Canonical ptr-path local/LDS forwarding & DSE (enhanced LOADS, bit 16):
  unbounded GEP-chain canonicalization (signed indices, per-level array/struct
  bounds, exact scalar-leaf types) and escape analysis separating constant
  tables, thread-private space-0 globals, shared space-3 LDS, and DXIL resource
  memory for store-to-load forwarding, non-aliasing preservation across
  unrelated stores/barriers, and intra-block overwritten dead store removal.
- Redundant barrier elimination (bit 256, in MODULE/DEFAULT/ALL): drops
  immediately adjacent covered dx.op.barrier(80, mode) calls and coalesces
  bounded intra-block read-after-read barriers between non-escaping LDS read
  phases bounded by covering group+TGSM barriers (or shader return when no UAV
  fence bits are set).
- Update VICTORY_SHADER_OPT docs/tests (DEFAULT=447 without WIDE, ALL=511 with
  WIDE) and add test-only with_shader_opt override in emit/mod.rs without
  changing translation_fingerprint switches.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 07:52:45 +00:00
Refresh translations for explicit pass masks whose values stay the same even when the generated DXIL changes.
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-27 08:08 UTC · original

@⁠Vladimir-Human I bumped the translator cache version to 8 on this PR. An explicit pass mask can keep the same value while the revised folds emit different DXIL. The version bump makes those runs rebuild their translations. The local pass-mask test passed.

**@⁠TaynanGT** on GitHub · 2026-11-27 08:08 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/193#issuecomment-7213196810) @⁠Vladimir-Human I bumped the translator cache version to 8 on this PR. An explicit pass mask can keep the same value while the revised folds emit different DXIL. The version bump makes those runs rebuild their translations. The local pass-mask test passed.
Author
Owner

@⁠Vladimir-Human on GitHub · 2026-11-27 08:18 UTC · original

Thanks @⁠TaynanGT — bumping the translator cache version to 8 in 173bde0 makes total sense so runs with an explicit pass mask rebuild cached DXIL instead of reusing pre-opt entries. Everything on this PR is clean and ready on our side.

**@⁠Vladimir-Human** on GitHub · 2026-11-27 08:18 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/193#issuecomment-7213379161) Thanks @⁠TaynanGT — bumping the translator cache version to 8 in `173bde0` makes total sense so runs with an explicit pass mask rebuild cached DXIL instead of reusing pre-opt entries. Everything on this PR is clean and ready on our side.
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-27 08:24 UTC · original

@⁠Vladimir-Human The CI run passed on 173bde0. The remaining runtime check is a matched capture on the default mask, with the same scene, upscaler and frame generation settings. The version bump will give that run a fresh set of translations.

**@⁠TaynanGT** on GitHub · 2026-11-27 08:24 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/193#issuecomment-7213498935) @⁠Vladimir-Human The CI run passed on `173bde0`. The remaining runtime check is a matched capture on the default mask, with the same scene, upscaler and frame generation settings. The version bump will give that run a fresh set of translations.
Author
Owner

@⁠Vladimir-Human on GitHub · 2026-11-27 08:35 UTC · original

Great to hear CI is green on 173bde0 — standing by if anything comes up in the matched capture!

**@⁠Vladimir-Human** on GitHub · 2026-11-27 08:35 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/193#issuecomment-7213703863) Great to hear CI is green on `173bde0` — standing by if anything comes up in the matched capture!
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-27 08:39 UTC · original

@⁠Vladimir-Human Thanks. I’ll post the matched-capture results here with the two build hashes and settings.

**@⁠TaynanGT** on GitHub · 2026-11-27 08:39 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/193#issuecomment-7213766580) @⁠Vladimir-Human Thanks. I’ll post the matched-capture results here with the two build hashes and settings.
Author
Owner

@⁠efsebayern on GitHub · 2026-11-27 10:42 UTC · original · reviewed

I reviewed 173bde0 against its base 70ac49d. I found one correctness concern; the other passes look right to me.

Groupshared store-to-load forwarding drops wave-ordered LDS exchange (crates/victory-shader/src/emit/bitcode/opt.rs ~1829-1856 for the load lookup, ~1930-1965 where a store records its value in shared_const / shared_dyn)

Within a block, store lds[p], v followed by load lds[p] with no barrier in between is replaced by v. The PR's own test does exactly this (per-lane v1 stored to lds0, then forwarded).

DXIL allows that, since a cross-thread race without a barrier is undefined there. But the console code relies on LDS being ordered within one wave, and the translator keeps that reliance: lower.rs (~1872 and ~1912) adds no barrier when the group is ≤ 32 threads, or when it runs natively as wave64 on a 64-lane host.

Failure scenario. The "elect a leader per bucket" idiom: lds[bucket] = laneId; if (lds[bucket] == laneId) { ... }.

  • Before: lanes that collide on a bucket read the winning lane's id, so exactly one lane wins.
  • After: every lane reads back its own value, so every lane wins. That means duplicate appends, double counting, and broken binning or culling.

The DXIL validator can't catch this, because the program stays valid.

Suggestion: don't forward a store to a later load in address space 3. Load-to-load reuse, the LDS dead-store elimination and private (space 0) forwarding are fine. Alternatively, forward only when the stored value is wave-uniform.

Also worth noting: the new passes are on by default (DEFAULT 63 → 447). Because FOLD, FACTS and LOADS changed too, VICTORY_SHADER_OPT=63 doesn't give back the old output. A switch that restores the old behaviour would make A/B checks of rendering regressions easier.

Checked, nothing found:

  • LICM: wave, quad and derivative ops, loads and resource reads are never hoisted. Divisions are hoisted only for a non-zero constant divisor, and SDiv also excludes −1.
  • Barrier dedup: the superset and anchor rules hold.
  • Integer folds: shifts ≥ the bit width, division by zero and MIN/−1 are left alone. The fcmp NaN handling and canonical_cmp are correct.
  • Pointer and escape analysis: no constant-expression GEPs.

Offline results:

  • cargo test -p victory-shader --lib: 334 passed, 0 failed, 5 ignored. Clippy is clean.
  • VICTORY_HOST_WAVE=32 victory translate --list --validate over the title's shaders gives identical validation results for base and PR: VS/PS 14262/14262, CS 2759/2761, MS 8694/8765, with the same failing programs.
  • The emitted DXIL differs for 22,044 programs, so only a matched runtime comparison can rule out the LDS issue.

AI-assisted review (Claude Code).

**@⁠efsebayern** on GitHub · 2026-11-27 10:42 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/193#pullrequestreview-6086894781) · **reviewed** I reviewed 173bde0 against its base 70ac49d. I found one correctness concern; the other passes look right to me. **Groupshared store-to-load forwarding drops wave-ordered LDS exchange** (`crates/victory-shader/src/emit/bitcode/opt.rs` ~1829-1856 for the load lookup, ~1930-1965 where a store records its value in `shared_const` / `shared_dyn`) Within a block, `store lds[p], v` followed by `load lds[p]` with no barrier in between is replaced by `v`. The PR's own test does exactly this (per-lane `v1` stored to `lds0`, then forwarded). DXIL allows that, since a cross-thread race without a barrier is undefined there. But the console code relies on LDS being ordered within one wave, and the translator keeps that reliance: `lower.rs` (~1872 and ~1912) adds no barrier when the group is ≤ 32 threads, or when it runs natively as wave64 on a 64-lane host. **Failure scenario.** The "elect a leader per bucket" idiom: `lds[bucket] = laneId; if (lds[bucket] == laneId) { ... }`. - Before: lanes that collide on a bucket read the winning lane's id, so exactly one lane wins. - After: every lane reads back its own value, so every lane wins. That means duplicate appends, double counting, and broken binning or culling. The DXIL validator can't catch this, because the program stays valid. **Suggestion:** don't forward a store to a later load in address space 3. Load-to-load reuse, the LDS dead-store elimination and private (space 0) forwarding are fine. Alternatively, forward only when the stored value is wave-uniform. **Also worth noting:** the new passes are on by default (`DEFAULT` 63 → 447). Because FOLD, FACTS and LOADS changed too, `VICTORY_SHADER_OPT=63` doesn't give back the old output. A switch that restores the old behaviour would make A/B checks of rendering regressions easier. **Checked, nothing found:** - LICM: wave, quad and derivative ops, loads and resource reads are never hoisted. Divisions are hoisted only for a non-zero constant divisor, and SDiv also excludes −1. - Barrier dedup: the superset and anchor rules hold. - Integer folds: shifts ≥ the bit width, division by zero and MIN/−1 are left alone. The fcmp NaN handling and `canonical_cmp` are correct. - Pointer and escape analysis: no constant-expression GEPs. **Offline results:** - `cargo test -p victory-shader --lib`: 334 passed, 0 failed, 5 ignored. Clippy is clean. - `VICTORY_HOST_WAVE=32 victory translate --list --validate` over the title's shaders gives identical validation results for base and PR: VS/PS 14262/14262, CS 2759/2761, MS 8694/8765, with the same failing programs. - The emitted DXIL differs for 22,044 programs, so only a matched runtime comparison can rule out the LDS issue. *AI-assisted review (Claude Code).*
Single-wave shaders (group <= 32 or native wave64) rely on wave-ordered
LDS exchange without an explicit barrier (for example, bucket leader
election `lds[bucket] = lane; winner = lds[bucket]`). Forwarding a
space-3 store directly to a following load in the same block causes each
lane to read back its own stored value instead of the winning lane's
value.

- Remove space-3 (`PtrRoot::SharedGlobal`) store-to-load forwarding in
  `opt::Module::merge` (`shared_const.remove(&slot)` on constant stores
  instead of inserting the stored value; omit `shared_dyn.insert` on
  dynamic stores).
- Preserve sound space-3 load-to-load reuse across non-aliasing writes,
  overwritten dead-store elimination, and space-0 thread-private
  store-to-load forwarding.
- Update existing `LOADS` unit tests and add both IR and D3D12 HW/DXIL
  regression tests (`shared_store_to_load_not_forwarded_wave_leader_election`
  and `wave_ordered_lds_leader_election_preserved`).

Addresses review feedback from @efsebayern on #193.
Author
Owner

@⁠Vladimir-Human on GitHub · 2026-11-27 12:27 UTC · original

Thank you @⁠efsebayern for catching the groupshared (space 3) store-to-load forwarding bug and validating the full shader set offline — pushed ef78e6c atop 173bde0:

  • Removed space-3 (PtrRoot::SharedGlobal) store-to-load forwarding in crates/victory-shader/src/emit/bitcode/opt.rs (Op::Store: shared_const.remove(&slot) on constant stores instead of inserting val, and omitted shared_dyn.insert(slot, val) on dynamic stores), preserving barrierless wave-ordered LDS exchange (group <= 32 or native wave64). Space-3 load-to-load reuse across non-aliasing writes, LDS overwritten-store DSE, and space-0 thread-private forwarding are preserved.
  • Regression tests: Updated local_and_shared_memory_forwarding_non_aliasing_and_dse and the scalar_lds alias check, and added both IR unit test shared_store_to_load_not_forwarded_wave_leader_election (dynamic bucket + constant slot invalidation/reuse) and D3D12 HW/WARP + dxil.dll test wave_ordered_lds_leader_election_preserved (verifying both Op::Load instructions remain under DEFAULT and 1-winner-per-bucket/constant-slot parity on hardware).
  • A/B switch note: VICTORY_SHADER_OPT=0 disables all module passes, 63 disables LICM+BARRIERS, and 47 disables LOADS too; @⁠TaynanGT, if you also want the new FOLD/FACTS/LOADS refinements split behind separate opt-in bits so 63 is bit-identical to main, happy to add that cleanly.
  • Verification (VICTORY_D3D12_DEBUG=1): clippy -p victory-shader --all-targets --locked -- -D warnings (default & --all-features) 0 warnings; xtask policy 303 files ok; HW full victory-shader 336/336 passed (5 ignored); HW --all-features opt::tests 26/26 passed (1 ignored); WARP opt::tests::hw_tests 3/3 passed (1 ignored).
**@⁠Vladimir-Human** on GitHub · 2026-11-27 12:27 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/193#issuecomment-7218266503) Thank you @⁠efsebayern for catching the groupshared (`space 3`) store-to-load forwarding bug and validating the full shader set offline — pushed `ef78e6c` atop `173bde0`: - **Removed space-3 (`PtrRoot::SharedGlobal`) store-to-load forwarding** in `crates/victory-shader/src/emit/bitcode/opt.rs` (`Op::Store`: `shared_const.remove(&slot)` on constant stores instead of inserting `val`, and omitted `shared_dyn.insert(slot, val)` on dynamic stores), preserving barrierless wave-ordered LDS exchange (`group <= 32` or native wave64). Space-3 load-to-load reuse across non-aliasing writes, LDS overwritten-store DSE, and space-0 thread-private forwarding are preserved. - **Regression tests:** Updated `local_and_shared_memory_forwarding_non_aliasing_and_dse` and the `scalar_lds` alias check, and added both IR unit test `shared_store_to_load_not_forwarded_wave_leader_election` (dynamic bucket + constant slot invalidation/reuse) and D3D12 HW/WARP + `dxil.dll` test `wave_ordered_lds_leader_election_preserved` (verifying both `Op::Load` instructions remain under `DEFAULT` and 1-winner-per-bucket/constant-slot parity on hardware). - **A/B switch note:** `VICTORY_SHADER_OPT=0` disables all module passes, `63` disables `LICM`+`BARRIERS`, and `47` disables `LOADS` too; @⁠TaynanGT, if you also want the new `FOLD`/`FACTS`/`LOADS` refinements split behind separate opt-in bits so `63` is bit-identical to `main`, happy to add that cleanly. - **Verification (`VICTORY_D3D12_DEBUG=1`):** `clippy -p victory-shader --all-targets --locked -- -D warnings` (default & `--all-features`) 0 warnings; `xtask policy` 303 files ok; HW full `victory-shader` 336/336 passed (5 ignored); HW `--all-features` `opt::tests` 26/26 passed (1 ignored); WARP `opt::tests::hw_tests` 3/3 passed (1 ignored).
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-27 12:32 UTC · original

@⁠Vladimir-Human Yes, please put the new FOLD, FACTS, and LOADS refinements behind separate opt-in bits. That gives us a byte-identical main control for the warm-cache A/B and keeps LICM and barrier dedup independently testable. The LDS leader-election regression covers the behaviour that the forwarding change must preserve.

**@⁠TaynanGT** on GitHub · 2026-11-27 12:32 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/193#issuecomment-7218362132) @⁠Vladimir-Human Yes, please put the new FOLD, FACTS, and LOADS refinements behind separate opt-in bits. That gives us a byte-identical main control for the warm-cache A/B and keeps LICM and barrier dedup independently testable. The LDS leader-election regression covers the behaviour that the forwarding change must preserve.
github-bot force-pushed github-bot/gh-193 from ef78e6c6f3 to ac9923d8c0 2026-11-27 14:02:20 +00:00 Compare
Author
Owner

@⁠Vladimir-Human on GitHub · 2026-11-27 14:01 UTC · original

@⁠TaynanGT Done — rebased onto main (ac9923d) and split all new refinements behind separate opt-in VICTORY_SHADER_OPT bits while keeping DEFAULT = 63 bit-identical to main and TRANSLATOR_VERSION = 9 (lib.rs) untouched so warm caches stay valid on the baseline control (victory-gpu's shader cache keys on shader_opt().to_le_bytes()):

Mask Bit(s) Purpose
63 (unset) DEFAULT (1|2|4|8|16|32) Byte-identical main control (opt.rs:L98)
191 (+128) DEFAULT | EXT_FOLD Extended folds, undef-safe select, canonical Cmp/FACTS (opt.rs:L80)
319 (+256) DEFAULT | MEM_FWD Private-global forwarding, non-aliasing LDS load reuse, DSE — no space-3 store-to-load forwarding (opt.rs:L83)
575 (+512) DEFAULT | LICM Conservative pure LICM, guaranteed blocks only, blocking deriv*/wave*/quad*/getDimensions (opt.rs:L85, L2506)
1087 (+1024) DEFAULT | BARRIERS Adjacent covered & bounded read-after-read barrier dedup (opt.rs:L87)
2623 (+512+2048) DEFAULT | LICM | SPEC_LICM Adds opt-in speculative ALU/math/in-bounds const-table hoisting from conditional loop blocks (opt.rs:L90)
4031 / 4095 ALL & !WIDE / ALL All passes without / with WIDE (64) (opt.rs:L95, emit/mod.rs:L217)
  • Key tests (crates/victory-shader/src/emit/bitcode/opt.rs, emit/mod.rs):
    • DEFAULT = 63 invariance: default_63_leaves_ext_fold_off (L4384), default_63_leaves_all_opt_in_passes_off (L5756), the_clean_up_switch_parses_or_runs_every_pass (emit/mod.rs:L1399)
    • Groupshared (space 3) leader-election preservation: shared_store_to_load_not_forwarded_wave_leader_election (L4597), wave_ordered_lds_leader_election_preserved (L7288)
    • Per-pass unit, random-fuzz, and HW/WARP parity: every_pass_leaves_what_random_programs_store (L4026), select_bool_fold_skips_undef_operands (L4328), local_and_shared_memory_forwarding_non_aliasing_and_dse (L4511), licm_hoists_pure_invariants_splits_cond_entry_and_respects_traps (L4927), licm_negative_controls_speculative_resources_uniformity_discard_and_signed_const_gep (L5046), adjacent_redundant_barrier_elimination_and_negative_controls (L5396), read_after_read_barrier_coalescing_and_soundness_negatives (L5460), dxil_opt_hw_gpu_bit_exact_parity_and_validation (L6512), split_lds_wave32_read_after_read_barrier_coalescing_and_parity (L6728)
  • Status: CI is 4/4 green (Clippy, Default tests, Diagnostics tests, check), MERGEABLE / CLEAN.
**@⁠Vladimir-Human** on GitHub · 2026-11-27 14:01 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/193#issuecomment-7220229960) @⁠TaynanGT Done — rebased onto `main` (`ac9923d`) and split all new refinements behind separate opt-in `VICTORY_SHADER_OPT` bits while keeping `DEFAULT = 63` bit-identical to `main` and `TRANSLATOR_VERSION = 9` (`lib.rs`) untouched so warm caches stay valid on the baseline control (`victory-gpu`'s shader cache keys on `shader_opt().to_le_bytes()`): | Mask | Bit(s) | Purpose | | ---: | --- | --- | | `63` (unset) | `DEFAULT` (`1\|2\|4\|8\|16\|32`) | Byte-identical `main` control (`opt.rs:L98`) | | `191` (`+128`) | `DEFAULT \| EXT_FOLD` | Extended folds, `undef`-safe `select`, canonical `Cmp`/`FACTS` (`opt.rs:L80`) | | `319` (`+256`) | `DEFAULT \| MEM_FWD` | Private-global forwarding, non-aliasing LDS load reuse, DSE — no space-3 store-to-load forwarding (`opt.rs:L83`) | | `575` (`+512`) | `DEFAULT \| LICM` | Conservative pure LICM, guaranteed blocks only, blocking `deriv*`/`wave*`/`quad*`/`getDimensions` (`opt.rs:L85`, `L2506`) | | `1087` (`+1024`) | `DEFAULT \| BARRIERS` | Adjacent covered & bounded read-after-read barrier dedup (`opt.rs:L87`) | | `2623` (`+512+2048`) | `DEFAULT \| LICM \| SPEC_LICM` | Adds opt-in speculative ALU/math/in-bounds const-table hoisting from conditional loop blocks (`opt.rs:L90`) | | `4031` / `4095` | `ALL & !WIDE` / `ALL` | All passes without / with `WIDE` (`64`) (`opt.rs:L95`, `emit/mod.rs:L217`) | - **Key tests (`crates/victory-shader/src/emit/bitcode/opt.rs`, `emit/mod.rs`):** - `DEFAULT = 63` invariance: `default_63_leaves_ext_fold_off` (`L4384`), `default_63_leaves_all_opt_in_passes_off` (`L5756`), `the_clean_up_switch_parses_or_runs_every_pass` (`emit/mod.rs:L1399`) - Groupshared (`space 3`) leader-election preservation: `shared_store_to_load_not_forwarded_wave_leader_election` (`L4597`), `wave_ordered_lds_leader_election_preserved` (`L7288`) - Per-pass unit, random-fuzz, and HW/WARP parity: `every_pass_leaves_what_random_programs_store` (`L4026`), `select_bool_fold_skips_undef_operands` (`L4328`), `local_and_shared_memory_forwarding_non_aliasing_and_dse` (`L4511`), `licm_hoists_pure_invariants_splits_cond_entry_and_respects_traps` (`L4927`), `licm_negative_controls_speculative_resources_uniformity_discard_and_signed_const_gep` (`L5046`), `adjacent_redundant_barrier_elimination_and_negative_controls` (`L5396`), `read_after_read_barrier_coalescing_and_soundness_negatives` (`L5460`), `dxil_opt_hw_gpu_bit_exact_parity_and_validation` (`L6512`), `split_lds_wave32_read_after_read_barrier_coalescing_and_parity` (`L6728`) - **Status:** CI is 4/4 green (`Clippy`, `Default tests`, `Diagnostics tests`, `check`), `MERGEABLE` / `CLEAN`.
Author
Owner

@⁠TaynanGT on GitHub · 2026-11-27 14:12 UTC · original

@⁠Vladimir-Human The split switches give us a clean way to measure the passes one at a time. I moved DATAFLOW to bit 4096 in #281 so LICM keeps bit 512 here. Start the 63 vs 575 run in a fresh cache directory if you used the earlier dataflow branch with 575. The LDS leader-election tests cover the forwarding guard we needed.

**@⁠TaynanGT** on GitHub · 2026-11-27 14:12 UTC · [original](https://github.com/TaynanGT/Vice-Tay/pull/193#issuecomment-7220484219) @⁠Vladimir-Human The split switches give us a clean way to measure the passes one at a time. I moved DATAFLOW to bit 4096 in #281 so LICM keeps bit 512 here. Start the `63` vs `575` run in a fresh cache directory if you used the earlier dataflow branch with `575`. The LDS leader-election tests cover the forwarding guard we needed.
github-bot force-pushed github-bot/gh-193 from ac9923d8c0 to 1a34e9ca63 2026-11-27 20:13:10 +00:00 Compare
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/193/head:github-bot/gh-193'
git switch 'github-bot/gh-193'

Merge

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