shader: lower compute v_mac_f32 as an unfused multiply-add #2156
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2164"
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 henriazz10 on 2026-11-25T02:11:53Z.
Change
Refs #721. This is the
v_mac_f32slice claimed in https://github.com/R0Y00/Xbox2Windows/issues/721#issuecomment-7144791814. It touches onlytools/compute_store_aot.py,tests/compute_store_check.py,CMakeLists.txtanddocs/experiments.md.v_mac_f32_e32 vD, S0, vS1(VOP20x1f) andv_mac_f32_e64 vD, S0, S1(VOP3) computeD = S0 * S1 + Das an unfused binary32 multiply-add: the intermediate productS0 * S1rounds to binary32 before the addition.Dis both an input accumulator and the destination.f32_mac(a, b, c)with separateprecise float p = asfloat(a) * asfloat(b)andprecise float r = p + asfloat(c)so DXC does not contract the operation to FMA.0x7fc00000,0x7f800000,0x00000001);S0/S1(v40,s12), uninitialized accumulatorvD, andvDabovev255(v256);-0x45800800,|-2.0|),clamp,omod(mul:2),_e32with SGPRS1, and barev_mac_f32.v_mac_f32_e32refusal fromf32_controls().The existing
f32_controls()entry that usedv_mac_f32_e32as an unsupported example now usesv_mad_f32, which is still refused, so that list keeps the same number of refusal checks.Verification
Commit
da769b07, rebased onto8700da53. The draws,controls()and the LLVM 15 round trip were re-run onda769b07. Windows 11 build 26300, VS 2019 Build Tools 16.11 (MSVC 14.29), DXC 1.8.2502.11, Python 3.12, debug layer enabled.offscreen_checkwas built from an earliermain; this PR does not change it.groups=1 compared_words=320 mismatches=0,debug_errors=0 debug_warnings=0groups=1 compared_words=320 mismatches=0,debug_errors=0 debug_warnings=0docs_links_check.py(18 Markdown files, 398 links),bidi_controls_check.py(1439 tracked files), andgit diff --check HEAD~1all exited 0.The LLVM 15 round trip in Docker (
x2w-llvm15) exited 0 (binary_exit=0):mac_f32_binary()decodes the assembledMAC_F32fixture back to the samev_mac_f32lines and requires the same translation.Negative control. With
tools/compute_store_aot.pyfromorigin/main,mac_f32_controls()fails withValueError: Unsupported compute instruction: v_mac_f32_e32 v10, 0x45800800, v5.Evidence
The
MAC_F32fixture is source-built in LLVM 15 spelling. It runs one group of 64 threads (buffer_store_dwordx4, 256 output words plus 64SENTINELwords), covering4097 * 4097 + (-16785408)and(2 + 2^-23) * (1 + 2^-23) - (1 + 2^-22)(plus unique per-threadtid.xinputs) where unfused and fused results differ, and compares all 320 words against an independent Python model.outputData.Store4(...)line,float_wordliteral refusals, unknown/pending sources, uninitializedvD,v256, modifiers,_e32SGPRS1, and bare spelling.Compute readback differs:p - asfloat(c)instead ofp + asfloat(c)(WARP and hardware);mad()instead of unfused multiply+add (hardware, wheremad()contracts to FMA).Checklist
docs/experiments.md).AI-assisted. Gemini 4 Hydrogen (Antigravity CLI) wrote the change and ran the checks; Claude Code reviewed it.
🤖 Generated with Claude Code
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T02:40:27Z.
Review: COMMENTED
Review of head
da769b075dFinding (P2): the new
compute_store_aot_mac_f32_hardwaretest fails on Win2025.compute_store_aot_mac_f32_warppasses.groups=1 compared_words=320 mismatches=0.mac_f32_draw(tests/compute_store_check.py:3352):AssertionError: mac_f32: mutation 'fused mad() instead of unfused multiply+add' escaped detection.precise float r = mad(a, b, c). Because ofprecise, the compiler does not fuse it, so the mutant gives the same bits as the real lowering on this adapter. That makes it an equivalent mutant, not a weak lowering. Suggested fix: use a mutation that really changes results on every adapter (for examplep - c, which is already in the list), or compare against a true fused reference such asfma()withoutprecise. Do not require detection ofmadon every backend.What looked fine:
v_mac_f32are covered.f32_machelper sits next to the sibling f32 helpers, and the docs entry is present.v_mac_f32.dot_upattern.Commands executed locally (Linux):
python3 tests/docs_links_check.py: pass (18 files, 399 links)python3 tests/bidi_controls_check.py: passgit diff --check origin/main...HEAD: cleanmac_f32_controls(): pass. Mutation: the accumulator token replaced with0x0in the lowering made the controls fail, as expected. Mutation:p + cchanged top - cin the HLSL helper was NOT caught by the controls on Linux, because only the GPU draw test sees it.Commands executed on Win2025 (
x2w_pipe.py win2025 2164 --scope direct --targets offscreen_check --regex '^compute_store_aot_(mac_f32|dot_u|add_co)_(warp|hardware)$'):Not a merge candidate until the hardware test is fixed. Please push a fix and re-run.
AI-assisted; commands listed were executed locally.