shader: lower packed 16-bit integer VOP3P instructions in pixel_aot #391

Merged
KomaGuy merged 3 commits from upstream-pr/397 into main 2026-11-22 09:11:34 +00:00
KomaGuy commented 2026-11-22 00:18:31 +00:00 (Migrated from github.com)

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


Change

Lower all fourteen packed 16-bit integer VOP3P arithmetic and shift forms in tools/pixel_aot.py, covering the remaining 14 VOP3P forms on both gfx1013 and gfx1030:

  • Supported instructions: v_pk_add_i16, v_pk_add_u16, v_pk_sub_i16, v_pk_sub_u16, v_pk_min_i16, v_pk_min_u16, v_pk_max_i16, v_pk_max_u16, v_pk_mul_lo_u16, v_pk_mad_i16, v_pk_mad_u16, v_pk_lshlrev_b16, v_pk_lshrrev_b16, and v_pk_ashrrev_i16.
  • Lane selection, shifts, and saturation: op_sel (default [0, ...]) and op_sel_hi (default [1, ...]) select the low or high 16-bit half of each source operand for destination lanes 0 and 1. Shift instructions mask src0 shift counts to 4 bits (& 15) and apply logical or arithmetic 16-bit shifts to src1. Optional clamp saturates add/sub/mad to [-32768, 32767] (i16) or [0, 65535] (u16), while clamp on min/max/mul_lo/shifts and neg_lo/neg_hi/float inline constants are rejected.
  • No extra helpers: All 14 forms lower cleanly inline using 32-bit int/uint SM 6.0 HLSL (since mad_i16 fits within int32 and mad_u16 fits within uint32 without overflow).
  • Fixture & controls: Added PK_INT16_BODY and check_pk_int16_draw in tests/pixel_aot_check.py across 3 constant sets (exercising all 14 forms, shift counts >= 16, inline -1, signed/unsigned saturation boundaries, and cross-lane swaps, exporting all 4 bytes of the packed accumulator as exact [0, 255] integers), 5 negative mutations, and negative controls covering disallowed clamp/neg_*/float immediates, 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 4f6c39d:

  • 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 PK_INT16_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 14 packed 16-bit integer VOP3P forms against both docs/coverage/gfx1013.tsv and docs/coverage/rdna2.tsv.
  • Compiled the generated HLSL for PK_INT16_BODY and all 5 negative mutations (ashrrev sign fill, signed vs unsigned min, sub_u16 clamp, op_sel cross-lane swap, mad_i16 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 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, 5 forms), #389 (v_fma_mix*, 3 forms), and #391 (v_dot*, 7 forms) with zero opcode overlap; together the four PRs cover all 29/29 VOP3P forms on both gfx1013 and gfx1030.
  • 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:6536247394 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/397). Originally posted by [KomaGuy](https://github.com/KomaGuy) on 2026-11-22T00:18:31Z. --- ## Change Lower all fourteen packed 16-bit integer `VOP3P` arithmetic and shift forms in `tools/pixel_aot.py`, covering the remaining 14 `VOP3P` forms on both `gfx1013` and `gfx1030`: - **Supported instructions:** `v_pk_add_i16`, `v_pk_add_u16`, `v_pk_sub_i16`, `v_pk_sub_u16`, `v_pk_min_i16`, `v_pk_min_u16`, `v_pk_max_i16`, `v_pk_max_u16`, `v_pk_mul_lo_u16`, `v_pk_mad_i16`, `v_pk_mad_u16`, `v_pk_lshlrev_b16`, `v_pk_lshrrev_b16`, and `v_pk_ashrrev_i16`. - **Lane selection, shifts, and saturation:** `op_sel` (default `[0, ...]`) and `op_sel_hi` (default `[1, ...]`) select the low or high 16-bit half of each source operand for destination lanes 0 and 1. Shift instructions mask `src0` shift counts to 4 bits (`& 15`) and apply logical or arithmetic 16-bit shifts to `src1`. Optional `clamp` saturates `add`/`sub`/`mad` to `[-32768, 32767]` (`i16`) or `[0, 65535]` (`u16`), while `clamp` on `min`/`max`/`mul_lo`/shifts and `neg_lo`/`neg_hi`/float inline constants are rejected. - **No extra helpers:** All 14 forms lower cleanly inline using 32-bit `int`/`uint` SM 6.0 HLSL (since `mad_i16` fits within `int32` and `mad_u16` fits within `uint32` without overflow). - **Fixture & controls:** Added `PK_INT16_BODY` and `check_pk_int16_draw` in `tests/pixel_aot_check.py` across 3 constant sets (exercising all 14 forms, shift counts `>= 16`, inline `-1`, signed/unsigned saturation boundaries, and cross-lane swaps, exporting all 4 bytes of the packed accumulator as exact `[0, 255]` integers), 5 negative mutations, and negative controls covering disallowed `clamp`/`neg_*`/float immediates, 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 `4f6c39d`: - `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 `PK_INT16_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 14 packed 16-bit integer `VOP3P` forms against both `docs/coverage/gfx1013.tsv` and `docs/coverage/rdna2.tsv`. - Compiled the generated HLSL for `PK_INT16_BODY` and all 5 negative mutations (`ashrrev` sign fill, signed vs unsigned min, `sub_u16` clamp, `op_sel` cross-lane swap, `mad_i16` 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 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`, 5 forms), #389 (`v_fma_mix*`, 3 forms), and #391 (`v_dot*`, 7 forms) with zero opcode overlap; together the four PRs cover all 29/29 `VOP3P` forms on both `gfx1013` and `gfx1030`. - 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:50 +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!391
No description provided.