pixel_aot: v_fma_mix* reads op_sel and op_sel_hi the other way round from LLVM 15 #2047

Closed
opened 2026-11-24 23:43:43 +00:00 by Not-Saii · 3 comments
Not-Saii commented 2026-11-24 23:43:43 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by Not-Saii on 2026-11-24T23:43:43Z.


Problem

tools/pixel_aot.py lowers v_fma_mix_f32, v_fma_mixlo_f16 and v_fma_mixhi_f16. It treats op_sel as "this source is binary16" and op_sel_hi as "use the high half". parse_fma_mix zips them into fma_mix_operand(tok, is_f16=op_sel, is_hi=op_sel_hi), and it rejects op_sel_hi on a source without op_sel.

LLVM 15 uses the opposite assignment (AMDGPUDAGToDAGISel::SelectVOP3PMadMixModsImpl, llvmorg-15.0.7):

If the source's op_sel_hi is set, it indicates to do a conversion from fp16. If the sources's op_sel is set, it picks the high half of the source register.

That function sets SISrcMods::OP_SEL_1 for an fp16 source, and AMDGPUInstPrinter::printOpSelHi prints OP_SEL_1 as op_sel_hi. tools/ffx_dispatch_aot.py and tools/startup/gfx2hlsl.py both follow LLVM's reading.

Why the existing fixture passes

check_fma_mix_draw in tests/pixel_aot_check.py compares the WARP readback with fma_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] expects abs(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

  • A native readback or an assembler-and-ISA-backed reference settles the field assignment. Native hardware output for one op_sel-only and one op_sel_hi-only form would decide it.
  • pixel_aot and its reference follow that assignment, with a control that fails under the swapped reading.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6593722844 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2054). Originally posted by [Not-Saii](https://github.com/Not-Saii) on 2026-11-24T23:43:43Z. --- ## Problem `tools/pixel_aot.py` lowers `v_fma_mix_f32`, `v_fma_mixlo_f16` and `v_fma_mixhi_f16`. It treats `op_sel` as "this source is binary16" and `op_sel_hi` as "use the high half". `parse_fma_mix` zips them into `fma_mix_operand(tok, is_f16=op_sel, is_hi=op_sel_hi)`, and it rejects `op_sel_hi` on a source without `op_sel`. LLVM 15 uses the opposite assignment (`AMDGPUDAGToDAGISel::SelectVOP3PMadMixModsImpl`, llvmorg-15.0.7): > If the source's op_sel_hi is set, it indicates to do a conversion from fp16. If the sources's op_sel is set, it picks the high half of the source register. That function sets `SISrcMods::OP_SEL_1` for an fp16 source, and `AMDGPUInstPrinter::printOpSelHi` prints `OP_SEL_1` as `op_sel_hi`. `tools/ffx_dispatch_aot.py` and `tools/startup/gfx2hlsl.py` both follow LLVM's reading. ## Why the existing fixture passes `check_fma_mix_draw` in `tests/pixel_aot_check.py` compares the WARP readback with `fma_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]` expects `abs(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 - A native readback or an assembler-and-ISA-backed reference settles the field assignment. Native hardware output for one `op_sel`-only and one `op_sel_hi`-only form would decide it. - `pixel_aot` and its reference follow that assignment, with a control that fails under the swapped reading. AI-assisted (Claude Code).
ChazY11 commented 2026-11-25 01:02:03 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T00:11:47Z.


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.exe with 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_sel or in op_sel_hi select the fp16 interpretation. Executing
translated 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:

  1. RDNA 2 hardware (a console in dev mode, or an RX 6000 card) running the same operand pair through an op_sel-only and an
    op_sel_hi-only form, with the register preloaded with two distinguishable halves. This is the only path that answers the encoding
    question directly.
  2. A disassembler that shares no code with this repository — llvm-mc -mcpu=gfx1013 on the same words, checking which modifier
    name it prints for each field. That is what the issue already cites from printOpSelHi, but printing the same word through a
    different 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.
  3. Nothing on a non-AMD adapter, which is where I am.

What I did check, since it is cheap

  • tools/startup/gfx2hlsl.py mix() really does follow LLVM's reading, so the issue's second-to-last paragraph is accurate as written:
    it maps op_sel_hi to the fp16 conversion ('f16tof32(%s)' % self.u(tok) when the bit is set), and it refuses op_sel outright
    (raise Unsupported('op_sel on fma_mix')) rather than interpreting it.
  • tools/pixel_aot.py parse_fma_mix reads the fields the other way, and its guard
    if 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_draw observation is the strongest sentence in the report: a fixture whose reference is generated by the same model that
the 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_mix saying the assignment is LLVM-contradicting and
unverified, so the next reader does not take the passing draw check as evidence.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7148251056 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2054#issuecomment-7148251056). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-25T00:11:47Z. --- ## 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.exe` with 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_sel` or in `op_sel_hi` select the fp16 interpretation. Executing *translated 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: 1. **RDNA 2 hardware** (a console in dev mode, or an RX 6000 card) running the same operand pair through an `op_sel`-only and an `op_sel_hi`-only form, with the register preloaded with two distinguishable halves. This is the only path that answers the encoding question directly. 2. **A disassembler that shares no code with this repository** — `llvm-mc -mcpu=gfx1013` on the same words, checking which modifier name it prints for each field. That is what the issue already cites from `printOpSelHi`, but printing the same word through a *different* 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. 3. Nothing on a non-AMD adapter, which is where I am. ## What I did check, since it is cheap - `tools/startup/gfx2hlsl.py` `mix()` really does follow LLVM's reading, so the issue's second-to-last paragraph is accurate as written: it maps `op_sel_hi` to the fp16 conversion (`'f16tof32(%s)' % self.u(tok)` when the bit is set), and it refuses `op_sel` outright (`raise Unsupported('op_sel on fma_mix')`) rather than interpreting it. - `tools/pixel_aot.py` `parse_fma_mix` reads the fields the other way, and its guard `if 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_draw` observation is the strongest sentence in the report: a fixture whose reference is generated by the same model that the 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_mix` saying the assignment is LLVM-contradicting and unverified, so the next reader does not take the passing draw check as evidence. AI-assisted.
Not-Saii commented 2026-11-25 01:02:04 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by Not-Saii on 2026-11-25T00:18:32Z.


Agreed that an NVIDIA or WARP run can't decide this, and that parse_fma_mix should 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 into v_fma_mix_* sets opsel_hi[i] = true for that operand. It sets opsel_lo[i] only when the conversion read the high half (an SDWA sel at byte offset 2, or the conversion's own opsel[0]).
  • src/amd/compiler/aco_assembler.cpp: opsel_lo is written to w0[13:11] (op_sel), and opsel_hi to w1[28:27] plus w0[14] (op_sel_hi).

So in ACO, op_sel_hi also means "binary16 source" and op_sel means "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 an op_sel_hi-only form would still be the cleanest proof, if someone has an RX 6000 card.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7148373136 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2054#issuecomment-7148373136). Originally posted by [Not-Saii](https://github.com/Not-Saii) on 2026-11-25T00:18:32Z. --- Agreed that an NVIDIA or WARP run can't decide this, and that `parse_fma_mix` should 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 into `v_fma_mix_*` sets `opsel_hi[i] = true` for that operand. It sets `opsel_lo[i]` only when the conversion read the high half (an SDWA `sel` at byte offset 2, or the conversion's own `opsel[0]`). - `src/amd/compiler/aco_assembler.cpp`: `opsel_lo` is written to w0[13:11] (`op_sel`), and `opsel_hi` to w1[28:27] plus w0[14] (`op_sel_hi`). So in ACO, `op_sel_hi` also means "binary16 source" and `op_sel` means "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 an `op_sel_hi`-only form would still be the cleanest proof, if someone has an RX 6000 card. AI-assisted (Claude Code).
R0Y00 commented 2026-11-25 01:02:07 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-25T00:35:34Z.


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

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7148672612 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2054#issuecomment-7148672612). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-25T00:35:34Z. --- 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
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows#2047
No description provided.