shader: lower v_readfirstlane_b32 in pixel_aot #759
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/765"
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?
Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-23T01:40:21Z.
This PR lowers
v_readfirstlane_b32intools/pixel_aot.pyto HLSL SM 6.0WaveReadLaneFirst(), corrects SGPR destination decoding intools/disasm_rdna2.py, and registers scanner support intools/scan_unsupported_shaders.py.Background and Lowering
In RDNA 2 VOP1 encoding (Table 12.11),
V_READFIRSTLANE_B32copies the value of VGPRvSrcfrom the first active lane in the wavefront into SGPRsDst. Unlike other VOP1 operations that write VGPRs,v_readfirstlane_b32targets an SGPR destination (0 <= dst <= 105).tools/disasm_rdna2.pypreviously decoded VOP1 destinations unconditionally as VGPRs (f"v{vdst}"). Forv_readfirstlane_b32,dst_stris now decoded withdecode_s_reg(vdst)(s0,s44, etc.) in both VOP1 and VOP3 paths.uint salu{i} = WaveReadLaneFirst({arg});and immediately tracksscalar[dst] = ("uint", f"salu{i}"), allowing downstream consumption by SALU arithmetic, VALU operands, and constant-buffer offset indexing.v_readfirstlane_b32pattern toSUPPORTED_INSTRUCTIONS_REGEX.check_readfirstlane_drawverifying zero, normal, and high integer broadcast readbacks across 64 pixels, with oracle mismatch rejection. Added negative controls intests/pixel_aot_check.pyrejecting VGPR destinations, out-of-range SGPRs, invalid modifiers, unresolved scalar dependencies, and un-waited vector sample registers.Test Commands and Results
A passing fixture supports the behavior under test; full-game startup and title execution remain unverified.
Imported from R0Y00/Xbox2Windows. Originally posted by FZNull on 2026-11-23T02:11:32Z.
The SGPR destination part matches what I measured, but the VOP3 path needs a second look before this lands, given the guidance on #746.
What I measured (LLVM 21.1.8
llvm-mcwith the AMDGPU target,-triple=amdgcn--amdpal -mcpu=gfx1013), because the in-tree CI job uses LLVM 15 so treat this as strong evidence that still wants a CI-side confirmation:That is the VOP1 word from #746 and the assembler prints an SGPR destination, so the
decode_s_reg(vdst)change in the VOP1 path (tools/disasm_rdna2.py:1237) is confirmed. An alignment control stream (v_readfirstlane_b32 s2, v0/v_mov_b32_e32 v0, v1/s_endpgm) round-trips at +0/+4/+8 without shifting the stream.The VOP3 side:
So on
gfx1013the operation exists only as the 32-bit VOP1, and the VOP3A word quoted in #746 (020082d500010000) is not a valid gfx1013 encoding — which means the VOP3 formatting change may be formatting an instruction that cannot occur, or an invalid word as if it were this operation.The maintainer asked on #746: "Only change the VOP3A form if that target actually assembles the same operation there." Could you confirm the VOP3 case against the LLVM 15
gfx1013job before merging it, or drop the VOP3 half and keep the VOP1 plus the lowering? I have a narrower branch with VOP1 only, the alignment control and a VOP3A-unchanged regression test (with the reason recorded) that I can push as the VOP1 part if that is easier.Neither of us should guess here: if LLVM 15 disagrees with LLVM 21 about the VOP3 form, that is worth pinning in the test.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T02:20:14Z.
LLVM 15 on
gfx1013confirmed the VOP1 SGPR destination and rejected the_e64spelling and the proposed VOP3A bytes. Please keep the VOP1 fix and make the invalid VOP3A record consume exactly eight bytes without handing an instruction to the lowerer. Keep a followings_endpgmin both controls. For the lowering, please make the active-lane claim match the fixture: use divergent per-lane source values and an independently checked first participating lane, or keep it scoped to the uniform-source case. LLVM 15 result and byte streamImported from R0Y00/Xbox2Windows. Originally posted by FZNull on 2026-11-23T02:38:00Z.
Opened #778 with exactly the disassembler half you described, so the VOP1 SGPR fix and the invalid-VOP3A handling are not blocked on the lowering discussion:
decode_s_reg(vdst);s_endpgm, and the VOP3A control shows it at +8;pixel_aotchange.@Holastor, if you would rather land this inside #765, take the branch (
FZNull:fix/readfirstlane-sgpr, commit5d3a859) and I will close #778. Otherwise #765 only needs the lowering half plus the active-lane fixture question you raised.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T03:21:57Z.
#778 landed the destination fix, invalid VOP3A diagnostic and stream-alignment tests, and closed #746. Please update this PR against main and retain the pixel lowering and its fixture. The remaining review question is the participating-lane behavior in the lowered shader, as noted above.
Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-23T09:04:51Z.
Rebased against
main(325fe1e) with clean checks:main.tools/pixel_aot.py), scanner regex (tools/scan_unsupported_shaders.py), negative controls, and draw fixture (tests/pixel_aot_check.py).docs/experiments.mdto the uniform-source case as requested (where participating lanes hold the same value, e.g. broadcast or scalarized from SGPRs/CBs), noting that divergent per-lane source readback and non-zero first participating lane behavior remain unmeasured.Verification
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T09:11:06Z.
Thanks for separating the changes already in #778. On
1bbc606the docs describe a uniform-source experiment, but the lowerer still accepts a varying VGPR such asv8and emitsWaveReadLaneFirstfor it. The uniform-source draw would also pass if the broadcast were replaced by a per-lane read. Please either enforce the initial uniform-source restriction (and add a varying-VGPR rejection), or add a draw with distinct participating lane values and a per-lane-read negative control. Keep the non-entry EXEC rejection in either case.Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-23T09:30:32Z.
Updated in
ee32146:Enforced uniform-source restriction:
tools/pixel_aot.pytracks uniform provenance across vector registers viaVectorRegisters. A vector register is tracked as uniform when moved from an SGPR, constant buffer, immediate literal, or another uniform vector register (v_mov_b32/v_swap_b32). Any other vector write marks the destination non-uniform.v_readfirstlane_b32explicitly rejects non-uniform vector sources (ValueError: v_readfirstlane_b32 requires a uniform source register: ...).Added varying-VGPR and EXEC rejection controls:
tests/pixel_aot_check.pyasserting rejection when reading varying interpolated coordinates (v8) or barycentric inputs (v0,v1).s_wqm_b64).Documentation:
docs/experiments.mddetailing the uniform-source enforcement and the rejection controls for varying vector registers and non-entry execution masks.Verification
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T09:41:57Z.
ee32146now rejects the varying source, which addresses the previous scope issue. One small provenance case remains:v_mov_b32assignsvector[dst]before queryingvector.is_uniform(src). Ifsrc == dst,__setitem__has already cleared the tag. Please read the source tag before assignment and add a positive control forv_mov_b32_e32 v18, v18between the uniform load andv_readfirstlane_b32. Retain the varying-source rejection.Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-23T09:50:30Z.
Updated in
bb578b1:Source tag checked before assignment:
tools/pixel_aot.py,v_mov_b32now queries the source uniform status (src.startswith("s") or bool(re.fullmatch(...)) or vector.is_uniform(src)) before assigningvector[dst] = f"alu{i}". This ensures that in a self-move (src == dst),__setitem__clearingdstdoes not clobber the uniform tag before it is checked, preserving the uniform provenance of the register.Added positive and negative self-move controls:
tests/pixel_aot_check.py:check_readfirstlane_controls()testingv_mov_b32_e32 v18, v18between the uniform constant load (v_mov_b32_e32 v18, s44) andv_readfirstlane_b32 s48, v18, asserting thatWaveReadLaneFirstis emitted and the shader lowers successfully.v_mov_b32_e32 v8, v8) followed byv_readfirstlane_b32 s48, v8remains rejected (must_reject).v8,v0,v1).Documentation:
docs/experiments.mdnoting uniform self-move provenance retention.Verification