shader: lower gfx1013 v_mad_f32 and v_mac_f32 as unfused, denormal-flushing multiply-add #284
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/288"
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 Its3rr0rsWRLD on 2026-11-21T20:53:37Z.
Change
pixel_aotrejectedv_mad_f32andv_mac_f32. Both are gfx1013 multiply-adds that round the product to binary32 before the add and do not support binary32 denormals, so they cannot reuse thefma/fmaclowering. This lowers both through amad32helper that flushes each operand, the product and the sum to signed zero and keeps the two roundings withprecise;v_mac_f32accumulates into its destination likev_fmac_f32. Independent problem: it widens the arithmetic the pixel translator accepts. It touches theALUtable and the arithmetic match intools/pixel_aot.py; I found no open PR that lowers either instruction.Source for the semantics: LLVM 15 AMDGPU,
SITargetLowering::isFMADLegalinllvm/lib/Target/AMDGPU/SIISelLowering.cpp, which selectsv_mad_f32/v_mac_f32for an unfused multiply-add only when f32 denormals are flushed ("v_mad_f32/v_mac_f32 do not support denormals").Verification
Commit
d311159plus this change (0f6e404), Windows 10 Enterprise 26H2 build 26300.9974, MSVC 14.51.36231, Windows SDK 10.0.26100.0 DXC.pixel_aot_hardware: Passed on NVIDIA GeForce RTX 4070 Ti (vendor 10de, device 2782), driver 32.0.16.1088.pixel_aot_warp: Passed on Microsoft Basic Render Driver, WARP 10.0.26100.9818.debug_errors=0 debug_warnings=0andmax_absolute_error=0for every draw. Each test runs 41 draws with this change and 40 ond311159; the extra draw is the new one.c832696, before rebasing: 133/133 passed (bvh_wave64_hardware,bvh_wave64_warp,wave_shuffle_warpcapability-skipped).tests/docs_links_check.pyandtests/bidi_controls_check.pypass.tests/pixel_aot_check.py binarypasses with the program added to the binary fixtures: LLVM 15.0.6llvm-mcandllvm-objcopy, disassembled throughlibLLVM-17.soandlibLLVM-18.soon Linux (no shared LLVM 15 library was available). Unchanged main passes the same check with both libraries. The Ubuntu CI job runs it with LLVM 15.Evidence and follow-up
The fixture is synthetic. 4097 × 4097 = 2^24 + 2^13 + 1 rounds to 2^24 + 2^13, so 4097 × 4097 − 16785408 is 0 unfused and 1.0 fused; it is checked for both
v_mad_f32andv_mac_f32. 2^-127 × 2^126 + 0.5 is 0.5 with the denormal input flushed and 1.0 without. Negative controls: references expecting the fused result (for each instruction) or the denormal-preserving result must reportpixel_mismatch, and all three do. The translator on main rejects the program at its firstv_mad_f32. The controls also assert both instructions usemad32and reject a three-operandv_mac_f32and a two-operandv_mad_f32.Assumption not measured here: that Scarlett flushes a denormal product or sum, as the helper does, in addition to denormal inputs. Recorded in
docs/experiments.md.Checklist
AI-assisted: yes. Written with Claude; verified on the hardware listed above.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T20:57:37Z.
At
5b194053,tools/pixel_aot.pyconflicts after #258. Please retain truncation in the arithmetic matcher alongsidemadandmacand rerun the pixel checks, including the unfused and denormal controls.Imported from R0Y00/Xbox2Windows. Originally posted by Its3rr0rsWRLD on 2026-11-21T21:01:04Z.
Rebased onto
d311159. The only conflict was the arithmetic matcher intools/pixel_aot.py; it now reads...|floor|fract|trunc|add|...|fma|fmac|mad|mac, so truncation from #258 is retained alongsidemadandmac. Thedocs/experiments.mdentry now namesd311159as the tested commit; nothing else changed.At 0f6e404 (
d311159plus this change), Windows 10 Enterprise 26H2 build 26300.9974, MSVC 14.51.36231, Windows SDK 10.0.26100.0 DXC:pixel_aot_hardware: Passed, NVIDIA GeForce RTX 4070 Ti (10de:2782), driver 32.0.16.1088. 41 draws, every onedebug_errors=0andmax_absolute_error=0.pixel_aot_warp: Passed, WARP 10.0.26100.9818. 41 draws, same.d311159alone on the same machine: both pass with 40 draws; the extra draw is the mad/mac one.The run includes the controls (both instructions lower through
mad32, malformed operand counts are refused, and the truncation controls from #258 still pass) and the draw's three wrong references: the fused result forv_mad_f32, the fused result forv_mac_f32and the denormal-preserving result. All three were reported aspixel_mismatch.Imported from R0Y00/Xbox2Windows. Originally posted by Its3rr0rsWRLD on 2026-11-21T21:05:12Z.
Added one follow-up commit (f7c8e23): the mad/mac program is now in the
check_binaryfixtures, liketruncate_values()from #258, so the Ubuntu job assembles it with LLVM 15, disassembles it from the native program and compares the lowering.tests/pixel_aot_check.py binarypasses locally with LLVM 15.0.6 tools and libLLVM 17 and 18. No change to the translator or the draws.Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T21:28:21Z.
At
f7c8e23, the merge conflicts are intools/pixel_aot.py. Please retainceil,truncand the pending-destination check when integrating the unfused MAD/MAC matcher.Imported from R0Y00/Xbox2Windows. Originally posted by Its3rr0rsWRLD on 2026-11-21T21:41:58Z.
Rebased onto
b53bfb0after #270 and #299. The arithmetic matcher now listsceilfrom #270 alongsidemadandmac, and the mad/mac binary fixture follows the cube fixture from #299. Nothing else changed.At 64d4207 (
b53bfb0plus this change), Windows 10 Enterprise 26H2 build 26300.9974, MSVC 14.51.36231, Windows SDK 10.0.26100.0 DXC:pixel_aot_hardware: Passed, NVIDIA GeForce RTX 4070 Ti (10de:2782), driver 32.0.16.1088.pixel_aot_warp: Passed, WARP 10.0.26100.9818.b53bfb0, every onedebug_errors=0andmax_absolute_error=0.tests/pixel_aot_check.py binary, the controls,docs_links_check.pyandbidi_controls_check.pypass on Linux with LLVM 15.0.6 tools and libLLVM 17 and 18.This branch merges cleanly with each of my other open pixel_aot pull requests.
Imported from R0Y00/Xbox2Windows. Originally posted by R0Y00 on 2026-11-21T21:58:21Z.
At
64d4207the merge conflicts are intests/pixel_aot_check.py. Keep the literal fused controls from #292 and your separate unfused/FTZ MAD and MAC controls.Imported from R0Y00/Xbox2Windows. Originally posted by Its3rr0rsWRLD on 2026-11-21T21:59:47Z.
Rebased onto
1292d15after #279. The only conflict was incheck_render: the mad/mac draw now runs after the 64-bit scalar draws from #279. Nothing else changed.At
2843f2e(1292d15plus this change), same machine as before:pixel_aot_hardware(RTX 4070 Ti, driver 32.0.16.1088) andpixel_aot_warp(WARP 10.0.26100.9818) pass with 55 draws each against 54 on1292d15, every onedebug_errors=0andmax_absolute_error=0.tests/pixel_aot_check.py binary, the controls anddocs_links_check.pypass on Linux with LLVM 15.0.6 tools and libLLVM 17 and 18.