shader: lower three-source 16-bit integer VOP3 ops in the direct C++ compute path #3048

Merged
Holastor merged 2 commits from upstream-pr/3048 into main 2026-11-27 11:54:21 +00:00
Holastor commented 2026-11-27 11:10:28 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by Holastor on 2026-11-27T11:10:28Z.


Refs #669, part of integer ALU coverage in #2935. Follows the lowering in #3018.

Summary

The direct compute frontend refused the eight three-source 16-bit integer VOP3 operations with direct DXIL lowering for <name>:

  • v_mad_u16 and v_mad_i16;
  • v_min3_u16 and v_min3_i16;
  • v_max3_u16 and v_max3_i16;
  • v_med3_u16 and v_med3_i16.

Semantics: each computes D[15:0] from S0[15:0], S1[15:0] and S2[15:0], and D[31:16] preserves its value.

  • AMD RDNA 2 silicon behavior and LLVM GCNSubtarget::zeroesHigh16BitsOfDest: "On gfx10, all 16-bit instructions preserve the high bits".
  • v_mad_u16 and v_mad_i16: (S0[15:0] * S1[15:0] + S2[15:0]) mod 2^16. As LLVM 15.0.7 notes (VOP3_Profile<VOP_I16_I16_I16_I16, VOP3_CLAMP> with Ternary_i16_Pats<mul, add>), the signed and unsigned forms have identical low 16 bits when clamp is not modelled.
  • v_min3_u16, v_max3_u16, v_med3_u16: unsigned minimum, maximum and median of the three 16-bit halfwords.
  • v_min3_i16, v_max3_i16, v_med3_i16: sign-extended minimum, maximum and median of the three 16-bit halfwords.

Refused: op_sel would select high halves and stays refused (unsupported <name> op_sel). Modifiers (clamp, scale, neg, abs) stay refused with direct ALU operand modifiers by the path's common rule.

Fixture

tests/native_int16_ternary_check.py controls|hardware (tests/cmake/native_int16_ternary.cmake, docs/experiments/native-direct-int16-ternary.md). The words were assembled with LLVM 15.0.7 (clang -cc1as -triple amdgcn -target-cpu gfx1013 -filetype asm -show-encoding).

  • Dispatch: two groups of 32 lanes (64 lanes total). With G = lane + 32 * group:
    • S0 = mul_u32_u24(G, 0x05f3d1) ^ 0xa5800000
    • S1 = mul_u32_u24(G, 0x000371) ^ 0x7f9abcde
    • S2 = mul_u32_u24(G, 0x001001) ^ 0x80007fff
      Both halves are nonzero, values cross the 16-bit signed boundary (0x8000), 63 of 64 lanes wrap mad modulo 2^{16}, and all permutations of signed and unsigned orders are exercised.
  • Destinations: destination registers v10 through v17 are preloaded with 0xcafebabe. Each lane writes all 8 results into the UAV buffer at offset G \times 32.
  • Controls: verify CSO compilation, spot-check definitions, require op_sel and clamp to be refused, and verify that mutated references differ from the expected words (zeroed high half, signed comparisons as unsigned, median as minimum, mad without addend, mad operand from high half).
  • Hardware: dispatches the shader through native_store_replay --direct and compares all 512 words and the sentinel guards against the CPU reference.

Verification

Commit 93d18d4c, Windows 11 build 26300, AMD Radeon RX 6600M, driver 32.0.21045.11001.

Check Result
native_int16_ternary_controls pass: compiled; op_sel and clamp refused; definitions spot-checked; all mutants differ (0.19 s)
native_int16_ternary_hardware pass: eight 16-bit ternary operations: 512 words of two groups and the guards matched, high halves kept (0.21 s)
native_sad_controls / hardware (neighbour) pass (0.16 s / 0.20 s)
python -B tests/docs_links_check.py pass: Checked 65 Markdown files and 581 links.
python -B tests/bidi_controls_check.py pass: Checked 2225 tracked source, script and build/CI files: no bidirectional controls.
ctest --preset dev --no-tests=error -R '^native_int16_ternary_' -V

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:5525630304 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3048). Originally posted by [Holastor](https://github.com/Holastor) on 2026-11-27T11:10:28Z. --- Refs #669, part of integer ALU coverage in #2935. Follows the lowering in #3018. ## Summary The direct compute frontend refused the eight three-source 16-bit integer VOP3 operations with `direct DXIL lowering for <name>`: - `v_mad_u16` and `v_mad_i16`; - `v_min3_u16` and `v_min3_i16`; - `v_max3_u16` and `v_max3_i16`; - `v_med3_u16` and `v_med3_i16`. **Semantics:** each computes `D[15:0]` from `S0[15:0]`, `S1[15:0]` and `S2[15:0]`, and **`D[31:16]` preserves its value**. - AMD RDNA 2 silicon behavior and LLVM `GCNSubtarget::zeroesHigh16BitsOfDest`: "On gfx10, all 16-bit instructions preserve the high bits". - `v_mad_u16` and `v_mad_i16`: `(S0[15:0] * S1[15:0] + S2[15:0]) mod 2^16`. As LLVM 15.0.7 notes (`VOP3_Profile<VOP_I16_I16_I16_I16, VOP3_CLAMP>` with `Ternary_i16_Pats<mul, add>`), the signed and unsigned forms have identical low 16 bits when clamp is not modelled. - `v_min3_u16`, `v_max3_u16`, `v_med3_u16`: unsigned minimum, maximum and median of the three 16-bit halfwords. - `v_min3_i16`, `v_max3_i16`, `v_med3_i16`: sign-extended minimum, maximum and median of the three 16-bit halfwords. **Refused:** `op_sel` would select high halves and stays refused (`unsupported <name> op_sel`). Modifiers (`clamp`, `scale`, `neg`, `abs`) stay refused with `direct ALU operand modifiers` by the path's common rule. ## Fixture `tests/native_int16_ternary_check.py controls|hardware` (`tests/cmake/native_int16_ternary.cmake`, `docs/experiments/native-direct-int16-ternary.md`). The words were assembled with LLVM 15.0.7 (`clang -cc1as -triple amdgcn -target-cpu gfx1013 -filetype asm -show-encoding`). - **Dispatch:** two groups of 32 lanes (64 lanes total). With G = lane + 32 * group: - S0 = mul_u32_u24(G, 0x05f3d1) ^ 0xa5800000 - S1 = mul_u32_u24(G, 0x000371) ^ 0x7f9abcde - S2 = mul_u32_u24(G, 0x001001) ^ 0x80007fff Both halves are nonzero, values cross the 16-bit signed boundary (0x8000), 63 of 64 lanes wrap mad modulo $2^{16}$, and all permutations of signed and unsigned orders are exercised. - **Destinations:** destination registers `v10` through `v17` are preloaded with `0xcafebabe`. Each lane writes all 8 results into the UAV buffer at offset $G \times 32$. - **Controls:** verify CSO compilation, spot-check definitions, require `op_sel` and `clamp` to be refused, and verify that mutated references differ from the expected words (zeroed high half, signed comparisons as unsigned, median as minimum, mad without addend, mad operand from high half). - **Hardware:** dispatches the shader through `native_store_replay --direct` and compares all 512 words and the sentinel guards against the CPU reference. ## Verification Commit `93d18d4c`, Windows 11 build 26300, AMD Radeon RX 6600M, driver 32.0.21045.11001. | Check | Result | |---|---| | `native_int16_ternary_controls` | pass: `compiled; op_sel and clamp refused; definitions spot-checked; all mutants differ` (0.19 s) | | `native_int16_ternary_hardware` | pass: `eight 16-bit ternary operations: 512 words of two groups and the guards matched, high halves kept` (0.21 s) | | `native_sad_controls` / `hardware` (neighbour) | pass (0.16 s / 0.20 s) | | `python -B tests/docs_links_check.py` | pass: `Checked 65 Markdown files and 581 links.` | | `python -B tests/bidi_controls_check.py` | pass: `Checked 2225 tracked source, script and build/CI files: no bidirectional controls.` | ```powershell ctest --preset dev --no-tests=error -R '^native_int16_ternary_' -V ``` ## 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.
R0Y00 commented 2026-11-27 11:53:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-27T11:53:58Z.

Review: APPROVED


Reviewed 1f2d375a on main with #3051 applied (tested tree ca29dca7). ctest --preset <dev|release> --no-tests=error -V -R '^(native_int16_ternary_(controls|hardware)|native_bitscan_(controls|hardware)|native_f16_alu_(ir|hardware))$' gave 6/6 passes in both Debug and Release /O2. The eight ternary operations matched 512 words and guards across two groups and kept the high halves. The fixture compiled, rejected op_sel and clamp, checked definitions, and distinguished each mutant reference. The two-source #3018 uses separate opcodes and is not an ancestor of this PR. Windows 11 26200.9974, SDK 10.0.26100, RTX 4060 Laptop driver 32.0.16.1656, native replay debug layer off. Hosted Windows, Linux Python and gfx1013 passed.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6087729429 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/3048#pullrequestreview-6087729429). Originally posted by [R0Y00](https://github.com/R0Y00) on 2026-11-27T11:53:58Z. **Review:** APPROVED --- Reviewed `1f2d375a` on `main` with #3051 applied (tested tree `ca29dca7`). `ctest --preset <dev|release> --no-tests=error -V -R '^(native_int16_ternary_(controls|hardware)|native_bitscan_(controls|hardware)|native_f16_alu_(ir|hardware))$'` gave 6/6 passes in both Debug and Release /O2. The eight ternary operations matched 512 words and guards across two groups and kept the high halves. The fixture compiled, rejected `op_sel` and `clamp`, checked definitions, and distinguished each mutant reference. The two-source #3018 uses separate opcodes and is not an ancestor of this PR. Windows 11 26200.9974, SDK 10.0.26100, RTX 4060 Laptop driver 32.0.16.1656, native replay debug layer off. Hosted Windows, Linux Python and gfx1013 passed.
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!3048
No description provided.