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

Manually merged
github merged 2 commits from github-bot/gh-3048 into gh-pr/3048/base 2026-11-27 12:08:39 +00:00 AGit
Owner

@⁠Holastor on GitHub · 2026-11-27 11:10 UTC · original
Holastor:native/direct-int16-ternary → main · +303 −0 · 5 files · 2 commits · merged 2026-11-27 11:54 UTC

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.
**@⁠Holastor** on GitHub · 2026-11-27 11:10 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3048) `Holastor:native/direct-int16-ternary` → `main` · +303 −0 · 5 files · 2 commits · merged 2026-11-27 11:54 UTC 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.
Lowers the eight three-source 16-bit integer VOP3 operations in DirectCompute:
- 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

Each operation computes D[15:0] from S0[15:0], S1[15:0] and S2[15:0], and D[31:16]
preserves its previous value (matching RDNA 2 silicon behavior and LLVM
GCNSubtarget::zeroesHigh16BitsOfDest). op_sel would select other halves and stays
refused. Modifiers (clamp, scale, neg, abs) stay refused by the path's common rule.

Adds synthetic fixture tests tests/native_int16_ternary_check.py (controls and
hardware modes), registers them in tests/cmake/native_int16_ternary.cmake, and adds
docs/experiments/native-direct-int16-ternary.md.

Refs #669, part of integer ALU coverage in #2935.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 11:14:17 +00:00
github-bot changed target branch from main to gh-pr/3048/base 2026-11-27 12:08:38 +00:00
github manually merged commit 1f2d375a90 into gh-pr/3048/base 2026-11-27 12:08:39 +00:00
Author
Owner

@⁠R0Y00 on GitHub · 2026-11-27 11:53 UTC · original · approved these changes

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.

**@⁠R0Y00** on GitHub · 2026-11-27 11:53 UTC · [original](https://github.com/R0Y00/Xbox2Windows/pull/3048#pullrequestreview-6087729429) · **approved these changes** 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.
This discussion has been locked. Commenting is limited to contributors.
No description provided.