shader: lower packed binary16 VOP3P arithmetic in pixel_aot #376

Manually merged
github merged 4 commits from gh-pr/376/head into gh-pr/376/base 2026-11-26 21:47:00 +00:00
Owner

@⁠KomaGuy on GitHub · 2026-11-21 23:47 UTC · original
KomaGuy:shader/vop3p-packed-f16 → main · +251 −0 · 3 files · 4 commits · merged 2026-11-22 08:25 UTC

Change

Lower all five packed binary16 VOP3P arithmetic forms in tools/pixel_aot.py, advancing VOP3P instruction-form coverage from 0/29 to 5/29 on both gfx1013 and gfx1030:

  • Supported instructions: v_pk_add_f16, v_pk_mul_f16, v_pk_min_f16, v_pk_max_f16, and v_pk_fma_f16.
  • Modifiers: op_sel, op_sel_hi, neg_lo, neg_hi, and clamp, with default [0, ...] (op_sel, neg_lo, neg_hi) and [1, ...] (op_sel_hi) matching gfx1013 encoding. Duplicate, wrong-arity, or unsupported modifiers (including abs/|...|, bare -reg, and mul:2) are rejected.
  • gfx1013 inline constant and literal semantics: Each source operand lowers to a 32-bit uint word; the nine RDNA 2 inline f16 float constants (±0.5, ±1.0, ±2.0, ±4.0, 0.15915494) occupy bits [15:0] with bits [31:16] zeroed (matching gfx1013 rather than gfx11 replication), while 32-bit hex literals and integer inline constants (-16..64) supply both halves.
  • Deterministic binary16 rounding and NaN handling: Emits optional pack16_rne (bit-exact IEEE-754 binary32→binary16 round-to-nearest-even independent of driver f32tof16 RTZ/RNE differences) and min16_num / max16_num helpers only when a shader uses v_pk_*_f16. Existing shaders emit none of these helpers.
  • Rejected neighbors: Packed integer VOP3P (v_pk_add_u16, etc.), mixed-precision FMA (v_fma_mix_f32), and dot products (v_dot2_f32_f16) remain rejected and are covered as negative controls for follow-up PRs.

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 VOP3P_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 — all passed.
  • Verified tools/form_coverage.py records all 5 VOP3P forms (v_pk_add_f16, v_pk_fma_f16, v_pk_max_f16, v_pk_min_f16, v_pk_mul_f16) against both docs/coverage/gfx1013.tsv and docs/coverage/rdna2.tsv.
  • Compiled the generated HLSL for VOP3P_BODY and all 5 negative mutations (neg_lo, neg_hi, min vs max, inline hi zero-extension, 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 IEEE minNum against quiet NaN 0x7e00 and exact halfway tie-to-even rounding distinguishing pack16_rne from RTZ f32tof16) and all 5 mutations caught; 0 sanitizer errors.
  • Exhaustively cross-checked pack16_rne against IEEE binary16 across all 65,536 half encodings and 98,752 critical binary32 transition neighborhoods.
  • 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.
  • Instruction encodings, modifiers, and gfx1013 inline-constant behavior follow the AMD RDNA 2 Instruction Set Architecture Reference Guide.
  • Follow-up VOP3P work: v_fma_mix_f32/v_fma_mixlo_f16/v_fma_mixhi_f16, v_dot2_f32_f16, and the 14 packed 16-bit integer v_pk_*_u16/i16/b16 forms.
  • 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.
**@⁠KomaGuy** on GitHub · 2026-11-21 23:47 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/376) `KomaGuy:shader/vop3p-packed-f16` → `main` · +251 −0 · 3 files · 4 commits · merged 2026-11-22 08:25 UTC ## Change Lower all five packed binary16 `VOP3P` arithmetic forms in `tools/pixel_aot.py`, advancing `VOP3P` instruction-form coverage from `0/29` to `5/29` on both `gfx1013` and `gfx1030`: - **Supported instructions:** `v_pk_add_f16`, `v_pk_mul_f16`, `v_pk_min_f16`, `v_pk_max_f16`, and `v_pk_fma_f16`. - **Modifiers:** `op_sel`, `op_sel_hi`, `neg_lo`, `neg_hi`, and `clamp`, with default `[0, ...]` (`op_sel`, `neg_lo`, `neg_hi`) and `[1, ...]` (`op_sel_hi`) matching `gfx1013` encoding. Duplicate, wrong-arity, or unsupported modifiers (including `abs`/`|...|`, bare `-reg`, and `mul:2`) are rejected. - **`gfx1013` inline constant and literal semantics:** Each source operand lowers to a 32-bit `uint` word; the nine RDNA 2 inline `f16` float constants (`±0.5`, `±1.0`, `±2.0`, `±4.0`, `0.15915494`) occupy bits `[15:0]` with bits `[31:16]` zeroed (matching `gfx1013` rather than `gfx11` replication), while 32-bit hex literals and integer inline constants (`-16..64`) supply both halves. - **Deterministic binary16 rounding and NaN handling:** Emits optional `pack16_rne` (bit-exact IEEE-754 binary32→binary16 round-to-nearest-even independent of driver `f32tof16` RTZ/RNE differences) and `min16_num` / `max16_num` helpers only when a shader uses `v_pk_*_f16`. Existing shaders emit none of these helpers. - **Rejected neighbors:** Packed integer `VOP3P` (`v_pk_add_u16`, etc.), mixed-precision FMA (`v_fma_mix_f32`), and dot products (`v_dot2_f32_f16`) remain rejected and are covered as negative controls for follow-up PRs. ## 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 `VOP3P_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` — all passed. - Verified `tools/form_coverage.py` records all 5 `VOP3P` forms (`v_pk_add_f16`, `v_pk_fma_f16`, `v_pk_max_f16`, `v_pk_min_f16`, `v_pk_mul_f16`) against both `docs/coverage/gfx1013.tsv` and `docs/coverage/rdna2.tsv`. - Compiled the generated HLSL for `VOP3P_BODY` and all 5 negative mutations (`neg_lo`, `neg_hi`, `min vs max`, inline hi zero-extension, `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 IEEE `minNum` against quiet NaN `0x7e00` and exact halfway tie-to-even rounding distinguishing `pack16_rne` from RTZ `f32tof16`) and all 5 mutations caught; 0 sanitizer errors. - Exhaustively cross-checked `pack16_rne` against IEEE binary16 across all 65,536 half encodings and 98,752 critical binary32 transition neighborhoods. - 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. - Instruction encodings, modifiers, and `gfx1013` inline-constant behavior follow the [AMD RDNA 2 Instruction Set Architecture Reference Guide](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf). - Follow-up `VOP3P` work: `v_fma_mix_f32`/`v_fma_mixlo_f16`/`v_fma_mixhi_f16`, `v_dot2_f32_f16`, and the 14 packed 16-bit integer `v_pk_*_u16`/`i16`/`b16` forms. - 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 21:46:59 +00:00
github manually merged commit eddd8466e1 into gh-pr/376/base 2026-11-26 21:47:00 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-22 03:07 UTC · original

For your packed and DPP pixel changes, please refresh only #376 first. The packed arithmetic work shares the translator and draw fixtures with #389, #391 and #397. I’ll check the merged base before asking for the next branch, including the separate DPP series.

**@⁠R0Y00** on GitHub · 2026-11-22 03:07 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/376#issuecomment-7073344665) For your packed and DPP pixel changes, please refresh only #376 first. The packed arithmetic work shares the translator and draw fixtures with #389, #391 and #397. I’ll check the merged base before asking for the next branch, including the separate DPP series.
Author
Owner

@⁠KomaGuy on GitHub · 2026-11-22 08:10 UTC · original

Refreshed #376 onto current main (5a16ee9), keeping both draw suites and v_cvt_f32_ubyte0-3 intact; all 4 CI checks pass. Holding off on refreshing #389, #391, #397, and the DPP series until you check this base.

**@⁠KomaGuy** on GitHub · 2026-11-22 08:10 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/376#issuecomment-7076350062) Refreshed #376 onto current `main` (`5a16ee9`), keeping both draw suites and `v_cvt_f32_ubyte0-3` intact; all 4 CI checks pass. Holding off on refreshing #389, #391, #397, and the DPP series until you check this base.
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-22 08:26 UTC · original

Merged #376 at a46dac3. The ordered additions and removals on your refreshed head matched the reviewed patch, and all four CI checks passed. #389 is the next branch in this sequence. Please leave the later branches in place until its combined result lands.

**@⁠R0Y00** on GitHub · 2026-11-22 08:26 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/376#issuecomment-7076517330) Merged #376 at a46dac3. The ordered additions and removals on your refreshed head matched the reviewed patch, and all four CI checks passed. #389 is the next branch in this sequence. Please leave the later branches in place until its combined result lands.
This discussion has been locked. Commenting is limited to contributors.
No description provided.