Repository navigation
shader: lower uniform scalar loops in the mesh frontend - #3707
lukaslw-lab wants to merge 3 commits into
Conversation
Leyukaka
left a comment
There was a problem hiding this comment.
open_loop initializes the SCC slot to zero when its incoming value is unavailable. For example, s_or_b32 with an unmaterialized source register and an immediate 1 leaves SCC unavailable in the frontend. The guest result always has bit 0 set, so SCC is 1. If the loop starts with s_cbranch_scc1 to an exit before the body defines SCC, the guest takes the exit and the emitted first iteration falls through. Please retain a proven incoming SCC or refuse an unproven read, while still accepting a loop that defines SCC before reading it.
The carried-register analysis also loses a value at an early exit. Initialize s22 to 7, branch from the header to the exit, and on the path through the body write 9 to s22. Let the only read of s22 be at that exit. The guest reads 7 on an immediate exit and 9 after one completed iteration. The scan sees the write but misses the read outside the loop, so the header clears s22 and the exit snapshot contains an unbound value at either trip count. Please preserve s22 at that exit and test both trip counts. The existing fixture rewrites s20 in each exit block before reading it.
The mesh frontend emitted DXIL in one forward pass and refused every back edge. Accept one narrow shape: one header, one back edge (s_cbranch_scc0, s_cbranch_scc1 or s_branch), and a body of the 32-bit scalar ALU that is already allowed between a diamond join and its EXEC restore, scalar compares, scalar loads, waits and forward exits past the back edge inside the enclosing EXECZ region. The pass stays forward-only: registers the body writes after reading them, and SCC, live in local slots stored before the header and at the back edge and loaded in the header. A register the body only writes is unbound in the header; one it never writes keeps its entry value. Exits use the existing forward-join merge. Every other loop keeps a named refusal. The scalar ALU list moves to function scope so the loop check and the post-join check share it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Track SCC like an SGPR in the loop scan: give it a slot only when the body reads it before defining it, and refuse when its entry value is unknown instead of storing 0. Also carry any value the body writes after its first exit branch, so an exit sees the previous iteration's value; with no entry value it stays unbound and a later read refuses. Inline constant 0 shares operand code 128 with the SCC index, so operand reads stay limited to SGPRs and SCC reads are explicit. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1f15a0b to
802f682
Compare
|
Thanks, both points were real. Fixed in SCC entering the loop. SCC no longer always gets a slot, and nothing stores a literal 0. The scan tracks SCC like an SGPR. It gets a slot only when the body reads it before defining it, either at an exit or back edge, or in Values seen at an early exit. Every value the body writes after its first exit branch is now carried, so that exit sees the previous iteration's value. Your s22 case: the slot is stored 7 before the loop and 9 at the back edge, and the exit reads the header's load of it. If such a value has no entry value, it stays unbound at the exit, and a read after the loop refuses with
The harness checks emitted DXIL text and does not execute it. So the trip-count cases are checked through dataflow: zero trips read the entry store, and one trip reads the back-edge store. Controls: each line below is a one-line change, and
Local, Windows Release,
|
…-scalar-loop # Conflicts: # src/gfx1013_direct_mesh.inl
|
Merged main ( Release build: AI-assisted. |
Leyukaka
left a comment
There was a problem hiding this comment.
Re-review of edadb494 (fix in 802f682d, merge of main in edadb494). Read the diff; not built or run.
Both findings from my earlier review are addressed:
- SCC entering the loop.
open_loopno longer stores a literal 0. SCC (128) is tracked like an SGPR, and a slot is created only when the body reads it before writing it (exit, back edge, ors_cselect_b32/s_addc_u32/s_subb_u32). If the entry value is not available, the loop refuses withmesh loop reads SCC before the body defines it, without a known entry value.scalar-loop-scc-unknownandscalar-loop-scc-after-movecover the refusal, andscalar-loop-scc-knowncovers the carried case. The second control also checks thats_mov_b32is not counted as an SCC write. - Value read at an early exit. A register written only after the first exit branch is now carried, so the exit sees the previous iteration's value (or the entry value). In my s22 example, the slot is stored with 7 before the loop and 9 at the back edge, and the export reads the header load.
scalar-loop-exit-read-{80,81,15}check this for zero trips, one trip and a root bound. Without an entry value, the register is not carried. A later read refuses throughalu.read(unbound numeric SGPR s22), andscalar-loop-exit-unset-readcovers that.
I found no new problem in the loop scan. Non-forward branches inside the body are refused, a nested back edge hits the forward-exit check, and a carried value without a numeric entry value refuses instead of using a placeholder.
The merge with #3797 keeps the VCC-branch case and matches the loop back edge first, and the loop lowering itself is unchanged.
Approving edadb494.
Change
The C++ mesh frontend (
lower_mesh) emits DXIL in one forward pass, so it refused every back edge withunsupported mesh scalar branch destination. It now accepts one narrow shape, a uniform scalar loop, as designed in #3703:s_cbranch_scc0,s_cbranch_scc1ors_branch);s_waitcnt/s_nop/s_clause, and forward exits past the back edge inside the enclosing EXECZ region.The pass stays forward-only:
alloca i32) when one pass reads it before that write, or when an exit branch comes before that write. SCC is tracked like an SGPR. The slots are stored before the header and at the back edge, and loaded in the header. A value with no entry value that only an exit sees stays unbound there, so a read after the loop refuses.Each other loop keeps a named refusal:
mesh loop needs exactly one back edge… body holds an unsupported instruction: <name>… back edge needs SCC or an unconditional branch… is entered other than at its header… outside a uniform scalar region(after GS_ALLOC_REQ, under a per-lane else, or outside full EXEC and any EXECZ region)… carries a register without a numeric entry value… reads SCC before the body defines it, without a known entry valueThe scalar ALU list moves from the post-join check to function scope so both checks share it; that check is unchanged.
This is item 1 of #3703. 18 captured slot 86 requests share one such loop: a search over records of 0x130 bytes for a flag bit, bounded by dword 0 of root SRV 3. With #3702 and #3704 applied, all 18 pass the loop without any stand-in. Their next refusal is
mesh image load lacks a remapped Texture1D heap contract(item 4, open). Refs #3703, #3641.Verification
Build
releaseat this branch (Windows 10 19045, MSVC 2022, DXC 1.9.2609):42 of the 49 also fail on this host with
main's sources (Windows 10 without the Agility SDK; NVIDIA RTX 3080 Ti, driver 32.0.16.1047, debug layer on;pixel_aot_*use the local LLVM tools). The other 7 (pixel_aot_*_hardware) failed in the 6-way parallel run and passed 7 of 7 run one at a time with this change; they do not use the mesh frontend.New cases in
native_direct_mesh_check.py, next tomulti-edge:scalar-loop: counts s20 from 0 while it is below root constant s21, and leaves early at 5. The exits set 7 or 9 and join before the export reads s20. The IR check: only s20 gets a slot (the body defines SCC before reading it); s20 is stored before the header and at the back edge; the back edge branches on SCC == 0; the body compares with 5 and with s21.scalar-loop-scc-unknown,-scc-after-move(refused) and-scc-known(SCC slot, no literal 0): SCC entering the loop.scalar-loop-exit-read-{80,81,15}: s22 = 7 before the loop, set to 9 after the exit branch, read only after the exit. The export traces to the header load of the s22 slot, whose only stores are 7 and 9.-exit-unsettranslates, and-exit-unset-readrefuses.scalar-loop-branch-back: ans_branchback edge, leaving only through the early exit; no exit block is emitted.scalar-loop-vector,-vcc-back,-two-back,-enter-body.Controls:
scalar-loopfails withunsupported mesh scalar branch destination.Evidence and follow-up
Source-built words only. The 18-request counts are local and offline (
compile_dxil ... gfx1013-container-ms-texture-heap). Note:docs/experiments/native-mesh-scalar-loop.md.Checklist
AI-assisted.
🤖 Generated with Claude Code