shader: lower three-source 16-bit integer VOP3 ops in the direct C++ compute path #3048
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3048"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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_u16andv_mad_i16;v_min3_u16andv_min3_i16;v_max3_u16andv_max3_i16;v_med3_u16andv_med3_i16.Semantics: each computes
D[15:0]fromS0[15:0],S1[15:0]andS2[15:0], andD[31:16]preserves its value.GCNSubtarget::zeroesHigh16BitsOfDest: "On gfx10, all 16-bit instructions preserve the high bits".v_mad_u16andv_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>withTernary_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_selwould select high halves and stays refused (unsupported <name> op_sel). Modifiers (clamp,scale,neg,abs) stay refused withdirect ALU operand modifiersby 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).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.v10throughv17are preloaded with0xcafebabe. Each lane writes all 8 results into the UAV buffer at offsetG \times 32.op_selandclampto 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).native_store_replay --directand 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.native_int16_ternary_controlscompiled; op_sel and clamp refused; definitions spot-checked; all mutants differ(0.19 s)native_int16_ternary_hardwareeight 16-bit ternary operations: 512 words of two groups and the guards matched, high halves kept(0.21 s)native_sad_controls/hardware(neighbour)python -B tests/docs_links_check.pyChecked 65 Markdown files and 581 links.python -B tests/bidi_controls_check.pyChecked 2225 tracked source, script and build/CI files: no bidirectional controls.Checklist
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-27T11:53:58Z.
Review: APPROVED
Reviewed
1f2d375aonmainwith #3051 applied (tested treeca29dca7).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, rejectedop_selandclamp, 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.