shader: lower v_pk_fmac_f16 in pixel_aot #997

Merged
rasptum merged 3 commits from upstream-pr/1004 into main 2026-11-23 22:07:41 +00:00
rasptum commented 2026-11-23 20:44:38 +00:00 (Migrated from github.com)

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


Refs #990

Summary

  • Lower the VOP2 packed binary16 multiply-accumulate instruction (v_pk_fmac_f16 / v_pk_fmac_f16_e32, AMD RDNA 2 ISA §12.11 opcode 0x3c, LLVM 15 VOP2Instructions.td: V_PK_FMAC_F16) in tools/pixel_aot.py using vdst as the implicit packed accumulator (vdst.f16[0] = src0.f16[0] * vsrc1.f16[0] + vdst.f16[0], vdst.f16[1] = src0.f16[1] * vsrc1.f16[1] + vdst.f16[1]), reusing vop3p_f16_word, widen16, binary32 mad, and pack16_rne.
  • Enforce the plain VOP2 operand and rounding/denorm contract: refuse an uninitialized vdst (or scalar half16 value), non-VGPR vsrc1, modifiers (clamp, op_sel, op_sel_hi, neg_lo, neg_hi, abs, -, mul), unmodelled encodings (_e64, DPP, SDWA), out-of-range/unbound operands, and round-toward-zero mode.
  • Add draw-pk-fmac in tests/pixel_aot_check.py (exact R32G32B32A32_UINT readback across four constant sets covering VGPR/SGPR/32-bit literal/inline-f16 src0, chained accumulation, in-place dst == src1, exact binary16 halfway ties, subnormals under both -denorm preserve and -denorm ftz, and signed infinity overflow), three negative draw controls (dropped accumulator, swapped halves, truncated rounding—each must report pixel_mismatch), static refusal controls, and binary round-trip registration in check_binary.
  • Register pixel_aot_pk_fmac_warp and pixel_aot_pk_fmac_hardware (SKIP_RETURN_CODE 77, FORM_COVERAGE_RECORD) in CMakeLists.txt, add check_pk_fmac_coverage() in tests/form_coverage_check.py, and document the fixture in docs/experiments.md.

Verification

Commit: 09c7583 (based on origin/main d7c52d2), Windows 10 x64, D3D12 debug layer enabled.

  • ctest --preset dev --no-tests=error -R "^pixel_aot_pk_fmac_" -V:
    • pixel_aot_pk_fmac_hardware (NVIDIA GeForce RTX 3060, driver 32.0.15.9636, debug_layer=enabled, debug_errors=0 debug_warnings=0): Passed
    • pixel_aot_pk_fmac_warp (Microsoft Basic Render Driver, driver 10.0.19041.5794, debug_layer=enabled, debug_errors=0 debug_warnings=0): Passed
  • ctest --preset release --no-tests=error -R "^pixel_aot_pk_fmac_" -V:
    • pixel_aot_pk_fmac_hardware: Passed (4.25 sec)
    • pixel_aot_pk_fmac_warp: Passed (2.21 sec)
  • Regression check ctest --preset dev --no-tests=error -R "^pixel_aot_" and ctest --preset release --no-tests=error -R "^pixel_aot_":
    • 106/108 passed on both dev and release (including pixel_aot_warp, pixel_aot_hardware, pixel_aot_pk_fmac_warp, pixel_aot_pk_fmac_hardware, pixel_aot_blend_scalar_warp, pixel_aot_title_loads_hardware).
    • Two pre-existing unrelated local environment failures: pixel_aot_blend_scalar_hardware (RTX 3060) and pixel_aot_title_loads_warp (Win10 WARP 10.0.19041.5794).
  • Pure-Python checks:
    • .\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py: Passed (form coverage checks passed)
    • .\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py: Passed (Checked 13 Markdown files and 205 links.)
    • .\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py: Passed (Checked 827 tracked source, script and build/CI files: no bidirectional controls.)
  • LLVM 15 tests/pixel_aot_check.py binary: LLVM 15 (llvm-mc-15 / libLLVM-15) is not installed locally on this Windows host; pk_fmac_program() is registered in check_binary for Ubuntu CI.

AI-assisted (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6568465953 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1004). Originally posted by [rasptum](https://github.com/rasptum) on 2026-11-23T20:44:38Z. --- Refs #990 ## Summary - Lower the `VOP2` packed binary16 multiply-accumulate instruction (`v_pk_fmac_f16` / `v_pk_fmac_f16_e32`, AMD RDNA 2 ISA §12.11 opcode `0x3c`, LLVM 15 `VOP2Instructions.td`: `V_PK_FMAC_F16`) in `tools/pixel_aot.py` using `vdst` as the implicit packed accumulator (`vdst.f16[0] = src0.f16[0] * vsrc1.f16[0] + vdst.f16[0]`, `vdst.f16[1] = src0.f16[1] * vsrc1.f16[1] + vdst.f16[1]`), reusing `vop3p_f16_word`, `widen16`, binary32 `mad`, and `pack16_rne`. - Enforce the plain VOP2 operand and rounding/denorm contract: refuse an uninitialized `vdst` (or scalar `half16` value), non-VGPR `vsrc1`, modifiers (`clamp`, `op_sel`, `op_sel_hi`, `neg_lo`, `neg_hi`, `abs`, `-`, `mul`), unmodelled encodings (`_e64`, DPP, SDWA), out-of-range/unbound operands, and round-toward-zero mode. - Add `draw-pk-fmac` in `tests/pixel_aot_check.py` (exact `R32G32B32A32_UINT` readback across four constant sets covering VGPR/SGPR/32-bit literal/inline-`f16` `src0`, chained accumulation, in-place `dst == src1`, exact binary16 halfway ties, subnormals under both `-denorm preserve` and `-denorm ftz`, and signed infinity overflow), three negative draw controls (dropped accumulator, swapped halves, truncated rounding—each must report `pixel_mismatch`), static refusal controls, and binary round-trip registration in `check_binary`. - Register `pixel_aot_pk_fmac_warp` and `pixel_aot_pk_fmac_hardware` (`SKIP_RETURN_CODE 77`, `FORM_COVERAGE_RECORD`) in `CMakeLists.txt`, add `check_pk_fmac_coverage()` in `tests/form_coverage_check.py`, and document the fixture in `docs/experiments.md`. ## Verification Commit: `09c7583` (based on `origin/main` `d7c52d2`), Windows 10 x64, D3D12 debug layer enabled. - `ctest --preset dev --no-tests=error -R "^pixel_aot_pk_fmac_" -V`: - `pixel_aot_pk_fmac_hardware` (NVIDIA GeForce RTX 3060, driver `32.0.15.9636`, `debug_layer=enabled`, `debug_errors=0 debug_warnings=0`): **Passed** - `pixel_aot_pk_fmac_warp` (Microsoft Basic Render Driver, driver `10.0.19041.5794`, `debug_layer=enabled`, `debug_errors=0 debug_warnings=0`): **Passed** - `ctest --preset release --no-tests=error -R "^pixel_aot_pk_fmac_" -V`: - `pixel_aot_pk_fmac_hardware`: **Passed** (`4.25 sec`) - `pixel_aot_pk_fmac_warp`: **Passed** (`2.21 sec`) - Regression check `ctest --preset dev --no-tests=error -R "^pixel_aot_"` and `ctest --preset release --no-tests=error -R "^pixel_aot_"`: - 106/108 passed on both `dev` and `release` (including `pixel_aot_warp`, `pixel_aot_hardware`, `pixel_aot_pk_fmac_warp`, `pixel_aot_pk_fmac_hardware`, `pixel_aot_blend_scalar_warp`, `pixel_aot_title_loads_hardware`). - Two pre-existing unrelated local environment failures: `pixel_aot_blend_scalar_hardware` (RTX 3060) and `pixel_aot_title_loads_warp` (Win10 WARP `10.0.19041.5794`). - Pure-Python checks: - `.\out\pe-env\Scripts\python.exe -B tests/form_coverage_check.py`: **Passed** (`form coverage checks passed`) - `.\out\pe-env\Scripts\python.exe -B tests/docs_links_check.py`: **Passed** (`Checked 13 Markdown files and 205 links.`) - `.\out\pe-env\Scripts\python.exe -B tests/bidi_controls_check.py`: **Passed** (`Checked 827 tracked source, script and build/CI files: no bidirectional controls.`) - LLVM 15 `tests/pixel_aot_check.py binary`: LLVM 15 (`llvm-mc-15` / `libLLVM-15`) is not installed locally on this Windows host; `pk_fmac_program()` is registered in `check_binary` for Ubuntu CI. AI-assisted (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 06:45:48 +00:00
R0Y00 commented 2026-11-24 06:49:39 +00:00 (Migrated from github.com)

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


The current reference explicitly rounds the accumulated result to binary32 before packing, and the generated HLSL takes the same path. That does not cover the fused binary16 result discussed in #990. Please add the exact discriminator from that thread to the actual readback: low halves 0x3e00, 0x3956, accumulator 0x0001 give direct half RNE 0x3c01, intermediate f32 then half 0x3c00. Use an exact reference (integer or rational), establish the claimed denormal mode independently, and make the intermediate-f32 mutant fail at that lane. A broader input domain needs evidence for accepted NaNs, infinities, signed zero, and overflow. The fixture and alias checks can stay while the precision path is corrected.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7113528561 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1004#issuecomment-7113528561). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T20:46:03Z. --- The current reference explicitly rounds the accumulated result to binary32 before packing, and the generated HLSL takes the same path. That does not cover the fused binary16 result discussed in #990. Please add the exact discriminator from that thread to the actual readback: low halves `0x3e00`, `0x3956`, accumulator `0x0001` give direct half RNE `0x3c01`, intermediate f32 then half `0x3c00`. Use an exact reference (integer or rational), establish the claimed denormal mode independently, and make the intermediate-f32 mutant fail at that lane. A broader input domain needs evidence for accepted NaNs, infinities, signed zero, and overflow. The fixture and alias checks can stay while the precision path is corrected.
rasptum commented 2026-11-24 06:49:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by rasptum on 2026-11-23T21:46:08Z.


Thanks. Addressed in 5b2b07b (plus a merge of main, no force-push):

  1. Fused result, rounded once. The lowering no longer goes through binary32. A pure-integer HLSL helper (fma16_rne) forms the exact 22-bit significand product, aligns the accumulator with a sticky bit, and rounds once to binary16 RNE, independent of -denorm ftz.
  2. Discriminator in the actual readback. 0x3e00 × 0x3956 + 0x0001 is lane 0 low half of the precision program and lane 3 high half of alias_chain. Both read back 0x3c01 on WARP and RTX 3060, dev and release, under -denorm preserve and -denorm ftz.
  3. Intermediate-f32 mutant. pack16_rne(mad(widen16(...))) reports pixel_mismatch only at those lanes: expected=0xbc003c01 actual=0xbc003c00 and expected=0x3c010401 actual=0x3c000401. The other channels are unchanged.
  4. Exact reference. The Python reference uses fractions.Fraction and rounds once to binary16 RNE.
  5. Denormal mode established separately. Dedicated lanes differ between preserve and flush: 0x0001 × 0x3c00 + 0x0001 = 0x0002, 0x0400 × 0x3800 = 0x0200, and a subnormal-to-normal carry 0x0001 × 0x4000 + 0x03ff = 0x0401. Flush-in and flush-out mutants fail at exactly those lanes. The fixture asserts the preserve profile.
  6. Domain. Only the finite preserve/RNE profile is accepted. NaN/Inf halves, overflowing results, unproven runtime operands, RTZ and unknown denormal modes are refused at translation time, so no claim is made about them.

The alias checks, distinct lane inputs, uninitialized-destination and modifier refusals stay. Tests: ctest -R "^pixel_aot_pk_fmac_" 2/2 in dev and release; neighbours pack_b32, dpp_extra, f16_arith and region_body pass on the merged tree, along with the three Python checks.

AI-assisted (Claude Code).

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7114893135 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1004#issuecomment-7114893135). Originally posted by [rasptum](https://github.com/rasptum) on 2026-11-23T21:46:08Z. --- Thanks. Addressed in `5b2b07b` (plus a merge of `main`, no force-push): 1. **Fused result, rounded once.** The lowering no longer goes through binary32. A pure-integer HLSL helper (`fma16_rne`) forms the exact 22-bit significand product, aligns the accumulator with a sticky bit, and rounds once to binary16 RNE, independent of `-denorm ftz`. 2. **Discriminator in the actual readback.** `0x3e00 × 0x3956 + 0x0001` is lane 0 low half of the `precision` program and lane 3 high half of `alias_chain`. Both read back `0x3c01` on WARP and RTX 3060, dev and release, under `-denorm preserve` and `-denorm ftz`. 3. **Intermediate-f32 mutant.** `pack16_rne(mad(widen16(...)))` reports `pixel_mismatch` only at those lanes: `expected=0xbc003c01 actual=0xbc003c00` and `expected=0x3c010401 actual=0x3c000401`. The other channels are unchanged. 4. **Exact reference.** The Python reference uses `fractions.Fraction` and rounds once to binary16 RNE. 5. **Denormal mode established separately.** Dedicated lanes differ between preserve and flush: `0x0001 × 0x3c00 + 0x0001 = 0x0002`, `0x0400 × 0x3800 = 0x0200`, and a subnormal-to-normal carry `0x0001 × 0x4000 + 0x03ff = 0x0401`. Flush-in and flush-out mutants fail at exactly those lanes. The fixture asserts the preserve profile. 6. **Domain.** Only the finite preserve/RNE profile is accepted. NaN/Inf halves, overflowing results, unproven runtime operands, RTZ and unknown denormal modes are refused at translation time, so no claim is made about them. The alias checks, distinct lane inputs, uninitialized-destination and modifier refusals stay. Tests: `ctest -R "^pixel_aot_pk_fmac_"` 2/2 in dev and release; neighbours `pack_b32`, `dpp_extra`, `f16_arith` and `region_body` pass on the merged tree, along with the three Python checks. AI-assisted (Claude Code).
R0Y00 commented 2026-11-24 06:49:45 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-23T21:56:03Z.


The updated 4648502f passes the LLVM 15 round trip and both focused Windows draws on RTX 4060 Laptop and in-box WARP. I reproduced 0x3c01 in both witness lanes, and the intermediate-f32 mutation returned 0x3c00 where expected. The emitted 32-bit integer helper also matched an independent exact-integer reference across 163,824 finite triples, including cancellations, signed zeros, subnormals and the overflow boundary. The accepted slice remains statically proven finite operands, declared f16 preserve and RNE.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7115110637 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/1004#issuecomment-7115110637). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-23T21:56:03Z. --- The updated `4648502f` passes the LLVM 15 round trip and both focused Windows draws on RTX 4060 Laptop and in-box WARP. I reproduced `0x3c01` in both witness lanes, and the intermediate-f32 mutation returned `0x3c00` where expected. The emitted 32-bit integer helper also matched an independent exact-integer reference across 163,824 finite triples, including cancellations, signed zeros, subnormals and the overflow boundary. The accepted slice remains statically proven finite operands, declared f16 preserve and RNE.
Sign in to join this conversation.
No reviewers
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!997
No description provided.