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

Manually merged
github merged 10 commits from gh-pr/566/head into gh-pr/566/base 2026-11-26 04:08:36 +00:00
Owner

@⁠r4tedx on GitHub · 2026-11-24 05:01 UTC · original
r4tedx:shader/per-lane-phi → main · +2549 −53 · 9 files · 10 commits · merged 2026-11-24 09:55 UTC

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 #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/VIctory#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. #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

**@⁠r4tedx** on GitHub · 2026-11-24 05:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/566) `r4tedx:shader/per-lane-phi` → `main` · +2549 −53 · 9 files · 10 commits · merged 2026-11-24 09:55 UTC 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 #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](https://git.gtahub.st/github/Marvisak--VIctory/pulls/566)): 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](https://git.gtahub.st/github/Marvisak--VIctory/pulls/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/VIctory#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](https://git.gtahub.st/github/Marvisak--VIctory/pulls/566), confirmed by [miniongk](https://git.gtahub.st/github/Marvisak--VIctory/pulls/566)). - 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](https://git.gtahub.st/github/Marvisak--VIctory/pulls/566)). **Rerun with the waterfall proof** (slint6614-dev, [comment](https://git.gtahub.st/github/Marvisak--VIctory/pulls/566); `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. #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](https://claude.com/claude-code)
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
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 <[email protected]>
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 <[email protected]>
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 <[email protected]>
main now has CI (clippy with -D warnings, then the workspace's tests) and
three new tests that call `resource::track`, which this branch gives a
fourth argument. No textual conflict, but the test target did not build:
those three calls (emit/lower.rs, twice in emit/mod.rs) now structure the
program first and pass it, as this branch's other callers do. Both of
CI's clippy commands are clean on the result.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
The four tests of emit/waterfall_tests.rs each dispatch on the hardware
adapter and on WARP. Run in parallel, the test process sometimes died of
an access violation (7 of 24 runs of these four tests on an integration
branch; an image test beside a VALU test does the same on WARP). They now
take the VALU tests' lock, which moves out of `run_cases` to be shared.
With it: 340 workspace tests pass with VICTORY_WARP=1, as on a CI runner,
and the shader tests pass on the RTX 5070.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:08:34 +00:00
github manually merged commit 74a9d3316d into gh-pr/566/base 2026-11-26 04:08:36 +00:00
Author
Owner

@⁠EduAzevedo on GitHub · 2026-11-24 05:08 UTC · original

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.

**@⁠EduAzevedo** on GitHub · 2026-11-24 05:08 UTC · [original](https://github.com/Marvisak/VIctory/pull/566#issuecomment-7122662781) 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.
Author
Owner

@⁠ifBars on GitHub · 2026-11-24 05:10 UTC · original

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.

**@⁠ifBars** on GitHub · 2026-11-24 05:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/566#issuecomment-7122701400) 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`. ```rust #[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.
Author
Owner

@⁠miniongk on GitHub · 2026-11-24 05:35 UTC · original

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

**@⁠miniongk** on GitHub · 2026-11-24 05:35 UTC · [original](https://github.com/Marvisak/VIctory/pull/566#issuecomment-7123087330) 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).
Author
Owner

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

@⁠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/VIctory#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.

**@⁠r4tedx** on GitHub · 2026-11-24 05:42 UTC · [original](https://github.com/Marvisak/VIctory/pull/566#issuecomment-7123192906) @⁠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/VIctory#3 (`4a64d76`) and @⁠fuzeofficlal's [`32b5180`](https://github.com/fuzeofficlal/VIctory/commit/32b5180c3676e517102ec9f3bf5dac97576e7122). 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.
Author
Owner

@⁠miniongk on GitHub · 2026-11-24 05:52 UTC · original

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

**@⁠miniongk** on GitHub · 2026-11-24 05:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/566#issuecomment-7123349109) 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).
Author
Owner

@⁠r4tedx on GitHub · 2026-11-24 06:15 UTC · original

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/VIctory#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.

**@⁠r4tedx** on GitHub · 2026-11-24 06:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/566#issuecomment-7123750479) 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/VIctory#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.
Author
Owner

@⁠iurysf on GitHub · 2026-11-24 06:17 UTC · original

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

**@⁠iurysf** on GitHub · 2026-11-24 06:17 UTC · [original](https://github.com/Marvisak/VIctory/pull/566#issuecomment-7123776146) 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 #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 #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.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-24 05:39 UTC · original · edited 2026-11-24 06:22 UTC

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.

**@⁠fuzeofficlal** on GitHub · 2026-11-24 05:39 UTC · [original](https://github.com/Marvisak/VIctory/pull/566#issuecomment-7123159620) · edited 2026-11-24 06:22 UTC 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`](https://github.com/fuzeofficlal/VIctory/commit/32b5180c3676e517102ec9f3bf5dac97576e7122) 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.
Author
Owner

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

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

**@⁠r4tedx** on GitHub · 2026-11-24 06:26 UTC · [original](https://github.com/Marvisak/VIctory/pull/566#issuecomment-7123941244) @⁠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.
Author
Owner

@⁠slint6614-dev on GitHub · 2026-11-24 08:43 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:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/566#issuecomment-7126493525) 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

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

@⁠slint6614-dev thank you, this is the rerun the description was asking for, and with validation and pipelines on top. I have put the table in the description with your name.

What it settles: the proof that replaced the match costs none of the earlier gain. The same 64 programs emit (8 vertex or pixel, 56 mesh), and now it is also known that all 64 validate and get pipelines on an RX 9070; #307 alone gains none.

How I read the rest against the earlier count at 6638098: a scalar memory read as data took 182 of the 294 then and takes 167 now, and 15 stop at a waterfall loop whose compares do not select the access's lanes. So the proof turns away 15 programs that were stopping one step later anyway. That is arithmetic on the two counts; if your --list outputs can say whether those 15 are among the earlier 182, that would make it a fact.

Two small questions, only if you have them at hand: which head of this branch you ran (6c63dea, or a7e60cf with main merged in), and whether any program stops at a waterfall loop nested in another or split over blocks (the description's known limit; your list has none, which I take as zero).

The 167 at the scalar-memory reason are the next step for these programs, and that is other PRs' ground (#136 was one; it is closed now), not this one's.

The title was not used in my tests; the counts are yours. AI-assisted.

**@⁠r4tedx** on GitHub · 2026-11-24 08:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/566#issuecomment-7126652104) @⁠slint6614-dev thank you, this is the rerun the description was asking for, and with validation and pipelines on top. I have put the table in the description with your name. What it settles: the proof that replaced the match costs none of the earlier gain. The same 64 programs emit (8 vertex or pixel, 56 mesh), and now it is also known that all 64 validate and get pipelines on an RX 9070; #307 alone gains none. How I read the rest against the earlier count at `6638098`: `a scalar memory read as data` took 182 of the 294 then and takes 167 now, and 15 stop at `a waterfall loop whose compares do not select the access's lanes`. So the proof turns away 15 programs that were stopping one step later anyway. That is arithmetic on the two counts; if your `--list` outputs can say whether those 15 are among the earlier 182, that would make it a fact. Two small questions, only if you have them at hand: which head of this branch you ran (`6c63dea`, or `a7e60cf` with `main` merged in), and whether any program stops at `a waterfall loop nested in another or split over blocks` (the description's known limit; your list has none, which I take as zero). The 167 at the scalar-memory reason are the next step for these programs, and that is other PRs' ground (#136 was one; it is closed now), not this one's. The title was not used in my tests; the counts are yours. AI-assisted.
Author
Owner

@⁠iurysf on GitHub · 2026-11-24 09:07 UTC · original

@⁠r4tedx the run was at 6638098, the head before your 06:15 push. So @⁠slint6614-dev's rerun is the one that covers 6c63dea, and it shows the same 64 programs. AI-assisted.

**@⁠iurysf** on GitHub · 2026-11-24 09:07 UTC · [original](https://github.com/Marvisak/VIctory/pull/566#issuecomment-7126998764) @⁠r4tedx the run was at `6638098`, the head before your 06:15 push. So @⁠slint6614-dev's rerun is the one that covers `6c63dea`, and it shows the same 64 programs. AI-assisted.
Author
Owner

@⁠Vaximous on GitHub · 2026-11-24 09:21 UTC · original

A data point for this PR on real hardware (RTX 4070 Ti, Windows 11, 32-lane waves). It is what makes the open-world geometry draw in GTA VI (1.0.2.1) on my local integration branch (main + many open PRs).

  • Without it, every world mesh shader I could see (13 programs) stopped with "a descriptor read from the first lane of a phi": the if/else join of per-lane descriptors inside waterfall loops. All their draws were dropped. The depth and G-buffer targets stayed empty (0.02% of pixels written), and only sky and clouds reached the screen.
  • With #307 merged plus this PR's core commit (6638098), 8 of the 13 translate, pass dxil.dll validation and make pipelines. Over the title's 1,449 programs at --host-lanes 32-32, the count goes 1377 → 1385 (mesh 192 → 200). #307 alone changes nothing on this dump.
  • In the game: depth and G-buffer coverage went from 0.02% to about 16% of pixels. The presented frame now shows the character, power lines, vehicles and the distant city lights. The run was stable for 300 s.
  • The 3 waterfall GPU tests pass on hardware and WARP.

Notes from the port:

  • I applied 6638098 on top of a pr/307 merge, because merging the PR head brought in old main.
  • I did not take b1c8306/6c63dea, which conflicted with other wave64 mask work on my branch.
  • Under a wave64-on-32 "console flow" (#233/#320/#439), every lane arrives by every edge, so a per-lane descriptor join there would pick the wrong descriptor. I refuse that combination locally, so such programs lower per lane instead. Worth a guard here if those PRs land together.

The remaining world mesh programs stop at a related pattern, "first lane of computed VGPRs": a sampler copied into VGPRs under a per-iteration EXEC subset inside an outer loop.

**@⁠Vaximous** on GitHub · 2026-11-24 09:21 UTC · [original](https://github.com/Marvisak/VIctory/pull/566#issuecomment-7127309673) A data point for this PR on real hardware (RTX 4070 Ti, Windows 11, 32-lane waves). It is what makes the open-world geometry draw in GTA VI (1.0.2.1) on my local integration branch (main + many open PRs). - Without it, every world mesh shader I could see (13 programs) stopped with "a descriptor read from the first lane of a phi": the if/else join of per-lane descriptors inside waterfall loops. All their draws were dropped. The depth and G-buffer targets stayed empty (0.02% of pixels written), and only sky and clouds reached the screen. - With #307 merged plus this PR's core commit (6638098), 8 of the 13 translate, pass dxil.dll validation and make pipelines. Over the title's 1,449 programs at `--host-lanes 32-32`, the count goes 1377 → 1385 (mesh 192 → 200). #307 alone changes nothing on this dump. - In the game: depth and G-buffer coverage went from 0.02% to about 16% of pixels. The presented frame now shows the character, power lines, vehicles and the distant city lights. The run was stable for 300 s. - The 3 waterfall GPU tests pass on hardware and WARP. Notes from the port: - I applied 6638098 on top of a pr/307 merge, because merging the PR head brought in old main. - I did not take b1c8306/6c63dea, which conflicted with other wave64 mask work on my branch. - Under a wave64-on-32 "console flow" (#233/#320/#439), every lane arrives by every edge, so a per-lane descriptor join there would pick the wrong descriptor. I refuse that combination locally, so such programs lower per lane instead. Worth a guard here if those PRs land together. The remaining world mesh programs stop at a related pattern, "first lane of computed VGPRs": a sampler copied into VGPRs under a per-iteration EXEC subset inside an outer loop.
Author
Owner

@⁠claude-GTA6 on GitHub · 2026-11-24 09:57 UTC · original

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

A wrong "satisfiable" from Bools::meet here makes the per-lane trace give up on programs it can translate. Fix on top of this PR's head 74a9d331: one commit, claude-GTA6/VIctory@7b535a3 (branch pr566-meet-budget). Take it or adapt it as you like.

What happens. meet_in returns true when its MAX_MEET (65,536) case splits run out. In world mesh 903776ba469c8bac, the sampler's dwords are joined at 0x55d0 after an if/else whose else arm holds a v_cmpx waterfall loop. Both arms copy the same s_load_dwordx4 into v99..v102. For the edge from the else-arm skip (0x4eac), the trace goes on into the join at 0x4ea8 and asks whether lanes can also have come by the then-arm skip (0x4e1c). No lane can, but that meet (5 conditions) spends the whole budget and answers true. The trace then follows the pre-branch value (float math at 0x27e0..0x280c) and stops at a descriptor read from the first lane of computed VGPRs. The same budget makes waterfall() refuse loops it can prove.

The change (structure.rs only). Each condition set is sorted and deduplicated. A set that needs one condition both to hold and to fail is unsatisfiable at once. Sets found unsatisfiable are kept in a set, so each distinct set is split once. A "no" never depended on the budget, so meet stays exact; only an exhausted budget still answers "yes". New test: meet_sees_a_contradiction_deep_in_the_variables (a 24-variable parity and its negation as two conditions). It fails without the memo.

Measured (Windows 11, Rust 1.98.1, RTX 5090, retail v1.0.2.1 shaders, victory translate --validate --list, all 26,148 programs):

  • On this PR's head 74a9d331 vs head + fix: 61 programs leave this PR's refusals, none newly fail, nothing else changes:

    • a descriptor read from the first lane of computed VGPRs: 38 → 0
    • a waterfall loop whose compares do not select the access's lanes: 15 → 0
    • a descriptor partly joined by control flow: 8 → 0

    All 61 then stop at a scalar memory read as data, the next blocker on main.

  • On my integration branch (this PR plus #136 and others, --host-lanes 32-32), the same fix gives +55 validated (mesh 8,508 → 8,554). With VICTORY_EMIT_DUMP, 0 of the 23,697 programs that already emitted change by a byte. The world mesh programs adc5c689b0552cc2 and 903776ba469c8bac now translate and validate, as 910b4be059bfb28f and 321d411b20a35ef9 already did with this PR.

  • cargo test -p victory-shader at 7b535a3: 119 passed, 1 ignored. cargo clippy -p victory-shader --tests: nothing in structure.rs. cargo fmt --check: clean for the changed lines (the other fmt diffs were already on 74a9d331).

Not checked in game: on my machine the world hang comes before these programs draw. No game files are attached.

**@⁠claude-GTA6** on GitHub · 2026-11-24 09:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/566#issuecomment-7128124792) *From a tester working with Claude (AI-assisted); measured on my own machine.* A wrong "satisfiable" from `Bools::meet` here makes the per-lane trace give up on programs it can translate. Fix on top of this PR's head `74a9d331`: one commit, [claude-GTA6/VIctory@`7b535a3`](https://github.com/claude-GTA6/VIctory/commit/7b535a3bb9eed88afddc86204a2fd9a407915798) (branch `pr566-meet-budget`). Take it or adapt it as you like. **What happens.** `meet_in` returns `true` when its `MAX_MEET` (65,536) case splits run out. In world mesh `903776ba469c8bac`, the sampler's dwords are joined at `0x55d0` after an if/else whose else arm holds a `v_cmpx` waterfall loop. Both arms copy the same `s_load_dwordx4` into v99..v102. For the edge from the else-arm skip (`0x4eac`), the trace goes on into the join at `0x4ea8` and asks whether lanes can also have come by the then-arm skip (`0x4e1c`). No lane can, but that `meet` (5 conditions) spends the whole budget and answers `true`. The trace then follows the pre-branch value (float math at `0x27e0`..`0x280c`) and stops at `a descriptor read from the first lane of computed VGPRs`. The same budget makes `waterfall()` refuse loops it can prove. **The change** (`structure.rs` only). Each condition set is sorted and deduplicated. A set that needs one condition both to hold and to fail is unsatisfiable at once. Sets found unsatisfiable are kept in a set, so each distinct set is split once. A "no" never depended on the budget, so `meet` stays exact; only an exhausted budget still answers "yes". New test: `meet_sees_a_contradiction_deep_in_the_variables` (a 24-variable parity and its negation as two conditions). It fails without the memo. **Measured** (Windows 11, Rust 1.98.1, RTX 5090, retail v1.0.2.1 shaders, `victory translate --validate --list`, all 26,148 programs): - On this PR's head `74a9d331` vs head + fix: 61 programs leave this PR's refusals, none newly fail, nothing else changes: - `a descriptor read from the first lane of computed VGPRs`: 38 → 0 - `a waterfall loop whose compares do not select the access's lanes`: 15 → 0 - `a descriptor partly joined by control flow`: 8 → 0 All 61 then stop at `a scalar memory read as data`, the next blocker on `main`. - On my integration branch (this PR plus #136 and others, `--host-lanes 32-32`), the same fix gives **+55 validated** (mesh 8,508 → 8,554). With `VICTORY_EMIT_DUMP`, 0 of the 23,697 programs that already emitted change by a byte. The world mesh programs `adc5c689b0552cc2` and `903776ba469c8bac` now translate and validate, as `910b4be059bfb28f` and `321d411b20a35ef9` already did with this PR. - `cargo test -p victory-shader` at `7b535a3`: 119 passed, 1 ignored. `cargo clippy -p victory-shader --tests`: nothing in `structure.rs`. `cargo fmt --check`: clean for the changed lines (the other `fmt` diffs were already on `74a9d331`). Not checked in game: on my machine the world hang comes before these programs draw. No game files are 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!566
No description provided.