shaders: MOVREL waterfall proof and exact cost rewrites (VICTORY_*) #121

Open
github-bot wants to merge 2 commits from github-bot/gh-120 into main AGit
Owner

@⁠SovietBearz0r on GitHub · 2026-12-05 13:17 UTC · original
SovietBearz0r:longroad-movrel-exact → main · +7650 −471 · 65 files · 48 commits · draft

Shader exactness/cost rewrites from longroad: VICTORY_MOVREL_WATERFALL, VICTORY_MINMAX_NONZERO, VICTORY_MED3_CLAMP, VICTORY_LEGACY_MUL_FORMS.

What

  • VICTORY_MOVREL_WATERFALL (on unless 0): a v_movrel* whose M0 holds a first-lane read defined in the same block joins the waterfall's compares/reads, so the M0-indexed loop is proven and runs once with each lane picking its register (main's per-lane movrel lowering already does the pick). Ported from longroad ea1d83a2 (Darner de329bf); main already had the descriptor/first-lane proof machinery, only this proof was missing.
  • Exact rewrites in new emit/cost.rs + lower/operands.rs: MINMAX_NONZERO (min/max with a nonzero constant drops the two-zeros test; on unless 0), MED3_CLAMP (median of value and two normal/infinite constants = clamp, console-exact +0 where the general form leaves -0; on unless 0), LEGACY_MUL_FORMS (legacy product identities; off unless 1, since main already has its own VICTORY_LEGACY_MUL forms and host-RDNA forms that drop the zero test).
  • Switches added to the shader-cache key; TRANSLATOR_VERSION 20→21 (default translations change). Original exactness/cost suite (emit/valu_tests/cost_checks.rs, GPU + WARP over ±0/denormals/NaNs/infinities) and the M0 waterfall test ported.
  • Skipped from the source commit: LONGROAD_BIG_NO_BACK_MB (host/shadow GPU copy-back experiment, off by default, belongs with the heap-twin work).

Verification

  • cargo test -p victory-shader --lib: 328 passed, 0 failed, 2 ignored (240 s), including the four new exactness/cost GPU+WARP tests (identical bits, fewer instructions via census) and the movrel proof test.
  • cargo check -p victory, cargo xtask policy, clippy: clean.
  • Needs in-game: three rewrites are on by default, so compare pictures and fps on AMD RX 9070 XT and NVIDIA (the movrel loops are in the title's compute programs, medians in colour math), and check victory shaders re-translation counts. MOVREL touches loop proof — a too-loose proof would miscompile; the exactness tests are the guard.

Source: Lesloo/longroad ea1d83a2 + ea580ea9.

**@⁠SovietBearz0r** on GitHub · 2026-12-05 13:17 UTC · [original](https://github.com/ReTerryDavis/ReVIctory/pull/120) `SovietBearz0r:longroad-movrel-exact` → `main` · +7650 −471 · 65 files · 48 commits · draft Shader exactness/cost rewrites from longroad: `VICTORY_MOVREL_WATERFALL`, `VICTORY_MINMAX_NONZERO`, `VICTORY_MED3_CLAMP`, `VICTORY_LEGACY_MUL_FORMS`. ## What - `VICTORY_MOVREL_WATERFALL` (on unless `0`): a `v_movrel*` whose M0 holds a first-lane read defined in the same block joins the waterfall's compares/reads, so the M0-indexed loop is proven and runs once with each lane picking its register (main's per-lane movrel lowering already does the pick). Ported from longroad `ea1d83a2` (Darner `de329bf`); main already had the descriptor/first-lane proof machinery, only this proof was missing. - Exact rewrites in new `emit/cost.rs` + `lower/operands.rs`: `MINMAX_NONZERO` (min/max with a nonzero constant drops the two-zeros test; on unless `0`), `MED3_CLAMP` (median of value and two normal/infinite constants = clamp, console-exact `+0` where the general form leaves `-0`; on unless `0`), `LEGACY_MUL_FORMS` (legacy product identities; off unless `1`, since main already has its own `VICTORY_LEGACY_MUL` forms and host-RDNA forms that drop the zero test). - Switches added to the shader-cache key; `TRANSLATOR_VERSION` 20→21 (default translations change). Original exactness/cost suite (`emit/valu_tests/cost_checks.rs`, GPU + WARP over ±0/denormals/NaNs/infinities) and the M0 waterfall test ported. - Skipped from the source commit: `LONGROAD_BIG_NO_BACK_MB` (host/shadow GPU copy-back experiment, off by default, belongs with the heap-twin work). ## Verification - `cargo test -p victory-shader --lib`: **328 passed, 0 failed, 2 ignored (240 s)**, including the four new exactness/cost GPU+WARP tests (identical bits, fewer instructions via census) and the movrel proof test. - `cargo check -p victory`, `cargo xtask policy`, clippy: clean. - **Needs in-game**: three rewrites are on by default, so compare pictures and fps on AMD RX 9070 XT and NVIDIA (the movrel loops are in the title's compute programs, medians in colour math), and check `victory shaders` re-translation counts. MOVREL touches loop proof — a too-loose proof would miscompile; the exactness tests are the guard. Source: Lesloo/longroad `ea1d83a2` + `ea580ea9`.
Ports Lesloo/longroad ea1d83a (+104) and ea580ea (+600), from Darner
de329bf (MOVREL_WATERFALL) and Darner's emit::cost, lower/minmax.rs and
valu_tests/cost_checks.rs (CodeFloe). What main already had is left as it
is: its own descriptor waterfall machinery and its VICTORY_LEGACY_MUL forms
are untouched, and the host RDNA forms already drop the legacy product's
zero test where it cannot change a bit.

Ported, as switches (defaults as in the source; every one joins the shader
cache's key):

- VICTORY_MOVREL_WATERFALL (on unless 0): a v_movrel* whose M0 holds a
  first-lane read made in the same block joins the waterfall's compares and
  reads, so the loop is proven and runs once, each lane picking its own
  register (the movrel lowering already does that per lane).
- VICTORY_MINMAX_NONZERO (on unless 0): a maximum or minimum with a
  constant whose magnitude bits are not zero leaves out the two-zeros test.
- VICTORY_MED3_CLAMP (on unless 0): the median of a value and two normal or
  infinite constants is min(max(x, lo), hi); the median of a value, +0 and a
  positive constant is x > 0 ? min(x, hi) : +0, the console's median for
  every value but a denormal.
- VICTORY_LEGACY_MUL_FORMS (off unless 1): a legacy product of a value with
  itself is a plain product; of a value and a finite constant of size over
  1, a plain product plus +0. Changes non-RDNA hosts only.

Tests: the console's M0-indexed loop proves to one compare and one read
(and not without its back edge), and each rewrite's programs are translated
with every rewrite off, with one on and with all on, then run on the card
and WARP over zeros of both signs, denormals, NaNs, infinities and ordinary
numbers: every translation stores the same bits, and the rewrites write
fewer instructions (the module census). The census has a test-only
per-thread hook for this (victory-dxil, where it lives now) and the median
between +0 and a constant is checked against the console's median, the
general form's -0 being the host's.

Bumps TRANSLATOR_VERSION to 21 (the default translation changes) and fixes
a test helper that named its temp file by the process id alone (side-by-side
tests wrote and deleted each other's file).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-05 13:20:08 +00:00
Author
Owner

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

Nice compact, well-tested shader win (great bit-exact GPU+WARP test coverage over ±0/denorms/NaNs)! Marking as draft for two quick items before merge:

  1. Rebase conflict: Trivial 1-line conflict at the tail of crates/victory-shader/src/emit/valu_tests.rs after #136 merged.
  2. In-game check: Since 3 of the 4 rewrites (MINMAX_NONZERO, MED3_CLAMP, MOVREL_WATERFALL) are default-on, please confirm one quick in-game visual sanity check after rebasing onto main.

Mark ready once rebased/checked and we'll get this in!

**@⁠ReTerryDavis** on GitHub · 2026-12-05 17:39 UTC · [original](https://github.com/ReTerryDavis/ReVIctory/pull/120#issuecomment-7442374532) Nice compact, well-tested shader win (great bit-exact GPU+WARP test coverage over ±0/denorms/NaNs)! Marking as draft for two quick items before merge: 1. **Rebase conflict:** Trivial 1-line conflict at the tail of `crates/victory-shader/src/emit/valu_tests.rs` after #136 merged. 2. **In-game check:** Since 3 of the 4 rewrites (`MINMAX_NONZERO`, `MED3_CLAMP`, `MOVREL_WATERFALL`) are default-on, please confirm one quick in-game visual sanity check after rebasing onto `main`. Mark ready once rebased/checked and we'll get this in!
Author
Owner

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

Rebased onto current main; the only conflict (tail of emit/valu_tests.rs) is resolved by keeping #136's DPP/SDWA test block and appending the branch's mod cost_checks; after it (diff vs main is now exactly +2 lines there). Full shader suite 331 passed, including the bit-exact cost tests on hardware+WARP; clippy clean. Staying draft for the in-game visual sanity check you asked for on the three default-on rewrites — no game runs available here.

**@⁠SovietBearz0r** on GitHub · 2026-12-05 18:55 UTC · [original](https://github.com/ReTerryDavis/ReVIctory/pull/120#issuecomment-7443554797) Rebased onto current `main`; the only conflict (tail of `emit/valu_tests.rs`) is resolved by keeping #136's DPP/SDWA test block and appending the branch's `mod cost_checks;` after it (diff vs main is now exactly +2 lines there). Full shader suite 331 passed, including the bit-exact cost tests on hardware+WARP; clippy clean. Staying draft for the in-game visual sanity check you asked for on the three default-on rewrites — no game runs available here.
Rebased onto origin/main 8bff52be. The only conflict was the one the
maintainer flagged at the tail of
crates/victory-shader/src/emit/valu_tests.rs: main's #135 DPP/SDWA test
tail block (NativeFp16Guard, vopc/dpp16_quad_perm/sdwa_word and the three
stale-cache tests) is kept, and the branch's `mod cost_checks;` goes after
it, so both the DPP/SDWA coverage and emit::valu_tests::cost_checks are
compiled.

No rewrite default is changed: MINMAX_NONZERO, MED3_CLAMP and
MOVREL_WATERFALL stay default-on, LEGACY_MUL_FORMS stays default-off. The
maintainer's in-game visual sanity check remains owed before un-drafting.
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/121/head:github-bot/gh-120'
git switch 'github-bot/gh-120'

Merge

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