fix(shader): give a tiny f32 product that rounds to 2^-126 that value #17932
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/17932"
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 Gonic0 on 2026-11-09T23:46:05Z.
What
To nearest even,
flushTinyProductscales one factor by 2^64 and compares the scaled product with 2^-62. A product below it is flushed to a zero of its sign; otherwise the multiply's own result is kept. That relies on the host rounding a product whose exact value is just below 2^-126 up to 2^-126, as RDNA2 does.Apple GPUs do not: KosmicKrisp and MoltenVK on an M5 Pro flush such a product before rounding, so
0x3f7ffffe * 0x00800001comes back as zero instead of0x00800000, andagc_driver_f32_constant_factor_tininessfails on both.When the scaled product is exactly 2^-62, the result is now 2^-126 of the product's sign. That is the value the multiply returns on RDNA2, so nothing changes there. The new select wraps the existing one, which keeps the shape
DenormalFlushEliminatorrecognizes; with the select the other way round,agc_denormal_flush_eliminationfails (3 f32 exponent masks, expected 1).The startup flush probe runs these products, so on both Apple drivers it now reports
emulated (264 of 5472 probe results differ from the emulated flush): the hardware flush does not round them the way the console does. MoltenVK therefore keeps the emulated flush, as KosmicKrisp already does after #17588. That costs speed on MoltenVK. PPSA21564 on MoltenVK 1.4.2, same binary with and withoutAPS5_NO_HW_F32_FLUSH=1(what this change makes the probe choose), fixed save, runs alternated hardware/emulated/emulated/hardware, mean of the four 10 s windows from 45 to 85 s:About 8.5 % fewer presents and 13 % more GPU time. Only that early window could be measured: on MoltenVK the title stops presenting about 81 s in, with or without this change (no error is logged), so the heavier scenes were not reached. The tree for these runs is
main31b4aa91e8with #17611, #17588, the macOS build pull requests and imellag's mesh list restart change from #9356, without which the title stops 7 s in on MoltenVK. The trade is the exact 2^-126 result for a measurable slowdown on MoltenVK.A fused result with a nonzero addend that rounds up to 2^-126 is still flushed on Apple GPUs (
agc_driver_f32_denormal_flush,v_fma_f32with0x00800000,0x80800001,0x00800000). Fixing it would need a second, scaled fma for every fma, so it is left out and recorded indocs/dev/debt/shader.md.Tested
macOS 27.3, Apple M5 Pro, Apple clang, x86-64 Release under Rosetta 2. Tree:
mainb673b14c39with #16591, #17425, #17532 and #17767, which macOS needs to build, and this change. Nothing inOperandAccess.cpp,FloatInstructions.cpporDenormalFlushEliminator.cppchanged between that commit andmain1c288270a7.ctest -R 'f32|f16|denorm|float32|mullit'(77 tests,ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1), before and after:main94ff826188c)agc_driver_f32_constant_factor_tininessnow passesagc_driver_f32_constant_factor_tininessnow passesNo test newly fails on either driver,
agc_denormal_flush_eliminationincluded. The remaining failures are the ones that already failed: on KosmicKrisp the NaN and interpolation cases listed in #15859, andagc_driver_f32_denormal_flushon both for the nonzero-addend fma above.Linux, Windows, AMD and NVIDIA: not run. On a device that rounds the product to 2^-126 itself, the new select picks the same value.
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)main94ff826188c) and MoltenVK 1.4.2, macOS 27.3🤖 Generated with Claude Code