shader: lower the SDWA forms of binary16 add, sub, subrev and mul in direct compute #2973
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2973"
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 Leyukaka on 2026-11-27T00:47:44Z.
Fixes #2963 (it needs closing by hand, since the base is not the default branch). Part of #2935. Target branch
cpp-migration. Builds on #2964.Change (
src/gfx1013_compute_native.cpp,src/gfx1013_direct_compute.inl): the SDWA forms ofv_add_f16,v_sub_f16,v_subrev_f16andv_mul_f16, which #2964 refused, are lowered in direct compute, followingtools/startup/gfx2hlsl.pysdwa_half().src*_selWORD_0orWORD_1picks the half, andDWORDreads the low half. abs/neg are allowed.packed_half_rne. For add, sub and mul of binary16 inputs, binary32 has enough precision (24 >= 2*11 + 2) that this matches a direct binary16 rounding. This assumes the default FP mode (round to nearest even, binary16 denormals kept), as #2964 andsdwa_half()do.dst_selWORD_0orWORD_1, placed withplace_subword.UNUSED_PADzeroes the other half, andUNUSED_PRESERVEkeeps the old register's other half.sext;dst_sel:DWORD,UNUSED_SEXT;clampandomod.v_min_f16/v_max_f16SDWA forms stay refused, and so do the DPP forms of these ops.tests/native_f16_alu_check.pydrops the one control that expected these SDWA forms to be refused.docs/experiments.mdalso gets an index entry for #2964's plain binary16 experiment next to this one, andf16-alu-direct.mdlinks to the new note.Tests. The setup was Windows 11 with an NVIDIA GeForce RTX 5080 and DXC from the Windows SDK 10.0.26100, on
cpp-migration2b678fd3plus this commit.native_sdwa_f16_irpassed: 17 results evaluated from the DXIL text with #2964's interpreter, and 10 refusals.native_sdwa_f16_hardwarepassed: 34 results in two workgroups, with 2,030 guard words intact.dst_sel:WORD_0 UNUSED_PRESERVE src0_sel:WORD_1 src1_sel:DWORD;dst_sel:WORD_0 UNUSED_PAD src0_sel:DWORD src1_sel:WORD_0;dst_sel:WORD_1case with abs and neg on one source;-(1.0) + |-2.0| = 1.0. Without either modifier, the sum would differ.native_f16_alu_ir,native_f16_alu_hardwareandnative_bytewin_store_hardwarestill pass.Mutation checks on the lowering, run by hand; each fails both the IR and the hardware check:
WORD_0/WORD_1source;Measured on a local capture (counts and instruction shape only) with
compile_dxil --jobs 8 gfx1013-direct-cs@36 --requests.2b678fd3and 389 with this commit; none that compiled before stops compiling.8946fb16(before #2967), 14 did.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-27T01:01:07Z.
Review: APPROVED
Review of head
2e312dd6, tested merged ontocpp-migration2b678fd3. It merges cleanly, and CI on the head is green. Approving and merging.Code read:
WORD_0/WORD_1pick the half andDWORDreads the low half (sel == 6 ? 4 : sel). Byte selects, SGPR sources and sign extension are refused.WORD_0/WORD_1withUNUSED_PADorUNUSED_PRESERVE, placed throughplace_subword, while the plain form keeps zeroing the high half.packed_half_rnerounding as #2964.native_f16_alu_check.pyis the old "SDWA form refused" expectation that this PR replaces with implementation plus its own refusals, so it is not a weakened test.Run on AMD: Windows 11 26300.9974, AMD Radeon RX 9070 XT (driver 32.0.32029.2010), release.
ctest --preset release --no-tests=error -R '^native_'gives 53 tests, 52 passed and 1 skipped (77,native_comparison_pso_warp), includingnative_sdwa_f16_{ir,hardware}andnative_f16_alu_{ir,hardware}.Mutation here: always reading the low half (ignoring
WORD_1) fails bothnative_sdwa_f16_ir((0, 'add', '0xa55a4600', '0xa55a4200')) andnative_sdwa_f16_hardware((8, 'add', …)). With it restored, both pass.As with #2964, the default FP mode (RNE, binary16 denormals kept) is assumed rather than read from RSRC1. I will close #2963 by hand.
AI-assisted; the commands above were run locally.