shader: lower v_pk_fmac_f16 in direct Compute and Pixel DXIL #3259
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3259"
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 legacy-code-archaeologist on 2026-11-28T02:28:31Z.
Lowers plain VOP2
v_pk_fmac_f16(0x3c) in the direct Compute and Pixel DXIL paths, unblockingdirect DXIL lowering for v_pk_fmac_f16in the #3224 start-up census.Fixes #3258. Refs #2935, #3224.
Summary
src/gfx1013_direct_compute.inl:v_pk_fmac_f16topacked_f16_arithmetic()(which also enableshalf_binary = truetracking inDirectCompute::lower()).packed_f16_alu(i, permuted)to accept plain VOP2v_pk_fmac_f16with zero modifiers (refusing_e64/wide,subword,dpp_control,permuted,abs,neg,clamp,scale), read the in-place binary16x2 accumulator fromi.dst, select low halves (0) and high halves (7), and reusefused_half_rne()under the full0x8000ccubinary16 mode contract.tests/native_f16_alu_check.py:v_pk_fmac_f16(0x3c) to fail withdirect DXIL lowering for v_pk_fmac_f16.tests/native_pk_fmac_f16_check.py,tests/cmake/native_pk_fmac_f16.cmake:17cases: distinct low/high VGPR FMA, fused cancellation(1 + 2^-6)^2 - 1 = 0x2808(distinguishing fusedfused_half_rnefrom unfused mul+add0x2800), multi-accumulate intovdst,vdstaliasingsrc0andvsrc1, SGPR/literalsrc0, inline binary16 float/integer constants (0.5,1.0,-1.0,0,0x0001), binary16 subnormals, finite-to-Inf overflow, partialEXEC_LO(0xAAAAAAAA) lane preservation, signed zero, Inf, and NaN.8refusals: VOP3_e64(0xD53C0000), DPP16, DPP8, SDWA,vcc_losrc0,s_round_mode 0x4,s_denorm_mode 0x3, and conditionalMODEwrite.Verification (
devandrelease/O2, Windows10.0.26100)ctest --preset dev --no-tests=error -V -R '^native_(pk_fmac_f16|packed_f16)_'&ctest --preset release --no-tests=error -V -R '^native_pk_fmac_f16_':native_pk_fmac_f16_ir: Passed (17cases matched exact rational model;8refusals matched).native_pk_fmac_f16_controls: Passed (17cases compiled to DXIL;8refusals verified).native_pk_fmac_f16_pixel_warp: Passed (4quad draws matched on WARP).native_pk_fmac_f16_pixel_hardware: Passed (4quad draws matched; host hardware pixel adapter isNVIDIA Quadro M1000M,32.0.15.7371,debug_layer=unavailable).native_pk_fmac_f16_compute_hardware: Skipped (77) (Intel(R) HD Graphics 530, vendor8086, device191b, driver31.0.101.2111lacks SM 6.6 wave32 — needs testing on a wave32-capable GPU).native_packed_f16_*&native_packed_f16_inline_*(dev): all non-compute-hardware tests Passed (_compute_hardwareskipped77on HD 530).ctest --preset dev --no-tests=error -V -R '^native_f16_alu_ir$'&--preset release: Passed (82results,13refusals); the remaining70native_.*_(controls|ir)tests indevalso passed prior to the single-line stale refusal removal intests/native_f16_alu_check.py.rc=8): using low half for high lane (fmac ? 3u :), disablingfusedforfmac(fused_cancellationmismatch), and removingv_pk_fmac_f16frompacked_f16_arithmeticall failednative_pk_fmac_f16_ir.AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by pigalot on 2026-11-28T04:26:09Z.
Review: APPROVED
Independently reviewed
a6513f54integrated overmaindbb933d1(treecc413710). The merge is clean andgit diff --cached --checkis clean.What I traced.
v_pk_fmac_f16is VOP20x3c. The low lane computesS0.lo * S1.lo + D.loand the high laneS0.hi * S1.hi + D.hi, with one rounding each. The PR reads the accumulator fromi.dst, which the decoder already stores as256 + vdst. It selects all-low (0) and all-high (7) halves with no negation, and reusesfused_half_rne()._e64/wide, SDWA, DPP,abs,neg,clampandscale. It keeps the same0x8000ccbinary16 mode gate and the same source decode as the VOP3P forms. Inline constants therefore get the zero-high-half rule frompacked_f16_inline_constant().tests/native_f16_alu_check.pyis the old "not lowered yet" refusal for this opcode. The new fixture replaces it with positive cases, so no test is weakened.What I ran. I built
compile_dxil native_store_replay native_compute_ir_dump offscreen_checkindevandrelease, then ranctest --test-dir out/build/<preset> --no-tests=error -j 1 -V -R '^native_pk_fmac_f16_.+$'. The_hardwaretests ran at-j 1. All 5 pass in Debug and in Release/O2, with no skips:_irand_controls: 17 cases and 8 refusals._pixel_warpand_pixel_hardware: 4 quad draws each._compute_hardware: "17 cases matched across 2x32 lanes and guards" on the RTX 5090, at wave32. This is the run the PR body could not do on its HD 530.The neighbours also pass in both presets: the 86
native_f16_alu_*,native_packed_f16_*and^native_.*_(controls|ir)$tests, and their 6_hardwaretests.Negative control and mutants. Each was rebuilt in
devand run against all 5 tests:src/gfx1013_direct_compute.inlback tomaindbb933d17u→0u)_ircase 0vgpr_basic, both pixel tests, compute)7u→3u)_ircase 0, both pixel tests, compute)_ircase 1fused_cancellationand others,_controls, both pixel tests, compute)vdst_ircase 0, both pixel tests, compute)_irand_controlsrefusal 7, the conditional MODE write)_e64/wideaccepted_irand_controlsrefusal 0)Restored and rebuilt afterwards;
git diff --quietis clean.Non-blocking. The new
permutedrefusal in the fmac branch isn't reached by the fixture. The DPP16 and DPP8 refusals stop earlier, with "unsupported DPP arithmetic".Verdict: approve on
a6513f54.Environment: NVIDIA GeForce RTX 5090 driver 32.0.16.1088, Windows 11 25H2 build 26200.9974; MSVC 19.52.37029; SDK 10.0.28000.0
dxc.exe(the one CTest picked up); Python 3.12.10; wave32; D3D12 debug layer enabled in the pixel tests.CI:
Build and test on Windowspasses ona6513f54.This reply was AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-28T04:35:26Z.
A note after merge, from reading the diff (not run). I found nothing wrong in the lowering: it uses the same fused helper as
v_pk_fma_f16, reads D before writing it, and pairs low with low and high with high.The fixture's fused-rounding case does not separate a fused result from a binary32 multiply-add, though.
fused_cancellationuses low halves0x3c10 * 0x3c10 + 0xbc00:1 + 2^-5 + 2^-12is exact in binary32, so a fused result and a binary32fmul+fadd+ round-to-binary16 both give0x2808.0x2800).The pixel_aot discriminator in
docs/experiments.md,0x3e00 * 0x3956 + 0x0001, separates the two: the fused result is0x3c01, and a binary32 multiply-add gives0x3c00. Adding it toall_cases()would pin the single rounding. Thecontrolsstring checks (unaryBits.i32(i32 33,andmul i32) are consistent with the helper being emitted, but do not check its rounding.AI-assisted.