fix(shader): mark the fused exact f32 operations NoContraction #16967
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16967"
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 boykopovar/AnyPS5. Originally posted by sherySJ on 2026-11-08T02:24:14Z.
Cause and design
Not an ANV float-controls deviation and not a test problem: the fused lowering lost the exactness marker its unfused sibling has.
fusedExactArithmeticlowers the f32 multiply, add and subtract toFma(x, y, -0.0),Fma(1.0, x, y)andFma(-1.0, y, x). Production sets it for MoltenVK only (VulkanDevice.cpp:1592);F32DenormalFlush.cpp:524-526forces it on every device, which is how ANV reaches it. The unfused branch of each emitter isOpFMul/OpFAdd/OpFSubplusNoContraction; the fusedFmacarried no decoration.flushTinyProduct(OperandAccess.cpp:159, line 169) decides "tiny after rounding to 24 bits with an unbounded exponent" from(lhs * 2^64) * rhs. Mesa 26.2.5 rewrites an undecoratedFma(x, y, -0.0)tofmul(nir_opt_algebraic.py:311), thennir_opt_algebraic_before_ffma(brw_nir.c:3241) moves the constant to the outer multiply (nir_opt_algebraic.py:3607-3609). Those rules are inexact (~) and skip an instruction flagged exact (nir_search.c:332;NoContractionbecomesnir_fp_exact,vtn_alu.c:466).0x3f7fffff * 0x00800000, exact value 2^-126 - 2^-150) was therefore judged on the rounded product: the tie rounds to0x00800000, times 2^64 is0x20800000, not tiny, so0x00800000was kept where the console flushes to zero.INTEL_DEBUG=cson the HD 520, before:fmul(fmul(lhs, rhs), 2^64)with no exact flag; after:fmul(lhs, 2^64) // exactthenfmul(.., rhs) // exact, the authored order.DenormPreserve 32andSignedZeroInfNanPreserve 32; the[float-controls]hardware flush probe reports 0 of 5472 results differing; the unfused variants pass), so no probe is needed. The fix is the decoration, asEmitFPFma32and theExact(Fma)polynomials already do. Any NIR driver that runs the fused lowering is exposed the same way; only the HD 520 and llvmpipe were run.What
Marks every fused-exact f32
FmaNoContraction, like the unfused operation it replaces:core/shader/recompiler/SpirvBackend/src/SpirvAlu/SpirvAluEmitterMath.cpp:ExactMul(152),ExactSub(157),EmitFPAdd32(1931),EmitFPSub32(1936),EmitFPMul32(1941).core/shader/recompiler/SpirvBackend/src/SpirvImageEmitter.cpp: the offset fold inFoldedOffsetCoord(528) andtexelFloorin the packed horizontal gather (1508); the same pattern, no test samples through the fused lowering on this host.core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp:verifyFusedExactArithmetic(7055) now requires everyFmaof the plain and the fused module to be decorated.agc_driver_f32_denormal_flushpasses on llvmpipe before and after the change, so this device-independent assertion is what keeps CI from losing the decoration.No float semantics change on a driver that did not reassociate, and none for the console measurements in the debt files. No shader cache version edit:
ShaderCacheVersion.cmakehashes the recompiler sources.v_fma_f32already carried the decoration (SpirvAluEmitterMath.cpp:2109), so MoltenVK sees nothing new in kind.Refs: #15817 (four failing tests; this change covers
agc_driver_f32_denormal_flush; the f64 frexp one is https://github.com/boykopovar/AnyPS5/pull/16930)Tested
Linux 7.2.8 x86_64 (Arch), GCC 16.2.1 Release, Mesa 26.2.5. Windows and macOS (MoltenVK) not tested. No title run.
Same machine, test binaries rebuilt for each commit,
ctest --test-dir build -R '^agc_driver_f32_denormal_flush$' -VwithANYPS5_GPU=<gpu> ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation. The layer isvulkan-validation-layers1.4.363.0 from the Archextramirror, SHA-256 checked againstextra.db, extracted without root;VK_LOADER_DEBUG=layershows it loaded, and no log haswas not found but was requested by env var VK_INSTANCE_LAYERS.210676ad86fused lane 4 no float mode v_mul_f32 v12, v4, v5 is 0x00800000, expected 0x00000000f32 denormal flush tests passedThe main and change logs differ only in that result line and the host memory budget figures; no
VUID-or validation line in either, on either GPU.The table ran on the change rebased onto
main210676ad86; the float, shader and full-sweep runs below ran on it rebased onto6daf9a1cb6, and the focused test andagc_shader_memorywere run again on the head rebased onto4c4ff42a6cwith the same results. Between210676ad86and this head the only change undercore/shaderorcore/libs/prx/libSceAgcDriveriscore/libs/prx/libSceAgcDriver/tests/TextureTiling.cpp.agc_shader_memorywith the test change and main's emitters fails withfused exact arithmetic: a fused multiply-add is not marked NoContraction ...; with this change it passes.agc_driver_f32_*,agc_driver_f16_*,f64,fma,ldexp,mullit,vcmpand other denormal, rounding, NaN and float-mode test), with the layer. HD 520: main failsf32_denormal_flushandf64_rounding_denormal_modes; this change fails onlyf64_rounding_denormal_modes(the frexp mantissa of https://github.com/boykopovar/AnyPS5/pull/16930, out of scope). llvmpipe:f64_div_scale_denormal_modesandf64_fma_denormal_modesfail on main and with this change alike (not touched here). ZeroVUID-lines in all four runs.agc_shader_*tests, with the layer: all pass (agc_shader_disk_cache_large_fileskips).ctest -R '^agc_driver_' --timeout 90on the HD 520, without the layer (1026 registered, 984 passed, 33 skipped, 9 failed):f64_rounding_denormal_modes,image_sample_lod_clamp(T# MIN_LOD),sample_multisample_target, the fournative_color_initial_nonuniform*andpacked_float_blend(missing capabilities) with the same messages as on main411718d8d9, andguest_memory_lifetime_converted(loader error 127,libGuestMemoryFixture.prxnot found, before any shader runs; not re-run on main).f32_denormal_flushis the only test that changed from fail to pass.python3 tools/check_conventions.py --base origin/mainpasses.Overlap
Base
bbb638e808.claims.py check-branch HEAD: no open PR overlaps a changed block (58, 9 and 41 open PRs touchShaderMemory.cpp,SpirvAluEmitterMath.cppandSpirvImageEmitter.cppelsewhere).tools/pr_overlap.py --branch: 73 open PRs share a file with the branch, all 73 merge into the base and none reports shared lines or exports; for 33 of them that conflict withmainalready, the shared files were not compared, so I read their hunks in the two emitters: https://github.com/boykopovar/AnyPS5/pull/12324 (EntryLaneWalkand wave64 analysis), https://github.com/boykopovar/AnyPS5/pull/16321 (QuantizeStoreTexel), https://github.com/boykopovar/AnyPS5/pull/16260 (ExpandFmaskTexel,PackedImageTexel,EmitImageMode), https://github.com/boykopovar/AnyPS5/pull/10652 (EmitAtomicOp) and https://github.com/boykopovar/AnyPS5/pull/14853 (EmitTableWord) edit other functions than the ones here.VectorInstructions.cpp,debt/shader.md, a new test), merges cleanly with this head bygit merge-tree. Built onmainit leaves this failure unchanged on the HD 520 (same lane 4 line), so it is not a substitute.OpFmaKHRfor f32 fma on RADV): editsEmitFPFma32in the same file, a different function; it also wraps itsFmainExact. ItsShaderMemory.cppconflict exists againstmainwithout this change.ShaderMemory.cppconflict of #13929 exists againstmainalready; #15548 merges cleanly.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)