Recompiler: f32 product tininess is checked before rounding (RDNA2 checks after), and the check makes float-heavy shaders slow to compile #2682
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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 AlxcBTW on 2026-10-10T10:51:11Z.
With f32 denormals flushed,
flushTinyProductchecks a product for tininess on its exact value, from the factor exponents and aUMulHiof the significands. RDNA2 checks after rounding to 24 bits with an unbounded exponent. The f32 denormals entry in TechnicalDebt records this as measured on gfx1036:0x3f7ffffe * 0x00800001gives0x00800000on the hardware and 0 here.The check also costs about 20 IR instructions per product, and that makes float-heavy pixel shaders slow for drivers to compile. The ps5-opengl UI renderer's large pixel shader (VITA5 PPSA39410, Homebrew UI Lab PPSA99050) has 1,587 checked products. Creating its graphics pipeline takes 14.7 s on an RTX 5070 Laptop (616.92) with a cold driver cache. UI Lab waits at most 2 s for a submission to retire, so it stops at
submission retirement failedon every cold start. I timed the module dumped fromPipeline.cppin a standalone Vulkan program. With only the tiny-product select replaced by a pass-through (a timing experiment, not correct), NVIDIA's time dropped from about 15.5 s to 8.3 s.Fix
AlxcBTW/AnyPS5#18 (
bb822ef5, onmainbe403084). One factor is multiplied by 2^64, which is exact below 2^64, and the product with the other factor is rounded once to 24 bits in the normal range. One unsigned compare of its magnitude bits minus 1 against0x207fffffthen gives the tininess. That is 6 IR instructions instead of 20, and it gives the hardware's result for the row above. Full CI passed, merged ontomain507f49fb. I can't open it as a PR while intake is limited, so it's here if a collaborator wants to cherry-pick it.That still exceeds UI Lab's 2 s wait. The NaN-result and denormal-flush selects are the other two large costs: replacing all three with pass-throughs brings the module to 1.4 s.
Tested
Windows 11, WinLibs GCC 15.2.0 r7, NVIDIA RTX 5070 Laptop (616.92) and AMD Radeon 880M (AMDVLK 2.0.353).
agc_driver_f32_constant_factor_tininesspins the lane0x3f7ffffe * 0x00800001. It fails without the change (is 0x00000000, expected ... 0x00800000) and passes with it.agc_driverfloat tests pass on both GPUs, in a fresh build.vector_constant_factor_tininessnow counts the new compare: one per checked product, with no significand product.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-10T12:35:43Z.
Measured on RDNA2 hardware (gfx1036, Ryzen 7950X3D iGPU,
tools/hw-oracle) and compared withmain197ffac9and with AlxcBTW/AnyPS5#18 (bb822ef5, cherry-picked onto it). Both ran throughKernelReplay, on the same iGPU through RADV (Mesa 26.2.4) and on an RTX 3080 (NVIDIA 615.71.09). Linux (CachyOS, kernel 7.2.9, GCC 16.2.1), Release withANYPS5_ENABLE_SPIRV_TOOLS=ON.The sweep has 3,214 rows of two factors:
0x3f800000 - ktimes0x00800000 + j(k 1 to 48, j 0 to 40).Each row runs through six instructions:
v_mul_f32in both operand orders,v_fma_f32with a 0 and with a varying addend,v_fmac_f32with a 0 accumulator, andv_mul_legacy_f32. The mode is round to nearest even with f32 denormals flushed (FLOAT_MODE bits 5:4 = 0), at IEEE=0 and IEEE=1.mainv_mul_f32(both orders),v_fma_f32with 0,v_fmac_f32,v_mul_legacy_f32v_fma_f32with a varying addendThe counts are the same on both hosts and in both IEEE modes.
mainthey are the rows whose exact product is below 2^-126 in magnitude but rounds to 2^-126 (this issue's row appears twice); 12 of them are negative. The hardware gives ±0x00800000 on all of them, for each of the five instructions in the first row, andmaingives ±0. So the zero-addendv_fma_f32andv_fmac_f32forms andv_mul_legacy_f32, which #18 lists as not measured, detect tininess after rounding likev_mul_f32. The 12 rows with a varying addend are the 12 of the 49 whose addend is ±0 or a denormal (all with positive products here); for the other 37 the addend is ±2^-126 or 1.0.v_fma_legacy_f32is left out. On RDNA2, VOP3 0x140 is the fusedv_fma_legacy_f32, but the recompiler translates it asv_mad_legacy_f32, as measured on gfx1010 and as LLVM decodes it for the PS5's gfx1013 (TechnicalDebt). So a gfx1036 measurement is not evidence for it.mainand 1,050 to 1,152 with #18. With rounding toward −∞ or toward zero, this issue's row gives 0 on the hardware and onmain, and 0x00800000 with #18.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-10T12:41:07Z.
@SleglJan thank you, that is exactly the measurement the PR was missing. I added it to the TechnicalDebt entry on AlxcBTW/AnyPS5#18 (
336a8486, docs only). The zero-addendv_fma_f32,v_fmac_f32andv_mul_legacy_f32now count as measured instead of assumed.On the directed modes, you're right that the rounding toward −∞ / toward zero row now gives
0x00800000where the hardware gives 0. The check rounds the scaled product to nearest, like the rest of the f32 arithmetic, which doesn't round in those directions on any build. Onmainthat row matched only because "tiny before rounding" happens to agree with rounding down there. The entry now says this. Directed f32 rounding as a whole would be its own change.AI-assisted: yes (Claude Code).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T22:57:23Z.
Fixed in part by #2839: f32 product tininess is now detected after rounding in all four round modes, covered by
agc_driver_f32_denormal_flush; the compile cost of the check is still open.Imported from boykopovar/AnyPS5. Originally posted by BharatYadav007 on 2026-10-12T04:13:55Z.
There is a further update beyond #2839:
mainatd146ec1b6also contains commit4e7511dc3(perf(shader): check f32 product tininess in one multiply to nearest even). The nearest-even path inTranslationContext::flushTinyProductnow uses the scaled-product check and magnitude comparison against0x207fffff, rather than the significand-product calculation. Directed rounding retains its separate handling.The commit also adds the
0x3f7ffffe * 0x00800001 -> 0x00800000regression toF32ConstantFactorTininess.cppand updates the IR checks. The original correctness fix and the proposed cheaper nearest-even check are therefore both present in main. I have not rerun the title’s cold-pipeline benchmark, so this is a source-status update rather than a claim that its startup timeout is resolved.Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-12T04:14:55Z.
Thanks @BharatYadav007, confirmed: #2839 (tininess after rounding) and
4e7511dc3(the one-multiply nearest-even check) are both onmain, with the0x3f7ffffe * 0x00800001 -> 0x00800000regression inF32ConstantFactorTininess.cpp. Both halves of this issue are addressed, so I'm closing it. If the cold-pipeline startup timeout still shows up on that title, it deserves its own issue with fresh numbers.AI-assisted: yes (Claude Code)