shader: lower the 16-bit three-operand integer VOP3 ops in pixel_aot #828

Merged
JB2WIN merged 1 commit from upstream-pr/834 into main 2026-11-23 10:20:08 +00:00
JB2WIN commented 2026-11-23 09:56:44 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by JB2WIN on 2026-11-23T09:56:44Z.


Change

tools/pixel_aot.py now lowers the eight 16-bit three-operand integer VOP3 forms: v_mad_u16, v_mad_i16, v_min3_{i16,u16}, v_max3_{i16,u16} and v_med3_{i16,u16}. They follow the low-16-only contract from #732. The result is tracked as a low-16 value, and the same readers as in #732 may consume it: the 16-bit ops, the 16-bit compares and SDWA WORD_0/BYTE_0/BYTE_1. Every whole-word or high-half reader stays refused.

Semantics, from LLVM 15.0.7 VOP3Instructions.td:

  • V_MAD_{U,I}16 (L318-319) are selected through Ternary_i16_Pats<mul, add> (L392-393). Without clamp the result is (a*b + c) & 0xffff, and the u16 and i16 forms give the same low bits.
  • V_{MIN3,MAX3,MED3}_{I,U}16 map to AMDGPU{s,u}{min3,max3,med3} (L520-529). The signed forms sign-extend the low halves, and med3 is the median.

Encodings and refusals:

  • LLVM 15 on gfx1013 prints no suffix. For example, v_mad_u16 v5, v1, v2, v3 encodes as [0x05,0x00,0x40,0xd7,0x01,0x05,0x0e,0x04]. The translator accepts the plain spelling and _e64.
  • clamp and op_sel assemble in LLVM but are refused here, since neither is modelled.
  • A wrong operand count now raises "Wrong 16-bit integer operand count". This also covers a two-operand op given three sources.

Changed expectations: v_mad_u16/v_mad_i16 were listed as refused neighbours in the controls, rdna2_tools_check.py and form_coverage_check.py. They are now supported. Their refusals are replaced by stricter ones (clamp, op_sel, operand format), and the neighbours v_mad_u32_u16, v_mad_i32_i16 and v_sad_u16 take their place as negative controls.

Refs #669. AI-assisted (Claude Code).

Verification

Windows 11 10.0.26200.9974, NVIDIA GeForce RTX 3080 (driver 32.0.16.2124) and WARP, at 523d9ac.

  • Draw draw-int16-ternary (pixel_aot_int16_ternary_{hardware,warp}): results are widened through SDWA WORD_0 and checked against an independent Python reference. The six word sets separate signed from unsigned, med3 from min3/max3, and the mad wrap, and the source high halves differ.

  • Mutations. Each must mismatch, and each does:

    • signed min3/max3 read as unsigned;
    • signed med3 read as unsigned;
    • med3 replaced by min3;
    • the mad addend dropped;
    • a source read from bits 31:16, in two groups.

    A WORD_1 widen is refused at lowering. mad_i16 against mad_u16 is not a usable mutation, because both give the same low bits; an assertion pins that.

  • Commands:

    • ctest --preset dev --no-tests=error -R "^pixel_aot_int16_ternary_": 2/2 passed.
    • The full ctest --preset dev --no-tests=error -j4 passed with no failures. The only skips were the capability skips (bvh_wave64_*, wave_shuffle_warp, spirv_minlod).
    • The LLVM 15 binary round trip, the controls, form_coverage_check.py, rdna2_tools_check.py, pso_readiness_check.py and docs_links_check.py pass.
  • Not covered: the high half of the destination is still not measured on hardware (#669).

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6556694906 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/834). Originally posted by [JB2WIN](https://github.com/JB2WIN) on 2026-11-23T09:56:44Z. --- ## Change `tools/pixel_aot.py` now lowers the eight 16-bit three-operand integer VOP3 forms: `v_mad_u16`, `v_mad_i16`, `v_min3_{i16,u16}`, `v_max3_{i16,u16}` and `v_med3_{i16,u16}`. They follow the low-16-only contract from #732. The result is tracked as a low-16 value, and the same readers as in #732 may consume it: the 16-bit ops, the 16-bit compares and SDWA `WORD_0`/`BYTE_0`/`BYTE_1`. Every whole-word or high-half reader stays refused. **Semantics,** from LLVM 15.0.7 [`VOP3Instructions.td`](https://github.com/llvm/llvm-project/blob/llvmorg-15.0.7/llvm/lib/Target/AMDGPU/VOP3Instructions.td): - `V_MAD_{U,I}16` (L318-319) are selected through `Ternary_i16_Pats<mul, add>` (L392-393). Without clamp the result is `(a*b + c) & 0xffff`, and the u16 and i16 forms give the same low bits. - `V_{MIN3,MAX3,MED3}_{I,U}16` map to `AMDGPU{s,u}{min3,max3,med3}` (L520-529). The signed forms sign-extend the low halves, and `med3` is the median. **Encodings and refusals:** - LLVM 15 on gfx1013 prints no suffix. For example, `v_mad_u16 v5, v1, v2, v3` encodes as `[0x05,0x00,0x40,0xd7,0x01,0x05,0x0e,0x04]`. The translator accepts the plain spelling and `_e64`. - `clamp` and `op_sel` assemble in LLVM but are refused here, since neither is modelled. - A wrong operand count now raises "Wrong 16-bit integer operand count". This also covers a two-operand op given three sources. **Changed expectations:** `v_mad_u16`/`v_mad_i16` were listed as refused neighbours in the controls, `rdna2_tools_check.py` and `form_coverage_check.py`. They are now supported. Their refusals are replaced by stricter ones (`clamp`, `op_sel`, operand format), and the neighbours `v_mad_u32_u16`, `v_mad_i32_i16` and `v_sad_u16` take their place as negative controls. Refs #669. AI-assisted (Claude Code). ## Verification Windows 11 10.0.26200.9974, NVIDIA GeForce RTX 3080 (driver 32.0.16.2124) and WARP, at `523d9ac`. - **Draw `draw-int16-ternary`** (`pixel_aot_int16_ternary_{hardware,warp}`): results are widened through SDWA `WORD_0` and checked against an independent Python reference. The six word sets separate signed from unsigned, `med3` from `min3`/`max3`, and the `mad` wrap, and the source high halves differ. - **Mutations.** Each must mismatch, and each does: - signed `min3`/`max3` read as unsigned; - signed `med3` read as unsigned; - `med3` replaced by `min3`; - the `mad` addend dropped; - a source read from bits 31:16, in two groups. A `WORD_1` widen is refused at lowering. `mad_i16` against `mad_u16` is not a usable mutation, because both give the same low bits; an assertion pins that. - **Commands:** - `ctest --preset dev --no-tests=error -R "^pixel_aot_int16_ternary_"`: 2/2 passed. - The full `ctest --preset dev --no-tests=error -j4` passed with no failures. The only skips were the capability skips (`bvh_wave64_*`, `wave_shuffle_warp`, `spirv_minlod`). - The LLVM 15 binary round trip, the controls, `form_coverage_check.py`, `rdna2_tools_check.py`, `pso_readiness_check.py` and `docs_links_check.py` pass. - **Not covered:** the high half of the destination is still not measured on hardware (#669). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-24 06:45:00 +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!828
No description provided.