Repository navigation
Shaders: lower waterfall loops over per-lane descriptors (and s_cselect-chosen descriptors) - #307
Conversation
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
|
I reproduced a case where the rewrite changes a first-lane selection that is outside a waterfall loop. Starting from This seems to come from This was reproduced with the CPU lowering fixture on Windows. No game files or GPU were used for the counterexample. AI-assisted (Codex). |
|
Independent local check of head |
|
Review note from building this on current
A smaller question: This is the PR aimed at the second row of #293 ( |
|
The new (Claude Code, Claude Opus 5.5: hit this building the PR to test it on the title, and wrote this.) |
The resource tally in `victory translate` matched every `Source` variant by hand, so the new `Select`, `Fetched` and `Lanes` kinds left it non-exhaustive and `cargo check -p victory` failed. A fetched descriptor is counted with the loaded ones; selections and per-lane choices are never leaves. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
|
Tested The merge needed two compatibility adjustments: keep the waterfall On the native title path, the Only aggregate counts and error classes shared, no game data or raw game logs. AI-assisted (Kimi Code). |
|
Corpus-wide numbers for what was seen on one shader above:
So nearly all of what this PR unlocks goes through that phi case, which matches the #320 combination results above. AI-assisted. |
…a waterfall loop A descriptor read with v_readfirstlane_b32 was traced to each lane's own dwords wherever it was, so a first-lane read outside a loop, or one without the v_cmp_eq that hands every lane its turn, sampled for lanes the program skipped (reported on the PR with the back edge of the fetched waterfall test replaced by s_nop). Now: - a compare counts only when it and the v_readfirstlane it reads are in one loop (each block reaches the other); - every descriptor read from the first lane needs each of its dwords compared that way, or translation stops with "a descriptor read from the first lane outside a waterfall loop". Two tests cover the missing back edge and the missing compare. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66
|
@AntoninMichelq are you working on The approach I intend, so it can be shot down early:
@EduAzevedo, if it is cheap for you: what the phi looks like in those 294 would tell me whether this is the right shape before I write tests against the wrong one. Yes/no or counts, no shader contents:
No game data used on my side. |
|
Tested
No game files used. |
Yes, measuring it now |
|
Verified the updated head
No game data used for this check. AI-assisted (Kimi Code). |
|
Ran
One shape is accepted and comes out wrong: the same complete loop (readfirstlane x8, four Not covered: the title (no game data here). |
Measured on
So the shape is "one of two |
|
@EduAzevedo thank you, your answers changed the design. The phi case is up as #566, one commit ( What your numbers showed: the "unrelated values" on other edges ( @AntoninMichelq two things for you:
If you can rerun, Not run against the title on my side. |
…73d66, and Marvisak#180) The wave64 stack (Marvisak#223, Marvisak#233, Marvisak#320, Marvisak#439, with Peter Bonanni's whole-wave sections across the halves, 9b73d66) merged with Marvisak#180 (twin descriptor loads and quad gradients for compute samples), at 24b3bcc. That commit has one parent (e49302a); Marvisak#180's changes come in without its commits. Marvisak#233 is in this tree as 1eb9995, the same tree as 3098672, so each file was merged with 3098672 as the base instead of the e0865d2 git chooses. Conflict resolutions: - emit/wave.rs, v_permlane16/x16 in whole-wave sections: Marvisak#98's "every lane active" and 9b73d66's "or fi set" are both kept, for both instructions. - emit/lower.rs, Lower::new: Marvisak#320's test for lane reads and writes in divergent programs counts live instructions only, as Marvisak#233's does with Marvisak#309 (dead SGPR-spill lane instructions are no lane reads). Marvisak#307's waterfall arm of v_readfirstlane still comes before the console-flow arm; Marvisak#320 adds no arm of its own. - Compute samples with implicit derivatives (Marvisak#160, Marvisak#180, Marvisak#306): Marvisak#180 decides plain and biased samples, all of Marvisak#160's forms of them (implicit_derivatives from sample_form: _o, _cl, cube, a16), with Marvisak#160's bias address (bias_at) and level clamp; Marvisak#306's validator 1.8 is now declared only for what still uses the host's derivatives in compute (comparison samples, op 64). The Marvisak#306 test of image_sample now asserts no 1.8 (48-byte PSV0) and still validates and creates the pipeline; a twin test with image_sample_c asserts 1.8. - sgpr_spill test (Marvisak#309): without forwarding, the per-lane form still stops with "a lane mask holding lanes elsewhere read as data", but emit now takes the console flow (Marvisak#320); the test checks both, and that forwarded spills do not ask for the console flow. - Mechanical: per_lane_only in two hand-built Parts in emit/lower.rs tests; emit/mod.rs module order (split_tests before threading). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Independent check of head Read against the RDNA2 ISA (30-November-2020)
One more accepted shape that differs from the console (same family as the use-after-loop case; a compiler would not emit it, but it is accepted rather than refused):
Run on hardware. NVIDIA RTX 3070, driver 616.56, Windows 11, Rust 1.98.1,
I did not dispatch waterfall programs on this GPU; @marquezinii's RTX 5070 runs above cover that. Not checked: the title (no game files here), AMD hardware, #566. AI-assisted (Claude Code). |
…isak#306 Marvisak#333 Marvisak#105 Marvisak#288 Marvisak#343 Marvisak#353 Marvisak#326 Marvisak#259 Marvisak#179 Marvisak#176 Marvisak#226 Marvisak#286) Conflicts: - emit/lower.rs: shader-opcodes and shader-tracking each keyed heap handles by the resource properties (a tuple vs two flattened words); the same key, shader-tracking's form and comment kept. Lowered's test-only fields, test imports and tests of both sides kept. - emit/wave.rs: tests of both sides kept. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ntains Marvisak#223) Conflicts: - crates/victory-shader/src/emit/lower.rs, Lower::new: shader-tracking (Marvisak#309) ignores the dead lane instructions of SGPR spills when deciding a compute program reads other lanes; Marvisak#233 splits that test into in-half reads (swizzles, DPP) and whole-wave reads. Marvisak#233's split is kept, with both of its lane-read tests over the live instructions only (a `live` closure over sgpr_spill::dead). Its other instruction scans (v_readfirstlane, permutes) stay over all instructions, as Marvisak#233 has them. - lower.rs, v_readfirstlane_b32: shader-tracking's (Marvisak#307) arm for a waterfall loop's read of a descriptor dword (each lane's own) and Marvisak#233's arm for the console flow (the console wave's first lane in EXEC) are both kept, the waterfall arm first: the waterfall's compares are taken as true per lane before anything else (Lower::valu), in the console flow too, so its reads must stay each lane's own. - crates/victory-shader/src/emit/mod.rs: module list (threading and split_tests) and test imports of both; the test import of bitcode::Attr stays removed as shader-opcodes left it (the tests take it from `super::*`). emit_program (split from emit by Marvisak#48 in the opcodes branch, for the retry after edge threading) takes and passes Marvisak#233's `target`. - crates/victory-gpu/src/shader_cache.rs: tests of both sides kept. Mechanical, for Marvisak#233's new arguments (no test checks changed): `target: Target::ANY, console_cf: false` in hand-built lower::Parts in emit/lower.rs tests (two), and Target::ANY as emit's last argument in emit/image_tests.rs, emit/mod.rs tests (two) and sgpr_spill.rs tests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A waterfall loop whose descriptor dwords are VGPR phis stopped with "a
descriptor read from the first lane of a phi" (294 programs of the
title on #307, all at if/else joins of two s_load_dwordx4 descriptors
copied into VGPRs). An EXEC if/else leaves two phis per dword: the
flow block's joins an arm's dwords with what lanes that skipped the arm
held before (inputs, unrelated loads and arithmetic in the title), the
join after the other arm picks per path. Only lanes that never read the
descriptor bring those other values, so tracing every edge fails.
Tracing (resource::track now takes the program's per-lane form):
- per-lane phis of one block are traced on each edge into it that the
lanes accessing the descriptor can take, from structure's lane
conditions (new Structured::reach, the exits' conditions, and
Bools::meet, a read-only satisfiability check); the trace starts from
what holds in the access's block. Edges no such lane takes are None
in the new Source::LanePhi { block, args };
- every per-lane write it follows (v_mov_b32 copies, v_cndmask_b32,
global_load_dword*) must run in all those lanes: a guarded one fails
with "a per-lane descriptor written where some lanes may keep the old
one". On #307 an else arm without its s_cbranch_execz traced as the
second descriptor for every lane;
- a loop header's phi fails with "a descriptor read from the first lane
of a phi at a loop header", words defined after the join with "a
descriptor partly joined by control flow"; without the per-lane form
(structurisation failed) the join is refused.
Lowering computes each traced edge's heap index at its predecessor's end
(through lane_heap_index, so loads, per-lane loads, choices and nested
joins work), joins them with a phi (0 on untaken edges) and makes the
handle non-uniform. The waterfall compares need no change.
Tests: the if/else of two loaded image descriptors, a join of a per-lane
load and a v_cndmask choice, nested arms choosing a buffer descriptor
with lanes that skip both and do not load (pruned only by the access's
condition), a loop header phi, and an unskipped else arm. On #307's head
the three join programs fail with "...of a phi" and the unskipped arm is
traced as one descriptor for all lanes. On an RTX 5070 and WARP, each
lane reads its own arm's texture or buffer; the shaders pass dxil.dll
1.8.2502.11. Reversing the phi's inputs fails validation, flipping the
heap index fails the GPU check.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
main moved under #307 and this branch. One conflict, in the test module of emit/lower.rs: the imports take both sides' names (#117's `half_shift` beside `Lowered`), and #117's `scalar_bit_tests_lower` sits after this branch's waterfall tests. No code outside the test module was touched by hand. A merge rather than a rebase so #307's commits keep their ids. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Shaders: per-lane descriptors chosen by control flow (stacked on #307)
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>
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>
Shaders: per-lane descriptors chosen by control flow (stacked on Marvisak#307)
Requested by 4nto · project thread
Summary
Descriptors that a waterfall loop reads lane by lane are now traced and lowered, so the loop runs once with every lane using its own descriptor. Before this, tracing stopped with "a descriptor neither loaded nor built" and the whole program was dropped, along with every draw that used it. The branch also traces descriptors that are chosen without a branch, by
s_cselect/s_cmov.What changed
Two commits, both based on main:
Trace descriptors chosen by
s_cselectands_cmov. The compiler sometimes hoists both descriptor loads and replaces the if/else withs_cselect_b64per half, ors_cselect_b32/s_cmovper dword. Those words are now split by the SCC value they read, and each side is traced into a newSource::Select. Lowering picks the heap index of the two loaded descriptors by SCC and creates one heap handle. A choice that mixes two descriptors still stops, with "a descriptor changed after loading".Lower waterfall loops over per-lane descriptors in one pass. The
v_readfirstlane_b32reads of a VGPR descriptor are followed to where each lane gets its own dwords:global_load_dword*from a table or heap at a per-lane address, orv_cndmask_b32per-lane choice between such sources.Other sources fail and name what they are (LDS, buffer load, phi, input, computed VGPRs). The access gets each lane's heap index, with
createHandleFromHeap'snonUniformIndexset. The recorded readfirstlanes are lowered as the lane's own dword and theirv_cmp_eqas true.docs/architecture.mdis updated.Adapted to main:
lower_with/lower_wave/roottoemit::lower::tests.paramanddynamiconly. Theincludes_basefield it also compared is not on main.How it was tested
cargo test -p victory-shaderon Linux: all tests pass. New tests:resource::tests::descriptors_selected_by_scc_are_traced_per_outcomeresource::tests::a_selection_that_mixes_two_descriptors_failsresource::tests::descriptors_read_from_the_first_lane_of_per_lane_loads_are_traced_to_themresource::tests::descriptors_read_from_the_first_lane_of_a_per_lane_choice_are_traced_per_laneresource::tests::descriptors_read_from_the_first_lane_of_lds_fail_naming_itemit::lower::tests::a_descriptor_selected_by_scc_picks_its_heap_indexemit::lower::tests::waterfall_loops_over_per_lane_descriptors_sample_with_each_lanes_own(Wave32 and Wave64)cargo check -p victory-shader --target x86_64-pc-windows-msvcpasses.victory translateon the integration stack.Where 3D rendering stands on an RX 7600 (Windows 11)
These observations come from the integration stack (upstream main plus many open PRs), not from this branch alone.
🤖 Generated with Claude Code
https://claude.ai/code/session_01AZ9pSB4ZoXYUifuXg8gm66