Repository navigation
startup: lower v_fma_mix* through a precise mad so a zero product keeps its sign - #2818
Conversation
…ps its sign On an RX 5700 XT (R0Y00#2729) and an RX 9070 XT (R0Y00#2746) the -0 case of startup_gfx2hlsl_fma_mix_dispatch_hardware read back 00000000. Their probes lost the sign only when a binary16 operand widened by f16tof32 fed a non-precise multiply or mad. Non-precise HLSL arithmetic need not keep a zero's sign. All three forms now call mix32(a, b, c), a precise mad. Operand order, half selection and modifiers are unchanged; saturate stays outside. mad still lets a backend fuse, so the 1 ULP note stands. The dispatch mode prints a fused/unfused probe per adapter, and a control helper that clears a -0 result must fail exactly the -0 case. The translation changes, so the cache revision moves to x2w-startup-shader-28 (and 28cs) in gfx2hlsl.py, d3d12_draw.inl and the tests that spell it. Refs R0Y00#2729 Refs R0Y00#2746 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
tedin7
left a comment
There was a problem hiding this comment.
Review of 9b6f6473 (comment only).
Looks sound.
Stage.mix()now emitsmix32(a, b, c). The helper isprecise float result = mad(a, b, c), defined next tomul16inPipeline.common(). Operand order, half selection and modifiers are unchanged, andsaturatestays outside the call.- No overlap: #2779 (
mul16) and #2806 (half selection per source position) are merged and touch other lines. #2055 (the original lowering) is merged. No open PR covers this slice. - The cache revision moves from 27 to 28 (graphics and
cs).git grep x2w-startup-shader-27is empty at this head, and every test that spells the revision or a known-answer key was updated. - Test:
startup_gfx2hlsl_fma_mix_dispatch_*reads back from a real D3D12 dispatch and compares with a CPU reference. It includes the-0 productcase (80000000). A negative control swaps in a helper that clears the sign of a zero and must fail exactly that case. - Limit: the AMD cards from #2729 and #2746 were not available to me, so the fix on those drivers is not verified here.
Refsinstead ofFixesis right. - Real-GPU run not available (RunPod stopped).
Commands run:
python3onstartup_gfx2hlsl_fma_mix_check.py,_fract_check.py,_buffer_store_check.py,_const_copy_join_check.py,startup_compute_request_offline_check.py,startup_shader_cache_key_check.py,startup_packed_position_provenance_check.py,tests/docs_links_check.pyandtests/bidi_controls_check.py: all rc=0git diff --check origin/main...HEAD: clean- Mutation:
preciseremoved fromMIX32. The Linux text check still passes, as expected, because the readback needs D3D12. The behavior is guarded by the Windows dispatch test and its sign-clearing control.
Windows Server 2025 (WARP), same head: ctest --preset dev and --preset release with -R on the fma_mix, fract, buffer_store, const_copy, shader_cache_key, compute_request, packed_position, indirect_draw_indexed and resource_retire tests: 100% passed, 42/42 in each preset. This includes startup_gfx2hlsl_fma_mix, _fxc, _dispatch_warp and _dispatch_hardware (on WARP). All Windows Python checks rc=0, including startup_gfx2hlsl_fma_mix_check.py.
AI-assisted; commands listed were executed locally.
|
Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
AI-assisted; commands listed were executed locally. |
Change
startup_gfx2hlsl_fma_mix_dispatch_hardwarefails on an AMD Radeon RX 5700 XT (#2729) and an RX 9070 XT (#2746). The casenegated inline 0 addend keeps a -0 productreads back00000000instead of80000000, while WARP keeps the sign. The probes in those issues lost the sign only when a binary16 operand widened byf16tof32fed a non-precisemultiply ormad, and kept it underprecise. Non-preciseHLSL arithmetic does not have to keep the sign of a zero.Stage.mix()now lowersv_fma_mix_f32,v_fma_mixlo_f16andv_fma_mixhi_f16tomix32(a, b, c). This is a helper inPipeline.common(), next tomul16from #2779:saturatestays outside the call.madstill lets a backend fuse or round the product, so the existing 1 ULP note for binary32 sources still applies.FMadwith!dx.preciseon theFMadand on thelegacyF16ToF32that feeds it.The translated text changes, so the cache revision moves from
x2w-startup-shader-27(and27cs) to28(and28cs). That coverstools/startup/gfx2hlsl.py,src/startup_stubs/d3d12_draw.inl,docs/startup-runtime.mdand the six tests that spell the revision or a known-answer key.git grep x2w-startup-shader-27is empty at this head.Refs #2729
Refs #2746
I'm using Refs rather than Fixes because the failing adapters are AMD and I have no AMD card here (see Verification). This is the candidate described in my comment on #2729. That comment gave ColorMeBoom first claim. No PR from them has appeared, so I'm sending this one. If theirs lands first, this one can be closed.
Verification
Commit
9b6f6473, rebased onmainat410f6004.devpreset built from this commit. Environment: Windows 11 10.0.26300.9974, DXC 1.9.2602.17 and FXC from Windows SDK 10.0.26100.0,X2W_TEST_DEBUG_LAYER=1.-0casemad(4097, 4097, -16785408)1414:008c)8000000000000000(unfused)-0case10de:2684)800000003f800000(fused)-0caseThe debug layer was enabled and every report showed
debug_errors=0 debug_warnings=0.Controls in the dispatch mode:
mad(4097, 4097, -16785408)per adapter.mix32allows either result, so it isn't checked.-0result, which is what the RDNA 1 and RDNA 4 drivers did withoutprecise. It must fail exactlynegated inline 0 addend keeps a -0 productand no other case.Revision-dependent tests: at the same build, before committing, a wider run of 43 tests passed on WARP and the RTX 4090. That covered the four above, plus
startup_shader_cache_key,startup_shader_cache_rekey,startup_compute_request_*,startup_indirect_draw_indexed_*,startup_resource_retire*,startup_gfx2hlsl_fract*,startup_gfx2hlsl_buffer_storeandstartup_gfx2hlsl_const_copy_join. The negative-control paths in those tests printFAIL:and debug-layer lines while the tests pass.Python checks: these pass at this head:
startup_gfx2hlsl_fma_mix_check,startup_compute_request_offline_check,startup_gfx2hlsl_buffer_store_check,startup_gfx2hlsl_const_copy_join_check,startup_gfx2hlsl_fract_check,startup_packed_position_provenance_check,startup_shader_cache_key_check,startup_shader_cache_rekey_check,startup_gfx2hlsl_mad_check,docs_links_checkandbidi_controls_check.Not shown: the RTX 4090 also passed before this change, so these runs do not demonstrate the fix on RDNA. They show that
mix32keeps every existing word and the-0sign on WARP and NVIDIA, and that the control can catch a dropped sign. The RX 5700 XT (#2729) and RX 9070 XT (#2746) retests are still needed:Evidence and follow-up
docs/experiments.mdgets a "Signed zero: aprecisemad(cache revision 28)" subsection under the existingv_fma_mixsection.docs/startup-runtime.mdlists revision 28.preciseon themadis enough for the RDNA drivers. That rests on the probes posted on gfx2hlsl: the v_fma_mix lowering is notprecise, so RDNA 1 drops the sign of a -0 product (startup_gfx2hlsl_fma_mix_dispatch_hardware) #2729 and startup_gfx2hlsl_fma_mix_dispatch_hardware fails on RX 9070 XT: -0 addend reads back as +0 #2746, not on a run of this commit.Checklist
AI-assisted with Claude Code (Claude Opus 5.5). The commands listed were run locally.
🤖 Generated with Claude Code