shaders: opt-in wave64→wave32 fold (VICTORY_WAVE_FOLDED) #125

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

@⁠SovietBearz0r on GitHub · 2026-12-05 13:26 UTC · original
SovietBearz0r:longroad-wave-fold → main · +5412 −84 · 24 files · 1 commits · draft

Port Darner/longroad's wave64→wave32 fold as an opt-in translator path: VICTORY_WAVE_FOLDED=1 (off by default).

What

A console wave64 compute program becomes a wave32 program where host lane t runs console lanes t and t+32: VGPR twins, EXEC kept in a spare SGPR pair, every vector operation run twice; translated as wave32. Ported from longroad 526ec934 (itself Darner e6245bf5): fold.rs (~1700 L), oracle64.rs (CPU 64-lane oracle, ~2000 L), the folded GPU/join tests, and the folded() integration into structure/resource/lowering. Adapted to this tree: IR VGPR numbers widened to u16 (MAX_VGPRS=512, opcode base table), gfx14/ir::machine_effects, hooks spread over the split lowering modules, cache keys on the switch/filters only when on, VICTORY_* names.

Integration is conservative: attempted only inside main's stuck wave64-compute block (Cs && wave64 && host_max_wave()==32), at the head of the non-exact phase of the retry ladder — after every exact wave32 form failed, before barrier-costing forms and approximate local waves, so it overrides none of main's safety decisions. VICTORY_WAVE_FOLDED_ONLY/_SKIP name filters with lightAtlas skipped by default; TRANSLATOR_VERSION unchanged (default output unchanged).

Not ported (honest scope): longroad's VICTORY_EXACT64 LDS-ordering layer and its oracle feed (needed before folding reflection programs relying on 64-lane LDS order); THREAD_TICKET (main takes 2-D/3-D console threads from an LDS counter already). The upstream doc file is gitignored here; provenance is in the commit/module docs.

Verification (private target dir — the shared one served a stale cross-worktree binary once)

  • cargo test -p victory-shader --lib: 343 passed, 0 failed, 2 ignored (226 s); 19/19 folded tests pass, and they really dispatch on this machine's RX 9070 XT (wave32 D3D12 pipelines accepted, console semantics bit-for-bit); 5 also go through the integrated folded()/emit() path.
  • CPU oracle: halves_round_trip and the new folded CPU-oracle test pass (16 worlds identical, 1024 memory words, 257 instructions), so the fold is validated on CPU here too; the title/refused-program digest tests skip honestly (need VICTORY_EXACT64_SHADERS/VICTORY_FOLD_CHECK_DIR).
  • cargo test -p victory-dxil 21 passed; cargo check -p victory; cargo xtask policy (443 files); clippy: only main's pre-existing lints.
  • Owes an in-game NVIDIA A/B (the intended target; AMD does not enter the fold here) and measured perf (fold doubles per-lane ALU/register pressure). Default-on would need a verified-digest gating list like wide_by_default.
  • Known conservative simplification: main's all_lane_blocks lacks longroad's extra waterfall-reads argument, so a few masks may refuse to fold (fallback, not miscompile).

Source: Lesloo/longroad 526ec934 / Darner e6245bf5.

**@⁠SovietBearz0r** on GitHub · 2026-12-05 13:26 UTC · [original](https://github.com/ReTerryDavis/ReVIctory/pull/124) `SovietBearz0r:longroad-wave-fold` → `main` · +5412 −84 · 24 files · 1 commits · draft Port Darner/longroad's wave64→wave32 **fold** as an opt-in translator path: `VICTORY_WAVE_FOLDED=1` (off by default). ## What A console wave64 compute program becomes a wave32 program where host lane t runs console lanes t and t+32: VGPR twins, EXEC kept in a spare SGPR pair, every vector operation run twice; translated as wave32. Ported from longroad `526ec934` (itself Darner `e6245bf5`): `fold.rs` (~1700 L), `oracle64.rs` (CPU 64-lane oracle, ~2000 L), the folded GPU/join tests, and the `folded()` integration into structure/resource/lowering. Adapted to this tree: IR VGPR numbers widened to `u16` (`MAX_VGPRS=512`, opcode base table), `gfx14/ir::machine_effects`, hooks spread over the split lowering modules, cache keys on the switch/filters only when on, `VICTORY_*` names. Integration is conservative: attempted only inside main's `stuck` wave64-compute block (`Cs && wave64 && host_max_wave()==32`), at the head of the **non-exact** phase of the retry ladder — after every exact wave32 form failed, before barrier-costing forms and approximate local waves, so it overrides none of main's safety decisions. `VICTORY_WAVE_FOLDED_ONLY`/`_SKIP` name filters with `lightAtlas` skipped by default; `TRANSLATOR_VERSION` unchanged (default output unchanged). Not ported (honest scope): longroad's `VICTORY_EXACT64` LDS-ordering layer and its oracle feed (needed before folding reflection programs relying on 64-lane LDS order); `THREAD_TICKET` (main takes 2-D/3-D console threads from an LDS counter already). The upstream doc file is gitignored here; provenance is in the commit/module docs. ## Verification (private target dir — the shared one served a stale cross-worktree binary once) - `cargo test -p victory-shader --lib`: **343 passed, 0 failed, 2 ignored** (226 s); **19/19 folded tests pass**, and they really dispatch on this machine's RX 9070 XT (wave32 D3D12 pipelines accepted, console semantics bit-for-bit); 5 also go through the integrated `folded()`/`emit()` path. - CPU oracle: `halves_round_trip` and the new folded CPU-oracle test pass (16 worlds identical, 1024 memory words, 257 instructions), so the fold is validated on CPU here too; the title/refused-program digest tests skip honestly (need `VICTORY_EXACT64_SHADERS`/`VICTORY_FOLD_CHECK_DIR`). - `cargo test -p victory-dxil` 21 passed; `cargo check -p victory`; `cargo xtask policy` (443 files); clippy: only main's pre-existing lints. - **Owes an in-game NVIDIA A/B** (the intended target; AMD does not enter the fold here) and measured perf (fold doubles per-lane ALU/register pressure). Default-on would need a verified-digest gating list like `wide_by_default`. - Known conservative simplification: main's `all_lane_blocks` lacks longroad's extra waterfall-reads argument, so a few masks may refuse to fold (fallback, not miscompile). Source: Lesloo/longroad `526ec934` / Darner `e6245bf5`.
Port longroad's wave64->wave32 "fold" onto main's IR and lowering, opt-in
behind VICTORY_WAVE_FOLDED=1 (off by default; Darner's ladder had it on).

A console wave64 compute program becomes a wave32 program where host lane t
runs console lanes t and t+32: VGPR twins named through per-instruction VGPR
bases (the IR's VGPR numbers widened to u16, MAX_VGPRS = 512), the console's
EXEC kept in a spare SGPR pair, every vector instruction run twice; the
result is translated as wave32 by the ordinary exact path. Cross-lane
operations become exact: ballots, lane reads/writes, v_mbcnt, mask
arithmetic, saveexec branches, LDS/barriers (one host wave per console wave).

Source: Lesloo/longroad commit 526ec93466643bd2efb661b483c56cc376baaa7f
("Shader: console wave64 compute folded two lanes to a host lane (Darner's
fold)"), itself ported from Darner (trustno1-coder, GPL-3.0-or-later,
darner-shader e6245bf5). Both are GPL-3.0-or-later, as ReVIctory.

Ported: crates/victory-shader/src/fold.rs (the rewrite), oracle64.rs (the
CPU 64-lane oracle, test-only), emit/folded_tests.rs and
emit/folded_join_tests.rs (19 GPU tests + a CPU-oracle test), the IR's u16
VGPRs and VGPR bases (gfx10::Instruction::vgpr_base, gfx10::opcode), and the
lowering hooks for a folded program: FOLDED/with_folded and Lower::every_lane
(lower/settings.rs, lower/mod.rs), the mask_dword "whole" test
(lower/operands.rs), the read-join walk (lower/export.rs), and the permlane
OP_SEL[2:3] relaxation (lower/valu.rs) that one folded test needs.

Placement: at the head of the non-exact phase of emit()'s wave64 retry ladder.
It only runs after every exact wave32 form failed, before the forms that cost
group barriers and the approximate ones, so no safety decision of main's is
overridden. VICTORY_WAVE_FOLDED_ONLY/_SKIP filter programs by name
(lightAtlas skipped by default, as in longroad). The shader cache keys on the
switch and the filters (victory-gpu/src/shader_cache.rs), only when on so
existing caches keep their key.

Not ported (longroad-only follow-ups): its VICTORY_EXACT64 LDS-ordering layer
and oracle feed, and VICTORY_THREAD_TICKET as such (main already takes 2-D/3-D
groups' console threads from an LDS counter).

The porting notes (including the longroad docs/wave64-folded.md content) are
kept out of the tree because ReVIctory gitignores /docs/; the module docs of
fold.rs carry the summary and provenance.

Tests (private CARGO_TARGET_DIR, isolated from the shared qol/target whose
cross-worktree artifacts can collide):
- cargo test -p victory-shader --lib: 343 passed, 0 failed, 2 ignored.
  Of these, the 19 folded tests and the folded CPU-oracle test pass, and the
  19 really dispatch on this machine's RX 9070 XT (wave32 D3D12 pipelines are
  accepted) bit for bit against console semantics; AMD is not the intended
  target, so in-game NVIDIA verification is still owed.
- oracle64: halves_round_trip passes; refused_programs_fold_exactly and
  title_programs_fold_exactly skip (they need title shader containers via
  VICTORY_EXACT64_SHADERS / VICTORY_FOLD_CHECK_DIR, which this checkout
  does not have).
- cargo test -p victory-dxil: 21 passed. cargo check -p victory: ok.
  cargo xtask policy: 443 files ok. clippy -p victory-shader --all-targets
  and -p victory-gpu --lib: only main's pre-existing host.rs byte-grouping and
  victory-gpu lints, none from this change.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-05 13:31:34 +00:00
Author
Owner

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

Marking this as draft for now. At +5,412 lines across 24 files (including widening Reg::V(u8 -> u16) across IR/GFX10/lowering), this is a very large maintenance surface to carry on main without any NVIDIA in-game A/B verification yet — especially while VICTORY_EXACT64 LDS ordering isn't included and known VGPR spills on lightAtlas still need a hardcoded skip list. Happy to revisit once it has real NVIDIA in-game testing and frame-time/visual A/B results.

**@⁠ReTerryDavis** on GitHub · 2026-12-05 17:38 UTC · [original](https://github.com/ReTerryDavis/ReVIctory/pull/124#issuecomment-7442351999) Marking this as draft for now. At +5,412 lines across 24 files (including widening `Reg::V(u8 -> u16)` across IR/GFX10/lowering), this is a very large maintenance surface to carry on `main` without any NVIDIA in-game A/B verification yet — especially while `VICTORY_EXACT64` LDS ordering isn't included and known VGPR spills on `lightAtlas` still need a hardcoded skip list. Happy to revisit once it has real NVIDIA in-game testing and frame-time/visual A/B results.
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/125/head:github-bot/gh-124'
git switch 'github-bot/gh-124'

Merge

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