dxil: opt-in loop-invariant code motion (VICTORY_SHADER_OPT=256, default off) #163

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

@⁠SovietBearz0r on GitHub · 2026-12-05 19:31 UTC · original
SovietBearz0r:shader-opt-licm → main · +497 −8 · 5 files · 1 commits · draft

LICM split out of #126, per the review there ("once individual passes are soaked in-game with real A/B results (ideally split cleanly)"). Default off; existing output unchanged.

What

  • opt::LICM = 256 in VICTORY_SHADER_OPT (e.g. =319 = defaults 63 + LICM): natural-loop detection, dominance/preheader placement and conditional-entry splitting; never moves loads (no volatile/in-bounds proof), effect instructions break the chain. Sub-switch VICTORY_LICM_CBUF (1 = constant-buffer rows at constant indices only — the default; 2 also descriptor handles; 0 neither).
  • DEFAULT stays 63; the opt-in mask is already in the shader-cache key, so no version bump for default users; VICTORY_LICM_CBUF ≠1 is appended to the key.
  • Split cleanliness: the dominator-tree (Tree.idom) change is LICM-only and kept out of the barrier branch. The shared MODULE/ALL/DEFAULT bookkeeping block is pass-specific here (mask union is 1023 when LICM+BARRIERS are merged).

Verification

  • cargo test -p victory-dxil 22 passed (base 21 + hoist/keep test); cargo test -p victory-shader --lib 323 passed / 2 ignored, and 323 passed with VICTORY_SHADER_OPT=319; cargo check -p victory; policy 442 files; clippy -D warnings clean.
  • In-game A/B owed (cannot be produced here): 1.0.2.1, one save + scripted route, ≥3 runs each, =319 vs default 63, report avg FPS, 1% low, p50/p95/p99 frame time, GPU busy, and visual equality; also VICTORY_LICM_CBUF=0/1/2 to justify the conditional-row policy. Include one RDNA3/4 and one NVIDIA card, cold+warm shader cache.

Source: MiniVI/sixmoon via longroad lineage (source claim RTX 2080 Ti 23.4→25 fps needs independent replication).

**@⁠SovietBearz0r** on GitHub · 2026-12-05 19:31 UTC · [original](https://github.com/ReTerryDavis/ReVIctory/pull/162) `SovietBearz0r:shader-opt-licm` → `main` · +497 −8 · 5 files · 1 commits · draft LICM split out of #126, per the review there ("once individual passes are soaked in-game with real A/B results (ideally split cleanly)"). Default off; existing output unchanged. ## What - `opt::LICM = 256` in `VICTORY_SHADER_OPT` (e.g. `=319` = defaults 63 + LICM): natural-loop detection, dominance/preheader placement and conditional-entry splitting; never moves loads (no volatile/in-bounds proof), effect instructions break the chain. Sub-switch `VICTORY_LICM_CBUF` (1 = constant-buffer rows at constant indices only — the default; 2 also descriptor handles; 0 neither). - `DEFAULT` stays 63; the opt-in mask is already in the shader-cache key, so no version bump for default users; `VICTORY_LICM_CBUF` ≠1 is appended to the key. - Split cleanliness: the dominator-tree (`Tree.idom`) change is LICM-only and kept out of the barrier branch. The shared `MODULE`/`ALL`/`DEFAULT` bookkeeping block is pass-specific here (mask union is 1023 when LICM+BARRIERS are merged). ## Verification - `cargo test -p victory-dxil` **22 passed** (base 21 + hoist/keep test); `cargo test -p victory-shader --lib` **323 passed / 2 ignored**, and **323 passed** with `VICTORY_SHADER_OPT=319`; `cargo check -p victory`; policy 442 files; clippy `-D warnings` clean. - **In-game A/B owed** (cannot be produced here): 1.0.2.1, one save + scripted route, ≥3 runs each, `=319` vs default 63, report avg FPS, 1% low, p50/p95/p99 frame time, GPU busy, and visual equality; also `VICTORY_LICM_CBUF=0/1/2` to justify the conditional-row policy. Include one RDNA3/4 and one NVIDIA card, cold+warm shader cache. Source: MiniVI/sixmoon via longroad lineage (source claim RTX 2080 Ti 23.4→25 fps needs independent replication).
Loop-invariant code motion to a natural loop's preheader, ported from
sixmoon 1.3.0 (Darner de329bffd6, GPL-3.0-or-later). Natural-loop
detection runs through the dominator tree; a loop's preheader must
dominate every outside edge (a conditionally entered loop gets one split
for it), and pure, non-trapping instructions whose operands are loop
invariant and dominate the preheader are hoisted. Loads are never moved
(the module has no volatile tag and no in-bounds proof); any instruction
with a write effect ends the speculatable chain. A block that runs
conditionally may leave only the reads VICTORY_LICM_CBUF admits: 1 (the
default) a constant buffer row at a constant index, 2 also a descriptor
handle, 0 neither.

Switch: VICTORY_SHADER_OPT bit 256 (opt::LICM); VICTORY_SHADER_OPT=319
runs it with the established passes. DEFAULT stays 63 and a default
run's output, behaviour and cache keys are unchanged (the pass bit is
already part of the shader cache's key; VICTORY_LICM_CBUF is appended to
the key only when it is not the default 1).

Split out of draft #125 into one pass per PR, as the maintainer asked.
VICTORY_LEGACY_FINITE (unsound: assumes reads, sums and loop phis are
finite) is dropped, not shipped.

Tests: cargo test -p victory-dxil: 22 passed (new: a constant row at a
constant index leaves a loop from a block that runs conditionally, while
a row at the loop's index and a handle at a loop-varying index stay).
cargo test -p victory-shader --lib: 323 passed, 2 ignored, and again 323
passed with VICTORY_SHADER_OPT=319. cargo check -p victory; cargo xtask
policy (442 files ok); clippy -p victory-shader -p victory-dxil -p
victory-gpu --all-targets -- -D warnings; git diff --check: clean.

Still needs in-game differential A/B on the target cards before any
promotion to default (see the PR description).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-05 19:35:24 +00:00
Author
Owner

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

First in-game data point — and it is a negative one on AMD, so please don't merge this as-is; reporting it rather than dropping it.

Machine: RX 9070 XT 16 GB (RDNA4, driver 32.0.32029.2010), Ryzen 9 9900X, Windows, diag build, bench.ps1 builtin:cruise, -Gpu 0. Same binary for both sides; baseline = the play profile (VICTORY_SHADER_OPT=255 via -GpuOpt), on-side =511 (255 + LICM). 2 runs per side, medians; 0 shaders were translated during the measured spots on both sides (the lap's cache lines show 45-49 translations only during loading, before the first spot; the spot windows are clean).

spot base avg fps on avg fps delta base p99 ms on p99 ms
spawn_idle 33.10 27.40 -17.2% 47.6 101.4
cruise_out 32.22 17.62 -45.3% 58.9 180.7
cruise_back 33.46 17.54 -47.6% 85.2 173.9

That is not noise (both on-runs were consistently slow; the parity runs before/after are back at ~32 fps), and it is the opposite sign of the source's NVIDIA measurement. Two plausible explanations: (a) the port has an interaction bug on RDNA4 — e.g. the pass hoisting loads the driver then spills/serialises heavily; (b) the source numbers don't carry over to this card/title build. The sibling splits are neutral-to-positive on the same rig: barrier dedup #164 is within noise, InstCombine #122 is +0.5..+3.7%.

I don't have NVIDIA hardware to reproduce the intended setup; if you have seen the pass on AMD or have a hint (e.g. interaction with WIDE/DOM_LOADS, which the play profile enables), I'll dig further. Until then this one should stay draft / not be recommended.

**@⁠SovietBearz0r** on GitHub · 2026-12-05 20:20 UTC · [original](https://github.com/ReTerryDavis/ReVIctory/pull/162#issuecomment-7444741930) First in-game data point — and it is a **negative** one on AMD, so please don't merge this as-is; reporting it rather than dropping it. Machine: **RX 9070 XT 16 GB (RDNA4, driver 32.0.32029.2010)**, Ryzen 9 9900X, Windows, diag build, `bench.ps1` builtin:cruise, `-Gpu 0`. Same binary for both sides; baseline = the play profile (`VICTORY_SHADER_OPT=255` via `-GpuOpt`), on-side `=511` (255 + LICM). 2 runs per side, medians; **0 shaders were translated during the measured spots** on both sides (the lap's cache lines show 45-49 translations only during *loading*, before the first spot; the spot windows are clean). | spot | base avg fps | on avg fps | delta | base p99 ms | on p99 ms | |---|---|---|---|---|---| | spawn_idle | 33.10 | 27.40 | -17.2% | 47.6 | 101.4 | | cruise_out | 32.22 | 17.62 | -45.3% | 58.9 | 180.7 | | cruise_back | 33.46 | 17.54 | -47.6% | 85.2 | 173.9 | That is not noise (both on-runs were consistently slow; the parity runs before/after are back at ~32 fps), and it is the opposite sign of the source's NVIDIA measurement. Two plausible explanations: (a) the port has an interaction bug on RDNA4 — e.g. the pass hoisting loads the driver then spills/serialises heavily; (b) the source numbers don't carry over to this card/title build. The sibling splits are neutral-to-positive on the same rig: barrier dedup #164 is within noise, InstCombine #122 is +0.5..+3.7%. I don't have NVIDIA hardware to reproduce the intended setup; if you have seen the pass on AMD or have a hint (e.g. interaction with WIDE/DOM_LOADS, which the play profile enables), I'll dig further. Until then this one should stay draft / not be recommended.
Author
Owner

@⁠Saksukella on GitHub · 2026-12-05 21:55 UTC · original

Tested combined with PR #163 (LICM) + VICTORY_BATCH_PFP=1 on AMD Radeon RX 9070 XT (RDNA 4, 16 GB) / Ryzen 9 7900X / Windows 11, production --release build on 8bff52b + PR #81 (DXR 1.1 HWRT) + PR #87, fixed deterministic route (motel_strip, 10s idle + 15s 67 mph cruise, locked noon clear weather, FSR 4.1.2 Balanced 4K, FG off, VICTORY_WIDE_THREADS=8, fully warmed pipe=0 via play.ps1 -Warm):

Mode Baseline (8bff52b + #81 + #87, --release, opt=255) With #166 (VICTORY_FIRSTLANE_UNIFORM=1) + #163 (opt=511) + BATCH_PFP=1 Delta
DXR 1.1 HWRT (idle / cruise) 38.3 / 37.8 FPS 40.2 / 39.2 FPS +1.9 / +1.4 FPS
Non-RT (idle / cruise) 41.4 / 41.5 FPS 41.8 / 43.7 FPS (49.1 peak) +0.4 / +2.2 FPS
  • CPU tests: ictory-dxil 22/22 passed, ictory-shader --lib 329/329 passed, cargo xtask policy 446/446 ok.
  • All 5/5 benchmark runs exited cleanly (
**@⁠Saksukella** on GitHub · 2026-12-05 21:55 UTC · [original](https://github.com/ReTerryDavis/ReVIctory/pull/162#issuecomment-7446143503) Tested combined with PR #163 (LICM) + VICTORY_BATCH_PFP=1 on **AMD Radeon RX 9070 XT (RDNA 4, 16 GB) / Ryzen 9 7900X / Windows 11**, production --release build on 8bff52b + PR #81 (DXR 1.1 HWRT) + PR #87, fixed deterministic route (motel_strip, 10s idle + 15s 67 mph cruise, locked noon clear weather, FSR 4.1.2 Balanced 4K, FG off, VICTORY_WIDE_THREADS=8, fully warmed pipe=0 via play.ps1 -Warm): | Mode | Baseline (8bff52b + #81 + #87, --release, opt=255) | With #166 (VICTORY_FIRSTLANE_UNIFORM=1) + #163 (opt=511) + BATCH_PFP=1 | Delta | |---|---:|---:|---:| | **DXR 1.1 HWRT** (idle / cruise) | 38.3 / 37.8 FPS | **40.2 / 39.2 FPS** | **+1.9 / +1.4 FPS** | | **Non-RT** (idle / cruise) | 41.4 / 41.5 FPS | **41.8 / 43.7 FPS** (49.1 peak) | **+0.4 / +2.2 FPS** | - CPU tests: ictory-dxil 22/22 passed, ictory-shader --lib 329/329 passed, cargo xtask policy 446/446 ok. - All 5/5 benchmark runs exited cleanly (
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/163/head:github-bot/gh-162'
git switch 'github-bot/gh-162'

Merge

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