dxil: opt-in LICM, barrier dedup, mask recipes, first-lane uniformity (default off) #126

Closed
github-bot wants to merge 2 commits from github-bot/gh-125 into main AGit
Owner

@⁠SovietBearz0r on GitHub · 2026-12-05 13:29 UTC · original
SovietBearz0r:sixmoon-shader-opt → main · +1310 −35 · 11 files · 2 commits · closed without merging

Port sixmoon/Darner's translator improvements as opt-in, default-off switches (existing output and cache keys unchanged; no TRANSLATOR_VERSION bump).

What

  • VICTORY_SHADER_OPT bits: opt::LICM = 256 (natural-loop detection, dominance/preheader, conditional-entry split; never moves loads — main lacks a volatile tag/in-bounds proof; effect instructions break the chain) and opt::BARRIERS = 512 (in-block barrier-state machine: adjacent covered barriers across pure ALU, group-only barrier dropped between LDS read phases bounded by group+TGSM barriers/return, tail-before-ret; loads classified by main's own pointer tracing). DEFAULT stays 63; enable e.g. VICTORY_SHADER_OPT=831 (defaults + both).
  • VICTORY_LICM_CBUF: 1 = default — LICM only constant-buffer rows at constant indices; 2 also descriptor handles; 0 neither.
  • VICTORY_MASK_RECIPES=1 (off): structure recipes recorded and used by boolean lowering, with cost/decision accounting and a cfg(test) equivalence assertion.
  • VICTORY_FIRSTLANE_UNIFORM=1 (off): lane-uniform set for exchange-less programs; v_readfirstlane returns the lane's own VGPR value.
  • VICTORY_LEGACY_FINITE=<bits> (0): assumed-finite bits for legacy-multiply guards (cbuffer/texture/buffer reads, sums+products, joins), applied only in the RDNA legacy-product form.
  • Cache-key entries for every switch when set.

Ported from sixmoon 4480e169 (passes credited there to Darner). Skipped: sixmoon's DEFAULT=ALL (switches the WIDE load lowering on for everyone; main keeps WIDE opt-in and documents no gain on RX 7900 XTX), and its enhanced LOADS/FOLD/finite-data analysis (main has its own VICTORY_LEGACY_MUL=data).

Verification (private target dir — shared one can serve stale cross-worktree binaries)

  • cargo test -p victory-dxil: 25 passed (3 new: LICM fire/no-fire, BARRIERS coverage + must-not-fire + LDS read-after-read, assumed-finite bits; random-program all-passes equivalence still passes).
  • cargo test -p victory-shader --lib: 321 passed, 2 ignored (~3.5 min), and again with VICTORY_SHADER_OPT=831 VICTORY_MASK_RECIPES=1 VICTORY_FIRSTLANE_UNIFORM=1: 321 passed — end-to-end evidence the non-default paths translate the whole suite identically.
  • cargo check -p victory, cargo xtask policy (439 files), clippy: no warnings in touched code (only main's pre-existing lints).
  • Needs in-game differential replay + visual soak on RX 9070 XT and NVIDIA before promoting any switch to default (source author measured 23.4→25 fps median on an RTX 2080 Ti; not reproducible here). Risk: LICM speculation and barrier-elimination are exact by construction but are the kind of change that needs a real soak; since everything is default-off, merging cannot change current behaviour.

Source: srmooon/sixmoon 4480e169 (Darner's passes).

**@⁠SovietBearz0r** on GitHub · 2026-12-05 13:29 UTC · [original](https://github.com/ReTerryDavis/ReVIctory/pull/125) `SovietBearz0r:sixmoon-shader-opt` → `main` · +1310 −35 · 11 files · 2 commits · closed without merging Port sixmoon/Darner's translator improvements as opt-in, **default-off** switches (existing output and cache keys unchanged; no `TRANSLATOR_VERSION` bump). ## What - `VICTORY_SHADER_OPT` bits: `opt::LICM = 256` (natural-loop detection, dominance/preheader, conditional-entry split; never moves loads — main lacks a volatile tag/in-bounds proof; effect instructions break the chain) and `opt::BARRIERS = 512` (in-block barrier-state machine: adjacent covered barriers across pure ALU, group-only barrier dropped between LDS read phases bounded by group+TGSM barriers/return, tail-before-ret; loads classified by main's own pointer tracing). `DEFAULT` stays 63; enable e.g. `VICTORY_SHADER_OPT=831` (defaults + both). - `VICTORY_LICM_CBUF`: 1 = default — LICM only constant-buffer rows at constant indices; 2 also descriptor handles; 0 neither. - `VICTORY_MASK_RECIPES=1` (off): structure recipes recorded and used by boolean lowering, with cost/decision accounting and a `cfg(test)` equivalence assertion. - `VICTORY_FIRSTLANE_UNIFORM=1` (off): lane-uniform set for exchange-less programs; `v_readfirstlane` returns the lane's own VGPR value. - `VICTORY_LEGACY_FINITE=<bits>` (0): assumed-finite bits for legacy-multiply guards (cbuffer/texture/buffer reads, sums+products, joins), applied only in the RDNA legacy-product form. - Cache-key entries for every switch when set. Ported from sixmoon `4480e169` (passes credited there to Darner). Skipped: sixmoon's `DEFAULT=ALL` (switches the `WIDE` load lowering on for everyone; main keeps `WIDE` opt-in and documents no gain on RX 7900 XTX), and its enhanced LOADS/FOLD/finite-data analysis (main has its own `VICTORY_LEGACY_MUL=data`). ## Verification (private target dir — shared one can serve stale cross-worktree binaries) - `cargo test -p victory-dxil`: **25 passed** (3 new: LICM fire/no-fire, BARRIERS coverage + must-not-fire + LDS read-after-read, assumed-finite bits; random-program all-passes equivalence still passes). - `cargo test -p victory-shader --lib`: **321 passed, 2 ignored** (~3.5 min), and again with `VICTORY_SHADER_OPT=831 VICTORY_MASK_RECIPES=1 VICTORY_FIRSTLANE_UNIFORM=1`: **321 passed** — end-to-end evidence the non-default paths translate the whole suite identically. - `cargo check -p victory`, `cargo xtask policy` (439 files), clippy: no warnings in touched code (only main's pre-existing lints). - **Needs in-game differential replay + visual soak** on RX 9070 XT and NVIDIA before promoting any switch to default (source author measured 23.4→25 fps median on an RTX 2080 Ti; not reproducible here). Risk: LICM speculation and barrier-elimination are exact by construction but are the kind of change that needs a real soak; since everything is default-off, merging cannot change current behaviour. Source: srmooon/sixmoon `4480e169` (Darner's passes).
Source: srmooon/sixmoon 4480e169295e08aa770544a2afb21bebdc6b00a3
(1.3.0, GPL-3.0-or-later; the passes are Darner's, credited in the
code). Five translator improvements, all exact, all opt-in.

Bitcode optimiser passes (`victory-dxil`):

- `opt::LICM` (bit 256): pure, non-trapping loop-invariant instructions
  move to a natural loop's preheader, which is split from a conditional
  entry when the loop has one. `VICTORY_LICM_CBUF` picks what may leave
  a block that runs conditionally: 1 (the default) a constant-buffer row
  at a constant index, 2 also descriptor handles, 0 neither. The source
  author measured this one alone at 2.8 ms of an RTX 2080 Ti's frame.
- `opt::BARRIERS` (bit 512): a `dx.op.barrier` whose mode bits an
  earlier barrier in the same block already covers is dropped where
  nothing it orders ran between them, and a group-only barrier between
  two read phases of thread-group memory is dropped between a covering
  group+TGSM barrier and the shader's return.

Lowering clean-ups (`victory-shader`):

- `VICTORY_MASK_RECIPES=1`: structurisation keeps the operation tree a
  lane mask was first built from, and lowering builds the mask in one i1
  operation over those operands where that is fewer than one per
  decision node.
- `VICTORY_FIRSTLANE_UNIFORM=1`: a `v_readfirstlane` of a VGPR value
  every lane holds alike (`lane_uniform`, without the LDS-read rule) is
  the lane's own value, so no `WaveReadLaneFirst` is emitted.
- `VICTORY_LEGACY_FINITE=<bits>` (0 by default): take reads and their
  sums and products to be finite when choosing a legacy multiply's zero
  guard (1 constant buffers, 2 textures, 4 buffers, 8 sums, 16 joins).
  An approximation; it applies only in the RDNA legacy-product form.

Defaults: `opt::DEFAULT` is unchanged (63) and every lowering switch is
off, so default translations and shader-cache keys do not move and no
`TRANSLATOR_VERSION` bump is needed. Opt in with `VICTORY_SHADER_OPT`
(319 adds LICM, 575 adds barriers, 831 both, 1023 every pass) plus the
three `VICTORY_*` switches above; all are part of the shader cache's
key when set.

Adapted, not copied: LICM never moves a load (main has no volatile tag
or in-bounds proof for one) and its "guaranteed" block chain breaks at
any instruction with an effect rather than only at discard-like calls.
BARRIERS keeps sixmoon's in-block state machine but classifies loads
with main's own pointer tracing (address space 3 is thread-group
memory). Skipped: sixmoon's `DEFAULT = ALL`, which switches the `WIDE`
load lowering on for everyone. Main documents `WIDE` as worth nothing
on an RX 7900 XTX and keeps it opt-in; enabling it here would change
every translation for a number from one NVIDIA card. No other extra
clean-up pass exists in the source commit.

Tests: `cargo test -p victory-dxil` (25), `cargo test -p
victory-shader --lib` (321), `cargo check -p victory`, `cargo xtask
policy` (439 files). The whole victory-shader suite also passes with
`VICTORY_SHADER_OPT=831 VICTORY_MASK_RECIPES=1
VICTORY_FIRSTLANE_UNIFORM=1`. New tests cover LICM firing and
must-not-fire, the barrier coverage and read-after-read rules, mask
recipe shape and `given` equivalence, and the assumed-finite bits.

In-game A/B still needed. The author's fixed bench had 23.4 -> 25 fps
median; this port makes no in-game claim. Enable on the target card and
compare the replay bench, watching for barrier-ordering faults on AMD.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-05 13:31:43 +00:00
Author
Owner

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

Marking this as draft for now. This bundles 5 separate unverified default-off DXIL passes (+1,492 lines across 12 files — LICM, barrier dedup, mask recipes, first-lane uniformity, and the unsound VICTORY_LEGACY_FINITE assumption) with no in-game visual soak or ReVIctory perf measurements yet, and conflicts directly with #122 in opt.rs. Once individual passes are soaked in-game with real A/B results (ideally split cleanly), happy to take another look.

**@⁠ReTerryDavis** on GitHub · 2026-12-05 17:38 UTC · [original](https://github.com/ReTerryDavis/ReVIctory/pull/125#issuecomment-7442353532) Marking this as draft for now. This bundles 5 separate unverified default-off DXIL passes (`+1,492` lines across 12 files — LICM, barrier dedup, mask recipes, first-lane uniformity, and the unsound `VICTORY_LEGACY_FINITE` assumption) with no in-game visual soak or ReVIctory perf measurements yet, and conflicts directly with #122 in `opt.rs`. Once individual passes are soaked in-game with real A/B results (ideally split cleanly), happy to take another look.
The legacy product's assumed-finite levels took reads, their sums and loop
phis as finite to skip the zero test of an RDNA legacy multiply. That is an
assumption, not an exact test: an infinity read from memory, or an overflow
the program computes, gives 0 where the console gives NaN. The maintainer
called it out as unsound, so remove it rather than ship it. The default form
is already exact (Module::bounded); this deletes only code behind
VICTORY_LEGACY_FINITE (default 0), its docs and its cache-key entry.

This branch is now superseded. Draft #125 is being split into one
default-off, self-contained branch per pass on top of origin/main, each with
its own tests:
  - shader-opt-licm          VICTORY_SHADER_OPT bit 256 (LICM)
  - shader-opt-barriers      VICTORY_SHADER_OPT bit 512 (BARRIERS)
  - shader-opt-mask-recipes  VICTORY_MASK_RECIPES=1
  - shader-opt-first-lane    VICTORY_FIRSTLANE_UNIFORM=1
Those branches are the ones to review; #125 can be closed in favour of them.
The umbrella keeps LICM + barrier dedup + mask recipes + first-lane, all
default-off, in case a combined A/B is wanted.

Tests: cargo test -p victory-dxil: 24 passed (the assumed-finite test is
removed); cargo test -p victory-shader --lib: 321 passed, 2 ignored; cargo
check -p victory; cargo xtask policy (439 files ok); git diff --check:
clean.
github-bot closed this pull request 2026-12-05 19:36:10 +00:00
Author
Owner

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

Split cleanly per this review, into four default-off PRs (each rebased on current main, each independently tested):

  • #163 LICM — VICTORY_SHADER_OPT bit 256 (=319 = defaults + LICM), sub-switch VICTORY_LICM_CBUF
  • #164 barrier dedup — bit 512 (=575), no sub-switch
  • #165 structure mask recipes — VICTORY_MASK_RECIPES=1
  • #166 first-lane uniformity — VICTORY_FIRSTLANE_UNIFORM=1

Also dropped the piece you called out as unsound: VICTORY_LEGACY_FINITE (the "reads/sums/phis are finite" assumption) is deleted from all four branches and from this umbrella branch. No branch bumps TRANSLATOR_VERSION; DEFAULT stays 63; only the non-default switches are appended to the shader-cache key.

Closing #126 in favour of the four split PRs. Each one's description lists exactly the in-game A/B data you'd need (route/scene, ≥3 runs, avg FPS, 1% low, p50/p95/p99, GPU busy, visual equality, RDNA3/4 + NVIDIA, cold+warm cache; plus per-pass specifics like barriers dropped, i1 delta, lane-read elisions). No in-game data can be produced in this environment.

**@⁠SovietBearz0r** on GitHub · 2026-12-05 19:31 UTC · [original](https://github.com/ReTerryDavis/ReVIctory/pull/125#issuecomment-7444061544) Split cleanly per this review, into four default-off PRs (each rebased on current `main`, each independently tested): - #163 LICM — `VICTORY_SHADER_OPT` bit 256 (`=319` = defaults + LICM), sub-switch `VICTORY_LICM_CBUF` - #164 barrier dedup — bit 512 (`=575`), no sub-switch - #165 structure mask recipes — `VICTORY_MASK_RECIPES=1` - #166 first-lane uniformity — `VICTORY_FIRSTLANE_UNIFORM=1` Also dropped the piece you called out as unsound: `VICTORY_LEGACY_FINITE` (the "reads/sums/phis are finite" assumption) is deleted from all four branches and from this umbrella branch. No branch bumps `TRANSLATOR_VERSION`; `DEFAULT` stays 63; only the non-default switches are appended to the shader-cache key. Closing #126 in favour of the four split PRs. Each one's description lists exactly the in-game A/B data you'd need (route/scene, ≥3 runs, avg FPS, 1% low, p50/p95/p99, GPU busy, visual equality, RDNA3/4 + NVIDIA, cold+warm cache; plus per-pass specifics like barriers dropped, i1 delta, lane-read elisions). No in-game data can be produced in this environment.

Pull request closed

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