shader: lower binary16 add, sub, subrev and mul in direct compute #2964
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2964"
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 SimSalabimse on 2026-11-26T23:55:00Z.
Change
Fixes #2945.
This targets
cpp-migration. Head under test:5b580cb3, based one3670100.The decoder already names the VOP2 forms
v_add_f16,v_sub_f16,v_subrev_f16andv_mul_f16, but the direct C++ compute path had no rule for them and refused each by name. This change lowers the VOP2 and_e64spellings:v_subrev_f16swaps the sources). An f32 significand is wide enough for a correctly rounded binary16 add, sub or mul.v_cvt_f16_f32uses. The low 16 bits are written and the high half is zero, matching RDNA 2.SDWA and DPP forms, clamp and omod, a high-half
op_sel, and a binary16 rounding or denormal mode other than the implemented contract (round-to-nearest-even, f16 denormals kept on input and output,FP16_OVFLclear) are refused with a named diagnostic.s_setreg_b32of those MODE bits is refused because the source is a register. A guest branch together with a MODE write makes the contract unprovable and is refused the same way.s_round_modeands_denorm_modethat leave the f16 fields at that contract, and that leave the f32 fields unchanged, are accepted. The handler returns without lowering when the stage is graphics, so a graphics program keeps the generic direct-lowering refusal.v_fmac_f16andv_min_f16stay on the generic diagnostic, as do the other forms listed as out of scope in #2945.Verification
Linux, after the rebase onto
e3670100:The model check passed. The
python-linuxlist passed 211 checks, and thepixel-binarylist passed 136 checks.Windows, dev preset, on the test PC, at
5b580cb3:Both of two runs: 2/2 passed, ctest exit 0, no skips.
native_f16_alu_ir: 82 results match the model; 20 refusals carry the named diagnostic (1.68 s, 1.53 s).native_f16_alu_hardware: 164 words matched the model, high half zero (1.66 s, 0.87 s).A
^native_regression sweep on the same build ran once:ctest exit 0. 44 passed, 1 skipped, 0 failed, 142.93 s. The skip was
native_comparison_pso_warp(compute requires wave32: WaveOps=1 range=4..4), which is WARP's 4-lane wave limit; it is not a skip of the new f16 tests.native_f16_alu_hardwareusesWaveSize=32and ran on the hardware adapter in this environment, so it did not take the skip code 77.Evidence and follow-up
The new checks use a source-built compute container and a bit-pattern table (signed zeros, subnormals, infinities, NaN, 65504, and round-to-nearest-even ties and overflow to infinity). No game files or captured programs. The model check fails a mutant that swaps
v_sub_f16andv_subrev_f16, and one that leaves the upper half unzeroed. The 20 IR refusals cover SDWA and DPP for each of the four ops, clamp, omod, a high-halfop_sel, a non-default f16 rounding or denormal mode, an SGPR MODE write, an f32 rounding or denormal write that keeps the previous control-instruction refusal, and the out-of-scopev_fmac_f16andv_min_f16forms.Checklist
AI-assisted (Cursor)
Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-27T00:32:19Z.
Review: APPROVED
Review of head
5b580cb3, tested merged ontocpp-migrationb260984f. It auto-merges cleanly, and CI on the head is green. Approving and merging.Code read:
legacyF16ToF32widening, one f32fadd/fsub/fmul, then the existingpacked_half_rne, with the high half zeroed. The f32-then-f16 rounding is innocuous for these ops (24 ≥ 2·11+2), and every f16 subnormal and every f16 product is normal in f32, so an f32 denormal flush cannot affect the result.op_sel, a non-contract f16 MODE, an SGPRs_setreg, and a MODE write together with a guest branch. Graphics stays on the generic refusal.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_': 47 tests, 46 passed and 1 skipped (77,native_comparison_pso_warp), includingnative_f16_alu_irandnative_f16_alu_hardware.python -B tests/native_f16_alu_check.py model:82 results match f32-then-round; a sub/subrev swap and a non-zero upper half are rejected.Mutation here: dropping the
v_subrev_f16operand swap fails bothnative_f16_alu_irandnative_f16_alu_hardware, each showing the expected sign flips, for example(2, '0xbc00', '0x3c00'). With it restored, both pass.One assumption to keep in mind, not blocking: the starting MODE is fixed at the contract (RNE, f16 denormals kept,
FP16_OVFLclear). On the console the initial f16 round and denormal fields of a compute wave come fromCOMPUTE_PGM_RSRC1.FLOAT_MODE, which this path does not read from the request. A program launched with a different float mode would therefore be lowered under the wrong contract instead of being refused. If.sacarries RSRC1, checking it against0xf0at entry would close that gap.I will close #2945 by hand.
AI-assisted; the commands above were run locally.