Skip to content

Shaders: per-lane descriptors chosen by control flow (stacked on #307) - #566

Merged
Marvisak merged 10 commits into
Marvisak:mainfrom
r4tedx:shader/per-lane-phi
Nov 24, 2026
Merged

Marvisak merged 10 commits into
Marvisak:mainfrom
r4tedx:shader/per-lane-phi

Conversation

@r4tedx

@r4tedx r4tedx commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #307 (its head 6285e19). Three commits on top are the change: 6638098 (per-lane descriptors chosen by control flow), b1c8306 (by @fuzeofficlal: prove a waterfall loop before collapsing it) and 6c63dea (a reason per failed proof, and tests). If #307 is merged first this rebases to those three; its author is welcome to take them into #307 instead.

Merged with main 42361b0 (head a7e60cf, 2026-11-24). main moved and #307 itself now conflicts with it, so this branch took main in as a merge commit, which keeps #307's commits and the three above at their ids. The one conflict was in the test module of emit/lower.rs (imports, and #117's test beside this branch's); no code outside tests was edited by hand. cargo test -p victory-shader at a7e60cf: 107 passed, 1 ignored, on the RTX 5070; cargo check --workspace --all-targets is clean.

What

With #307, a descriptor neither loaded nor built goes from 298 programs to 3 over the title's shaders, but 294 of them (259 mesh, 35 vertex) then stop at a descriptor read from the first lane of a phi (measured by EduAzevedo on #307). This PR handles that case.

What the programs look like, from EduAzevedo's answers on #307 (counts and shapes only): every phi is at an if/else join, none at a loop header; chains are 2 phis deep in 277 programs, 5 in 10 and 7 in 7; every dword traces to one of two s_load_dwordx4 descriptors copied into VGPRs; the descriptor is 4 dwords (a buffer) and all 4 are phis of one block; other edges of the chains reach unrelated values (buffer_load_dwordx3, input VGPRs, arithmetic).

Those unrelated values are the crux. An EXEC if/else leaves two phis per dword: one joins an arm's dwords with what lanes that skipped the arm held before, the other picks per path after the other arm. Only lanes that never read the descriptor bring the unrelated values, so tracing every edge cannot work; edges have to be dropped by what the accessing lanes can actually take.

  • Tracing (resource.rs). resource::track now takes the program's per-lane form (Structured). Per-lane phis of one block are traced on each edge the lanes that access the descriptor can take, starting from what holds in the access's block (new Structured::reach, and Bools::meet, a read-only satisfiability check). Edges no such lane takes are None in the new Source::LanePhi { block, args }.
  • Guarded writes are refused. Every per-lane write followed (v_mov_b32, v_cndmask_b32, global_load_dword*) must run in all those lanes; otherwise a per-lane descriptor written where some lanes may keep the old one. On Shaders: lower waterfall loops over per-lane descriptors (and s_cselect-chosen descriptors) #307's head an else arm without its s_cbranch_execz is traced as the second descriptor for every lane, with no error; a test covers it.
  • Lowering (emit/lower.rs). Each traced edge's heap index is computed at its predecessor's end through lane_heap_index (so loads, per-lane loads, choices and nested joins work), joined with a DXIL phi (0 on untaken edges); the handle is non-uniform. The existing SGPR Source::Phi lowering is unchanged.

Still refused, each with its reason: a phi at a loop header (... of a phi at a loop header), some dwords joined and others defined at or after the join (a descriptor partly joined by control flow), joins in several blocks, nesting past the join limit, and programs whose structurisation failed (..., without the lanes' paths).

A wrong-output defect found in review, fixed in b1c8306 and 6c63dea

Taking the first lane's descriptor as each lane's own is only right in a waterfall loop. The matcher this PR inherited from #307 checked that equality compares of the first lane's dwords exist in the loop, not that they select the lanes of the access or that the loop retries the others. Two reviewers showed programs it mistranslated without an error:

  • @ifBars (here): the compares are there but never narrow EXEC, so on the console every lane samples with the first lane's descriptor. 6638098 gave lanes 16 to 31 their own. Reproduced here on a hardware adapter.
  • marquezinii (on #307): the sample placed after the loop, where EXEC is restored.

b1c8306 replaces the match with a proof on the per-lane masks: at each access the EXEC mask must be exactly the lanes whose descriptor equals the first lane's, on every dword, and the back edge must keep exactly the lanes that were waiting and did not perform the access. Wave64 uses both halves. 6c63dea gives each failure its own reason:

Reason Example
a descriptor read from the first lane outside a waterfall loop the access after the loop
a waterfall loop whose compares do not select the access's lanes ifBars's case; a dword pair left uncompared; a further mask on the access; wave64 with exec_hi overwritten
a waterfall loop whose retry does not keep the lanes still waiting a retry that drops lanes; a wave64 retry of one half
a waterfall loop nested in another or split over blocks see "Known limits"

Both of those programs are now refused. Neither is translated to what the console does (one descriptor for every lane, outside a waterfall); that is separate work.

An alternative fix was offered as r4tedx#3. It was not taken: an independent review found it still accepts a loop whose retry drops the waiting lanes (now the test a_retry_that_keeps_other_lanes_than_those_waiting_is_no_waterfall), and it refuses the waterfall LLVM's AMDGPU backend writes for GFX10 and later (a v_cmpx_eq chain with the retry as todo & !EXEC), which this PR accepts and tests on the GPU.

Known limits

  • Nested waterfalls are refused, and 6638098 accepted them. An image whose resource and sampler are both per lane, with one loop per operand and the sampler's loop inside the resource's, stops at a waterfall loop nested in another or split over blocks. In review that shape gave the right output on 6638098, so this is a step back in coverage made for the proof; following the outer loop's reads into the inner block is left for a follow-up. Whether the title has such programs is not known (see the rerun asked for below).
  • A loop split over blocks by an unconditional branch is refused. No compiler shape that produces one was found.
  • Other per-lane work in a waterfall loop is taken to run once for each lane, as the access does. A body whose effect adds up over the passes a lane waits through would differ. Marked shortcut: in the code; compilers put nothing but the reads, the compares and the access there.

Measured on the title's shaders (by testers, at 6638098, before the waterfall fix)

victory translate --jobs 8 --list over the retail shaders, #307 at 6285e19 against 6638098, all 26,148 programs:

  • a descriptor read from the first lane of a phi: 294 to 0 (EduAzevedo, confirmed by miniongk).
  • Of those 294: 64 translate (56 mesh, 8 vertex). The rest stop one step later: 182 at a scalar memory read as data, 38 at a descriptor read from the first lane of computed VGPRs, 8 at a descriptor partly joined by control flow, 2 at a lane mask read as data.
  • None stops at the guarded-write reason, and no program that translated on 6285e19 stopped translating.
  • Mesh modules emitted 8,191 to 8,247; vertex and pixel 12,284 to 12,292 (miniongk).
  • In a title run on an RTX 5080 with six other PRs, shader does not translate fell from 32 to 29 with this PR, with no device removal; the run still ended in a separate null-write failure this PR does not address (miniongk).

Rerun with the waterfall proof (slint6614-dev, comment; victory translate --validate --pipelines over the full retail shader pack, pipelines created on an AMD RX 9070, against main 1f858b0):

VS/PS emitted / validated MS emitted / validated a descriptor neither loaded nor built
main 12,272 / 12,172 8,191 / 8,129 298
#307 12,272 / 12,172 8,191 / 8,129 3
this PR 12,280 / 12,180 8,247 / 8,185 3
  • The same 64 programs as before the proof (8 vertex or pixel, 56 mesh) emit, and all 64 validate and get pipelines on that card. Shaders: lower waterfall loops over per-lane descriptors (and s_cselect-chosen descriptors) #307 alone gains none.
  • The rest stop one step later: a scalar memory read as data 573 to 740 (so 167 of them), a descriptor read from the first lane of computed VGPRs 38, a waterfall loop whose compares do not select the access's lanes 15, a descriptor partly joined by control flow 8.
  • My reading of the difference from the earlier count: the proof refuses 15 programs that used to stop at the scalar-memory reason anyway (182 then, 167 now); it costs none of the 64. That is arithmetic on the two counts, not a program-by-program comparison. No program is reported at the nested-waterfall reason.

Tested

Windows 11, NVIDIA RTX 5070 and WARP, hand-assembled programs only:

  • Tracing: an if/else of two loaded image descriptors; a join of a per-lane load and a v_cndmask_b32 choice; nested arms choosing a 4-dword buffer descriptor where lanes that skip both arms keep unrelated values and do not load; a loop-header phi (refused); an else arm without its skip branch (refused).
  • Waterfall proof: eleven refusal tests for the shapes above, each asserting its reason; the v_cmpx_eq waterfall accepted in wave32 and wave64, plain and folded into s_andn2_wrexec.
  • GPU: every lane reads its own arm's texture or buffer on both adapters, also through the v_cmpx_eq waterfall; the shaders pass dxil.dll 1.8.2502.11.
  • cargo test --workspace at 6c63dea: 293 passed, 4 ignored. cargo clippy -p victory-shader --all-targets: no warnings. cargo xtask policy: ok.

Not checked: wave64 waterfalls were proven by tracking only, not dispatched on a 64-lane GPU in this round. Nothing was checked with the D3D12 debug layer (not installed here).

The title was not used in these tests; the counts above are the named testers'. AI-assisted.

🤖 Generated with Claude Code

claude and others added 5 commits November 24, 2026 02:06
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
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
…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
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>
@EduAzevedo

Copy link
Copy Markdown

Measured 6638098 against #307's head 6285e19, retail v1.0.2.1 shaders, victory translate --jobs 8 --list, all 26,148 programs:

  • a descriptor read from the first lane of a phi: 294 → 0.
  • Where the 294 go:
Next Programs
translate 64 (56 mesh, 8 vertex)
a scalar memory read as data 182
a descriptor read from the first lane of computed VGPRs 38
a descriptor partly joined by control flow 8
a lane mask read as data 2
  • No program stops at the guarded-write reason (a per-lane descriptor written where some lanes may keep the old one), and no program that translated on 6285e19 stops translating here.
  • None stops at ... of an input VGPR or ... of a buffer load, so the pruning did prove the unrelated edges dead in these programs; the 38 at computed VGPRs and the 8 partly joined are what it leaves.

The 182 at a scalar memory read as data are the reason #136 and #180 address, so the next jump for these mesh shaders probably needs this PR plus one of those. I can measure that combination if useful.

@ifBars

ifBars commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

I hit a wrong-output case on 6638098 using a small change to the authored WATERFALL_JOINED_WAVE32 fixture. The DXIL passed Windows SDK validation and dispatched on Agility SDK 620 WARP. Lanes 0–15 returned 1.0 and lanes 16–31 returned 2.0. All 32 should return 1.0.

Replacing s_and_saveexec_b32 s21, s21 with s_mov_b32 s21, exec_lo leaves the descriptor comparisons in the same CFG loop but disconnects them from EXEC. All lanes execute the sample with the descriptor that v_readfirstlane reads from lane 0. The following XOR clears EXEC and the retry branch falls through.

This can go at the bottom of crates/victory-shader/src/emit/waterfall_tests.rs.

#[test]
fn dead_descriptor_compares_do_not_turn_a_loop_into_a_waterfall() {
    use crate::resource::tests::WATERFALL_JOINED_WAVE32;
    let mut words = WATERFALL_JOINED_WAVE32.to_vec();
    let save = words.iter().position(|&w| w == 0xBE95_3C15).unwrap();
    words[save] = 0xBE95_037E; // s_mov_b32 s21, exec_lo
    let shader = build(&words, false);
    let results = sampled(&shader);
    assert!(!results.is_empty());
    for (label, red) in results {
        assert_eq!(red, vec![1.0; 32], "{label}");
    }
}

I ran VICTORY_WARP=1 cargo test -p victory-shader --lib dead_descriptor_compares_do_not_turn_a_loop_into_a_waterfall with the SDK 620 exports in the test executable. The current match in resource::Tracer::waterfall looks for equality comparisons and loop membership. I think it also needs to prove the comparisons actually narrow EXEC for the resource access and that the back edge retries the remaining lanes before treating the first lane's descriptor as each lane's own.

@miniongk

Copy link
Copy Markdown

Corpus comparison on the local Xbox Series 1.0.2.1 files, using the same victory translate --list input for #307 6285e19 and this PR at 6638098 (26,148 programs):

  • a descriptor read from the first lane of a phi: 294 → 0.
  • a descriptor neither loaded nor built: 3 → 3.
  • a per-lane descriptor written where some lanes may keep the old one: 0 → 0.
  • a descriptor partly joined by control flow: 0 → 8.
  • a descriptor read from the first lane of computed VGPRs: 0 → 38.
  • Mesh DXIL emitted: 8,191 → 8,247 (+56).
  • Vertex/pixel DXIL emitted: 12,284 → 12,292 (+8).
  • a scalar memory read as data moves 573 → 755 as more programs reach lowering.

cargo test --workspace: 282 passed, 0 failed, 4 ignored. Only aggregate counts shared; no program list, shader contents or game data posted. AI-assisted (Kimi Code).

@fuzeofficlal

fuzeofficlal commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

I followed up on @ifBars's dead-compare case at 6638098. The patch checks the actual EXEC mask at each descriptor access in the single-block loop, then proves that the back edge keeps exactly the eligible lanes that did not perform that access. Wave64 checks use the full low/high SSA pair.

  • The regression tests reject disconnected comparisons, a retry that discards the remaining lanes, an access after EXEC restoration, and a Wave64 access whose EXEC high half was overwritten.
  • The three existing Wave32 readback cases pass SDK DXIL validation and return all 32 expected values on RTX 5090, Radeon iGPU, and WARP. The shader suite reports 91 passed.

The DXIL and readback checks use synthetic inputs. Coverage of the previously measured shader corpus is still open. Incremental commit on 6638098

Retested 6c63dea. Both LLVM-style v_cmpx retry variants passed SDK DXIL validation and matched all 32 lanes on the Radeon iGPU, RTX 5090, and WARP. The serial shader suite reported 98 passing tests.

@r4tedx

r4tedx commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@ifBars reproduced, thank you. Your test fails the same way on 6638098 on a hardware adapter here (RTX 5070), not only on WARP: lanes 0–15 return 1.0, lanes 16–31 return 2.0. So the matcher takes this loop for a waterfall although the comparisons never narrow EXEC, as you say.

Two fixes have been offered, both on top of 6638098: @MichaelSmithAI's r4tedx#3 (4a64d76) and @fuzeofficlal's 32b5180. I ran both here:

cargo test -p victory-shader --lib your program
6638098 (this PR) passes translated, wrong output as above
4a64d76 91 passed refused: a descriptor read from the first lane outside a waterfall loop
32b5180 91 passed refused, same reason

Neither translates it to all 1.0 as your test asserts. A refusal is the safe result; lowering a first-lane descriptor outside a waterfall loop is a separate piece of work.

I am reviewing the two against each other now and will push one to this PR, with credit to its author and a form of your test that expects the refusal. Until then, treat 6638098 as unsafe for programs of this shape. The corpus counts above (294 → 0, 64 programs gained) will need a rerun on the fixed head, since a stricter matcher can give some of the 64 back.

Hand-assembled test programs only; no game data used. AI-assisted.

@upipibi upipibi mentioned this pull request Nov 24, 2026
@miniongk

Copy link
Copy Markdown

Real-title follow-up for 6638098, combined with #413, #320, #483, #89, #137 and #458 on RTX 5080 / 621.24 / Windows 11 26300.

The test helpers needed the new structure parameter and heap-guard values; after that, the three waterfall GPU tests passed. Full serial workspace verification: 310 passed, 0 failed, 4 ignored. One preceding default parallel test run had a process access violation, so this result explicitly covers the serial run.

In the native title run, shader does not translate fell from 32 on the same integration without #566 to 29 with it. There were no host-pipeline refusals, texture-creation/readback warnings or host-device removal, but the same explicit null-write fatal path still occurred. So this improves the descriptor coverage measured above, but does not resolve that later title failure.

Only aggregate counts and error classes shared. AI-assisted (Kimi Code).

fuzeofficlal and others added 2 commits November 24, 2026 08:07
…n review

The previous commit proves that a loop's compares select the lanes of
the access and that its retry keeps exactly the lanes still waiting.
Every failure of that proof was reported with one reason. They now say
which part failed:

- the access is in no single-block loop ending in s_cbranch_execnz;
- the loop is nested in another or split over blocks;
- the compares do not select the access's lanes;
- the retry does not keep the lanes still waiting.

Without the per-lane form the proof cannot run. Nothing is emitted then,
and that failure is the one reported, as before.

Tests, all hand-assembled:

- the case ifBars reported on upstream PR Marvisak#566 (the compares never
  narrow EXEC), an access under a further mask, a retry that keeps other
  lanes than those waiting, a wave64 retry of one half: refused, each
  with its reason;
- the waterfall LLVM writes for GFX10 and later (a v_cmpx_eq chain, the
  retry as todo & !EXEC, also folded into s_andn2_wrexec) is accepted in
  wave32 and wave64, and each lane samples its own texture on the GPU;
- one loop per operand, the sampler's inside the resource's, is refused
  by name. The console gives each lane its own pair there; following the
  outer loop's reads into the inner block is left for later.

Other per-lane work in a waterfall loop is still taken to run once for
each lane; marked as a shortcut.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@r4tedx

r4tedx commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

The fix is pushed: head is now 6c63dea (was 6638098).

What went in

  • b1c8306 is @fuzeofficlal's 32b5180, cherry-picked with their authorship. It replaces the waterfall match with a proof on the per-lane masks: the access runs for exactly the lanes whose descriptor equals the first lane's, and the back edge keeps exactly the lanes still waiting. Thank you; that is the right shape of fix.
  • 6c63dea (mine) gives each failed proof its own reason and adds tests.

@ifBars: your program is now refused with a waterfall loop whose compares do not select the access's lanes (test a_compare_that_does_not_mask_the_access_is_no_waterfall). It is not translated to all 1.0 as your test asserted; lowering a first-lane descriptor outside a waterfall is separate work. marquezinii's shape from #307 (the sample after the loop) is refused too.

Why not r4tedx#3, @MichaelSmithAI. I had both fixes reviewed independently and ran the counterexamples. Two things decided it, both now tests on this branch:

  • 4a64d76 still accepts a loop whose retry drops the waiting lanes. In WATERFALL_JOINED_WAVE32, 0x897E157E → 0x8A7E7E6A (s_andn2_b32 exec_lo, vcc_lo, exec_lo): on the console lanes 16 to 31 never sample, with 4a64d76 they get 2.0 on the GPU.
  • It refuses the waterfall LLVM's AMDGPU backend writes for GFX10 and later, a v_cmpx_eq chain with the retry as todo & !EXEC (also folded into s_andn2_wrexec). b1c8306 accepts it, and each lane samples its own texture on hardware and WARP.

Thank you for the work all the same; the dead-branch case in your second commit is covered here by the retry proof.

What the fix costs. One shape that 6638098 translated correctly is now refused: an image whose resource and sampler are both per lane, with one loop per operand, nested. It stops at a waterfall loop nested in another or split over blocks. The description lists this under "Known limits".

A rerun would settle what matters, @EduAzevedo @miniongk, if either of you has the time: the same victory translate --jobs 8 --list comparison, 6638098 against 6c63dea. The numbers: how many of the 64 gained programs still translate, and how many programs stop at each of the four waterfall reasons (they all start with a waterfall loop or a descriptor read from the first lane outside a waterfall loop). If the nested reason shows up in the title's shaders, that follow-up moves to the front. EduAzevedo, on your earlier offer: yes, #566 together with #180 or #136 would be useful after that, since 182 of the 294 stop at a scalar memory read as data.

Tested here at 6c63dea, on an RTX 5070 and WARP, with hand-assembled programs: cargo test --workspace 293 passed, 4 ignored. The title was not used in these tests. AI-assisted.

@iurysf

iurysf commented Nov 24, 2026

Copy link
Copy Markdown

Tested offline against main d2a4bae with victory translate --list --validate over the title's shaders.rpf + executable (26,096 programs), dxil.dll 1.9.2602.17. This measures the full stack, since the branch carries #307's four commits plus this PR's own.

  • Translation failures: 3,733 on main -> 3,668 with the stack (-65: 56 mesh, 8 vertex/pixel, 1 compute; none newly failing). "resources: a descriptor neither loaded nor built" drops 298 -> 3, matching Shaders: lower waterfall loops over per-lane descriptors (and s_cselect-chosen descriptors) #307. The freed programs mostly stop next at "a scalar memory read as data" (573 -> 755). The refusals this PR predicts appear: "a descriptor read from the first lane of computed VGPRs" (38) and "a descriptor partly joined by control flow" (8).
  • Emitted: mesh 8,191 -> 8,247 (+56), vertex+pixel 12,284 -> 12,292 (+8), compute 1,693 -> 1,694 (+1). The one new compute module fails validation with "incompatible with the shader stage" (185 -> 186). That is the implicit-derivative dx.valver case that Shader: fix biased 16-bit image samples and DXIL validator failures #306 fixes. No module that validated on main fails now.
  • With the stack, the per-stage program totals shift (vertex/pixel 14,013 -> 14,042, mesh 8,506 -> 8,725). I didn't look into why.

AI-assisted.

@r4tedx

r4tedx commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@iurysf thank you, that is the comparison this PR needed, and "none newly failing" with 56 mesh and 8 vertex/pixel gained matches the two earlier counts.

One question decides how to read it: which head of this branch did you run? It moved from 6638098 to 6c63dea at about 06:15 UTC, two minutes before your comment. 6c63dea proves a waterfall loop before collapsing it (the fix for the wrong-output case above), so it is stricter and could give some of those 64 back.

  • If it was 6c63dea: the fix cost nothing in the title's shaders, and a count of programs stopping at reasons that start with a waterfall loop (expected: 0) would close it.
  • If it was 6638098: the same run on 6c63dea is the open measurement.

@fuzeofficlal thank you for retesting 6c63dea on the Radeon iGPU, the RTX 5090 and WARP.

Nothing was run for this note. AI-assisted.

Ortomanic pushed a commit to Ortomanic/VIctory that referenced this pull request Nov 24, 2026
…ops over them (port of upstream PR Marvisak#566, stacked on Marvisak#307)

Squashed port of Marvisak#566 (head 6c63dea), which carries
Marvisak#307 (AntoninMichelq) underneath:

  a3d3bc9 Shaders: trace descriptors chosen by s_cselect and s_cmov
  ffa6635 Shaders: lower waterfall loops over per-lane descriptors in one pass
  077ec8b translate: count per-lane fetched descriptors
  6285e19 Shaders: take the first lane's descriptor ...
  6638098 Shaders: per-lane descriptors chosen by control flow (r4tedx)
  b1c8306 Shaders: prove EXEC selection before collapsing a waterfall (fuzeofficial)
  6c63dea Shaders: name why a loop is no waterfall, and tests (r4tedx)

Adapted to linux-bringup: conflicts with the raw-view tracing, the
first-lane address tracing (the PR's `first_lane_source` is
`first_lane_vgpr` here), unspill and the threading retry resolved;
`resource::track` keeps its three-argument form (it structures the
program itself) and the per-lane form is `resource::track_lanes`, so
callers outside the crate (the shader lab) keep building; the PR's
`lower_with` test helper is `lower_lanes`.

(cherry picked from commit 6c63dea, PR Marvisak#566 and Marvisak#307)
Co-authored-by: fuzeofficial <bochunran@gmail.com>
Co-authored-by: AntoninMichelq <AntoninMichelq@users.noreply.github.com>
Ortomanic added a commit to Ortomanic/VIctory that referenced this pull request Nov 24, 2026
…ux-bringup added

Follow-up to the Marvisak#566 port: waterfall_tests.rs builds only with
cfg(all(test, windows)) and was missed by the Linux test build.
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>
r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 24, 2026
…rol flow; waterfall loops proven)

Marvisak#566 is stacked on Marvisak#307, which this tree holds as its first two commits
(the tree's resource.rs was identical to ffa6635's). The merge so also
brings Marvisak#307's last two commits, 077ec8b and 6285e19. Git found upstream
main as the base, which sets Marvisak#307's own lines against themselves; each
file was merged with ffa6635 as the base instead.

- crates/victory-shader/src/resource.rs: Marvisak#566's, unchanged (the tree had
  no edits of its own there).
- crates/victory-shader/src/emit/lower.rs: no conflict on that base. The
  tree's lowering is kept (Marvisak#307's waterfall arm of v_readfirstlane before
  the console-flow form, fetched_index through Marvisak#483's heap guard), with
  Marvisak#566's Source::LanePhi arms and tests. lane_heap_index joins the
  indices heap_index and fetched_index return, so each is already
  guarded. Marvisak#226's annotation test passes the per-lane form to track.
- crates/victory-shader/src/structure.rs: both sides' additions kept:
  MAX_MEMO (Marvisak#288) with MAX_MEET, and in Structured the wave64 stack's
  execs, others and pairs with Marvisak#566's reach and paired_masks.
  paired_masks is filled last, since it takes the masks pairs reads.
- crates/victory-shader/src/emit/mod.rs: translate keeps Marvisak#309's spill
  forwarding and Marvisak#223's target, structures first and passes the per-lane
  form to track as Marvisak#566 does. The threading retry of emit passes its
  own. The tests' helpers (Marvisak#223's, Marvisak#306's, Marvisak#459's, Marvisak#48's) pass it too.
- apps/victory/src/translate.rs: Marvisak#566's arm (Source::LanePhi is no
  leaf); the tree's fix already counted Fetched as loaded, as 077ec8b
  does.
- docs/architecture.md: no conflict on that base; Marvisak#566's text.
- emit/image_tests.rs (Marvisak#160), emit/lane_read_loop_tests.rs (Marvisak#439),
  sgpr_spill.rs (Marvisak#309, Marvisak#320): track takes the per-lane form. Helpers
  that return the error keep the order of failures (resources, I/O,
  then structure).
- emit/waterfall_tests.rs (new, Marvisak#566): lower::Parts gets the tree's
  target, console_cf and per_lane_only; the dispatch fills Marvisak#483's guard
  dwords.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 24, 2026
The four tests of emit/waterfall_tests.rs each dispatch on the hardware
adapter and on WARP. Started together from the test threads, the test
binary sometimes died of an access violation (0xC0000005) before any of
them finished: 7 of 24 runs of `cargo test -p victory-shader
waterfall_tests` on the integration machine (RTX 5070; 6 of the first
12, 1 of 12 later, with less else running on the PC), 3 of 8 on WARP
alone, 1 of 10 with the DXIL validator left out. With
`--test-threads=1` they pass.

They now take a lock around their dispatches, as Marvisak#433 does for the VALU
tests: 0 of 36 runs died. Which call faults was not found (no debugger
on the machine).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 24, 2026
…rol flow

Marvisak#566 lowers a descriptor each lane holds by the path it took
(Source::LanePhi) as a DXIL phi of the heap index of each edge. That is
right in the per-lane form, where a lane takes its own edges. In the
console flow of the wave64 stack (Marvisak#233, Marvisak#320, Marvisak#439) every lane runs
every block and comes to the join by the edge the wave took, so the phi
gave every lane that edge's descriptor, without an error.

Found with Marvisak#566's joined-descriptor program plus a v_readlane_b32, which
with the arms' branches asks for the console flow on every host: on the
RTX 5070 all 32 lanes sampled the second texture, where lanes 0 to 15
hold the first. The module passed dxil.dll.

The console flow now stops such a program with `a per-lane descriptor
chosen by control flow in the console flow`, and emit keeps the per-lane
form where that translates, as it does for whatever else the console
flow cannot lower. New test (emit/waterfall_tests.rs): both refusals by
name, then each lane's own texture on the hardware adapter. The tests'
lock now also covers that test.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 24, 2026
…nes)

By MichaelSmithAI (commit author "swarm"), written against this tree at
f61acfa. The wave64 stack carries the same change as 055aef9 (upstream
Marvisak#439), where its owner reviewed it and ran it on both GPUs here. No
textual conflict; its new test's call of resource::track takes Marvisak#566's
per-lane argument (one line, in this merge).

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 24, 2026
main merged Marvisak#566, which gives `resource::track` a fourth argument (the
structured program, for per-lane descriptor tracking). No textual
conflict, but this branch's image test helper called it with three and
the test target no longer built on main (reported by DeerSilver on the
PR). The helper now structures the program first and passes it, as
main's own tests do.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@P2xe1 P2xe1 mentioned this pull request Nov 24, 2026
r4tedx added a commit to r4tedx/VIctory that referenced this pull request Nov 24, 2026
116 commits, among them Marvisak#566 (which this tree carried), upstream's CI,
the AMD form of v_cmp_lg, the SGPRs the hardware initializes, the Wine
upload path and the stencil-ref feature. Conflicts and what was kept:

- victory-gpu list.rs: both sides in CopyResource and CopyTextureRegion
  (the tree's skip of mixed packed copies, then main's upload of a
  title-written source); the tree's `prepare_footprint_upload` stays and
  its plain path takes main's `defer_fill`.
- native.rs: main's `initialized_sgprs` and its test beside the tree's
  three-component thread id and its test.
- emit/shader.rs: both feature flags (tiled resources, stencil ref).
- emit/mod.rs: the tree's `harmonize_row_interp`, then main's centroid
  position under a conservative depth output; the tree's `constant_color`
  for every host.
- emit/lower.rs: the tree's barycentric inputs with main's zero for an
  SGPR the hardware does not initialize; the tree's IsNaN compares with
  main's `olt | ogt` for v_cmp_lg in place of `fcmp one`; Marvisak#160's sample
  forms in place of main's list of sample names; one test helper for
  both (`lower_inputs`, with `lower_words` and main's two-argument
  `lowers` on top of it).
- emit/valu_tests.rs, emit/waterfall_tests.rs: merged item by item. All
  of both sides' tests; main's shared `ONE_AT_A_TIME` replaces the
  tree's lock inside `run_cases`, which keeps the tree's guard entries;
  the tree's `run` in the waterfall tests is kept.

Changes where the merge was clean but did not build:
- emit/lower.rs: main's immediate-offset block in the plain sample arm
  is dropped (it reads `offset_word`, which Marvisak#160's forms replace; Marvisak#160
  handles offsets before the arm). `Module::int_value` loses its only
  caller with it.
- New tests of main's get Marvisak#223's `Target` argument of `emit` and the
  `target`, `console_cf` and `per_lane_only` fields of `Parts`.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Callimann8 pushed a commit to Callimann8/VIctory-fork that referenced this pull request Nov 24, 2026
…rol flow

Main lowers a descriptor each lane holds by the path it took
(Source::LanePhi, Marvisak#566) as a DXIL phi over the edges into the join. In
the console flow every lane reaches the join by the edge the wave took,
so the phi gave every lane that edge's descriptor, silently: the joined
if/else program of the waterfall tests, lowered in the console flow,
sampled the second texture in all 32 lanes where lanes 0-15 hold the
first (RTX 5070; the module passes dxil.dll).

The console flow now stops with its own reason there. A program that
takes the console flow only for its lane reads keeps the per-lane form
where that translates; one that needs it for the host's wave size stops
with the reason.

Found on the testers' branch, where Marvisak#566 and the console flow first met.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
mpDom pushed a commit to mpDom/VIctory that referenced this pull request Nov 24, 2026
…at 055aef9)

Brings the black-scene branch (6d7ead4: Marvisak#489, Marvisak#294, Marvisak#346, root UAVs as
bounded one-view tables, VICTORY_ROOT_SRV_MB) up to the tester tree's
update 4. No file conflicted.

The tree's Marvisak#566 gives `resource::track` a fourth argument, the program as
one lane runs it, and this branch's tests called it with three. Adapted,
tests only:
- emit/valu_tests.rs: the root UAV test structures the program first and
  passes it; the spill-table helper keeps `emit::translate`'s order (a
  program that cannot be structured is still traced and fails where it
  did before).
- resource.rs: the spill-table descriptor test passes `lanes(&p)`, as its
  neighbours do.
- victory-gpu draw.rs: the two root-view tests structure first.
- emit/waterfall_tests.rs (the tree's): its `HostShader` gets this
  branch's `root_uavs` field.

Run once each, one process at a time on the RTX 5070 and WARP:
victory-shader --lib 210 passed, 1 ignored; victory-gpu --lib 95 passed,
1 ignored. `cargo build -p victory` builds. Not run in the title.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
mpDom pushed a commit to mpDom/VIctory that referenced this pull request Nov 24, 2026
…ne-704 at 56018e8)

Brings the merge of upstream Marvisak#704 at fb8ea43 (raw views for unknown-stride
reads; see 70eedad for how it was fitted to Marvisak#483's guard slot and this
branch's root SRV and UAV tables) and the root SRV refresh test onto the
branch that already holds the tester tree at 2b1a569. No file conflicted.

Adapted, tests only, where the two sides meet:
- the tree's Marvisak#566 gives `resource::track` a fourth argument: the Marvisak#704
  side's test helpers (emit/mod.rs, victory-gpu raw_view_tests.rs) and the
  refresh test's program builder in draw.rs structure the program first
  and pass it;
- emit/waterfall_tests.rs (the tree's) fills Marvisak#704's `stride_table` field.

Run once each, one process at a time, on the RTX 5070 and WARP:
victory-shader --lib 214 passed, 1 ignored; victory-gpu --lib 98 passed,
1 ignored. `cargo build -p victory` builds. Not run in the title.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
suirentakamura referenced this pull request in suirentakamura/victory-suiren Nov 24, 2026
…n review

The previous commit proves that a loop's compares select the lanes of
the access and that its retry keeps exactly the lanes still waiting.
Every failure of that proof was reported with one reason. They now say
which part failed:

- the access is in no single-block loop ending in s_cbranch_execnz;
- the loop is nested in another or split over blocks;
- the compares do not select the access's lanes;
- the retry does not keep the lanes still waiting.

Without the per-lane form the proof cannot run. Nothing is emitted then,
and that failure is the one reported, as before.

Tests, all hand-assembled:

- the case ifBars reported on upstream PR #566 (the compares never
  narrow EXEC), an access under a further mask, a retry that keeps other
  lanes than those waiting, a wave64 retry of one half: refused, each
  with its reason;
- the waterfall LLVM writes for GFX10 and later (a v_cmpx_eq chain, the
  retry as todo & !EXEC, also folded into s_andn2_wrexec) is accepted in
  wave32 and wave64, and each lane samples its own texture on the GPU;
- one loop per operand, the sampler's inside the resource's, is refused
  by name. The console gives each lane its own pair there; following the
  outer loop's reads into the inner block is left for later.

Other per-lane work in a waterfall loop is still taken to run once for
each lane; marked as a shortcut.

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)
suirentakamura referenced this pull request in suirentakamura/victory-suiren Nov 24, 2026
…loops

Main's heap_handle now takes whether the index may differ between lanes
(#566, waterfall loops over per-lane descriptors). The 64-bit atomic
path builds its own heap handle, so it passes the same answer handle()
does: per lane when the descriptor load belongs to a waterfall loop.

translate --validate on shaders.rpf against main 6889aa9: VS/PS
12155 -> 12673, CS 1417 -> 1419; no 64-bit image atomic refusals or
"Flags must match usage" errors.

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
…n review

The previous commit proves that a loop's compares select the lanes of
the access and that its retry keeps exactly the lanes still waiting.
Every failure of that proof was reported with one reason. They now say
which part failed:

- the access is in no single-block loop ending in s_cbranch_execnz;
- the loop is nested in another or split over blocks;
- the compares do not select the access's lanes;
- the retry does not keep the lanes still waiting.

Without the per-lane form the proof cannot run. Nothing is emitted then,
and that failure is the one reported, as before.

Tests, all hand-assembled:

- the case ifBars reported on upstream PR Marvisak#566 (the compares never
  narrow EXEC), an access under a further mask, a retry that keeps other
  lanes than those waiting, a wave64 retry of one half: refused, each
  with its reason;
- the waterfall LLVM writes for GFX10 and later (a v_cmpx_eq chain, the
  retry as todo & !EXEC, also folded into s_andn2_wrexec) is accepted in
  wave32 and wave64, and each lane samples its own texture on the GPU;
- one loop per operand, the sampler's inside the resource's, is refused
  by name. The console gives each lane its own pair there; following the
  outer loop's reads into the inner block is left for later.

Other per-lane work in a waterfall loop is still taken to run once for
each lane; marked as a shortcut.

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)
geiyiliyabumo pushed a commit to geiyiliyabumo/VIctory that referenced this pull request Nov 24, 2026
docs: describe the project without naming a specific title
alex3112 pushed a commit to alex3112/VIctory that referenced this pull request Nov 25, 2026
…aterfall changes

41 upstream pull requests merged into local/essai-3d. Conflicts resolved:
- kept ours: descriptor heap sizes and capped samplers, dropped-table
  handling, f16 inline constants in both halves, compare NaN handling
  (with upstream's ordered "lg" as olt|ogt for the AMD driver), sample
  offsets (sample_form), the dispatch thread/twin code;
- took upstream: capture formats (unorm16, 89), packed-operand int vs
  float inline constants, initialized SGPRs (combined with ours);
- combined: descriptor heap publication, copy uploads with skipped mips.
Not merged: Marvisak#566 per-lane phi and the waterfall loop (ffe310e), which
rewrite the same per-lane descriptor tracking as ours.
Tests: same failures as before the merge (wait cut, xmem x5, wave32
ballot, repository policy).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.