shader: scalar instructions inside pixel_aot masked regions — proposed first stage #987
Labels
No labels
accessibility
awaiting author
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
priority: P0
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/R0Y00--Xbox2Windows#987
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@MasterDomino on GitHub · 2026-11-23 20:02 UTC · original
Question
How should
tools/pixel_aot.pytreat scalar instructions inside a masked region? What is the smallest first stage you would accept?This builds on #957 and #975/#976. With #976's body set, most real regions that remain blocked contain only scalar instructions besides admitted VALU work. Scalar instructions ignore EXEC, but
s_cbranch_execzjumps over the whole region when the wave's mask is empty. Their effects therefore depend on a wave-level condition ("any lane active"), which the per-lane model can't compute. Today every scalar instruction is refused in a region withInstruction cannot run in a masked region.Evidence so far
Measured on one local input (the 12,101 PS records from #932; aggregates only), decoded with
tools/disasm_rdna2.py. I counted the regions #957 accepts structurally (save + f32/i32/u32_e32v_cmpx+ restore of the same pair, no further branch) whose body is fully admitted by #976 apart from scalar instructions.Totals. 604 regions in 532 records. 596 of them have an
s_cbranch_execzskip; only 8 don't (those contains_nopands_mov_b32).Scalar instructions in the 596, by occurrence:
s_waitcnts_buffer_load_dwords_load_dwordx4s_add_i32s_mul_i32s_mov_b32s_cmp_gt_i32s_cselect_b32s_movk_i32s_buffer_load_dwordx4Where the SGPRs they write are first read after the restore (linear order, before being rewritten):
s_buffer_loaddescriptors, or as av_cmpsource)The read detection is a syntactic scan of the decoded text (destinations of scalar instructions excluded), and the decoder stops at the first
s_endpgm, so treat these as approximate.Semantics I'm relying on. The AMD RDNA 2 ISA guide §3.1 (p. 12 of 283) says EXEC "affects vector-ALU, vector-memory, LDS, GDS, and export instructions. It does not affect scalar (ALU or memory) execution or branches." It also says EXECZ "can be used as a condition for branches to skip code when EXEC is zero."
Inference, not measured. If the region is entered, the scalar results are the ones computed inside it. If the whole wave skips it, the registers keep their earlier values. A per-lane translation can't tell those cases apart, except where the results aren't observed after the region.
Proposed first stage
Admit side-effect-free scalar instructions in the region body, executed unconditionally as the vector body already is (the skip stays elided). Every SGPR and SCC they write becomes region-conditional: readable inside the same region, refused after the restore until rewritten outside any region. This mirrors the existing rule for VGPRs defined only on the masked path.
s_waitcntands_nop, which have no architectural effect here;s_mov_b32,s_movk_i32,s_add_i32,s_mul_i32,s_cmp_*_i32ands_cselect_b32, through their existing lowerings;s_load_dwordx4ands_buffer_load_dword/x4on descriptors the translator already tracks, with the existing pending-load rules.s_mov_b64close leave SCC unknown when the body wrote it.On this input that admits the 371 regions whose scalar results are dead after the restore. The other 225 stay refused.
I would implement this, but not before #976 has merged and you have answered the questions below.
Questions for you
s_waitcnt/s_nop(no state) land first on their own, before the ALU and load forms?Completion condition (first stage)
Required environment
Translation and the LLVM 15 round trip run on Linux. The draws need Windows (WARP in CI). No physical GPU and no game files.
AI-assisted.
@R0Y00 on GitHub · 2026-11-23 20:16 UTC · original
Start with s_nop and waits whose counters are already satisfied in the tracked state. A wait that would resolve any pending work, or whose counter state is unknown, stays refused. Keep the current save pair, restore target, branch and EXEC restrictions. Exercise both openers and show that a pending-load wait still rejects.
Then a separate patch can admit already modeled, side-effect-free scalar ALU using proven inputs, with writes to ordinary SGPRs and SCC readable inside the region only. A read after restore stays refused until an unconditional rewrite defines it. Include a post-restore SCC consumer and a sentinel for a preexisting SGPR, along with mixed/full/empty mask readback and the unmasked control. Keep scalar loads and their waits outside both slices. A descriptor that can be bound does not establish that a load skipped by an empty wave can be executed unconditionally.
@MasterDomino on GitHub · 2026-11-23 21:16 UTC · original
Taking stage 1 as approved above:
s_nopand waits whose counters are already satisfied in the tracked state, both openers covered, and a pending-load wait shown to still reject. Stage 2 (scalar ALU) will follow as a separate PR after this one.AI-assisted.
@MasterDomino on GitHub · 2026-11-23 21:52 UTC · original
Stage 1 is up as #1023.
AI-assisted.
@R0Y00 on GitHub · 2026-11-24 00:41 UTC · original
The two agreed slices are on main. #1023 admitted s_nop and already-satisfied waits, and #1064 (
f7c9f579) added the scoped scalar ALU. The latter passed LLVM 15 and all six Windows masked-region checks across RTX 4060 Laptop and WARP. The in-region SGPR/SCC results, post-restore refusals, unconditional rewrite, saved pair and mixed/full/empty masks are covered. A wait that would resolve pending work and a scalar load inside the region still reject. This stays open for those effects if a separate source-built case establishes their execution and visibility rules.@tedin7 on GitHub · 2026-11-24 01:30 UTC · original
Claiming Stage 3 in tools/pixel_aot.py: s_waitcnt that resolves outstanding vm/lgkm work and scalar loads (s_load_dword*, s_buffer_load_dword*) inside masked regions (s_and_saveexec_b64 / v_cmpx_*), with a draw readback and independent CPU reference. Environment: Linux with LLVM 19 locally; I rely on the Ubuntu LLVM 15 job and the Windows WARP jobs for the rest. AI-assisted.
@R0Y00 on GitHub · 2026-11-24 01:53 UTC · original
Please take the wait slice first. Use a source-built case where the wait must make a particular pending result available, and include full, mixed and empty masks. Check what remains pending after restore, and make a dropped or misplaced wait fail. Keep scalar loads separate until there is an independent reference for execution and result visibility.