compute: admit SDWA profiles for lowered f16, frexp and conversion ops #3470
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3470"
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 Ammmae0x on 2026-11-29T16:22:17Z.
Refs #3224, #2935
Eliminates the
unimplemented direct SDWA operand profilediagnostic (ranked #8 in the #3224 census at 24,469 dispatches) for 21 VOP1/VOP2 opcodes across 34 new SDWA test profiles (46 profiles in total, with the twelve from the earlier SDWA note), for operations whose base operations already have direct-compute lowering.Admitted profiles
v_floor_f16,v_ceil_f16,v_trunc_f16,v_rndne_f16,v_fract_f16,v_frexp_mant_f16,v_frexp_exp_i16_f16v_cvt_f16_u16,v_cvt_f16_i16,v_cvt_u16_f16,v_cvt_i16_f16,v_cvt_norm_i16_f16,v_cvt_norm_u16_f16v_max_f16,v_min_f16,v_ldexp_f16v_frexp_mant_f32,v_frexp_exp_i32_f32,v_cvt_flr_i32_f32,v_cvt_rpi_i32_f32,v_cvt_off_f32_i4Rules
Validation is per operand, mirroring
tools/disasm_rdna2.py(_vop1_sdwa_spec,_vop2_sdwa_spec):v_ldexp_f16is the mixed case: src0 float16, src1 int16, dst float16.sdwa_half, exceptv_ldexp_f16src1 which readssubword(operand32), see below) andplace_subworddestination placement; no modifier or subword selection is silently ignored.Still refused in SDWA:
v_sin_f16/v_cos_f16(no direct lowering),v_fmac_f32/v_fmac_f16and the rest ofVOP2_SDWA_UNSUPPORTED_OPS, 64-bit_f64/_b64forms, and VOP3-only ops (v_fma_f16,v_min3_f16,v_med3_f16,v_cvt_pknorm_*). Graphics translation still refuses all of these SDWA forms.v_max_f16,v_min_f16,v_floor_f16,v_ceil_f16,v_trunc_f16,v_rndne_f16,v_frexp_mant_f16andv_frexp_exp_i16_f16were missing from the binary16 MODE scan insrc/gfx1013_direct_compute.inl, so a program using one of them together with ans_round_mode/s_denorm_modewrite was refused as an unsupported control instruction instead of having the MODE write consumed under the keep-denorm contract. They are now listed there, matchingv_fract_f16,v_ldexp_f16and the conversion ops. A MODE write that moves the binary16 rounding or denormal bits is still refused.Tests
tests/native_sdwa_profiles_check.pygains a second and third program (12, 28 and 6 slots, each under the 32-slot hardware layout) with an independent Python/ISA reference model, plus 15 refusal controls: disallowed VOP2 SDWA ops, float/int modifier violations, omod/clamp on integer destinations, invalid 16-bit destination selection and unused mode, a byte source pick, literal 255, andv_sin_f16.tests/native_sdwa_f16_scalar_check.pygains admitted SDWAv_max_f16/v_min_f16cases with SGPR sources and a MODE-write refusal.tests/native_fract_f16_check.py,tests/native_cvt_norm_f16_check.py: the SDWA form is refused for its DWORD destination select, now that the op itself is admitted); both programs are still refused.tests/native_sdwa_f16_check.py: the two obsolete max/min SDWA refusals are replaced withv_fmac_f32/v_fmac_f16, which stay refused.docs/experiments/direct-sdwa-profiles.md, a pointer section indocs/experiments.md, and the stale "SDWA min and max remain refused" line indocs/experiments/native-sdwa-f16.mdcorrected.Note: this extends the existing
native_sdwa_profilessuite rather than adding anative_compute_sdwa_profilessuite, so the WIN-VERIFY tag below names the real CTest namesnative_sdwa_profiles_(ir|dxil|hardware).Review follow-ups (
efb53ad0)@Leyukaka's review of
9541306f(above), addressed inefb53ad0:docs/experiments/direct-sdwa-profiles.mddrops the Linux-verification section and records the verified9541306fWindows baseline above, with the exact count of 21 opcodes across 34 new profiles.v_frexp_*_f32SDWA coverage: a WORD_1 source pick (the picked value is a subnormal, since only the high half of the f32 word is read) and a WORD destination with UNUSED_PRESERVE now pinsubword()andplace_subword()in that handler.v_max_f16/v_min_f16: new cases with a non-canonical NaN payload (0x7C01, and0x7C01vs0xFC01where both are NaN) and with signed zeros (+0.0vs-0.0). The model (sign-magnitude key; NaN yields the other operand, both NaN yield canonical0x7E00; max(+0,-0)=+0, min(+0,-0)=-0) matches the lowering's emitted icmp/select IR exactly, and the signed-zero order matches IEEE maxNum/minNum.v_ldexp_f16inline float constant as src1: the SDWA path now readssubword(operand32)instead ofsdwa_half, so inline 242 (1.0) reads its f32 pattern0x3F800000— delta 0 from WORD_0, delta 16256 clamped to 64 from WORD_1 — matching the plain path, which reads the low 16 bits ofoperand32. Register sources read the same word either way. Two cases pin this (WORD_0 gives 1.0, WORD_1 gives +inf; reading the binary16 pattern0x3C00would give +inf in both).src/gfx1013_compute_native.cppis removed; all listed ops now honouri.subwordandplace_subword.Linux re-verification (
efb53ad0)Run on Linux against a throwaway harness build of
native_compute_ir_dump/native_pixel_ir_dump(stubd3d12.hand root-signature deserializer only, never committed):Five spot-mutations on
/tmpcopies of the sources, each killed:subword()in thev_frexp_*_f32handler: interpreted values fail (mantissa0x3F400000vs0x3F028000, exponent4vs-133).place_subword()in thev_frexp_*_f32handler: interpreted values fail (mantissa0x3F412345vs0x23451357, exponent0x4vs0xA55A0004).v_ldexp_f16src1 tosdwa_half: the dump refuses withunsupported SDWA binary16 inline constant selection(the WORD_1 inline pick).0x7C01payload instead of0x7E00).irrun fails (thev_ldexp_f16src0-sext refusal case is admitted).Note: the
irmode checks admission, needles and refusals, not values, so it stays green under the first two reverts; the interpreted-IR value check over the same dumped IR (the Linux stand-in for the hardware run) is what fails on the new cases.The follow-up edits above await a fresh Windows rerun on the new commit.
Windows Verification
AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-29T17:27:02Z.
Review: COMMENTED
Diff reading only at
9541306f; nothing built or run.Checked:
sdwa_profile()operand types match the ops (float or integer, 16-bit or not, per source and destination;v_ldexp_f16src1 as int16).sdwa_newfalse,src_float,dst_16,src_16and the clamp/scale conditions reduce to the old expressions. The non-SDWA lowering paths keep the old expressions behindi.subword ? ... : old.sdwa_newrequires!graphics, and the fixture runs every new profile through the pixel dumper and expects a refusal.half_binary, so a MODE write next to them goes toconsume_half_modeinstead of the control-instruction refusal.SHOULD
docs/experiments/direct-sdwa-profiles.md:98-99: the note says the DXIL/hardware CTest runs and GPU readback await Windows verification and that no hardware result is claimed. The PR body reports those runs passing on this head (dev and release, 3/3, plus 20/20 f16/SDWA regressions). Please put that result in the note. The "Linux verification" section (:74-96) describes a harness that is not in the repo.SHOULD
tests/native_sdwa_profiles_check.py:90-91: both f32 frexp profiles usesrc0=DWORD, dst=DWORD, so the new SDWA code in that handler is not exercised. Reverting thesubword(...)pick atsrc/gfx1013_direct_compute.inl:2280-2281or theplace_subwordat:2309leaves every test green. One case with a WORD_1 (or byte) source pick and one with a WORD_0/WORD_1 destination would cover it.NITs:
tests/native_sdwa_profiles_check.py:229-245: the min/max model uses the same sign-magnitude key and NaN rule as the lowering, and only the 0x7E00 NaN is tested.v_ldexp_f16with an inline float constant as src1: the SDWA path reads the binary16 pattern (sdwa_half), the plain path reads the low 16 bits ofoperand32. The two differ and neither is tested.src/gfx1013_compute_native.cpp:40-41: "the lowering is the second gate" only holds for handlers that testi.subword; all listed ops now handle it.Imported from R0Y00/Xbox2Windows. Originally posted by Ammmae0x on 2026-11-29T17:56:12Z.
Addressed all items from
@Leyukaka's review (PRR_kwDOV10-fc8AAAABa9Mn3w) inefb53ad0:docs/experiments/direct-sdwa-profiles.md&docs/experiments.md): Removed the Linux throwaway-harness section and stale pending wording, recorded the verified9541306fWindows baseline, and aligned the counts (21opcodes across34new /46total SDWA profiles).v_frexp_*_f32SDWA coverage (tests/native_sdwa_profiles_check.py): AddedWORD_1source-pick andWORD_0/WORD_1UNUSED_PRESERVEdestination cases so bothsubword()andplace_subword()in thev_frexp_*_f32handler are pinned against mutation.v_max_f16/v_min_f16non-canonical NaN (0x7C01,0xFC01) and signed-zero (+0.0/-0.0) cases, alignedv_ldexp_f16src1SDWA tosubword(operand32(...))for inline constants (withreg1=242WORD_0/WORD_1coverage), and removed the stale comment insrc/gfx1013_compute_native.cpp.Windows Verification (
efb53ad0)AI-assisted.
Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-29T18:09:12Z.
Review: APPROVED
Re-reviewed
9541306f..efb53ad0. Both earlier points are fixed:docs/experiments/direct-sdwa-profiles.md:82-97now records the Windows results on9541306fand says the new cases still need a rerun.tests/native_sdwa_profiles_check.py:104-113adds frexp f32 cases with aWORD_1source andWORD_1/WORD_0preserve destinations; by reading, revertingsubword()atsrc/gfx1013_direct_compute.inl:2283orplace_subword()at:2311changes the expected value (not run as a mutation).inl:2469now picks the subword ofoperand32, so an inline constant reads its f32 pattern on both paths;tests:133-136coverWORD_0andWORD_1.Hardware rerun on
efb53ad0(NVIDIA GeForce RTX 508010de:2c02, driver32.0.16.2101; D3D12 debug layer not installed; configured with-DX2W_WITH_OPUS=OFF):ctest --preset dev --no-tests=error -R '^(native_sdwa_|native_cvt_norm_f16|native_cvt_pknorm_f16|native_fract_f16)'-> 20/20 passed, 0 skipped, 71 s.native_sdwa_profiles_hardware: "46 results and all guards matched".native_frexp_f16_*andnative_f16_alu_*are outside this filter and were not rerun.Nit, non-blocking:
direct-sdwa-profiles.md:94names a GitHub handle; a commit reference would age better, and that paragraph can now cite the rerun above.Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-30T03:54:37Z.
This change is green on its branch but leaves
mainred at44a3ad5aa: four native SDWA tests fail because the programs they mark asunimplemented direct SDWA operand profileare profiles this PR now admits, so they are refused one gate later on the destination. Reported with the measurements in #3547.One finding there may be worth your judgement specifically:
v_sin_f16andv_cos_f16translate successfully in this build when the destination is well formed (rc=0), although the note added here says they are still refused.063d4e1a5added that lowering before this PR, so the sentence looks out of date rather than the code being wrong.