Shaders: per-lane descriptors chosen by control flow (stacked on #307) #566
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!566
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/566/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@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 UTCStacked 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) and6c63dea(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
main42361b0(heada7e60cf, 2026-11-24).mainmoved and #307 itself now conflicts with it, so this branch tookmainin as a merge commit, which keeps #307's commits and the three above at their ids. The one conflict was in the test module ofemit/lower.rs(imports, and #117's test beside this branch's); no code outside tests was edited by hand.cargo test -p victory-shaderata7e60cf: 107 passed, 1 ignored, on the RTX 5070;cargo check --workspace --all-targetsis clean.What
With #307,
a descriptor neither loaded nor builtgoes from 298 programs to 3 over the title's shaders, but 294 of them (259 mesh, 35 vertex) then stop ata 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_dwordx4descriptors 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.
resource.rs).resource::tracknow 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 (newStructured::reach, andBools::meet, a read-only satisfiability check). Edges no such lane takes areNonein the newSource::LanePhi { block, args }.v_mov_b32,v_cndmask_b32,global_load_dword*) must run in all those lanes; otherwisea per-lane descriptor written where some lanes may keep the old one. On #307's head an else arm without itss_cbranch_execzis traced as the second descriptor for every lane, with no error; a test covers it.emit/lower.rs). Each traced edge's heap index is computed at its predecessor's end throughlane_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 SGPRSource::Philowering 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
b1c8306and6c63deaTaking 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:
6638098gave lanes 16 to 31 their own. Reproduced here on a hardware adapter.b1c8306replaces 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.6c63deagives each failure its own reason:a descriptor read from the first lane outside a waterfall loopa waterfall loop whose compares do not select the access's lanesexec_hioverwrittena waterfall loop whose retry does not keep the lanes still waitinga waterfall loop nested in another or split over blocksBoth 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 (av_cmpx_eqchain with the retry astodo & !EXEC), which this PR accepts and tests on the GPU.Known limits
6638098accepted 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 ata waterfall loop nested in another or split over blocks. In review that shape gave the right output on6638098, 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).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 --listover the retail shaders, #307 at6285e19against6638098, all 26,148 programs:a descriptor read from the first lane of a phi: 294 to 0 (EduAzevedo, confirmed by miniongk).a scalar memory read as data, 38 ata descriptor read from the first lane of computed VGPRs, 8 ata descriptor partly joined by control flow, 2 ata lane mask read as data.6285e19stopped translating.shader does not translatefell 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 --pipelinesover the full retail shader pack, pipelines created on an AMD RX 9070, againstmain1f858b0):a descriptor neither loaded nor builtmaina scalar memory read as data573 to 740 (so 167 of them),a descriptor read from the first lane of computed VGPRs38,a waterfall loop whose compares do not select the access's lanes15,a descriptor partly joined by control flow8.Tested
Windows 11, NVIDIA RTX 5070 and WARP, hand-assembled programs only:
v_cndmask_b32choice; 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).v_cmpx_eqwaterfall accepted in wave32 and wave64, plain and folded intos_andn2_wrexec.v_cmpx_eqwaterfall; the shaders passdxil.dll1.8.2502.11.cargo test --workspaceat6c63dea: 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
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_01AZ9pSB4ZoXYUifuXg8gm6642361b0) into shader/per-lane-phi a7e60cfac08e79c80) into shader/per-lane-phi e09dbb6dae@EduAzevedo on GitHub · 2026-11-24 05:08 UTC · original
Measured
6638098against #307's head6285e19, 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.a scalar memory read as dataa descriptor read from the first lane of computed VGPRsa descriptor partly joined by control flowa lane mask read as dataa per-lane descriptor written where some lanes may keep the old one), and no program that translated on6285e19stops translating here.... of an input VGPRor... of a buffer load, so the pruning did prove the unrelated edges dead in these programs; the 38 atcomputed VGPRsand the 8partly joinedare what it leaves.The 182 at
a scalar memory read as dataare 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 on GitHub · 2026-11-24 05:10 UTC · original
I hit a wrong-output case on
6638098using a small change to the authoredWATERFALL_JOINED_WAVE32fixture. The DXIL passed Windows SDK validation and dispatched on Agility SDK 620 WARP. Lanes 0–15 returned1.0and lanes 16–31 returned2.0. All 32 should return1.0.Replacing
s_and_saveexec_b32 s21, s21withs_mov_b32 s21, exec_loleaves the descriptor comparisons in the same CFG loop but disconnects them from EXEC. All lanes execute the sample with the descriptor thatv_readfirstlanereads 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.I ran
VICTORY_WARP=1 cargo test -p victory-shader --lib dead_descriptor_compares_do_not_turn_a_loop_into_a_waterfallwith the SDK 620 exports in the test executable. The current match inresource::Tracer::waterfalllooks 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 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 --listinput for #3076285e19and this PR at6638098(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.a scalar memory read as datamoves 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).@r4tedx on GitHub · 2026-11-24 05:42 UTC · original
@ifBars reproduced, thank you. Your test fails the same way on
6638098on a hardware adapter here (RTX 5070), not only on WARP: lanes 0–15 return1.0, lanes 16–31 return2.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's32b5180. I ran both here:cargo test -p victory-shader --lib6638098(this PR)4a64d76a descriptor read from the first lane outside a waterfall loop32b5180Neither translates it to all
1.0as 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
6638098as 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.
@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 translatefell 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).
@r4tedx on GitHub · 2026-11-24 06:15 UTC · original
The fix is pushed: head is now
6c63dea(was6638098).What went in
b1c8306is @fuzeofficlal's32b5180, 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(testa_compare_that_does_not_mask_the_access_is_no_waterfall). It is not translated to all1.0as 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:
4a64d76still accepts a loop whose retry drops the waiting lanes. InWATERFALL_JOINED_WAVE32,0x897E157E→0x8A7E7E6A(s_andn2_b32 exec_lo, vcc_lo, exec_lo): on the console lanes 16 to 31 never sample, with4a64d76they get2.0on the GPU.v_cmpx_eqchain with the retry astodo & !EXEC(also folded intos_andn2_wrexec).b1c8306accepts 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
6638098translated correctly is now refused: an image whose resource and sampler are both per lane, with one loop per operand, nested. It stops ata 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 --listcomparison,6638098against6c63dea. 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 witha waterfall loopora 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 ata scalar memory read as data.Tested here at
6c63dea, on an RTX 5070 and WARP, with hand-assembled programs:cargo test --workspace293 passed, 4 ignored. The title was not used in these tests. AI-assisted.@iurysf on GitHub · 2026-11-24 06:17 UTC · original
Tested offline against main
d2a4baewithvictory translate --list --validateover the title'sshaders.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.dx.valvercase that #306 fixes. No module that validated on main fails now.AI-assisted.
@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 DXIL and readback checks use synthetic inputs. Coverage of the previously measured shader corpus is still open. Incremental commit on
6638098Retested
6c63dea. Both LLVM-stylev_cmpxretry 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 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
6638098to6c63deaat about 06:15 UTC, two minutes before your comment.6c63deaproves 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.6c63dea: the fix cost nothing in the title's shaders, and a count of programs stopping at reasons that start witha waterfall loop(expected: 0) would close it.6638098: the same run on6c63deais the open measurement.@fuzeofficlal thank you for retesting
6c63deaon the Radeon iGPU, the RTX 5090 and WARP.Nothing was run for this note. AI-assisted.
@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 main1f858b0. Counts are emitted / validated / pipelines.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.
@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 datatook 182 of the 294 then and takes 167 now, and 15 stop ata 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--listoutputs 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, ora7e60cfwithmainmerged in), and whether any program stops ata 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.
@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 covers6c63dea, and it shows the same 64 programs. AI-assisted.@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).
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.Notes from the port:
6638098on top of a pr/307 merge, because merging the PR head brought in old main.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.
@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::meethere makes the per-lane trace give up on programs it can translate. Fix on top of this PR's head74a9d331: one commit, claude-GTA6/VIctory@7b535a3(branchpr566-meet-budget). Take it or adapt it as you like.What happens.
meet_inreturnstruewhen itsMAX_MEET(65,536) case splits run out. In world mesh903776ba469c8bac, the sampler's dwords are joined at0x55d0after an if/else whose else arm holds av_cmpxwaterfall loop. Both arms copy the sames_load_dwordx4into v99..v102. For the edge from the else-arm skip (0x4eac), the trace goes on into the join at0x4ea8and asks whether lanes can also have come by the then-arm skip (0x4e1c). No lane can, but thatmeet(5 conditions) spends the whole budget and answerstrue. The trace then follows the pre-branch value (float math at0x27e0..0x280c) and stops ata descriptor read from the first lane of computed VGPRs. The same budget makeswaterfall()refuse loops it can prove.The change (
structure.rsonly). 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, someetstays 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
74a9d331vs 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 → 0a waterfall loop whose compares do not select the access's lanes: 15 → 0a descriptor partly joined by control flow: 8 → 0All 61 then stop at
a scalar memory read as data, the next blocker onmain.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). WithVICTORY_EMIT_DUMP, 0 of the 23,697 programs that already emitted change by a byte. The world mesh programsadc5c689b0552cc2and903776ba469c8bacnow translate and validate, as910b4be059bfb28fand321d411b20a35ef9already did with this PR.cargo test -p victory-shaderat7b535a3: 119 passed, 1 ignored.cargo clippy -p victory-shader --tests: nothing instructure.rs.cargo fmt --check: clean for the changed lines (the otherfmtdiffs were already on74a9d331).Not checked in game: on my machine the world hang comes before these programs draw. No game files are attached.