shader: lower packed binary16 VOP3P arithmetic in pixel_aot #370

Merged
KomaGuy merged 4 commits from upstream-pr/376 into main 2026-11-22 08:25:41 +00:00
KomaGuy commented 2026-11-21 23:47:02 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by KomaGuy on 2026-11-21T23:47:02Z.


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.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6535947267 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/376). Originally posted by [KomaGuy](https://github.com/KomaGuy) on 2026-11-21T23:47:02Z. --- ## 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.
upstream-sync closed this pull request 2026-11-24 06:42:43 +00:00
R0Y00 commented 2026-11-24 06:48:20 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T03:07:52Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7073344665 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/376#issuecomment-7073344665). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-22T03:07:52Z. --- 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.
KomaGuy commented 2026-11-24 06:48:28 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by KomaGuy on 2026-11-22T08:10:03Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7076350062 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/376#issuecomment-7076350062). Originally posted by [KomaGuy](https://github.com/KomaGuy) on 2026-11-22T08:10:03Z. --- 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.
R0Y00 commented 2026-11-24 06:48:28 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-22T08:26:14Z.


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.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7076517330 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/376#issuecomment-7076517330). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-22T08:26:14Z. --- 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.
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!370
No description provided.