shader: lower mixed-precision VOP3P FMA in pixel_aot #383

Merged
KomaGuy merged 3 commits from upstream-pr/389 into main 2026-11-22 08:50:23 +00:00
KomaGuy commented 2026-11-22 00:04:50 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by KomaGuy on 2026-11-22T00:04:50Z.


Change

Lower all three mixed-precision VOP3P FMA forms in tools/pixel_aot.py, covering 3 additional VOP3P forms on both gfx1013 and gfx1030:

  • Supported instructions: v_fma_mix_f32, v_fma_mixlo_f16, and v_fma_mixhi_f16.
  • Source format and modifiers: op_sel selects binary32 (0, default) vs binary16 (1), op_sel_hi selects low (0, default) vs high (1) half for binary16 sources (high-half selection on a binary32 source is rejected), -src and |src|/abs(src) apply after widening through widen16, and optional clamp saturates to [0, 1]. Inline f16 float constants zero-extend [31:16] = 0 matching gfx1013 hardware; unsupported modifiers (neg_lo, neg_hi, mul:2, duplicates, wrong arity) are rejected.
  • Destination half preservation & RNE packing: v_fma_mixlo_f16 writes bits [15:0] while preserving vdst[31:16], and v_fma_mixhi_f16 writes bits [31:16] while preserving vdst[15:0] (requiring vdst to hold a defined numeric value). Both emit an optional pack16_rne helper (bit-exact IEEE-754 binary32→binary16 round-to-nearest-even independent of desktop f32tof16 rounding) only when used; existing shaders emit no extra helpers.
  • Fixture & controls: Added FMA_MIX_BODY and check_fma_mix_draw in tests/pixel_aot_check.py across 3 constant sets (mixed f16/f32 modifiers, preserved high/low destination halves, [0, 1] clamp, and exact binary16 halfway ties distinguishing RNE from RTZ), 5 negative mutations, and negative controls covering uninitialized destination halves, invalid op_sel_hi on f32, WQM, and vmcnt/lgkmcnt hazards.

Verification

Tested on Linux x86_64 (Python 3.13.5, LLVM 19.1.7, Clang 19.1.7) on top of 9bdbb20:

  • python3 -B tests/pixel_aot_check.py binary llvm-mc-19 llvm-objcopy-19 libLLVM-19.so — passed (controls, negative controls, and llvm-mc -mcpu=gfx1013 assembly→DXBC/XDAT/XBCH/FSSM→disassembly→lowering parity for FMA_MIX_BODY and all existing fixtures).
  • python3 -B tests/ffx_dispatch_aot_check.py llvm-mc-19 llvm-objcopy-19 libLLVM-19.so — passed.
  • python3 -B tests/script_state_check.py, tests/bcpack_check.py, tests/resource_ranges_check.py, tests/layout_chunks_check.py, tests/docs_links_check.py, tests/bidi_controls_check.py — all passed.
  • Verified tools/form_coverage.py records all 3 forms (v_fma_mix_f32, v_fma_mixhi_f16, v_fma_mixlo_f16) against both docs/coverage/gfx1013.tsv and docs/coverage/rdna2.tsv.
  • Compiled the generated HLSL for FMA_MIX_BODY and all 5 negative mutations (abs, neg, op_sel_hi, mixhi half preservation, clamp) as C++20 with clang++-19 -std=c++20 -O2 -Wall -Wextra -Wpedantic -Werror -fsanitize=undefined,address — bit-exact match on all 3 constant sets (including odd-mantissa halfway ties distinguishing pack16_rne from RTZ f32tof16) and all 5 mutations caught; 0 sanitizer errors.
  • Windows C++, DXC (dxc -Gis -T ps_6_0), WARP (pixel_aot_warp), and hardware (pixel_aot_hardware) checks were not run locally on Linux; relying on the build-and-test Windows CI job to verify DXC compilation and D3D12 WARP readback.

Evidence and follow-up

  • All new test fixtures in tests/pixel_aot_check.py are original MIT-licensed gfx1013 assembly sequences built from source at test time.
  • Semantics follow the AMD RDNA 2 Instruction Set Architecture Reference Guide.
  • Complements #376 (v_pk_*_f16) without overlapping its opcodes; remaining VOP3P families (v_dot* and packed 16-bit integer v_pk_*_i16/u16/b16) stay rejected here for separate focused PRs.
  • This contribution was AI-assisted.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed.
  • I did not include game files, dumps, distribution links or secrets.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6536117960 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/389). Originally posted by [KomaGuy](https://github.com/KomaGuy) on 2026-11-22T00:04:50Z. --- ## Change Lower all three mixed-precision `VOP3P` FMA forms in `tools/pixel_aot.py`, covering 3 additional `VOP3P` forms on both `gfx1013` and `gfx1030`: - **Supported instructions:** `v_fma_mix_f32`, `v_fma_mixlo_f16`, and `v_fma_mixhi_f16`. - **Source format and modifiers:** `op_sel` selects binary32 (`0`, default) vs binary16 (`1`), `op_sel_hi` selects low (`0`, default) vs high (`1`) half for binary16 sources (high-half selection on a binary32 source is rejected), `-src` and `|src|`/`abs(src)` apply after widening through `widen16`, and optional `clamp` saturates to `[0, 1]`. Inline `f16` float constants zero-extend `[31:16] = 0` matching `gfx1013` hardware; unsupported modifiers (`neg_lo`, `neg_hi`, `mul:2`, duplicates, wrong arity) are rejected. - **Destination half preservation & RNE packing:** `v_fma_mixlo_f16` writes bits `[15:0]` while preserving `vdst[31:16]`, and `v_fma_mixhi_f16` writes bits `[31:16]` while preserving `vdst[15:0]` (requiring `vdst` to hold a defined numeric value). Both emit an optional `pack16_rne` helper (bit-exact IEEE-754 binary32→binary16 round-to-nearest-even independent of desktop `f32tof16` rounding) only when used; existing shaders emit no extra helpers. - **Fixture & controls:** Added `FMA_MIX_BODY` and `check_fma_mix_draw` in `tests/pixel_aot_check.py` across 3 constant sets (mixed f16/f32 modifiers, preserved high/low destination halves, `[0, 1]` clamp, and exact binary16 halfway ties distinguishing RNE from RTZ), 5 negative mutations, and negative controls covering uninitialized destination halves, invalid `op_sel_hi` on f32, WQM, and `vmcnt`/`lgkmcnt` hazards. ## Verification Tested on Linux x86_64 (Python 3.13.5, LLVM 19.1.7, Clang 19.1.7) on top of `9bdbb20`: - `python3 -B tests/pixel_aot_check.py binary llvm-mc-19 llvm-objcopy-19 libLLVM-19.so` — passed (controls, negative controls, and `llvm-mc -mcpu=gfx1013` assembly→DXBC/XDAT/XBCH/FSSM→disassembly→lowering parity for `FMA_MIX_BODY` and all existing fixtures). - `python3 -B tests/ffx_dispatch_aot_check.py llvm-mc-19 llvm-objcopy-19 libLLVM-19.so` — passed. - `python3 -B tests/script_state_check.py`, `tests/bcpack_check.py`, `tests/resource_ranges_check.py`, `tests/layout_chunks_check.py`, `tests/docs_links_check.py`, `tests/bidi_controls_check.py` — all passed. - Verified `tools/form_coverage.py` records all 3 forms (`v_fma_mix_f32`, `v_fma_mixhi_f16`, `v_fma_mixlo_f16`) against both `docs/coverage/gfx1013.tsv` and `docs/coverage/rdna2.tsv`. - Compiled the generated HLSL for `FMA_MIX_BODY` and all 5 negative mutations (`abs`, `neg`, `op_sel_hi`, `mixhi` half preservation, `clamp`) as C++20 with `clang++-19 -std=c++20 -O2 -Wall -Wextra -Wpedantic -Werror -fsanitize=undefined,address` — bit-exact match on all 3 constant sets (including odd-mantissa halfway ties distinguishing `pack16_rne` from RTZ `f32tof16`) and all 5 mutations caught; 0 sanitizer errors. - Windows C++, DXC (`dxc -Gis -T ps_6_0`), WARP (`pixel_aot_warp`), and hardware (`pixel_aot_hardware`) checks were not run locally on Linux; relying on the `build-and-test` Windows CI job to verify DXC compilation and D3D12 WARP readback. ## Evidence and follow-up - All new test fixtures in `tests/pixel_aot_check.py` are original MIT-licensed `gfx1013` assembly sequences built from source at test time. - Semantics follow the [AMD RDNA 2 Instruction Set Architecture Reference Guide](https://docs.amd.com/v/u/en-US/rdna2-shader-instruction-set-architecture). - Complements #376 (`v_pk_*_f16`) without overlapping its opcodes; remaining `VOP3P` families (`v_dot*` and packed 16-bit integer `v_pk_*_i16`/`u16`/`b16`) stay rejected here for separate focused PRs. - This contribution was AI-assisted. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [x] I updated README/docs when a capability or build requirement changed. - [x] I did not include game files, dumps, distribution links or secrets.
upstream-sync closed this pull request 2026-11-24 06:42:47 +00:00
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!383
No description provided.