shader: lower v_pk_fmac_f16 in pixel_aot #983

Closed
opened 2026-11-23 20:12:53 +00:00 by rasptum · 2 comments
rasptum commented 2026-11-23 20:12:53 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by rasptum on 2026-11-23T20:12:53Z.


tools/pixel_aot.py currently rejects the VOP2 packed binary16 multiply-accumulate form (v_pk_fmac_f16 / v_pk_fmac_f16_e32) with ValueError: Unsupported instruction 23: v_pk_fmac_f16 v12, v13, v14 (same for _e32), leaving VOP2 v_pk_fmac_f16 uncovered in docs/coverage/gfx1013.tsv and docs/coverage/rdna2.tsv.

ISA definition: AMD RDNA 2 ISA Reference Guide §12.11 (VOP2 Instructions, V_PK_FMAC_F16, opcode 60 / 0x3c) and LLVM 15 llvm/lib/Target/AMDGPU/VOP2Instructions.td (V_PK_FMAC_F16, VOP_MAC_F16 packed 32-bit VOP2 encoding): D.f16[0] = S0.f16[0] * S1.f16[0] + D.f16[0] and D.f16[1] = S0.f16[1] * S1.f16[1] + D.f16[1] with vdst as the implicit packed accumulator.

I am taking this as one small PR: lower v_pk_fmac_f16 / v_pk_fmac_f16_e32 in tools/pixel_aot.py reusing the existing packed binary16 widen16 / pack16_rne helpers, refusing uninitialized vdst, unsupported modifiers, op_sel/neg, and _e64/DPP/SDWA spellings.

Test plan: add draw-pk-fmac in tests/pixel_aot_check.py with exact R32G32B32A32_UINT readback on WARP (pixel_aot_pk_fmac_warp) and a hardware entry with SKIP_RETURN_CODE 77 (pixel_aot_pk_fmac_hardware), Python reference model, negative controls (dropped accumulator, swapped halves, wrong rounding must each report pixel_mismatch) plus static refusals, a tests/form_coverage_check.py assertion, and a docs/experiments.md entry.

AI-assisted (Claude Code)

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6567906680 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/990). Originally posted by [rasptum](https://github.com/rasptum) on 2026-11-23T20:12:53Z. --- `tools/pixel_aot.py` currently rejects the VOP2 packed binary16 multiply-accumulate form (`v_pk_fmac_f16` / `v_pk_fmac_f16_e32`) with `ValueError: Unsupported instruction 23: v_pk_fmac_f16 v12, v13, v14` (same for `_e32`), leaving `VOP2 v_pk_fmac_f16` uncovered in `docs/coverage/gfx1013.tsv` and `docs/coverage/rdna2.tsv`. ISA definition: AMD RDNA 2 ISA Reference Guide §12.11 (VOP2 Instructions, `V_PK_FMAC_F16`, opcode 60 / `0x3c`) and LLVM 15 `llvm/lib/Target/AMDGPU/VOP2Instructions.td` (`V_PK_FMAC_F16`, `VOP_MAC_F16` packed 32-bit VOP2 encoding): `D.f16[0] = S0.f16[0] * S1.f16[0] + D.f16[0]` and `D.f16[1] = S0.f16[1] * S1.f16[1] + D.f16[1]` with `vdst` as the implicit packed accumulator. I am taking this as one small PR: lower `v_pk_fmac_f16` / `v_pk_fmac_f16_e32` in `tools/pixel_aot.py` reusing the existing packed binary16 `widen16` / `pack16_rne` helpers, refusing uninitialized `vdst`, unsupported modifiers, `op_sel`/`neg`, and `_e64`/DPP/SDWA spellings. Test plan: add `draw-pk-fmac` in `tests/pixel_aot_check.py` with exact `R32G32B32A32_UINT` readback on WARP (`pixel_aot_pk_fmac_warp`) and a hardware entry with `SKIP_RETURN_CODE 77` (`pixel_aot_pk_fmac_hardware`), Python reference model, negative controls (dropped accumulator, swapped halves, wrong rounding must each report `pixel_mismatch`) plus static refusals, a `tests/form_coverage_check.py` assertion, and a `docs/experiments.md` entry. AI-assisted (Claude Code)
R0Y00 commented 2026-11-24 06:49:37 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T20:16:35Z.


Please proceed with the verified VOP2 scope and both halves of the original destination as the accumulator. Use exact half bits for a rounding control that distinguishes a fused half result from a binary32 computation followed by half packing. For example, in a finite preserve/RNE profile, 0x3e00 × 0x3956 + 0x0001 is exactly 16785409/16777216. Rounding it directly to half gives 0x3c01, while rounding through binary32 first gives 0x3c00. I checked that distinction with exact rational arithmetic and binary32/half conversion. Treat it as a differentiating reference case, and verify the mode used by the fixture. Include a source aliasing the destination, distinct lane inputs, and uninitialized destination/modifier refusals. The widening and packing helpers alone do not establish the intermediate precision.

AMD RDNA 2 VOP2 definition

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7112838246 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/990#issuecomment-7112838246). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T20:16:35Z. --- Please proceed with the verified VOP2 scope and both halves of the original destination as the accumulator. Use exact half bits for a rounding control that distinguishes a fused half result from a binary32 computation followed by half packing. For example, in a finite preserve/RNE profile, 0x3e00 × 0x3956 + 0x0001 is exactly 16785409/16777216. Rounding it directly to half gives 0x3c01, while rounding through binary32 first gives 0x3c00. I checked that distinction with exact rational arithmetic and binary32/half conversion. Treat it as a differentiating reference case, and verify the mode used by the fixture. Include a source aliasing the destination, distinct lane inputs, and uninitialized destination/modifier refusals. The widening and packing helpers alone do not establish the intermediate precision. [AMD RDNA 2 VOP2 definition](https://docs.amd.com/api/khub/documents/Et~wpu9g~Ffl7d9q0QZ~Og/content)
R0Y00 commented 2026-11-24 06:49:46 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T22:10:25Z.


The agreed VOP2 finite preserve/RNE slice landed in #1004 (64ecc873). The actual raw readback gives 0x3c01 for the exact half-FMA witness, and the intermediate-f32 control gives 0x3c00. Runtime operands without proven finite halves, other denormal or rounding modes, and DPP/SDWA remain separate work.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7115418702 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/990#issuecomment-7115418702). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T22:10:25Z. --- The agreed VOP2 finite preserve/RNE slice landed in #1004 (64ecc873). The actual raw readback gives 0x3c01 for the exact half-FMA witness, and the intermediate-f32 control gives 0x3c00. Runtime operands without proven finite halves, other denormal or rounding modes, and DPP/SDWA remain separate work.
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#983
No description provided.