Shaders: lower waterfall loops over per-lane descriptors (and s_cselect-chosen descriptors) #307

Manually merged
github merged 4 commits from gh-pr/307/head into gh-pr/307/base 2026-11-26 03:58:43 +00:00
Owner

@⁠AntoninMichelq on GitHub · 2026-11-24 02:13 UTC · original
AntoninMichelq:up/waterfall-descriptors → main · +1133 −14 · 5 files · 4 commits · merged 2026-11-24 09:55 UTC

Requested by 4nto · project thread

Summary

Descriptors that a waterfall loop reads lane by lane are now traced and lowered, so the loop runs once with every lane using its own descriptor. Before this, tracing stopped with "a descriptor neither loaded nor built" and the whole program was dropped, along with every draw that used it. The branch also traces descriptors that are chosen without a branch, by s_cselect/s_cmov.

What changed

Two commits, both based on main:

  1. Trace descriptors chosen by s_cselect and s_cmov. The compiler sometimes hoists both descriptor loads and replaces the if/else with s_cselect_b64 per half, or s_cselect_b32/s_cmov per dword. Those words are now split by the SCC value they read, and each side is traced into a new Source::Select. Lowering picks the heap index of the two loaded descriptors by SCC and creates one heap handle. A choice that mixes two descriptors still stops, with "a descriptor changed after loading".

  2. Lower waterfall loops over per-lane descriptors in one pass. The v_readfirstlane_b32 reads of a VGPR descriptor are followed to where each lane gets its own dwords:

    • global_load_dword* from a table or heap at a per-lane address, or
    • a v_cndmask_b32 per-lane choice between such sources.

    Other sources fail and name what they are (LDS, buffer load, phi, input, computed VGPRs). The access gets each lane's heap index, with createHandleFromHeap's nonUniformIndex set. The recorded readfirstlanes are lowered as the lane's own dword and their v_cmp_eq as true. docs/architecture.md is updated.

Adapted to main:

  • Added test helpers lower_with/lower_wave/root to emit::lower::tests.
  • The per-lane load line-up check compares param and dynamic only. The includes_base field it also compared is not on main.

How it was tested

  • cargo test -p victory-shader on Linux: all tests pass. New tests:
    • resource::tests::descriptors_selected_by_scc_are_traced_per_outcome
    • resource::tests::a_selection_that_mixes_two_descriptors_fails
    • resource::tests::descriptors_read_from_the_first_lane_of_per_lane_loads_are_traced_to_them
    • resource::tests::descriptors_read_from_the_first_lane_of_a_per_lane_choice_are_traced_per_lane
    • resource::tests::descriptors_read_from_the_first_lane_of_lds_fail_naming_it
    • emit::lower::tests::a_descriptor_selected_by_scc_picks_its_heap_index
    • emit::lower::tests::waterfall_loops_over_per_lane_descriptors_sample_with_each_lanes_own (Wave32 and Wave64)
  • cargo check -p victory-shader --target x86_64-pc-windows-msvc passes.
  • On the game's 26,148 programs, "a descriptor neither loaded nor built" went from 298 to 3. This was measured with victory translate on the integration stack.

Where 3D rendering stands on an RX 7600 (Windows 11)

  • In the world's first cutscene, props, characters, cables and vehicle tyres now render (seen in a G-buffer view).
  • Ground, roads, buildings, textures, sky and lighting are still missing: the lighting/compose output is black.
  • No GPU hang (DXGI_ERROR_DEVICE_HUNG) in the last two ~4-minute world runs.
  • About 10,000 draws per frame, at well under 1 fps.

These observations come from the integration stack (upstream main plus many open PRs), not from this branch alone.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66

**@⁠AntoninMichelq** on GitHub · 2026-11-24 02:13 UTC · [original](https://github.com/Marvisak/VIctory/pull/307) `AntoninMichelq:up/waterfall-descriptors` → `main` · +1133 −14 · 5 files · 4 commits · merged 2026-11-24 09:55 UTC <!-- claude-projects-attribution: {"github_login":"AntoninMichelq"} --> _Requested by **4nto** · [project thread](https://claude.ai/code/project/chan_01XYoPEzLL1bj63HP9pniGvs?thread=cmsg_01XYoPEzLL1bj63HP9pniGvsYRPS2v37oeDeGaCHT7dFsi)_ ## Summary Descriptors that a waterfall loop reads lane by lane are now traced and lowered, so the loop runs once with every lane using its own descriptor. Before this, tracing stopped with "a descriptor neither loaded nor built" and the whole program was dropped, along with every draw that used it. The branch also traces descriptors that are chosen without a branch, by `s_cselect`/`s_cmov`. ## What changed Two commits, both based on main: 1. **Trace descriptors chosen by `s_cselect` and `s_cmov`.** The compiler sometimes hoists both descriptor loads and replaces the if/else with `s_cselect_b64` per half, or `s_cselect_b32`/`s_cmov` per dword. Those words are now split by the SCC value they read, and each side is traced into a new `Source::Select`. Lowering picks the heap index of the two loaded descriptors by SCC and creates one heap handle. A choice that mixes two descriptors still stops, with "a descriptor changed after loading". 2. **Lower waterfall loops over per-lane descriptors in one pass.** The `v_readfirstlane_b32` reads of a VGPR descriptor are followed to where each lane gets its own dwords: - `global_load_dword*` from a table or heap at a per-lane address, or - a `v_cndmask_b32` per-lane choice between such sources. Other sources fail and name what they are (LDS, buffer load, phi, input, computed VGPRs). The access gets each lane's heap index, with `createHandleFromHeap`'s `nonUniformIndex` set. The recorded readfirstlanes are lowered as the lane's own dword and their `v_cmp_eq` as true. `docs/architecture.md` is updated. Adapted to main: - Added test helpers `lower_with`/`lower_wave`/`root` to `emit::lower::tests`. - The per-lane load line-up check compares `param` and `dynamic` only. The `includes_base` field it also compared is not on main. ## How it was tested - `cargo test -p victory-shader` on Linux: all tests pass. New tests: - `resource::tests::descriptors_selected_by_scc_are_traced_per_outcome` - `resource::tests::a_selection_that_mixes_two_descriptors_fails` - `resource::tests::descriptors_read_from_the_first_lane_of_per_lane_loads_are_traced_to_them` - `resource::tests::descriptors_read_from_the_first_lane_of_a_per_lane_choice_are_traced_per_lane` - `resource::tests::descriptors_read_from_the_first_lane_of_lds_fail_naming_it` - `emit::lower::tests::a_descriptor_selected_by_scc_picks_its_heap_index` - `emit::lower::tests::waterfall_loops_over_per_lane_descriptors_sample_with_each_lanes_own` (Wave32 and Wave64) - `cargo check -p victory-shader --target x86_64-pc-windows-msvc` passes. - On the game's 26,148 programs, "a descriptor neither loaded nor built" went from 298 to 3. This was measured with `victory translate` on the integration stack. ## Where 3D rendering stands on an RX 7600 (Windows 11) - In the world's first cutscene, props, characters, cables and vehicle tyres now render (seen in a G-buffer view). - Ground, roads, buildings, textures, sky and lighting are still missing: the lighting/compose output is black. - No GPU hang (DXGI_ERROR_DEVICE_HUNG) in the last two ~4-minute world runs. - About 10,000 draws per frame, at well under 1 fps. These observations come from the integration stack (upstream main plus many open PRs), not from this branch alone. 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
A descriptor picked without a branch, as the compiler does when it
hoists both loads (invariant memory) and turns the if/else into a
select, reaches the resource instruction through s_cselect_b64 per half
(or s_cselect_b32 / s_cmov per dword). None of its dwords is then a
load, so tracking stopped with "a descriptor neither loaded nor built"
and the whole program, and every draw using it, was dropped.

Such words are now split by the SCC value they all read: what each is
when SCC is set (S0) and when it is clear (S1, or the old destination
for s_cmov), with words not selected the same on both sides, and each
side traced on its own into a new Source::Select. Selections with
different conditions stop, and a choice that mixes two descriptors
still stops as "a descriptor changed after loading". The lowering picks
the heap index of the two loaded descriptors by SCC and creates one
heap handle, as a phi of loaded descriptors already does per edge.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
A descriptor held in VGPRs is used through a waterfall loop: each pass
reads the first active lane's dwords with v_readfirstlane_b32, compares
them with every lane's own (v_cmp_eq), runs the access with the lanes
that match and repeats for the rest. Tracing stopped at the readfirstlane
results ("a descriptor neither loaded nor built").

The tracer now follows the read lanes' dwords to where each lane gets its
own: global_load_dword* from a table or heap at a per-lane address (an
image descriptor's two x4 loads lined up), or a v_cndmask_b32 choice per
lane between such sources (e.g. two s_load descriptors). Other sources
fail naming them (LDS read, buffer load, phi, input, computed VGPRs).
The loop's compares of those reads with their own dwords are recorded.

Lowering gives the access each lane's heap index (its load address over
the descriptor size, or a per-lane select of indices) with
createHandleFromHeap's nonUniformIndex set, lowers the recorded
readfirstlanes as the lane's own dword and their compares as true, so
the loop runs once with all lanes. Wave32 and wave64 are tested.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
The resource tally in `victory translate` matched every `Source` variant
by hand, so the new `Select`, `Fetched` and `Lanes` kinds left it
non-exhaustive and `cargo check -p victory` failed. A fetched descriptor
is counted with the loaded ones; selections and per-lane choices are
never leaves.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
A descriptor read with v_readfirstlane_b32 was traced to each lane's
own dwords wherever it was, so a first-lane read outside a loop, or one
without the v_cmp_eq that hands every lane its turn, sampled for lanes
the program skipped (reported on the PR with the back edge of the
fetched waterfall test replaced by s_nop).

Now:
- a compare counts only when it and the v_readfirstlane it reads are in
  one loop (each block reaches the other);
- every descriptor read from the first lane needs each of its dwords
  compared that way, or translation stops with "a descriptor read from
  the first lane outside a waterfall loop".

Two tests cover the missing back edge and the missing compare.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:58:41 +00:00
github manually merged commit 6285e19a8a into gh-pr/307/base 2026-11-26 03:58:43 +00:00
Author
Owner

@⁠ifBars on GitHub · 2026-11-24 02:22 UTC · original

I reproduced a case where the rewrite changes a first-lane selection that is outside a waterfall loop.

Starting from WATERFALL_FETCHED_WAVE32, replace its only back edge, 0xBF89_FFE6 (s_cbranch_execnz), with 0xBF80_0000 (s_nop). The result is a single conditional sample. Only lanes whose descriptor matches the first active lane reach the sample, because the program never loops over the remaining lanes. On this patch, lower_wave still reports nonuniform_handles == 1 and wave_ops == false. The first-lane reads become per-lane values, and the equality checks become true, so the emitted program samples for lanes the original program skipped.

This seems to come from Tracer::waterfall matching the read and comparison operands without checking that they belong to a loop that removes the matched lanes and returns for the rest. The modified fixture would make a negative regression test. It should preserve the first-lane selection and EXEC gating or reject that form explicitly. If the first-lane values can have other uses, those also need to keep their original semantics.

This was reproduced with the CPU lowering fixture on Windows. No game files or GPU were used for the counterexample. AI-assisted (Codex).

**@⁠ifBars** on GitHub · 2026-11-24 02:22 UTC · [original](https://github.com/Marvisak/VIctory/pull/307#issuecomment-7120071466) I reproduced a case where the rewrite changes a first-lane selection that is outside a waterfall loop. Starting from `WATERFALL_FETCHED_WAVE32`, replace its only back edge, `0xBF89_FFE6` (`s_cbranch_execnz`), with `0xBF80_0000` (`s_nop`). The result is a single conditional sample. Only lanes whose descriptor matches the first active lane reach the sample, because the program never loops over the remaining lanes. On this patch, `lower_wave` still reports `nonuniform_handles == 1` and `wave_ops == false`. The first-lane reads become per-lane values, and the equality checks become true, so the emitted program samples for lanes the original program skipped. This seems to come from `Tracer::waterfall` matching the read and comparison operands without checking that they belong to a loop that removes the matched lanes and returns for the rest. The modified fixture would make a negative regression test. It should preserve the first-lane selection and EXEC gating or reject that form explicitly. If the first-lane values can have other uses, those also need to keep their original semantics. This was reproduced with the CPU lowering fixture on Windows. No game files or GPU were used for the counterexample. AI-assisted (Codex).
Author
Owner

@⁠tanishq-dubey on GitHub · 2026-11-24 02:33 UTC · original

Independent local check of head ffa663571fd0a14b9beb0889d6c48468010601fb on the high-impact mesh shader 910b4be059bfb28f from issue #293: main reports a descriptor neither loaded nor built at 0x2830; this PR reports the more specific a descriptor read from the first lane of a phi is not supported at the same offset. The shader still does not translate on this branch, consistent with the stated phi limitation. No game files or disassembly attached. AI-assisted.

**@⁠tanishq-dubey** on GitHub · 2026-11-24 02:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/307#issuecomment-7120268680) Independent local check of head `ffa663571fd0a14b9beb0889d6c48468010601fb` on the high-impact mesh shader `910b4be059bfb28f` from issue #293: main reports `a descriptor neither loaded nor built` at `0x2830`; this PR reports the more specific `a descriptor read from the first lane of a phi is not supported` at the same offset. The shader still does not translate on this branch, consistent with the stated phi limitation. No game files or disassembly attached. AI-assisted.
Author
Owner

@⁠r4tedx on GitHub · 2026-11-24 03:08 UTC · original

Review note from building this on current main (d2a4bae), RTX 5070: cargo test -p victory-shader passes, but the CLI no longer builds, so a tester cannot produce victory.exe from this branch as it is:

error[E0004]: non-exhaustive patterns: `Source::Select { .. }`, `Source::Fetched { .. }` and `Source::Lanes { .. }` not covered
   --> apps\victory\src\translate.rs:549:23

tally_resources matches Source exhaustively. Counting Fetched like Loaded, and handling Select / Lanes (not leaves) explicitly, fixes it; cargo check -p victory then passes here.

A smaller question: classify treats any descriptor read through v_readfirstlane as per-lane, also when waterfall() finds no matching v_cmp_eq. For a plain "first lane's index" that differs between lanes, the console uses the first lane's descriptor for the whole wave. Would requiring the compare be safer?

This is the PR aimed at the second row of #293 (a descriptor neither loaded nor built, about 462 draws per frame), so it is worth getting into a tester's hands. From building and reading only; I have no copy of the title.

**@⁠r4tedx** on GitHub · 2026-11-24 03:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/307#issuecomment-7120812662) Review note from building this on current `main` (`d2a4bae`), RTX 5070: `cargo test -p victory-shader` passes, but the CLI no longer builds, so a tester cannot produce `victory.exe` from this branch as it is: ``` error[E0004]: non-exhaustive patterns: `Source::Select { .. }`, `Source::Fetched { .. }` and `Source::Lanes { .. }` not covered --> apps\victory\src\translate.rs:549:23 ``` `tally_resources` matches `Source` exhaustively. Counting `Fetched` like `Loaded`, and handling `Select` / `Lanes` (not leaves) explicitly, fixes it; `cargo check -p victory` then passes here. A smaller question: `classify` treats any descriptor read through `v_readfirstlane` as per-lane, also when `waterfall()` finds no matching `v_cmp_eq`. For a plain "first lane's index" that differs between lanes, the console uses the first lane's descriptor for the whole wave. Would requiring the compare be safer? This is the PR aimed at the second row of #293 (`a descriptor neither loaded nor built`, about 462 draws per frame), so it is worth getting into a tester's hands. From building and reading only; I have no copy of the title.
Author
Owner

@⁠SpaghettiMaster545 on GitHub · 2026-11-24 03:11 UTC · original

cargo build -p victory fails on this PR's head ffa6635 (base d2a4bae, Rust 1.98.1 pinned, Windows 11), in both the release and the diag (--profile diag --features diagnostics) builds:

error[E0004]: non-exhaustive patterns: `victory_shader::resource::Source::Select { .. }`, `victory_shader::resource::Source::Fetched { .. }` and `victory_shader::resource::Source::Lanes { .. }` not covered
   --> apps\victory\src\translate.rs:549:23
    |
549 |         let a = match *leaf {

The new Source variants from crates/victory-shader/src/resource.rs are not handled in that match in the victory binary, so the PR could not be run on the title here. cargo test -p victory-shader alone would not show it, since the binary crate is not built.

(Claude Code, Claude Opus 5.5: hit this building the PR to test it on the title, and wrote this.)

**@⁠SpaghettiMaster545** on GitHub · 2026-11-24 03:11 UTC · [original](https://github.com/Marvisak/VIctory/pull/307#issuecomment-7120864915) `cargo build -p victory` fails on this PR's head `ffa6635` (base `d2a4bae`, Rust 1.98.1 pinned, Windows 11), in both the release and the diag (`--profile diag --features diagnostics`) builds: ``` error[E0004]: non-exhaustive patterns: `victory_shader::resource::Source::Select { .. }`, `victory_shader::resource::Source::Fetched { .. }` and `victory_shader::resource::Source::Lanes { .. }` not covered --> apps\victory\src\translate.rs:549:23 | 549 | let a = match *leaf { ``` The new `Source` variants from `crates/victory-shader/src/resource.rs` are not handled in that `match` in the `victory` binary, so the PR could not be run on the title here. `cargo test -p victory-shader` alone would not show it, since the binary crate is not built. (Claude Code, Claude Opus 5.5: hit this building the PR to test it on the title, and wrote this.)
Author
Owner

@⁠miniongk on GitHub · 2026-11-24 03:53 UTC · original

Tested 077ec8b combined with #320 (a5ba4a4) on an RTX 5080, driver 621.24, Windows 11 26300, using a local Xbox Series 1.0.2.1 copy.

The merge needed two compatibility adjustments: keep the waterfall v_readfirstlane case before the console-flow case, and add the new target/console-flow fields to the #307 test helper. With those changes, cargo test --workspace passed (288 passed, 0 failed, 4 ignored).

On the native title path, the a descriptor neither loaded nor built class fell from 16 distinct shaders with #320 alone to 2 with this combination; host-pipeline refusals stayed at zero. The run still ended in DXGI_ERROR_DEVICE_HUNG, with DRED implicating indirect execution and mesh dispatch. So this narrows descriptor support as intended, but does not by itself resolve #97 here.

Only aggregate counts and error classes shared, no game data or raw game logs. AI-assisted (Kimi Code).

**@⁠miniongk** on GitHub · 2026-11-24 03:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/307#issuecomment-7121510250) Tested `077ec8b` combined with #320 (`a5ba4a4`) on an RTX 5080, driver 621.24, Windows 11 26300, using a local Xbox Series 1.0.2.1 copy. The merge needed two compatibility adjustments: keep the waterfall `v_readfirstlane` case before the console-flow case, and add the new target/console-flow fields to the #307 test helper. With those changes, `cargo test --workspace` passed (288 passed, 0 failed, 4 ignored). On the native title path, the `a descriptor neither loaded nor built` class fell from 16 distinct shaders with #320 alone to 2 with this combination; host-pipeline refusals stayed at zero. The run still ended in `DXGI_ERROR_DEVICE_HUNG`, with DRED implicating indirect execution and mesh dispatch. So this narrows descriptor support as intended, but does not by itself resolve #97 here. Only aggregate counts and error classes shared, no game data or raw game logs. AI-assisted (Kimi Code).
Author
Owner

@⁠EduAzevedo on GitHub · 2026-11-24 04:03 UTC · original

Corpus-wide numbers for what was seen on one shader above: 077ec8b, retail shaders (v1.0.2.1), offline victory translate --list against main d2a4bae, all 26,148 programs.

  • a descriptor neither loaded nor built: 298 → 3.
  • 294 of those (259 mesh, 35 vertex) now stop at a descriptor read from the first lane of a phi, so only one more program translates on this branch alone.
  • No program that translated on main stops translating.

So nearly all of what this PR unlocks goes through that phi case, which matches the #320 combination results above.

AI-assisted.

**@⁠EduAzevedo** on GitHub · 2026-11-24 04:03 UTC · [original](https://github.com/Marvisak/VIctory/pull/307#issuecomment-7121670824) Corpus-wide numbers for what was seen on one shader above: `077ec8b`, retail shaders (v1.0.2.1), offline `victory translate --list` against `main` `d2a4bae`, all 26,148 programs. - `a descriptor neither loaded nor built`: 298 → 3. - **294 of those (259 mesh, 35 vertex) now stop at `a descriptor read from the first lane of a phi`**, so only one more program translates on this branch alone. - No program that translated on `main` stops translating. So nearly all of what this PR unlocks goes through that phi case, which matches the #320 combination results above. AI-assisted.
Author
Owner

@⁠r4tedx on GitHub · 2026-11-24 04:26 UTC · original

@⁠AntoninMichelq are you working on a descriptor read from the first lane of a phi? Going by @⁠EduAzevedo's corpus numbers above it is now the largest single gap behind this PR: 294 programs (259 mesh, 35 vertex), and the second row of #293's ranking (about 462 draws per frame). I do not want to duplicate it, so if you have it in hand, say so and I will stop. Otherwise I am starting a branch on top of this PR's head (6285e19) and will post it for you to take or pick from.

The approach I intend, so it can be shot down early:

  • Tracing (resource.rs, per_lane). When the lane's dwords are VGPR phis of one block, trace each predecessor's values with per_lane again (through lane_term), exactly as phi() does for SGPR words, and give Source::Phi { block, args } whose arguments are per-lane sources (Fetched, Lanes, Loaded). A phi of a block already being resolved stays refused (a descriptor that changes in a loop), and the join limit applies.
  • Lowering (lower.rs, handle). Source::Phi computes each predecessor's heap index at that predecessor's end and joins them with a DXIL phi, as it does today for Loaded arguments, but through lane_heap_index so the arguments can be per-lane; the handle is non-uniform when any leaf is. Since structurisation makes each lane take its own path, the phi gives each lane its own descriptor.
  • The waterfall compares need no change: they compare the first lane's dwords with the same VGPR values.

@⁠EduAzevedo, if it is cheap for you: what the phi looks like in those 294 would tell me whether this is the right shape before I write tests against the wrong one. Yes/no or counts, no shader contents:

  1. Is the phi at the join of an if/else (or a chain of them), or at a loop header (the VGPRs change inside a loop)?
  2. Where do the joined values come from on each path: global_load_dword* results, v_mov_b32 from SGPRs that an s_load_dword* filled, a v_cndmask_b32, or something else (which instruction)?
  3. Are all eight descriptor dwords phis of the same block, or only some of them?

No game data used on my side.

**@⁠r4tedx** on GitHub · 2026-11-24 04:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/307#issuecomment-7122027886) @⁠AntoninMichelq are you working on `a descriptor read from the first lane of a phi`? Going by @⁠EduAzevedo's corpus numbers above it is now the largest single gap behind this PR: 294 programs (259 mesh, 35 vertex), and the second row of #293's ranking (about 462 draws per frame). I do not want to duplicate it, so if you have it in hand, say so and I will stop. Otherwise I am starting a branch on top of this PR's head (`6285e19`) and will post it for you to take or pick from. The approach I intend, so it can be shot down early: - **Tracing (`resource.rs`, `per_lane`).** When the lane's dwords are VGPR phis of one block, trace each predecessor's values with `per_lane` again (through `lane_term`), exactly as `phi()` does for SGPR words, and give `Source::Phi { block, args }` whose arguments are per-lane sources (`Fetched`, `Lanes`, `Loaded`). A phi of a block already being resolved stays refused (`a descriptor that changes in a loop`), and the join limit applies. - **Lowering (`lower.rs`, `handle`).** `Source::Phi` computes each predecessor's heap index at that predecessor's end and joins them with a DXIL phi, as it does today for `Loaded` arguments, but through `lane_heap_index` so the arguments can be per-lane; the handle is non-uniform when any leaf is. Since structurisation makes each lane take its own path, the phi gives each lane its own descriptor. - **The waterfall compares** need no change: they compare the first lane's dwords with the same VGPR values. @⁠EduAzevedo, if it is cheap for you: what the phi looks like in those 294 would tell me whether this is the right shape before I write tests against the wrong one. Yes/no or counts, no shader contents: 1. Is the phi at the join of an if/else (or a chain of them), or at a loop header (the VGPRs change inside a loop)? 2. Where do the joined values come from on each path: `global_load_dword*` results, `v_mov_b32` from SGPRs that an `s_load_dword*` filled, a `v_cndmask_b32`, or something else (which instruction)? 3. Are all eight descriptor dwords phis of the same block, or only some of them? No game data used on my side.
Author
Owner

@⁠AnoHunted on GitHub · 2026-11-24 04:35 UTC · original

Tested 6285e19 merged onto main d2a4bae on NVIDIA GeForce RTX 5080, Windows 11, Rust 1.98.1, with dxil.dll validation on: pass.

  • cargo test -p victory-shader -- --test-threads=1: main 69 passed / 0 failed; this PR 78 passed / 0 failed (new tests: 9, e.g. waterfall_loops_over_per_lane_descriptors_sample_with_each_lanes_own, a_descriptor_selected_by_scc_picks_its_heap_index, a_first_lane_read_outside_a_loop_is_no_waterfall).
  • cargo test --workspace -- --test-threads=1: main 264 passed / 0 failed / 4 ignored; this PR 273 passed / 0 failed / 4 ignored.
  • cargo build -p victory --release also succeeds on this head (the non-exhaustive patterns error in translate.rs reported on ffa6635 is gone, fixed by 077ec8b).

No game files used.

**@⁠AnoHunted** on GitHub · 2026-11-24 04:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/307#issuecomment-7122159926) Tested `6285e19` merged onto `main` `d2a4bae` on **NVIDIA GeForce RTX 5080**, Windows 11, Rust 1.98.1, with `dxil.dll` validation on: **pass**. - `cargo test -p victory-shader -- --test-threads=1`: main 69 passed / 0 failed; this PR 78 passed / 0 failed (new tests: 9, e.g. `waterfall_loops_over_per_lane_descriptors_sample_with_each_lanes_own`, `a_descriptor_selected_by_scc_picks_its_heap_index`, `a_first_lane_read_outside_a_loop_is_no_waterfall`). - `cargo test --workspace -- --test-threads=1`: main 264 passed / 0 failed / 4 ignored; this PR 273 passed / 0 failed / 4 ignored. - `cargo build -p victory --release` also succeeds on this head (the `non-exhaustive patterns` error in `translate.rs` reported on `ffa6635` is gone, fixed by `077ec8b`). No game files used.
Author
Owner

@⁠EduAzevedo on GitHub · 2026-11-24 04:42 UTC · original

@⁠AntoninMichelq are you working on a descriptor read from the first lane of a phi? Going by @⁠EduAzevedo's corpus numbers above it is now the largest single gap behind this PR: 294 programs (259 mesh, 35 vertex), and the second row of #293's ranking (about 462 draws per frame). I do not want to duplicate it, so if you have it in hand, say so and I will stop. Otherwise I am starting a branch on top of this PR's head (6285e19) and will post it for you to take or pick from.

The approach I intend, so it can be shot down early:

  • Tracing (resource.rs, per_lane). When the lane's dwords are VGPR phis of one block, trace each predecessor's values with per_lane again (through lane_term), exactly as phi() does for SGPR words, and give Source::Phi { block, args } whose arguments are per-lane sources (Fetched, Lanes, Loaded). A phi of a block already being resolved stays refused (a descriptor that changes in a loop), and the join limit applies.
  • Lowering (lower.rs, handle). Source::Phi computes each predecessor's heap index at that predecessor's end and joins them with a DXIL phi, as it does today for Loaded arguments, but through lane_heap_index so the arguments can be per-lane; the handle is non-uniform when any leaf is. Since structurisation makes each lane take its own path, the phi gives each lane its own descriptor.
  • The waterfall compares need no change: they compare the first lane's dwords with the same VGPR values.

@⁠EduAzevedo, if it is cheap for you: what the phi looks like in those 294 would tell me whether this is the right shape before I write tests against the wrong one. Yes/no or counts, no shader contents:

  1. Is the phi at the join of an if/else (or a chain of them), or at a loop header (the VGPRs change inside a loop)?
  2. Where do the joined values come from on each path: global_load_dword* results, v_mov_b32 from SGPRs that an s_load_dword* filled, a v_cndmask_b32, or something else (which instruction)?
  3. Are all eight descriptor dwords phis of the same block, or only some of them?

No game data used on my side.

Yes, measuring it now

**@⁠EduAzevedo** on GitHub · 2026-11-24 04:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/307#issuecomment-7122265274) > @⁠AntoninMichelq are you working on `a descriptor read from the first lane of a phi`? Going by @⁠EduAzevedo's corpus numbers above it is now the largest single gap behind this PR: 294 programs (259 mesh, 35 vertex), and the second row of #293's ranking (about 462 draws per frame). I do not want to duplicate it, so if you have it in hand, say so and I will stop. Otherwise I am starting a branch on top of this PR's head (`6285e19`) and will post it for you to take or pick from. > > The approach I intend, so it can be shot down early: > > * **Tracing (`resource.rs`, `per_lane`).** When the lane's dwords are VGPR phis of one block, trace each predecessor's values with `per_lane` again (through `lane_term`), exactly as `phi()` does for SGPR words, and give `Source::Phi { block, args }` whose arguments are per-lane sources (`Fetched`, `Lanes`, `Loaded`). A phi of a block already being resolved stays refused (`a descriptor that changes in a loop`), and the join limit applies. > * **Lowering (`lower.rs`, `handle`).** `Source::Phi` computes each predecessor's heap index at that predecessor's end and joins them with a DXIL phi, as it does today for `Loaded` arguments, but through `lane_heap_index` so the arguments can be per-lane; the handle is non-uniform when any leaf is. Since structurisation makes each lane take its own path, the phi gives each lane its own descriptor. > * **The waterfall compares** need no change: they compare the first lane's dwords with the same VGPR values. > > @⁠EduAzevedo, if it is cheap for you: what the phi looks like in those 294 would tell me whether this is the right shape before I write tests against the wrong one. Yes/no or counts, no shader contents: > > 1. Is the phi at the join of an if/else (or a chain of them), or at a loop header (the VGPRs change inside a loop)? > 2. Where do the joined values come from on each path: `global_load_dword*` results, `v_mov_b32` from SGPRs that an `s_load_dword*` filled, a `v_cndmask_b32`, or something else (which instruction)? > 3. Are all eight descriptor dwords phis of the same block, or only some of them? > > No game data used on my side. Yes, measuring it now
Author
Owner

@⁠miniongk on GitHub · 2026-11-24 04:45 UTC · original

Verified the updated head 6285e19 on Windows 11 with the RTX 5080 setup.

  • resource::tests::a_first_lane_read_outside_a_loop_is_no_waterfall passes standalone.
  • cargo test --workspace: 273 passed, 0 failed, 4 ignored; the new negative regression also passes in that run.
  • Worktree remained clean.

No game data used for this check. AI-assisted (Kimi Code).

**@⁠miniongk** on GitHub · 2026-11-24 04:45 UTC · [original](https://github.com/Marvisak/VIctory/pull/307#issuecomment-7122309153) Verified the updated head `6285e19` on Windows 11 with the RTX 5080 setup. - `resource::tests::a_first_lane_read_outside_a_loop_is_no_waterfall` passes standalone. - `cargo test --workspace`: 273 passed, 0 failed, 4 ignored; the new negative regression also passes in that run. - Worktree remained clean. No game data used for this check. AI-assisted (Kimi Code).
Author
Owner

@⁠marquezinii on GitHub · 2026-11-24 04:51 UTC · original

Ran 6285e19 on an NVIDIA RTX 5070 (32-lane waves, driver 621.24), Windows 11: cargo test -p victory-shader passes (78). The PR's own lowering tests do not run on a GPU, so I dispatched a few synthetic programs through the test Host (all validated by dxil.dll), each sampling one of two descriptors (entry 0 samples 1.0, entry 1 samples 2.0):

program result
waterfall over a per-lane descriptor picked by v_cndmask (lanes < 16 / >= 16), wave32 1.0 x16, 2.0 x16, correct
same, wave64 split at lane 40 (the second host wave holds both descriptors) correct
waterfall over a descriptor fetched per lane with global_load_dwordx4 (entry = lane & 1), wave64 alternating 1.0 / 2.0, correct
s_cselect_b64 x4 chosen by a root constant, k = 0 and k = 1 entry 0 / entry 1, correct

One shape is accepted and comes out wrong: the same complete loop (readfirstlane x8, four v_cmp_eq_u64, s_and_saveexec, s_xor exec, s_cbranch_execnz), but with the image_sample_lz using s[12:19] placed after s_mov_b32 exec_lo, s20, outside the loop. On the console every lane samples with the last pass's descriptor (lane 16's, 2.0). Here it translates (nonuniform_handles = 1), validates, and returns 1.0 x16, 2.0 x16, because each recorded first-lane read becomes the lane's own value wherever it is used. A compiler would not normally emit this (the waterfall SGPRs are dead after the loop), but nothing ties the use to the s_and_saveexec region of the compare, so it is silently wrong rather than refused. Requiring every use of a recorded read to sit inside that region (or refusing reads used outside it) would close it.

Not covered: the title (no game data here).

**@⁠marquezinii** on GitHub · 2026-11-24 04:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/307#issuecomment-7122401627) Ran `6285e19` on an NVIDIA RTX 5070 (32-lane waves, driver 621.24), Windows 11: `cargo test -p victory-shader` passes (78). The PR's own lowering tests do not run on a GPU, so I dispatched a few synthetic programs through the test `Host` (all validated by `dxil.dll`), each sampling one of two descriptors (entry 0 samples 1.0, entry 1 samples 2.0): | program | result | |---|---| | waterfall over a per-lane descriptor picked by `v_cndmask` (lanes < 16 / >= 16), wave32 | 1.0 x16, 2.0 x16, correct | | same, wave64 split at lane 40 (the second host wave holds both descriptors) | correct | | waterfall over a descriptor fetched per lane with `global_load_dwordx4` (entry = lane & 1), wave64 | alternating 1.0 / 2.0, correct | | `s_cselect_b64` x4 chosen by a root constant, k = 0 and k = 1 | entry 0 / entry 1, correct | One shape is accepted and comes out wrong: the same complete loop (readfirstlane x8, four `v_cmp_eq_u64`, `s_and_saveexec`, `s_xor exec`, `s_cbranch_execnz`), but with the `image_sample_lz` using `s[12:19]` placed after `s_mov_b32 exec_lo, s20`, outside the loop. On the console every lane samples with the last pass's descriptor (lane 16's, 2.0). Here it translates (`nonuniform_handles = 1`), validates, and returns `1.0 x16, 2.0 x16`, because each recorded first-lane read becomes the lane's own value wherever it is used. A compiler would not normally emit this (the waterfall SGPRs are dead after the loop), but nothing ties the use to the `s_and_saveexec` region of the compare, so it is silently wrong rather than refused. Requiring every use of a recorded read to sit inside that region (or refusing reads used outside it) would close it. Not covered: the title (no game data here).
Author
Owner

@⁠EduAzevedo on GitHub · 2026-11-24 04:52 UTC · original

@⁠AntoninMichelq are you working on a descriptor read from the first lane of a phi? Going by @⁠EduAzevedo's corpus numbers above it is now the largest single gap behind this PR: 294 programs (259 mesh, 35 vertex), and the second row of #293's ranking (about 462 draws per frame). I do not want to duplicate it, so if you have it in hand, say so and I will stop. Otherwise I am starting a branch on top of this PR's head (6285e19) and will post it for you to take or pick from.

The approach I intend, so it can be shot down early:

  • Tracing (resource.rs, per_lane). When the lane's dwords are VGPR phis of one block, trace each predecessor's values with per_lane again (through lane_term), exactly as phi() does for SGPR words, and give Source::Phi { block, args } whose arguments are per-lane sources (Fetched, Lanes, Loaded). A phi of a block already being resolved stays refused (a descriptor that changes in a loop), and the join limit applies.
  • Lowering (lower.rs, handle). Source::Phi computes each predecessor's heap index at that predecessor's end and joins them with a DXIL phi, as it does today for Loaded arguments, but through lane_heap_index so the arguments can be per-lane; the handle is non-uniform when any leaf is. Since structurisation makes each lane take its own path, the phi gives each lane its own descriptor.
  • The waterfall compares need no change: they compare the first lane's dwords with the same VGPR values.

@⁠EduAzevedo, if it is cheap for you: what the phi looks like in those 294 would tell me whether this is the right shape before I write tests against the wrong one. Yes/no or counts, no shader contents:

  1. Is the phi at the join of an if/else (or a chain of them), or at a loop header (the VGPRs change inside a loop)?
  2. Where do the joined values come from on each path: global_load_dword* results, v_mov_b32 from SGPRs that an s_load_dword* filled, a v_cndmask_b32, or something else (which instruction)?
  3. Are all eight descriptor dwords phis of the same block, or only some of them?

No game data used on my side.

Measured on 6285e19 with a local, uncommitted trace at the a descriptor read from the first lane of a phi refusal (retail v1.0.2.1 shaders, victory translate, all 26,148 programs). It fires once per program: 294 (259 mesh, 35 vertex). Counts only:

  1. Join or loop: all 294 are joins; no phi block in the chain has a back edge. The chain is 2 phis deep in 277 programs, 5 in 10 and 7 in 7.
  2. Where the values come from: in every program, each dword's chain reaches two s_load_dwordx4 results (through VGPR copies of the SGPRs), i.e. one of two scalar-loaded descriptors. Every program also has other leaves in the same chains. Programs with each kind of other leaf: buffer_load_dwordx3 149, input VGPRs 130, v_mul_legacy_f32 110, v_sub_f32 74, v_fmac_f32 43, constants 17, v_rsq_f32 14, v_cndmask_b32 7, v_mad_u32_u24 5, v_lshrrev_b32 4, v_cvt_f32_u32 4, buffer_load_dwordx4 3, v_xor_b32 1. No global_load_dword* anywhere. They look like the VGPRs' contents on paths that do not reach the descriptor use, but I have not proved those edges are dead.
  3. Dwords: the descriptor operand is 4 dwords in all 294, and all 4 are phis of the same block.

So the shape is "one of two s_load_dwordx4 descriptors chosen by if/else joins, with unrelated values on the other edges", rather than per-lane loads.

**@⁠EduAzevedo** on GitHub · 2026-11-24 04:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/307#issuecomment-7122416241) > @⁠AntoninMichelq are you working on `a descriptor read from the first lane of a phi`? Going by @⁠EduAzevedo's corpus numbers above it is now the largest single gap behind this PR: 294 programs (259 mesh, 35 vertex), and the second row of #293's ranking (about 462 draws per frame). I do not want to duplicate it, so if you have it in hand, say so and I will stop. Otherwise I am starting a branch on top of this PR's head (`6285e19`) and will post it for you to take or pick from. > > The approach I intend, so it can be shot down early: > > * **Tracing (`resource.rs`, `per_lane`).** When the lane's dwords are VGPR phis of one block, trace each predecessor's values with `per_lane` again (through `lane_term`), exactly as `phi()` does for SGPR words, and give `Source::Phi { block, args }` whose arguments are per-lane sources (`Fetched`, `Lanes`, `Loaded`). A phi of a block already being resolved stays refused (`a descriptor that changes in a loop`), and the join limit applies. > * **Lowering (`lower.rs`, `handle`).** `Source::Phi` computes each predecessor's heap index at that predecessor's end and joins them with a DXIL phi, as it does today for `Loaded` arguments, but through `lane_heap_index` so the arguments can be per-lane; the handle is non-uniform when any leaf is. Since structurisation makes each lane take its own path, the phi gives each lane its own descriptor. > * **The waterfall compares** need no change: they compare the first lane's dwords with the same VGPR values. > > @⁠EduAzevedo, if it is cheap for you: what the phi looks like in those 294 would tell me whether this is the right shape before I write tests against the wrong one. Yes/no or counts, no shader contents: > > 1. Is the phi at the join of an if/else (or a chain of them), or at a loop header (the VGPRs change inside a loop)? > 2. Where do the joined values come from on each path: `global_load_dword*` results, `v_mov_b32` from SGPRs that an `s_load_dword*` filled, a `v_cndmask_b32`, or something else (which instruction)? > 3. Are all eight descriptor dwords phis of the same block, or only some of them? > > No game data used on my side. Measured on `6285e19` with a local, uncommitted trace at the `a descriptor read from the first lane of a phi` refusal (retail v1.0.2.1 shaders, `victory translate`, all 26,148 programs). It fires once per program: **294** (259 mesh, 35 vertex). Counts only: 1. **Join or loop:** all 294 are joins; no phi block in the chain has a back edge. The chain is 2 phis deep in 277 programs, 5 in 10 and 7 in 7. 2. **Where the values come from:** in every program, each dword's chain reaches **two `s_load_dwordx4` results** (through VGPR copies of the SGPRs), i.e. one of two scalar-loaded descriptors. **Every program also has other leaves** in the same chains. Programs with each kind of other leaf: `buffer_load_dwordx3` 149, input VGPRs 130, `v_mul_legacy_f32` 110, `v_sub_f32` 74, `v_fmac_f32` 43, constants 17, `v_rsq_f32` 14, `v_cndmask_b32` 7, `v_mad_u32_u24` 5, `v_lshrrev_b32` 4, `v_cvt_f32_u32` 4, `buffer_load_dwordx4` 3, `v_xor_b32` 1. No `global_load_dword*` anywhere. They look like the VGPRs' contents on paths that do not reach the descriptor use, but I have not proved those edges are dead. 3. **Dwords:** the descriptor operand is 4 dwords in all 294, and all 4 are phis of the same block. So the shape is "one of two `s_load_dwordx4` descriptors chosen by if/else joins, with unrelated values on the other edges", rather than per-lane loads.
Author
Owner

@⁠r4tedx on GitHub · 2026-11-24 05:01 UTC · original

@⁠EduAzevedo thank you, your answers changed the design. The phi case is up as #566, one commit (6638098) on top of this PR's head 6285e19.

What your numbers showed: the "unrelated values" on other edges (buffer_load_dwordx3, input VGPRs, arithmetic) are what an EXEC if/else leaves behind. Each dword gets two phis: one joins an arm's dwords with whatever the lanes that skipped the arm held before, the other picks per path after the other arm. Only lanes that never read the descriptor bring those values, so tracing every edge, as I first proposed above, cannot work. #566 traces only the edges that the lanes accessing the descriptor can take, using the per-lane conditions from structurisation, and joins the per-edge heap indices with a DXIL phi.

@⁠AntoninMichelq two things for you:

  1. You are welcome to take the commit into this PR, or tell me to rebase it however suits; it only makes sense on top of yours.
  2. A case on this PR's head that traces wrongly without an error. VGPR writes made with EXEC partly clear are followed as if every lane ran them. A program whose else arm lacks its s_cbranch_execz (so the arm's v_mov_b32s are guarded writes) is traced as the second descriptor for every lane. #566 refuses that (a per-lane descriptor written where some lanes may keep the old one) and has the test; the same check would fit here independently of the phi work.

If you can rerun, victory translate --list on #566 against this PR's head: a descriptor read from the first lane of a phi should go from 294 to 0, and what matters is where those 294 stop next. If the pruning cannot prove the unrelated edges dead in the real programs, they will stop at ... of an input VGPR, ... of a buffer load or ... of computed VGPRs, and the counts per reason will say what is still missing. Also worth counting separately: programs that translated here and stop on #566 at the guarded-write reason.

Not run against the title on my side.

**@⁠r4tedx** on GitHub · 2026-11-24 05:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/307#issuecomment-7122549650) @⁠EduAzevedo thank you, your answers changed the design. The phi case is up as #566, one commit (`6638098`) on top of this PR's head `6285e19`. What your numbers showed: the "unrelated values" on other edges (`buffer_load_dwordx3`, input VGPRs, arithmetic) are what an EXEC if/else leaves behind. Each dword gets two phis: one joins an arm's dwords with whatever the lanes that skipped the arm held before, the other picks per path after the other arm. Only lanes that never read the descriptor bring those values, so tracing every edge, as I first proposed above, cannot work. #566 traces only the edges that the lanes accessing the descriptor can take, using the per-lane conditions from structurisation, and joins the per-edge heap indices with a DXIL phi. @⁠AntoninMichelq two things for you: 1. **You are welcome to take the commit into this PR**, or tell me to rebase it however suits; it only makes sense on top of yours. 2. **A case on this PR's head that traces wrongly without an error.** VGPR writes made with EXEC partly clear are followed as if every lane ran them. A program whose else arm lacks its `s_cbranch_execz` (so the arm's `v_mov_b32`s are guarded writes) is traced as the second descriptor for every lane. #566 refuses that (`a per-lane descriptor written where some lanes may keep the old one`) and has the test; the same check would fit here independently of the phi work. If you can rerun, `victory translate --list` on #566 against this PR's head: `a descriptor read from the first lane of a phi` should go from 294 to 0, and what matters is where those 294 stop next. If the pruning cannot prove the unrelated edges dead in the real programs, they will stop at `... of an input VGPR`, `... of a buffer load` or `... of computed VGPRs`, and the counts per reason will say what is still missing. Also worth counting separately: programs that translated here and stop on #566 at the guarded-write reason. Not run against the title on my side.
Author
Owner

@⁠upipibi on GitHub · 2026-11-24 05:51 UTC · original

Independent check of head 6285e19 on main d2a4bae. I read the comments above first. The two open correctness points are already there (@⁠marquezinii: a first-lane value used after the loop; @⁠r4tedx: VGPR writes under a partly clear EXEC, refused in #566); I add one more input of the same family and otherwise found the operand orders right.

Read against the RDNA2 ISA (30-November-2020)

  • s_cselect_b32/_b64 (12.1, opcodes 10, 11, p. 103): D.u = SCC ? S0.u : S1.u. picked in resource.rs returns (set = src0, clear = src1), and Source::Select is documented and lowered as "set, then clear" (lower.rs: select(cond, set, clear)). Correct.
  • s_cmov_b32/_b64 (12.3, opcodes 5, 6, p. 111): if(SCC) then D.u = S0.u; endif. picked takes clear = the destination's old dwords. Correct, and it works although lower.rs has no arm for s_cmov_* as plain data: the descriptor's words are never lowered as values. No test in the PR uses s_cmov; a local one does (below).
  • v_cndmask_b32 (12.7, opcode 1, p. 131): D.u32 = VCC ? S1.u32 : S0.u32. lane_picked destructures [clear, set, mask]. Correct.
  • fetched_index mirrors heap_index (address low dword plus offsets, over 32 or 16), and the handle is made with nonUniformIndex = true, which is what D3D12 asks of a heap index that differs between lanes.

One more accepted shape that differs from the console (same family as the use-after-loop case; a compiler would not emit it, but it is accepted rather than refused):

WATERFALL_FETCHED_WAVE32 with the last s_and_b32 s21, s21, s22 (0x8715_1615, the one after the fourth v_cmp_eq_u64) replaced by s_nop. The fourth compare is still computed, so Tracer::waterfall records all 4 compares and 8 reads and track succeeds, but its result no longer reaches s_and_saveexec. On the console, lanes that match the first lane in dwords 0..5 and differ in dwords 6..7 sample with the first lane's descriptor; translated, each samples with its own. waterfall checks that the compare is in the loop and pairs the right operands, not that its mask is what narrows EXEC for the access. Tying the recorded compares to the s_and_saveexec operand would close this and the use-after-loop case together.

Run on hardware. NVIDIA RTX 3070, driver 616.56, Windows 11, Rust 1.98.1, dxil.dll from the Windows SDK 10.0.26100 validating; cargo test -p victory-shader -- --test-threads=1:

  • this PR on main: 78 passed, 0 failed (main: 69).
  • with three local probes (CPU only, like the PR's own lowering tests): 81 passed, 0 failed:
    • two descriptors and s_cmov_b64 s[0:1], s[4:5] / s_cmov_b64 s[2:3], s[6:7]: traced as Select { args: [second load, first load] }, i.e. SCC set picks the moved-in one. Correct.
    • the same through lower: lowers, 0 non-uniform handles. Correct.
    • the compare-left-out-of-EXEC input above: track returns Ok, 4 compares, 8 reads.

I did not dispatch waterfall programs on this GPU; @⁠marquezinii's RTX 5070 runs above cover that.

Not checked: the title (no game files here), AMD hardware, #566.

AI-assisted (Claude Code).

**@⁠upipibi** on GitHub · 2026-11-24 05:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/307#issuecomment-7123338321) Independent check of head `6285e19` on `main` `d2a4bae`. I read the comments above first. The two open correctness points are already there (@⁠marquezinii: a first-lane value used after the loop; @⁠r4tedx: VGPR writes under a partly clear EXEC, refused in #566); I add one more input of the same family and otherwise found the operand orders right. **Read against the RDNA2 ISA (30-November-2020)** - `s_cselect_b32/_b64` (12.1, opcodes 10, 11, p. 103): `D.u = SCC ? S0.u : S1.u`. `picked` in `resource.rs` returns (set = src0, clear = src1), and `Source::Select` is documented and lowered as "set, then clear" (`lower.rs`: `select(cond, set, clear)`). Correct. - `s_cmov_b32/_b64` (12.3, opcodes 5, 6, p. 111): `if(SCC) then D.u = S0.u; endif`. `picked` takes clear = the destination's old dwords. Correct, and it works although `lower.rs` has no arm for `s_cmov_*` as plain data: the descriptor's words are never lowered as values. No test in the PR uses `s_cmov`; a local one does (below). - `v_cndmask_b32` (12.7, opcode 1, p. 131): `D.u32 = VCC ? S1.u32 : S0.u32`. `lane_picked` destructures `[clear, set, mask]`. Correct. - `fetched_index` mirrors `heap_index` (address low dword plus offsets, over 32 or 16), and the handle is made with `nonUniformIndex = true`, which is what D3D12 asks of a heap index that differs between lanes. **One more accepted shape that differs from the console** (same family as the use-after-loop case; a compiler would not emit it, but it is accepted rather than refused): `WATERFALL_FETCHED_WAVE32` with the last `s_and_b32 s21, s21, s22` (`0x8715_1615`, the one after the fourth `v_cmp_eq_u64`) replaced by `s_nop`. The fourth compare is still computed, so `Tracer::waterfall` records all 4 compares and 8 reads and `track` succeeds, but its result no longer reaches `s_and_saveexec`. On the console, lanes that match the first lane in dwords 0..5 and differ in dwords 6..7 sample with the first lane's descriptor; translated, each samples with its own. `waterfall` checks that the compare is in the loop and pairs the right operands, not that its mask is what narrows EXEC for the access. Tying the recorded compares to the `s_and_saveexec` operand would close this and the use-after-loop case together. **Run on hardware.** NVIDIA RTX 3070, driver 616.56, Windows 11, Rust 1.98.1, `dxil.dll` from the Windows SDK 10.0.26100 validating; `cargo test -p victory-shader -- --test-threads=1`: - this PR on `main`: **78 passed, 0 failed** (`main`: 69). - with three local probes (CPU only, like the PR's own lowering tests): **81 passed, 0 failed**: - two descriptors and `s_cmov_b64 s[0:1], s[4:5]` / `s_cmov_b64 s[2:3], s[6:7]`: traced as `Select { args: [second load, first load] }`, i.e. SCC set picks the moved-in one. Correct. - the same through `lower`: lowers, 0 non-uniform handles. Correct. - the compare-left-out-of-EXEC input above: `track` returns `Ok`, 4 compares, 8 reads. I did not dispatch waterfall programs on this GPU; @⁠marquezinii's RTX 5070 runs above cover that. Not checked: the title (no game files here), AMD hardware, #566. AI-assisted (Claude Code).
Author
Owner

@⁠LoukaAyariPignel on GitHub · 2026-11-24 08:04 UTC · original

I merged current main into this branch to clear the conflict: fix-307 on my fork, merge commit 36b8fdb. The only conflict was in the emit::lower test module: this PR's new tests and imports against the half_shift import and scalar_bit_tests_lower test from main. I kept both sides. On Windows, cargo test -p victory-shader passes, including the new waterfall and s_cselect tests, and so do clippy -D warnings and fmt --check. It still merges cleanly with today's main. Feel free to pull it in.

**@⁠LoukaAyariPignel** on GitHub · 2026-11-24 08:04 UTC · [original](https://github.com/Marvisak/VIctory/pull/307#issuecomment-7125686894) I merged current `main` into this branch to clear the conflict: [`fix-307`](https://github.com/LoukaAyariPignel/VIctory/tree/fix-307) on my fork, merge commit `36b8fdb`. The only conflict was in the `emit::lower` test module: this PR's new tests and imports against the `half_shift` import and `scalar_bit_tests_lower` test from `main`. I kept both sides. On Windows, `cargo test -p victory-shader` passes, including the new waterfall and `s_cselect` tests, and so do `clippy -D warnings` and `fmt --check`. It still merges cleanly with today's `main`. Feel free to pull it in.
Author
Owner

@⁠slint6614-dev on GitHub · 2026-11-24 08:44 UTC · original

Measured on the full retail shader pack (26,503 containers) with victory translate --validate --pipelines (pipelines created on an AMD RX 9070, Adrenalin, Windows 11; dxil.dll from SDK 10.0.26100), against main 1f858b0. Counts are emitted / validated / pipelines.

VS/PS CS MS "descriptor neither loaded nor built"
main 12272 / 12172 1693 / 1670 8191 / 8129 298
#307 12272 / 12172 1694 / 1670 8191 / 8129 3 (294 become "a descriptor read from the first lane of a phi")
#566 (on #307) 12280 / 12180 1694 / 1670 8247 / 8185 3

With #566, of the 298: +8 VS/PS and +56 MS validated, the rest stop on "scalar memory read as data" (573 → 740), "a descriptor read from the first lane of computed VGPRs" (38), "a waterfall loop whose compares do not select the access's lanes" (15) and "a descriptor partly joined by control flow" (8). #307 alone gives no validated gain. All pipelines are created on the RX 9070.

**@⁠slint6614-dev** on GitHub · 2026-11-24 08:44 UTC · [original](https://github.com/Marvisak/VIctory/pull/307#issuecomment-7126494624) Measured on the full retail shader pack (26,503 containers) with `victory translate --validate --pipelines` (pipelines created on an AMD RX 9070, Adrenalin, Windows 11; dxil.dll from SDK 10.0.26100), against main 1f858b0. Counts are emitted / validated / pipelines. | | VS/PS | CS | MS | "descriptor neither loaded nor built" | |---|---|---|---|---| | main | 12272 / 12172 | 1693 / 1670 | 8191 / 8129 | 298 | | #307 | 12272 / 12172 | 1694 / 1670 | 8191 / 8129 | 3 (294 become "a descriptor read from the first lane of a phi") | | #566 (on #307) | 12280 / **12180** | 1694 / 1670 | 8247 / **8185** | 3 | With #566, of the 298: +8 VS/PS and +56 MS validated, the rest stop on "scalar memory read as data" (573 → 740), "a descriptor read from the first lane of computed VGPRs" (38), "a waterfall loop whose compares do not select the access's lanes" (15) and "a descriptor partly joined by control flow" (8). #307 alone gives no validated gain. All pipelines are created on the RX 9070.
Author
Owner

@⁠Vaximous on GitHub · 2026-11-24 10:12 UTC · original

A hang to know about before this lands: waterfall loops in pixel shaders never end on NVIDIA when only helper lanes are left.

On the console, whole-quad mode puts a pixel shader's helper lanes in EXEC, so a waterfall loop serves them too: v_readfirstlane the descriptor index, v_cmpx_eq the lanes with that index, run them, take them out of EXEC with s_andn2_wrexec. On the host, WaveReadLaneFirst (like the other wave operations) leaves helper lanes out. Once every non-helper lane has been served, the remaining helper lanes read no lane, none of them matches, and each one runs to the translator's loop limit.

Observed on an RTX 4070 Ti, GTA VI 1.0.2.1, local integration branch = main + many open PRs including this one and #566:

  • World pixel shaders using this pattern took 0.3-1.3 s per draw. Every world submission took about 1.16 s, frame after frame, until one passed the 2 s TDR limit: DEVICE_HUNG (0x887A0006) about 200 s into the world. DRED breadcrumbs stopped at the same instanced draws on every run.
  • Fix (local commit): in pixel shaders, a helper lane's v_readfirstlane takes its own value. It then matches in the first pass and leaves the loop. Its results only feed derivatives, and its stores are already dropped.
  • After the fix: zero slow submissions (it was 1.16 s every frame), and no device removal in the world for the length of the run.

The same applies to any v_readfirstlane / WaveReadLaneFirst lowering in a pixel shader that a loop exits on, so it may matter for the NVIDIA world hangs in #625, #71 and #619 as well.

**@⁠Vaximous** on GitHub · 2026-11-24 10:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/307#issuecomment-7128461640) A hang to know about before this lands: **waterfall loops in pixel shaders never end on NVIDIA when only helper lanes are left.** On the console, whole-quad mode puts a pixel shader's helper lanes in EXEC, so a waterfall loop serves them too: `v_readfirstlane` the descriptor index, `v_cmpx_eq` the lanes with that index, run them, take them out of EXEC with `s_andn2_wrexec`. On the host, `WaveReadLaneFirst` (like the other wave operations) leaves helper lanes out. Once every non-helper lane has been served, the remaining helper lanes read no lane, none of them matches, and each one runs to the translator's loop limit. Observed on an RTX 4070 Ti, GTA VI 1.0.2.1, local integration branch = main + many open PRs including this one and #566: - World pixel shaders using this pattern took 0.3-1.3 s per draw. Every world submission took about 1.16 s, frame after frame, until one passed the 2 s TDR limit: `DEVICE_HUNG` (0x887A0006) about 200 s into the world. DRED breadcrumbs stopped at the same instanced draws on every run. - Fix (local commit): in pixel shaders, a helper lane's `v_readfirstlane` takes its own value. It then matches in the first pass and leaves the loop. Its results only feed derivatives, and its stores are already dropped. - After the fix: zero slow submissions (it was 1.16 s every frame), and no device removal in the world for the length of the run. The same applies to any `v_readfirstlane` / `WaveReadLaneFirst` lowering in a pixel shader that a loop exits on, so it may matter for the NVIDIA world hangs in #625, #71 and #619 as well.
Author
Owner

@⁠SpaghettiMaster545 on GitHub · 2026-11-24 10:15 UTC · original

@⁠Vaximous could you push that local commit to a branch on your fork? Upstream PRs are paused (#712), so a branch is the only way NVIDIA testers on #71, #619 and #625 can try it.

I can run it on an RTX 5070 Ti (driver 621.24, Windows 11 26100, Ryzen 7 9800X3D). On main the world there drops to about 1 fps and ends in DEVICE_HUNG 59–111 s in. That is the same picture as yours: each world submission takes close to a second until one crosses the TDR limit (#400 has the per-frame breakdown). I'd compare it against main with the same settings and post the result here.

AI-assisted (Claude Code).

**@⁠SpaghettiMaster545** on GitHub · 2026-11-24 10:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/307#issuecomment-7128521880) @⁠Vaximous could you push that local commit to a branch on your fork? Upstream PRs are paused (#712), so a branch is the only way NVIDIA testers on #71, #619 and #625 can try it. I can run it on an RTX 5070 Ti (driver 621.24, Windows 11 26100, Ryzen 7 9800X3D). On `main` the world there drops to about 1 fps and ends in `DEVICE_HUNG` 59–111 s in. That is the same picture as yours: each world submission takes close to a second until one crosses the TDR limit (#400 has the per-frame breakdown). I'd compare it against `main` with the same settings and post the result here. AI-assisted (Claude Code).
Author
Owner

@⁠claude-GTA6 on GitHub · 2026-11-24 12:20 UTC · original

From a tester working with Claude (AI-assisted); measured on my own machine.

The finding is @⁠Vaximous's (#307 comment): pixel-shader waterfall loops never end on NVIDIA once only helper lanes are left. PR creation is closed right now, so here's the same idea as a branch you can merge or cherry-pick, with what I could check on my machine: claude-GTA6/VIctory pr-helper-readfirstlane, one commit on main ffe310e.

Problem

In a pixel shader, the console's whole-quad mode keeps helper lanes in EXEC. A waterfall loop (v_readfirstlane an index or count, v_cmpx_eq the lanes that hold it, run them, take them out of EXEC) therefore serves the helper lanes too. On the host, WaveReadLaneFirst leaves helper lanes out. Once every non-helper lane is served, the helpers read a value none of them holds, so none matches, and each runs to the translator's loop limit (2^20 iterations per lane).

Change

v_readfirstlane_b32 in a pixel shader: a helper lane (IsHelperLane, op 221) takes its own value. It then matches in its first pass and leaves. A helper lane's results only feed derivatives, and its stores are already dropped. Other stages are unchanged.

Measured (RTX 5090, driver 621.24, Windows 11; GTA VI 1.0.2.1 continuing from a save; my branch with about 60 merged PRs)

  • Pixel 1af4a50c7fb40c97 has a light loop of this shape (s59 = v_readfirstlane(v75), exits when it matches). Before the fix, at the default loop limit, it took 1,163 ms for one 4-group mesh draw, and 4 to 6 of its draws per run took over 100 ms. With the fix, one of its draws took over 100 ms in the run.
  • Other slow programs remain (compute 42683eebec081520 at about 495 ms per dispatch, pixel 6a3a8d3fe52b4eab). So this alone doesn't end the NVIDIA world hang on my card. With VICTORY_SHADER_LOOP_LIMIT=256, #454 and a skip of three mesh pipelines, runs with and without this change both ran 15 minutes with no device removal, so no regression showed.
  • On this branch (upstream main ffe310e + this commit): cargo test -p victory-shader 120 passed, 1 ignored. The two pixel shaders above emit and pass dxil.dll. Whole dump --validate: 12,243 vertex and pixel programs emitted, 12,167 validated. No validator error mentions the new op. I have no count from before the change to compare against.

Not verified

  • Not run on AMD. There, the per-lane form keeps the console's lanes, and I don't know whether helper lanes are ever left alone in a loop there.
  • No unit test with real helper lanes: the GPU test harness here only runs compute shaders.

No game data attached.

**@⁠claude-GTA6** on GitHub · 2026-11-24 12:20 UTC · [original](https://github.com/Marvisak/VIctory/pull/307#issuecomment-7131308199) *From a tester working with Claude (AI-assisted); measured on my own machine.* The finding is @⁠Vaximous's ([#307 comment](https://git.gtahub.st/github/Marvisak--VIctory/pulls/307)): pixel-shader waterfall loops never end on NVIDIA once only helper lanes are left. PR creation is closed right now, so here's the same idea as a branch you can merge or cherry-pick, with what I could check on my machine: [claude-GTA6/VIctory `pr-helper-readfirstlane`](https://github.com/claude-GTA6/VIctory/tree/pr-helper-readfirstlane), one commit on `main` `ffe310e`. ### Problem In a pixel shader, the console's whole-quad mode keeps helper lanes in EXEC. A waterfall loop (`v_readfirstlane` an index or count, `v_cmpx_eq` the lanes that hold it, run them, take them out of EXEC) therefore serves the helper lanes too. On the host, `WaveReadLaneFirst` leaves helper lanes out. Once every non-helper lane is served, the helpers read a value none of them holds, so none matches, and each runs to the translator's loop limit (2^20 iterations per lane). ### Change `v_readfirstlane_b32` in a pixel shader: a helper lane (`IsHelperLane`, op 221) takes its own value. It then matches in its first pass and leaves. A helper lane's results only feed derivatives, and its stores are already dropped. Other stages are unchanged. ### Measured (RTX 5090, driver 621.24, Windows 11; GTA VI 1.0.2.1 continuing from a save; my branch with about 60 merged PRs) - Pixel `1af4a50c7fb40c97` has a light loop of this shape (`s59 = v_readfirstlane(v75)`, exits when it matches). Before the fix, at the default loop limit, it took 1,163 ms for one 4-group mesh draw, and 4 to 6 of its draws per run took over 100 ms. With the fix, one of its draws took over 100 ms in the run. - Other slow programs remain (compute `42683eebec081520` at about 495 ms per dispatch, pixel `6a3a8d3fe52b4eab`). So this alone doesn't end the NVIDIA world hang on my card. With `VICTORY_SHADER_LOOP_LIMIT=256`, #454 and a skip of three mesh pipelines, runs with and without this change both ran 15 minutes with no device removal, so no regression showed. - On this branch (upstream `main` `ffe310e` + this commit): `cargo test -p victory-shader` 120 passed, 1 ignored. The two pixel shaders above emit and pass `dxil.dll`. Whole dump `--validate`: 12,243 vertex and pixel programs emitted, 12,167 validated. No validator error mentions the new op. I have no count from before the change to compare against. ### Not verified - Not run on AMD. There, the per-lane form keeps the console's lanes, and I don't know whether helper lanes are ever left alone in a loop there. - No unit test with real helper lanes: the GPU test harness here only runs compute shaders. No game data attached.
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!307
No description provided.