startup: keep gfx1013 non-fused multiply-add rounding in gfx2hlsl #1761
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1768"
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 Jess-Doit on 2026-11-24T18:16:26Z.
Refs #1728
Change
Lower gfx1013
v_mad_f32,v_mac_f32,v_madmk_f32,v_madak_f32andv_mad_legacy_f32with separatepreciseproduct and sum steps. Flushbinary32 denormals at the inputs and after each step. Apply the flush mask
as integer bits so FXC preserves negative zero. The legacy form retains
zero times anything as zero. Bump the startup shader cache revision so
cached bytecode with the previous lowering gets retranslated on request.
The existing HLSL for
v_fma_f32andv_fmac_f32does not guarantee a fused result.Verification
Tested
f7b7297d034651397a0294d64eecf66e2380bb8efrom9ffb85294fc99addb3df670904783435938019f7. Windows 10 22H2 build 19045.6456,Windows SDK 10.0.26100.0, DXC 1.9.2602.17 and FXC 10.0.26100.9457.
The source-built gfx1013 programs decode through the startup translator.
An exact rational Python model supplies the binary32 comparison words.
DXC uses raw UAV input and readback at
cs_6_0and atcs_6_2 -denorm preserve.FXC draws the translated pair at
vs_5_1/ps_5_1. The readback includes aflushed negative sum (
80000000) and the legacy result of zero timesinfinity plus one (
3f800000).40000003for 4 forms,40000002for legacy00c00000for all five40000002for all five00c00000for all fiveThe rounding reference is
40000002. The single-rounding reference is40000003. The text control rejects plain arithmetic even when thecompiler and driver produce the separate-rounding word.
Removing the flushes changes the product and addend cases from
00800000to00c00000on both adapters. That control requests SM 6.2and has its own capability gate. Both adapters reported zero D3D12
debug-layer errors and warnings.
Debug and Release each passed all 20 selected tests with zero failures
and zero skips. The selection includes the new fixture, the existing
startup translator tests, the pixel AOT MAD checks in
pixel_aot_blend_scalar, the legacy MAC and MAD64 tests, and the docs linkcheck. LLVM 15.0.7 and 23.1.6 both reproduced the recorded fixture words.
Newer LLVM can fill unused VOP3 fields differently in other forms.
After merging main at
a4d17cf5(25fbf27b), an independent rerun on the same host passed 18/18 in Debug and in Release with zero skips:ctest --preset <preset> --no-tests=error -j 1 -R '^(startup_gfx2hlsl_|startup_flat_param|docs_links$)', which covers the five newstartup_gfx2hlsl_mad_*tests on both adapters.AI-assisted (Codex, driven with Claude Code).