shader: lower gfx1013 v_madak_f32 and v_madmk_f32 in pixel_aot #595

Manually merged
github merged 2 commits from gh-pr/595/head into gh-pr/595/base 2026-11-26 22:04:29 +00:00
Owner

@⁠JB2WIN on GitHub · 2026-11-22 14:49 UTC · original
JB2WIN:shader/madak-madmk → main · +75 −3 · 5 files · 2 commits · merged 2026-11-22 15:29 UTC

Change

tools/pixel_aot.py now lowers the VOP2 literal multiply-adds v_madak_f32 (S0·S1 + K) and v_madmk_f32 (S0·K + S1) in the same branch as v_fmaak_f32/v_fmamk_f32. The operand rules are the same: K must be a 32-bit hex literal, in the last position for madak and the second for madmk; the entry mask applies; and no write may land on an outstanding sample. Unlike the fused forms, these go through the existing non-fused mad32 helper (ALU mad, as for v_mad_f32/v_mac_f32). They therefore round the product before the add and flush binary32 denormals as that helper does.

  • Rejections: a register in the K position, and the e64/DPP/SDWA spellings. LLVM 15 itself refuses v_madak_f32_e64 ("e64 variant of this instruction is not supported").
  • The scanner accepts madak/madmk only with a hex K in that position, so v_madak_f32 v5, v1, v2, v3 stays unsupported, matching lower(). The existing fmaak/fmamk scanner pattern is coarser (it allows any K). I left it unchanged because that is outside this change.

Fixes #590. AI-assisted (Claude Code).

Verification

Windows 11 (10.0.26200.9974), NVIDIA GeForce RTX 3080 (driver 32.0.16.2124) and WARP 10.0.26100.9818, head rebased on 8ae1377.

  • New draw check_mad_literal_draw in the blend-scalar mode, next to check_mad_draw. Channels 0/1 are madak/madmk on 4097·4097 − 16785408, which gives 0.0 non-fused and 1.0 fused. Channels 2/3 are madak/madmk on 2⁻¹²⁷·2¹²⁶ + 0.5, which gives 0.5 with the denormal flush and 1.0 without. A reference expecting the fused or denormal-preserving result in any one channel must report pixel_mismatch, and it does. A dev-time mutation (not part of CI) that lowered both through fma made the draw fail with pixel_mismatch.
  • ctest --preset dev --no-tests=error -R "^(pixel_aot_|rdna2_tools_check$|pso_readiness)" gives 20/20 on the rebased head. pixel_aot_blend_scalar_hardware takes about 35 s, under the 60 s timeout.
  • Full ctest --preset dev --no-tests=error (before the last trivial rebase) gives 278/278, with skips bvh_wave64_hardware, bvh_wave64_warp and wave_shuffle_warp.
  • tests/pixel_aot_check.py binary with LLVM 15.0.7, locally: exit 0. pixel_aot_check.py (controls), rdna2_tools_check.py, form_coverage_check.py and docs_links_check.py all pass.

Evidence and follow-up

  • Synthetic inputs only.
  • Not measured: whether Scarlett flushes denormals for these forms the same way the helper does. docs/experiments.md says so.
  • Gap noticed in passing: tools/disasm_rdna2.py does not know VOP2 opcodes 0x20/0x21, so binary scanning of madak/madmk shows v_vop2_20/21. That is a separate fix.

🤖 Generated with Claude Code

**@⁠JB2WIN** on GitHub · 2026-11-22 14:49 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/595) `JB2WIN:shader/madak-madmk` → `main` · +75 −3 · 5 files · 2 commits · merged 2026-11-22 15:29 UTC ## Change `tools/pixel_aot.py` now lowers the VOP2 literal multiply-adds `v_madak_f32` (S0·S1 + K) and `v_madmk_f32` (S0·K + S1) in the same branch as `v_fmaak_f32`/`v_fmamk_f32`. The operand rules are the same: K must be a 32-bit hex literal, in the last position for madak and the second for madmk; the entry mask applies; and no write may land on an outstanding sample. Unlike the fused forms, these go through the existing non-fused `mad32` helper (ALU `mad`, as for `v_mad_f32`/`v_mac_f32`). They therefore round the product before the add and flush binary32 denormals as that helper does. - Rejections: a register in the K position, and the e64/DPP/SDWA spellings. LLVM 15 itself refuses `v_madak_f32_e64` ("e64 variant of this instruction is not supported"). - The scanner accepts madak/madmk only with a hex K in that position, so `v_madak_f32 v5, v1, v2, v3` stays unsupported, matching `lower()`. The existing fmaak/fmamk scanner pattern is coarser (it allows any K). I left it unchanged because that is outside this change. Fixes #590. AI-assisted (Claude Code). ## Verification Windows 11 (10.0.26200.9974), NVIDIA GeForce RTX 3080 (driver 32.0.16.2124) and WARP 10.0.26100.9818, head rebased on `8ae1377`. - New draw `check_mad_literal_draw` in the `blend-scalar` mode, next to `check_mad_draw`. Channels 0/1 are madak/madmk on 4097·4097 − 16785408, which gives 0.0 non-fused and 1.0 fused. Channels 2/3 are madak/madmk on 2⁻¹²⁷·2¹²⁶ + 0.5, which gives 0.5 with the denormal flush and 1.0 without. A reference expecting the fused or denormal-preserving result in any one channel must report `pixel_mismatch`, and it does. A dev-time mutation (not part of CI) that lowered both through `fma` made the draw fail with `pixel_mismatch`. - `ctest --preset dev --no-tests=error -R "^(pixel_aot_|rdna2_tools_check$|pso_readiness)"` gives 20/20 on the rebased head. `pixel_aot_blend_scalar_hardware` takes about 35 s, under the 60 s timeout. - Full `ctest --preset dev --no-tests=error` (before the last trivial rebase) gives 278/278, with skips `bvh_wave64_hardware`, `bvh_wave64_warp` and `wave_shuffle_warp`. - `tests/pixel_aot_check.py binary` with LLVM 15.0.7, locally: exit 0. `pixel_aot_check.py` (controls), `rdna2_tools_check.py`, `form_coverage_check.py` and `docs_links_check.py` all pass. ## Evidence and follow-up - Synthetic inputs only. - Not measured: whether Scarlett flushes denormals for these forms the same way the helper does. `docs/experiments.md` says so. - Gap noticed in passing: `tools/disasm_rdna2.py` does not know VOP2 opcodes 0x20/0x21, so binary scanning of madak/madmk shows `v_vop2_20/21`. That is a separate fix. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Lower the non-fused VOP2 literal forms next to v_fmaak/v_fmamk with the
same operand rules (K is a 32-bit hex literal, last operand for madak and
second for madmk; entry mask; no write over an outstanding sample), using
the unfused, denormal-flushing mad32 helper instead of fma. Register in the
K position and e64/DPP/SDWA spellings are rejected.

Adds a draw whose fused and unfused results differ (4097*4097-16785408 is 0
unfused, 1.0 fused; 2^-127*2^126+0.5 tests denormal flushing), static and
rejection checks, an LLVM 15 round-trip fixture, scanner support with
tests, and a docs/experiments.md paragraph.

Fixes #590

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 22:04:28 +00:00
github manually merged commit e17124bb06 into gh-pr/595/base 2026-11-26 22:04:29 +00:00
Author
Owner

@⁠alexander-src on GitHub · 2026-11-22 15:11 UTC · original

Independent Linux x64 + LLVM 23.1.4 check on e17124b:

  • v_madak_f32 and v_madmk_f32 route cleanly through the existing unfused denormal-flushing mad32 helper with literal placement validated at operand 2 (ak) or operand 1 (mk), matching the updated regexes in tools/scan_unsupported_shaders.py.
  • Local checks passing on e17124b: pixel_aot_check.py binary (LLVM 23), rdna2_tools_check.py, pso_readiness_check.py, form_coverage_check.py, docs_links_check.py, and bidi_controls_check.py.

Windows DXC/WARP and hardware draws were not run locally on Linux.

AI-assisted: yes

**@⁠alexander-src** on GitHub · 2026-11-22 15:11 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/595#issuecomment-7081118921) Independent Linux x64 + LLVM 23.1.4 check on `e17124b`: - `v_madak_f32` and `v_madmk_f32` route cleanly through the existing unfused denormal-flushing `mad32` helper with literal placement validated at operand 2 (`ak`) or operand 1 (`mk`), matching the updated regexes in `tools/scan_unsupported_shaders.py`. - Local checks passing on `e17124b`: `pixel_aot_check.py binary` (LLVM 23), `rdna2_tools_check.py`, `pso_readiness_check.py`, `form_coverage_check.py`, `docs_links_check.py`, and `bidi_controls_check.py`. Windows DXC/WARP and hardware draws were not run locally on Linux. AI-assisted: yes
This discussion has been locked. Commenting is limited to contributors.
No description provided.