Shaders: DXIL bitcode clean-up passes (VICTORY_SHADER_OPT), census, and loop latch fixes #97

Closed
github-bot wants to merge 2 commits from gh-pr/97/head into gh-pr/97/base
Owner

@⁠dutch2005 on GitHub · 2026-11-25 14:02 UTC · original
perf/dxil-bitcode-optimizer → main · +3548 −68 · 7 files · 2 commits · closed without merging

Summary

Ports and consolidates DXIL bitcode cleanup passes (fxceless/victory-fork 1684989), Module::reachable / live / replace_const / empty-latch folding fixes (Zettrox/ztrx#110), and single-back-edge loop normalization (Zettrox/ztrx#119) onto Belobug/VIctory-Belobug-AMD:

  • DXIL bitcode optimizer (emit/bitcode/opt.rs, VICTORY_SHADER_OPT): exact module cleanup passes before bitcode emission — DEAD (dead code elimination), FOLD (integer constant folding, identity simplification, constant branch pruning, single-incoming phi folding), REUSE (dominator-tree CSE for pure ops), FACTS (branch-condition and compare propagation), and LOADS (block-local load/lane reuse across non-writing ops) — plus Module::usage() pruning so ShaderFlags / SFI0 never declare features whose last use was removed.
  • Shader cache key & census diagnostics: includes emit::shader_opt() in victory-gpu's shader_cache build key, and adds emit::census + VICTORY_SHADER_CENSUS=<file> reporting in apps/victory translate.
  • Control-flow & bitcode soundness (emit/bitcode.rs, emit/shader.rs):
    • replace_const evicts the stale const_ids cache key before overwriting a constant (ztrx#110).
    • reachable + live(&seen) ignore unreachable blocks and unreachable phi predecessors in both liveness and bitcode emission (ztrx#110).
    • layout + one_back_edge_each avoid folding two latches into one block / folding multi-latch headers and normalize multi-latch headers / multi-header latches prior to bitcode emission (ztrx#110, ztrx#119).
    • Op::Alloca handled safely in opt and census (Effect::Lanes, never deduplicated).
  • Zero lower.rs changes: left lower.rs untouched (so Tag::Guard / Tag::Counter and FIRST are omitted here) to avoid conflicting with open lower.rs split PRs (#72, #84).

Verification

Tested locally in isolated worktree on Windows (AMD Radeon RX 6700 XT + WARP + dxil.dll):

  • cargo clippy -p victory-shader -p victory-gpu -p victory --no-deps --all-targets --locked and --all-features: 0 warnings or errors in new/modified files (1 pre-existing int_value dead-code warning in bitcode.rs under --all-features without tests).
  • cargo check --workspace --all-targets --locked: passed.
  • cargo test -p victory-shader --lib -- --test-threads=1: 280 passed, 2 failed, 6 ignored (all new bitcode::opt::tests including 400-seed randomized equivalence fuzz, bitcode::tests including written_bytes_unchanged & replace_const_evicts_old_cache_key, emit::shader::tests::{two_empty_latches_to_same_header_validate, phi_with_unreachable_predecessor_validates}, and emit::tests::the_clean_up_switch_parses_or_runs_every_pass passed; the 2 failures are pre-existing baseline Wave32 failures in emit::valu_tests::{scalar_counted_in_a_divergent_loop_read_after_it, scalar_counted_in_nested_divergent_loops}, covered by #52/#68).
  • cargo xtask policy --staged: asset policy: 7 files ok.
**@⁠dutch2005** on GitHub · 2026-11-25 14:02 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/97) `perf/dxil-bitcode-optimizer` → `main` · +3548 −68 · 7 files · 2 commits · closed without merging ## Summary Ports and consolidates DXIL bitcode cleanup passes (`fxceless/victory-fork` `1684989`), `Module::reachable` / `live` / `replace_const` / empty-latch folding fixes (`Zettrox/ztrx#110`), and single-back-edge loop normalization (`Zettrox/ztrx#119`) onto `Belobug/VIctory-Belobug-AMD`: - **DXIL bitcode optimizer (`emit/bitcode/opt.rs`, `VICTORY_SHADER_OPT`)**: exact module cleanup passes before bitcode emission — `DEAD` (dead code elimination), `FOLD` (integer constant folding, identity simplification, constant branch pruning, single-incoming phi folding), `REUSE` (dominator-tree CSE for pure ops), `FACTS` (branch-condition and compare propagation), and `LOADS` (block-local load/lane reuse across non-writing ops) — plus `Module::usage()` pruning so `ShaderFlags` / `SFI0` never declare features whose last use was removed. - **Shader cache key & census diagnostics**: includes `emit::shader_opt()` in `victory-gpu`'s `shader_cache` build key, and adds `emit::census` + `VICTORY_SHADER_CENSUS=<file>` reporting in `apps/victory` `translate`. - **Control-flow & bitcode soundness (`emit/bitcode.rs`, `emit/shader.rs`)**: - `replace_const` evicts the stale `const_ids` cache key before overwriting a constant (`ztrx#110`). - `reachable` + `live(&seen)` ignore unreachable blocks and unreachable phi predecessors in both liveness and bitcode emission (`ztrx#110`). - `layout` + `one_back_edge_each` avoid folding two latches into one block / folding multi-latch headers and normalize multi-latch headers / multi-header latches prior to bitcode emission (`ztrx#110`, `ztrx#119`). - `Op::Alloca` handled safely in `opt` and `census` (`Effect::Lanes`, never deduplicated). - **Zero `lower.rs` changes**: left `lower.rs` untouched (so `Tag::Guard` / `Tag::Counter` and `FIRST` are omitted here) to avoid conflicting with open `lower.rs` split PRs (`#72`, `#84`). ## Verification Tested locally in isolated worktree on Windows (AMD Radeon RX 6700 XT + WARP + `dxil.dll`): - `cargo clippy -p victory-shader -p victory-gpu -p victory --no-deps --all-targets --locked` and `--all-features`: 0 warnings or errors in new/modified files (1 pre-existing `int_value` dead-code warning in `bitcode.rs` under `--all-features` without tests). - `cargo check --workspace --all-targets --locked`: passed. - `cargo test -p victory-shader --lib -- --test-threads=1`: **280 passed, 2 failed, 6 ignored** (all new `bitcode::opt::tests` including 400-seed randomized equivalence fuzz, `bitcode::tests` including `written_bytes_unchanged` & `replace_const_evicts_old_cache_key`, `emit::shader::tests::{two_empty_latches_to_same_header_validate, phi_with_unreachable_predecessor_validates}`, and `emit::tests::the_clean_up_switch_parses_or_runs_every_pass` passed; the 2 failures are pre-existing baseline Wave32 failures in `emit::valu_tests::{scalar_counted_in_a_divergent_loop_read_after_it, scalar_counted_in_nested_divergent_loops}`, covered by `#52`/`#68`). - `cargo xtask policy --staged`: `asset policy: 7 files ok`.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:35:43 +00:00
github-bot closed this pull request 2026-11-26 03:35:43 +00:00
Author
Owner

@⁠jmal423 on GitHub · 2026-11-25 15:05 UTC · original

Tested this PR on Windows 11 / AMD Radeon RX 9070 XT (Series X target, on top of 01aadd1):

With VICTORY_SHADER_OPT enabled (default), all prison/corridor walls disappear and cellmates' skin renders with corrupted/confetti textures. Running the exact same binary with VICTORY_SHADER_OPT=0 immediately restores all walls and fixes the cellmates' skin textures.

**@⁠jmal423** on GitHub · 2026-11-25 15:05 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/97#issuecomment-7166279159) Tested this PR on Windows 11 / AMD Radeon RX 9070 XT (Series X target, on top of `01aadd1`): With `VICTORY_SHADER_OPT` enabled (default), all prison/corridor walls disappear and cellmates' skin renders with corrupted/confetti textures. Running the exact same binary with `VICTORY_SHADER_OPT=0` immediately restores all walls and fixes the cellmates' skin textures.
Author
Owner

@⁠dutch2005 on GitHub · 2026-11-25 15:51 UTC · original

Addressed @⁠jmal423's regression report and hardened tests against cargo-mutants:

  • VICTORY_SHADER_OPT now defaults to 0 (opt-in) via parse_shader_opt() in crates/victory-shader/src/emit/mod.rs, preventing the missing walls / confetti skin regression seen on RX 9070 XT while keeping on/all or pass bitmasks (0x01–0x10) available for bisecting individual clean-up passes.
  • Strengthened unit tests in emit/mod.rs, emit/shader.rs, emit/bitcode/census.rs, and emit/bitcode.rs (covering Module::tag under VICTORY_SHADER_CENSUS=1, finish()/STENCIL_REF/live-op retention, empty-inner-latch folding, and 3-latch combining in one_back_edge_each).

Verification (after final edit)

  • cargo test -p victory-shader --lib --locked -- --skip scalar_counted_in_: 288 passed, 0 failed, 6 ignored (2 pre-existing RDNA2 wave-size tests skipped)
  • cargo test -p victory-gpu --lib --locked shader_cache::tests: 3 passed, 0 failed
  • cargo test -p victory --bin victory --locked translate::tests: 1 passed, 0 failed
  • cargo mutants --in-diff:
    • census.rs: 52 caught, 0 missed
    • mod.rs: 6 caught, 0 missed
    • shader.rs: 17 caught, 3 unviable, 2 equivalent/test-helper (ATOMIC_TYPED64 | ATOMIC_HEAP64 disjoint bits in finish_with; test helper validate_and_create_cs_pso)
    • bitcode.rs: 67 caught, 7 unviable, 2 timeouts (infinite loops in reachable) + follow-up 3 caught on line 757; remaining 2 in layout / line 729 are equivalent (pos[h] < pos[b] with h != b already forced by !succs(*p).contains(&h); hs.len() <= 2 because terminators have at most 2 successors)
  • cargo xtask policy --staged: 6 files ok
**@⁠dutch2005** on GitHub · 2026-11-25 15:51 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/97#issuecomment-7167376648) Addressed @⁠jmal423's regression report and hardened tests against `cargo-mutants`: - **`VICTORY_SHADER_OPT` now defaults to `0` (opt-in)** via `parse_shader_opt()` in `crates/victory-shader/src/emit/mod.rs`, preventing the missing walls / confetti skin regression seen on RX 9070 XT while keeping `on`/`all` or pass bitmasks (`0x01`–`0x10`) available for bisecting individual clean-up passes. - Strengthened unit tests in `emit/mod.rs`, `emit/shader.rs`, `emit/bitcode/census.rs`, and `emit/bitcode.rs` (covering `Module::tag` under `VICTORY_SHADER_CENSUS=1`, `finish()`/`STENCIL_REF`/live-op retention, empty-inner-latch folding, and 3-latch combining in `one_back_edge_each`). ### Verification (after final edit) - `cargo test -p victory-shader --lib --locked -- --skip scalar_counted_in_`: **288 passed, 0 failed, 6 ignored** (2 pre-existing RDNA2 wave-size tests skipped) - `cargo test -p victory-gpu --lib --locked shader_cache::tests`: **3 passed, 0 failed** - `cargo test -p victory --bin victory --locked translate::tests`: **1 passed, 0 failed** - `cargo mutants --in-diff`: - `census.rs`: **52 caught, 0 missed** - `mod.rs`: **6 caught, 0 missed** - `shader.rs`: **17 caught, 3 unviable, 2 equivalent/test-helper** (`ATOMIC_TYPED64 | ATOMIC_HEAP64` disjoint bits in `finish_with`; test helper `validate_and_create_cs_pso`) - `bitcode.rs`: **67 caught, 7 unviable, 2 timeouts** (infinite loops in `reachable`) + follow-up **3 caught** on line 757; remaining 2 in `layout` / line 729 are equivalent (`pos[h] < pos[b]` with `h != b` already forced by `!succs(*p).contains(&h)`; `hs.len() <= 2` because terminators have at most 2 successors) - `cargo xtask policy --staged`: **6 files ok**
Author
Owner

@⁠ySKELLETONX on GitHub · 2026-11-25 16:36 UTC · original

Tested on an RX 7600 XT 16 GB (RDNA3, Navi 33), driver 32.0.32015.2008, Windows 11 Pro build 26300, Rust 1.98.1, at 8a0bcda: cargo test -p victory-shader --lib --locked: 290 passed, 0 failed, 6 ignored, hardware dispatch tests included (main at 01aadd1: 266 passed). Two runs, with #140 applied on top. Without it, parallel victory-shader runs here sometimes crash inside WARP (d3d10warp.dll, STATUS_ACCESS_VIOLATION). main does that too, so it has nothing to do with this PR, but it made the first run of this PR look broken. Workspace tests only; not run in the title.

**@⁠ySKELLETONX** on GitHub · 2026-11-25 16:36 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/97#issuecomment-7168242268) Tested on an RX 7600 XT 16 GB (RDNA3, Navi 33), driver 32.0.32015.2008, Windows 11 Pro build 26300, Rust 1.98.1, at `8a0bcda`: `cargo test -p victory-shader --lib --locked`: **290 passed, 0 failed, 6 ignored**, hardware dispatch tests included (`main` at `01aadd1`: 266 passed). Two runs, with #140 applied on top. Without it, parallel `victory-shader` runs here sometimes crash inside WARP (`d3d10warp.dll`, STATUS_ACCESS_VIOLATION). `main` does that too, so it has nothing to do with this PR, but it made the first run of this PR look broken. Workspace tests only; not run in the title.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.