Skip to content

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

Merged
Marvisak merged 4 commits into
Marvisak:mainfrom
AntoninMichelq:up/waterfall-descriptors
Nov 24, 2026
Merged

Marvisak merged 4 commits into
Marvisak:mainfrom
AntoninMichelq:up/waterfall-descriptors

Conversation

@AntoninMichelq

Copy link
Copy Markdown

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

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 <noreply@anthropic.com>
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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
@ifBars

ifBars commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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).

@tanishq-dubey

Copy link
Copy Markdown

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.

@r4tedx

r4tedx commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

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.

@SpaghettiMaster545

Copy link
Copy Markdown

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.)

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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
@miniongk

Copy link
Copy Markdown

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).

@EduAzevedo

Copy link
Copy Markdown

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.

…a waterfall loop

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 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
@r4tedx

r4tedx commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

@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.

@AnoHunted

Copy link
Copy Markdown
Contributor

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.

@EduAzevedo

Copy link
Copy Markdown

@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

@miniongk

Copy link
Copy Markdown

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).

@marquezinii

Copy link
Copy Markdown
Contributor

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).

@EduAzevedo

Copy link
Copy Markdown

@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.

@r4tedx

r4tedx commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

@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. Shaders: per-lane descriptors chosen by control flow (stacked on #307) #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 added a commit to r4tedx/VIctory that referenced this pull request Nov 24, 2026
…73d66, and Marvisak#180)

The wave64 stack (Marvisak#223, Marvisak#233, Marvisak#320, Marvisak#439, with Peter Bonanni's
whole-wave sections across the halves, 9b73d66) merged with Marvisak#180 (twin
descriptor loads and quad gradients for compute samples), at 24b3bcc.
That commit has one parent (e49302a); Marvisak#180's changes come in without
its commits. Marvisak#233 is in this tree as 1eb9995, the same tree as
3098672, so each file was merged with 3098672 as the base instead of
the e0865d2 git chooses.

Conflict resolutions:
- emit/wave.rs, v_permlane16/x16 in whole-wave sections: Marvisak#98's "every
  lane active" and 9b73d66's "or fi set" are both kept, for both
  instructions.
- emit/lower.rs, Lower::new: Marvisak#320's test for lane reads and writes in
  divergent programs counts live instructions only, as Marvisak#233's does
  with Marvisak#309 (dead SGPR-spill lane instructions are no lane reads).
  Marvisak#307's waterfall arm of v_readfirstlane still comes before the
  console-flow arm; Marvisak#320 adds no arm of its own.
- Compute samples with implicit derivatives (Marvisak#160, Marvisak#180, Marvisak#306): Marvisak#180
  decides plain and biased samples, all of Marvisak#160's forms of them
  (implicit_derivatives from sample_form: _o, _cl, cube, a16), with
  Marvisak#160's bias address (bias_at) and level clamp; Marvisak#306's validator 1.8
  is now declared only for what still uses the host's derivatives in
  compute (comparison samples, op 64). The Marvisak#306 test of image_sample
  now asserts no 1.8 (48-byte PSV0) and still validates and creates
  the pipeline; a twin test with image_sample_c asserts 1.8.
- sgpr_spill test (Marvisak#309): without forwarding, the per-lane form still
  stops with "a lane mask holding lanes elsewhere read as data", but
  emit now takes the console flow (Marvisak#320); the test checks both, and
  that forwarded spills do not ask for the console flow.
- Mechanical: per_lane_only in two hand-built Parts in emit/lower.rs
  tests; emit/mod.rs module order (split_tests before threading).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown

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).

Xeltax pushed a commit to Xeltax/VIcky that referenced this pull request Nov 24, 2026
…isak#306 Marvisak#333 Marvisak#105 Marvisak#288 Marvisak#343 Marvisak#353 Marvisak#326 Marvisak#259 Marvisak#179 Marvisak#176 Marvisak#226 Marvisak#286)

Conflicts:
- emit/lower.rs: shader-opcodes and shader-tracking each keyed heap
  handles by the resource properties (a tuple vs two flattened words);
  the same key, shader-tracking's form and comment kept. Lowered's
  test-only fields, test imports and tests of both sides kept.
- emit/wave.rs: tests of both sides kept.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Xeltax pushed a commit to Xeltax/VIcky that referenced this pull request Nov 24, 2026
…ntains Marvisak#223)

Conflicts:
- crates/victory-shader/src/emit/lower.rs, Lower::new: shader-tracking
  (Marvisak#309) ignores the dead lane instructions of SGPR spills when deciding
  a compute program reads other lanes; Marvisak#233 splits that test into
  in-half reads (swizzles, DPP) and whole-wave reads. Marvisak#233's split is
  kept, with both of its lane-read tests over the live instructions only
  (a `live` closure over sgpr_spill::dead). Its other instruction scans
  (v_readfirstlane, permutes) stay over all instructions, as Marvisak#233 has
  them.
- lower.rs, v_readfirstlane_b32: shader-tracking's (Marvisak#307) arm for a waterfall
  loop's read of a descriptor dword (each lane's own) and Marvisak#233's arm for
  the console flow (the console wave's first lane in EXEC) are both kept,
  the waterfall arm first: the waterfall's compares are taken as true
  per lane before anything else (Lower::valu), in the console flow too,
  so its reads must stay each lane's own.
- crates/victory-shader/src/emit/mod.rs: module list (threading and
  split_tests) and test imports of both; the test import of
  bitcode::Attr stays removed as shader-opcodes left it (the tests take
  it from `super::*`). emit_program (split from emit by Marvisak#48 in the opcodes
  branch, for the retry after edge threading) takes and passes Marvisak#233's
  `target`.
- crates/victory-gpu/src/shader_cache.rs: tests of both sides kept.

Mechanical, for Marvisak#233's new arguments (no test checks changed):
`target: Target::ANY, console_cf: false` in hand-built lower::Parts in
emit/lower.rs tests (two), and Target::ANY as emit's last argument in
emit/image_tests.rs, emit/mod.rs tests (two) and sgpr_spill.rs tests.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@P2xe1 P2xe1 mentioned this pull request Nov 24, 2026
PastiiJay pushed a commit to PastiiJay/klbf-lab-beta that referenced this pull request Nov 24, 2026
suirentakamura referenced this pull request in suirentakamura/victory-suiren Nov 24, 2026
A waterfall loop whose descriptor dwords are VGPR phis stopped with "a
descriptor read from the first lane of a phi" (294 programs of the
title on #307, all at if/else joins of two s_load_dwordx4 descriptors
copied into VGPRs). An EXEC if/else leaves two phis per dword: the
flow block's joins an arm's dwords with what lanes that skipped the arm
held before (inputs, unrelated loads and arithmetic in the title), the
join after the other arm picks per path. Only lanes that never read the
descriptor bring those other values, so tracing every edge fails.

Tracing (resource::track now takes the program's per-lane form):
- per-lane phis of one block are traced on each edge into it that the
  lanes accessing the descriptor can take, from structure's lane
  conditions (new Structured::reach, the exits' conditions, and
  Bools::meet, a read-only satisfiability check); the trace starts from
  what holds in the access's block. Edges no such lane takes are None
  in the new Source::LanePhi { block, args };
- every per-lane write it follows (v_mov_b32 copies, v_cndmask_b32,
  global_load_dword*) must run in all those lanes: a guarded one fails
  with "a per-lane descriptor written where some lanes may keep the old
  one". On #307 an else arm without its s_cbranch_execz traced as the
  second descriptor for every lane;
- a loop header's phi fails with "a descriptor read from the first lane
  of a phi at a loop header", words defined after the join with "a
  descriptor partly joined by control flow"; without the per-lane form
  (structurisation failed) the join is refused.

Lowering computes each traced edge's heap index at its predecessor's end
(through lane_heap_index, so loads, per-lane loads, choices and nested
joins work), joins them with a phi (0 on untaken edges) and makes the
handle non-uniform. The waterfall compares need no change.

Tests: the if/else of two loaded image descriptors, a join of a per-lane
load and a v_cndmask choice, nested arms choosing a buffer descriptor
with lanes that skip both and do not load (pruned only by the access's
condition), a loop header phi, and an unskipped else arm. On #307's head
the three join programs fail with "...of a phi" and the unskipped arm is
traced as one descriptor for all lanes. On an RTX 5070 and WARP, each
lane reads its own arm's texture or buffer; the shaders pass dxil.dll
1.8.2502.11. Reversing the phi's inputs fails validation, flipping the
heap index fails the GPU check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
suirentakamura referenced this pull request in suirentakamura/victory-suiren Nov 24, 2026
main moved under #307 and this branch. One conflict, in the test module of
emit/lower.rs: the imports take both sides' names (#117's `half_shift`
beside `Lowered`), and #117's `scalar_bit_tests_lower` sits after this
branch's waterfall tests. No code outside the test module was touched by
hand. A merge rather than a rebase so #307's commits keep their ids.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
suirentakamura referenced this pull request in suirentakamura/victory-suiren Nov 24, 2026
Shaders: per-lane descriptors chosen by control flow (stacked on #307)
This was referenced Nov 24, 2026
itsonlysimbo pushed a commit to itsonlysimbo/VIctory that referenced this pull request Nov 24, 2026
A waterfall loop whose descriptor dwords are VGPR phis stopped with "a
descriptor read from the first lane of a phi" (294 programs of the
title on Marvisak#307, all at if/else joins of two s_load_dwordx4 descriptors
copied into VGPRs). An EXEC if/else leaves two phis per dword: the
flow block's joins an arm's dwords with what lanes that skipped the arm
held before (inputs, unrelated loads and arithmetic in the title), the
join after the other arm picks per path. Only lanes that never read the
descriptor bring those other values, so tracing every edge fails.

Tracing (resource::track now takes the program's per-lane form):
- per-lane phis of one block are traced on each edge into it that the
  lanes accessing the descriptor can take, from structure's lane
  conditions (new Structured::reach, the exits' conditions, and
  Bools::meet, a read-only satisfiability check); the trace starts from
  what holds in the access's block. Edges no such lane takes are None
  in the new Source::LanePhi { block, args };
- every per-lane write it follows (v_mov_b32 copies, v_cndmask_b32,
  global_load_dword*) must run in all those lanes: a guarded one fails
  with "a per-lane descriptor written where some lanes may keep the old
  one". On Marvisak#307 an else arm without its s_cbranch_execz traced as the
  second descriptor for every lane;
- a loop header's phi fails with "a descriptor read from the first lane
  of a phi at a loop header", words defined after the join with "a
  descriptor partly joined by control flow"; without the per-lane form
  (structurisation failed) the join is refused.

Lowering computes each traced edge's heap index at its predecessor's end
(through lane_heap_index, so loads, per-lane loads, choices and nested
joins work), joins them with a phi (0 on untaken edges) and makes the
handle non-uniform. The waterfall compares need no change.

Tests: the if/else of two loaded image descriptors, a join of a per-lane
load and a v_cndmask choice, nested arms choosing a buffer descriptor
with lanes that skip both and do not load (pruned only by the access's
condition), a loop header phi, and an unskipped else arm. On Marvisak#307's head
the three join programs fail with "...of a phi" and the unskipped arm is
traced as one descriptor for all lanes. On an RTX 5070 and WARP, each
lane reads its own arm's texture or buffer; the shaders pass dxil.dll
1.8.2502.11. Reversing the phi's inputs fails validation, flipping the
heap index fails the GPU check.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
itsonlysimbo pushed a commit to itsonlysimbo/VIctory that referenced this pull request Nov 24, 2026
main moved under Marvisak#307 and this branch. One conflict, in the test module of
emit/lower.rs: the imports take both sides' names (Marvisak#117's `half_shift`
beside `Lowered`), and Marvisak#117's `scalar_bit_tests_lower` sits after this
branch's waterfall tests. No code outside the test module was touched by
hand. A merge rather than a rebase so Marvisak#307's commits keep their ids.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
itsonlysimbo pushed a commit to itsonlysimbo/VIctory that referenced this pull request Nov 24, 2026
Shaders: per-lane descriptors chosen by control flow (stacked on Marvisak#307)
PastiiJay pushed a commit to PastiiJay/klbf-lab-beta that referenced this pull request Nov 25, 2026
@AntoninMichelq
AntoninMichelq deleted the up/waterfall-descriptors branch November 25, 2026 20:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.