pixel_aot: v_fma_mix* reads op_sel and op_sel_hi the other way round from LLVM 15 #2054
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#2054
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?
@Not-Saii on GitHub · 2026-11-24 23:43 UTC · original
Problem
tools/pixel_aot.pylowersv_fma_mix_f32,v_fma_mixlo_f16andv_fma_mixhi_f16. It treatsop_selas "this source is binary16" andop_sel_hias "use the high half".parse_fma_mixzips them intofma_mix_operand(tok, is_f16=op_sel, is_hi=op_sel_hi), and it rejectsop_sel_hion a source withoutop_sel.LLVM 15 uses the opposite assignment (
AMDGPUDAGToDAGISel::SelectVOP3PMadMixModsImpl, llvmorg-15.0.7):That function sets
SISrcMods::OP_SEL_1for an fp16 source, andAMDGPUInstPrinter::printOpSelHiprintsOP_SEL_1asop_sel_hi.tools/ffx_dispatch_aot.pyandtools/startup/gfx2hlsl.pyboth follow LLVM's reading.Why the existing fixture passes
check_fma_mix_drawintests/pixel_aot_check.pycompares the WARP readback withfma_mix_reference, and that reference encodes the same reading as the translator. For example,v_fma_mix_f32 v12, |s44|, -v19, v20 op_sel:[1,1,0] op_sel_hi:[1,0,0]expectsabs(a_hi) * (-b_lo) + c. Under LLVM's reading, src0 is binary16 high, src1 is binary32 with an op_sel bit set (not a valid fp16 selection), and src2 is binary32.Done when
op_sel-only and oneop_sel_hi-only form would decide it.pixel_aotand its reference follow that assignment, with a control that fails under the swapped reading.AI-assisted (Claude Code).
@ChazY11 on GitHub · 2026-11-25 00:11 UTC · original
One constraint on the "native readback" bullet: the deciding machine has to be RDNA 2, not just a GPU
I can run translated shaders on hardware here — an RTX 5080 Laptop (32.0.15.8142) and the in-box WARP, driven through
offscreen_check.exewith DXC 10.0.26100 — and I do not think that helps, which is worth saying before someone spends a day on it.The question is what the gfx1013 encoding means: whether bits in
op_selor inop_sel_hiselect the fp16 interpretation. Executingtranslated HLSL on an NVIDIA adapter measures DXC and the driver, both of which have already been told which reading to use. It cannot
distinguish the two readings, because the encoding never reaches the GPU. The same applies to WARP.
The evidence that would decide it, in decreasing order of directness:
op_sel-only and anop_sel_hi-only form, with the register preloaded with two distinguishable halves. This is the only path that answers the encodingquestion directly.
llvm-mc -mcpu=gfx1013on the same words, checking which modifiername it prints for each field. That is what the issue already cites from
printOpSelHi, but printing the same word through adifferent LLVM version would show whether the assignment is stable across versions or changed, which is the part I would want
confirmed before rewriting the translator.
What I did check, since it is cheap
tools/startup/gfx2hlsl.pymix()really does follow LLVM's reading, so the issue's second-to-last paragraph is accurate as written:it maps
op_sel_hito the fp16 conversion ('f16tof32(%s)' % self.u(tok)when the bit is set), and it refusesop_seloutright(
raise Unsupported('op_sel on fma_mix')) rather than interpreting it.tools/pixel_aot.pyparse_fma_mixreads the fields the other way, and its guardif any(hi and not f16 for f16, hi in zip(op_sel, op_sel_hi))only makes sense under that reading.So the divergence the issue describes is real and both sides are internally consistent — it is the assignment that is unsettled, and it
cannot be settled from inside this repository.
The part I would keep from the issue as written
The
check_fma_mix_drawobservation is the strongest sentence in the report: a fixture whose reference is generated by the same model thatthe translator implements cannot detect a wrong field assignment, however many pixels it compares. If the two readings are to coexist until
the hardware answer arrives, the honest form is a comment in
pixel_aot.parse_fma_mixsaying the assignment is LLVM-contradicting andunverified, so the next reader does not take the passing draw check as evidence.
AI-assisted.
@Not-Saii on GitHub · 2026-11-25 00:18 UTC · original
Agreed that an NVIDIA or WARP run can't decide this, and that
parse_fma_mixshould carry a note until it is settled. An RTX 4090 is all I have here too.On your point 2: there is a second compiler that shares no code with LLVM or this repository, and it reads the fields the same way as LLVM. Mesa's ACO (the RADV backend, shipped on RDNA 2 GPUs) at
mesa-24.2.0:src/amd/compiler/aco_optimizer.cpp,combine_mad_mix(): folding an f16-to-f32 conversion intov_fma_mix_*setsopsel_hi[i] = truefor that operand. It setsopsel_lo[i]only when the conversion read the high half (an SDWAselat byte offset 2, or the conversion's ownopsel[0]).src/amd/compiler/aco_assembler.cpp:opsel_lois written to w0[13:11] (op_sel), andopsel_hito w1[28:27] plus w0[14] (op_sel_hi).So in ACO,
op_sel_hialso means "binary16 source" andop_selmeans "high half". If ACO had these swapped, RADV's mixed-precision code would produce wrong results on RDNA 2 hardware in shipping drivers. That is indirect, but it is evidence from compiled code running on RDNA 2, not only from a printer.A direct RDNA 2 readback of an
op_sel-only and anop_sel_hi-only form would still be the cleanest proof, if someone has an RX 6000 card.AI-assisted (Claude Code).
@R0Y00 on GitHub · 2026-11-25 00:35 UTC · original
Fixed in #2100 (
72e26e7f). AMD RDNA 2 ISA section 12.10 lists full-width inputs for selector values 0 and 1, low half for 2, and high half for 3. LLVM documents op_sel_hi as the width bit and op_sel as the half selector for MIX, consistent with the independent ACO path linked above. The swapped-selector control is now exercised by the translated draw, which I reran on WARP and RTX 4060 Laptop. This closes the selector correction; the desktop runs exercise the translation and do not constitute native RDNA 2 readback. https://llvm.org/docs/AMDGPUModifierSyntax.html#vop3p-mad-mix-fma-mix-modifiers https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf