dxil: opt-in InstCombine / float web promotion / intra-loop DCE (VICTORY_SHADER_OPT=1024) #122

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

@⁠SovietBearz0r on GitHub · 2026-12-05 13:18 UTC · original
SovietBearz0r:minivi-shader-opt → main · +2358 −57 · 4 files · 3 commits · draft

Port MiniVI's InstCombine / float Select+PHI web promotion / intra-loop DCE into the DXIL optimiser as an off-by-default pass set: VICTORY_SHADER_OPT=1024 (or default|1024).

What

  • New opt::INST_COMBINE = 1024 bit in crates/victory-dxil/src/bitcode/opt.rs, included in MODULE/ALL but not in DEFAULT (stays 63 — default output is unchanged, proven by a contract test).
  • Ported from MiniVI 20be1548 (+2062), adapted to this tree's optimiser which has drifted substantially (main has its own folds, pure_reads, simplify_cfg; the source's were merged by hand, not cherry-picked):
    • InstCombine: depth-4 known-bits for integer and/or/cmp/select, dx.op.binary.i32 / dx.op.unaryBits.i32 folds, min/max/clamp, bool selects, is_complement;
    • float Select + PHI web promotion (i32 bitcast webs → f32) and the bitcast(select(..)) peephole;
    • intra-loop DCE inside the join rounds (gated too);
    • slot_word mark_pure for SLOT_STRIDES/VIEW_SIZES loads via the existing pure_reads mechanism (this one is a deliberate correctness fix, hence TRANSLATOR_VERSION 20→21 so caches retranslate).
  • 12 focused optimiser tests (fire/no-fire: DCE unblocking web promotion, signed-zero/NaN-bit preservation, live-int-user peephole, canonical CSE + never emitting pred::ONE, loop-header FACTS, dx.op folds, shift overflow/BFE/BFI/CBUF known-bits, float-equality/irreducible-loop non-substitution, handle-select invariants) and the random-program differential suite now also runs INST_COMBINE and INST_COMBINE|DEAD.
  • Left out: MiniVI's richer SimplifyCFG + LICM (dc55250f, ~2.5k L) — main has its own smaller simplify_cfg; that remains a follow-up slice.

Verification

  • cargo test -p victory-dxil: 34 passed (13 new); cargo test -p victory-shader --lib: 320 passed, 2 ignored (~4 min pipeline included), differential suite green.
  • cargo check -p victory, cargo xtask policy, clippy -p victory-dxil -D warnings: clean.
  • Needs in-game A/B before enabling: VICTORY_SHADER_OPT=1024 vs unset on AMD RX 9070 XT and NVIDIA — watch for visual corruption/hangs (miscompile surface: known-bits, integer dx.op folds, float web promotion) and frame time; the bump forces one retranslation pass.

Source: Androtim/MiniVI 20be1548 (opt.rs, +2062), adapted to this tree's optimiser; SimplifyCFG/LICM deliberately deferred.

**@⁠SovietBearz0r** on GitHub · 2026-12-05 13:18 UTC · [original](https://github.com/ReTerryDavis/ReVIctory/pull/121) `SovietBearz0r:minivi-shader-opt` → `main` · +2358 −57 · 4 files · 3 commits · draft Port MiniVI's InstCombine / float Select+PHI web promotion / intra-loop DCE into the DXIL optimiser as an **off-by-default** pass set: `VICTORY_SHADER_OPT=1024` (or `default|1024`). ## What - New `opt::INST_COMBINE = 1024` bit in `crates/victory-dxil/src/bitcode/opt.rs`, included in `MODULE`/`ALL` but not in `DEFAULT` (stays 63 — default output is unchanged, proven by a contract test). - Ported from MiniVI `20be1548` (+2062), adapted to this tree's optimiser which has drifted substantially (main has its own folds, `pure_reads`, `simplify_cfg`; the source's were merged by hand, not cherry-picked): - InstCombine: depth-4 known-bits for integer `and`/`or`/`cmp`/`select`, `dx.op.binary.i32` / `dx.op.unaryBits.i32` folds, min/max/clamp, bool selects, `is_complement`; - float `Select` + `PHI` web promotion (i32 bitcast webs → f32) and the `bitcast(select(..))` peephole; - intra-loop DCE inside the join rounds (gated too); - `slot_word mark_pure` for `SLOT_STRIDES`/`VIEW_SIZES` loads via the existing `pure_reads` mechanism (this one is a deliberate correctness fix, hence `TRANSLATOR_VERSION` 20→21 so caches retranslate). - 12 focused optimiser tests (fire/no-fire: DCE unblocking web promotion, signed-zero/NaN-bit preservation, live-int-user peephole, canonical CSE + never emitting `pred::ONE`, loop-header FACTS, dx.op folds, shift overflow/BFE/BFI/CBUF known-bits, float-equality/irreducible-loop non-substitution, handle-select invariants) and the random-program differential suite now also runs `INST_COMBINE` and `INST_COMBINE|DEAD`. - Left out: MiniVI's richer SimplifyCFG + LICM (`dc55250f`, ~2.5k L) — main has its own smaller `simplify_cfg`; that remains a follow-up slice. ## Verification - `cargo test -p victory-dxil`: **34 passed** (13 new); `cargo test -p victory-shader --lib`: **320 passed, 2 ignored** (~4 min pipeline included), differential suite green. - `cargo check -p victory`, `cargo xtask policy`, clippy `-p victory-dxil -D warnings`: clean. - **Needs in-game A/B before enabling**: `VICTORY_SHADER_OPT=1024` vs unset on AMD RX 9070 XT and NVIDIA — watch for visual corruption/hangs (miscompile surface: known-bits, integer dx.op folds, float web promotion) and frame time; the bump forces one retranslation pass. Source: Androtim/MiniVI `20be1548` (opt.rs, +2062), adapted to this tree's optimiser; SimplifyCFG/LICM deliberately deferred.
Port the first optimiser group from GPL-3.0 Androtim/MiniVI commit
20be1548a6b1f7b80ba66df54104da1fda13ce54 into victory-dxil's bitcode
optimiser as an opt-in pass, `opt::INST_COMBINE` (bit 1024, off by
default; `VICTORY_SHADER_OPT=1024`, or `1087` for the defaults with it):

- exact instruction combining beyond the established constants and
  identities: depth-4 known-bits simplification of integer `and`, `or`,
  `cmp` and `select`, integer `dx.op.binary.i32`/`dx.op.unaryBits.i32`
  folds, min/max/clamp folding, and bool select rewrites;
- float `Select` and `PHI` web promotion (i32 bitcast webs to f32),
  including the `bitcast(select(...))` peephole;
- intra-loop dead-instruction clean-up inside the join rounds, which
  unblocks web promotion on the first iteration;
- `learn` learns integer equalities with constants and canonical
  comparison order, and `merge`/`key` compare in canonical order.

All of the new rules are gated on the new bit, so the established
passes keep computing what they did; `DEFAULT` stays 63.

Also mark the host's per-view tables (`SLOT_STRIDES`, `VIEW_SIZES`) as
pure reads (`pure_reads`), adapted from the same commit's
`slot_word mark_pure`, so their loads CSE across stores and barriers
within an invocation; `TRANSLATOR_VERSION` is bumped because the DXIL
that results can differ.

SimplifyCFG and LICM from the follow-up MiniVI commit dc55250f are not
ported here.

Source: 20be1548
Tests: 12 focused optimiser tests ported plus an off-by-default contract
test; the random-program differential suite also runs INST_COMBINE alone
and with DEAD.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-05 13:20:12 +00:00
Author
Owner

@⁠ReTerryDavis on GitHub · 2026-12-05 17:38 UTC · original

Marking this as draft for now. We're keeping main clear of large unverified default-off compiler passes (+2,366 lines in opt.rs with zero in-game A/B perf or visual soak data yet, and it also directly conflicts with #126 in opt.rs).

Note also that this PR includes a default-ON 3-line change in lower/memory.rs (pure_reads.insert(id) for SLOT_STRIDES/VIEW_SIZES) that bumps TRANSLATOR_VERSION (invalidating everyone's shader cache) inside an otherwise opt-in PR — if that pure_reads fix stands on its own, it's better split into a tiny focused PR while INST_COMBINE is soaked and benchmarked in-game first.

**@⁠ReTerryDavis** on GitHub · 2026-12-05 17:38 UTC · [original](https://github.com/ReTerryDavis/ReVIctory/pull/121#issuecomment-7442352480) Marking this as draft for now. We're keeping `main` clear of large unverified default-off compiler passes (+2,366 lines in `opt.rs` with zero in-game A/B perf or visual soak data yet, and it also directly conflicts with #126 in `opt.rs`). Note also that this PR includes a default-ON 3-line change in `lower/memory.rs` (`pure_reads.insert(id)` for `SLOT_STRIDES`/`VIEW_SIZES`) that bumps `TRANSLATOR_VERSION` (invalidating everyone's shader cache) inside an otherwise opt-in PR — if that `pure_reads` fix stands on its own, it's better split into a tiny focused PR while `INST_COMBINE` is soaked and benchmarked in-game first.
The old branch marked the SLOT_STRIDES/VIEW_SIZES raw-buffer loads as pure reads in lower/memory.rs and bumped TRANSLATOR_VERSION 20 -> 21. That fix is default-ON and stands on its own, so it moves to its own PR (pure-reads-slots, branch pure-reads-slots); this branch keeps only the opt-in INST_COMBINE pass (VICTORY_SHADER_OPT=1024, not in DEFAULT).

With the marking gone nothing default-on changes: DEFAULT stays 63 and TRANSLATOR_VERSION stays 20. shader_opt() (the pass mask) is part of the shader cache key, so existing cached translations keep their key and VICTORY_SHADER_OPT=1024 is opted into explicitly.
Author
Owner

@⁠SovietBearz0r on GitHub · 2026-12-05 19:10 UTC · original

Split done per the review: the default-on pure_reads change (+ its TRANSLATOR_VERSION 20→21 bump) is now its own tiny PR — #162 — and has been removed from this branch. #122 now contains only the opt-in passes: DEFAULT is still 63, TRANSLATOR_VERSION stays 20 (the opt-in mask is already part of the shader-cache key), and lower/memory.rs + lib.rs are byte-identical to main. The branch was updated by merging current main (not force-pushed). Still draft for the in-game A/B soak of VICTORY_SHADER_OPT=1024 you asked for; no data can be produced here.

**@⁠SovietBearz0r** on GitHub · 2026-12-05 19:10 UTC · [original](https://github.com/ReTerryDavis/ReVIctory/pull/121#issuecomment-7443765334) Split done per the review: the default-on `pure_reads` change (+ its `TRANSLATOR_VERSION` 20→21 bump) is now its own tiny PR — #162 — and has been **removed** from this branch. #122 now contains only the opt-in passes: `DEFAULT` is still 63, `TRANSLATOR_VERSION` stays 20 (the opt-in mask is already part of the shader-cache key), and `lower/memory.rs` + `lib.rs` are byte-identical to main. The branch was updated by merging current main (not force-pushed). Still draft for the in-game A/B soak of `VICTORY_SHADER_OPT=1024` you asked for; no data can be produced here.
Author
Owner

@⁠SovietBearz0r on GitHub · 2026-12-05 20:20 UTC · original

First in-game data point on this branch (AMD side). Machine: RX 9070 XT 16 GB (RDNA4, driver 32.0.32029.2010), Ryzen 9 9900X, Windows, diag build, bench.ps1 builtin:cruise route, -Gpu 0. Same binary (the #122 branch build) for both sides; baseline = the play profile (VICTORY_SHADER_OPT=255 via -GpuOpt), on-side =1279 (255 + INST_COMBINE). 2 runs per side, medians; 0 shaders translated during the measured spots (cache was warmed before measuring).

spot base avg fps on avg fps delta base p99 ms on p99 ms base 1% low on 1% low
spawn_idle 32.65 32.80 +0.5% 48.4 49.0 20.7 20.4
cruise_out 32.12 32.41 +0.9% 49.6 50.0 20.3 20.0
cruise_back 29.46 30.55 +3.7% 94.2 81.2 10.65 12.8

Small positive on average, and the back spot's p99/-lows improved. Same caveats as the PR body: one card, two runs, one route, no visual A/B; the NVIDIA/RDNA3 data and a longer soak are still needed. pure_reads is split out to #162; this branch now only carries the opt-in pass.

**@⁠SovietBearz0r** on GitHub · 2026-12-05 20:20 UTC · [original](https://github.com/ReTerryDavis/ReVIctory/pull/121#issuecomment-7444741614) First in-game data point on this branch (AMD side). Machine: **RX 9070 XT 16 GB (RDNA4, driver 32.0.32029.2010)**, Ryzen 9 9900X, Windows, diag build, `bench.ps1` builtin:cruise route, `-Gpu 0`. Same binary (the #122 branch build) for both sides; baseline = the play profile (`VICTORY_SHADER_OPT=255` via `-GpuOpt`), on-side `=1279` (255 + INST_COMBINE). 2 runs per side, medians; **0 shaders translated during the measured spots** (cache was warmed before measuring). | spot | base avg fps | on avg fps | delta | base p99 ms | on p99 ms | base 1% low | on 1% low | |---|---|---|---|---|---|---|---| | spawn_idle | 32.65 | 32.80 | +0.5% | 48.4 | 49.0 | 20.7 | 20.4 | | cruise_out | 32.12 | 32.41 | +0.9% | 49.6 | 50.0 | 20.3 | 20.0 | | cruise_back | 29.46 | 30.55 | **+3.7%** | 94.2 | 81.2 | 10.65 | 12.8 | Small positive on average, and the back spot's p99/-lows improved. Same caveats as the PR body: one card, two runs, one route, no visual A/B; the NVIDIA/RDNA3 data and a longer soak are still needed. `pure_reads` is split out to #162; this branch now only carries the opt-in pass.
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/122/head:github-bot/gh-121'
git switch 'github-bot/gh-121'

Merge

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