agc_driver_f32_fma_denormal_mode2 fails on RADV before RDNA2: Mesa splits GLSL Fma, even with NoContraction #15316
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 ryanc2112 on 2026-11-02T23:37:04Z.
What
agc_driver_f32_fma_denormal_mode2(added by #12253) fails on an RX 570 (RADV POLARIS10, Mesa 26.2.5) and passes on a Steam Deck (RADV VANGOGH, the same Mesa).The expected value is the fused result. The exact value is 2^-126 · (1 − 2^-24) − 2^-126 · (1 + 2^-23) = −1.5 · 2^-149, which rounds to nearest-even as
0x80000002.0x80000001is what you get by rounding the product first, to 2^-126, and then adding. So the RX 570 runs thisFmaunfused.Why
vtn_glsl450.cturnsGLSLstd450Fmaintonir_op_ffma_weak, whatever the decorations.EmitFPFma32already decorates theFmawithNoContraction, but that doesn't stop it.nir_opt_algebraic.pyrewritesffma_weakasfadd(fmul)when the backend setsprefers_split.ac_nir.csetsprefers_splitfor f32 whenhas_mad32, whichac_gpu_info.cgives to every chip before GFX10.3 (and to GFX9 up to MI200). So this should apply to Polaris, Vega and RX 5000 on RADV, though I've only run Polaris. RDNA2 and later get a realffma, which matches the Deck passing.RADV_DEBUG=shaders, the RX 570's NIR for this test has noffmaleft (154fmul, 59fadd). The ISA is mostlyv_mad_f32/v_mul_f32.Fmais "inherited from OpFMul followed by OpFAdd", so I don't think it's a Mesa bug.Possible fix
OpFmaKHR(VK_KHR_shader_fma) is defined as correctly rounded.vtn_alu.cmaps it tonir_op_ffma, which isn't split. The RX 570 offers it (shaderFmaFloat32 = true,shaderFmaFloat64 = true,shaderFmaFloat16 = false). #11265 already enables the extension and emitsOpFmaKHRfor the packed f16 forms. Doing the same inEmitFPFma32whenshaderFmaFloat32is enabled should fix this test on these chips. Devices without the extension would keep today's behaviour.I tried a local prototype on the RX 570. It's
main9090972b7ewith #11265 merged in, plus about 20 lines on top:shaderFmaFloat32is offered, enable it, and addFMAKHR/SPV_KHR_fmato the device's capabilities.EmitFPFma32emitsOpFmaKHR(still withNoContraction) whenFMAKHRis supported. An environment variable switches this on, so both sides come from one build.OpFmaKHROpFmaKHRagc_driver_f32_fma_denormal_mode2^agc_driver_(f32|f64|f16|packed|float)(61 tests)The same 5 tests skip on both sides (the native f16 ones, because this device has no
shaderFloat16), and there are noVUID-errors. It's a prototype, not a PR. Notably, #11265'sfmaFloat16gate would need splitting so that f32-only devices don't advertise f16OpFmaKHR. I haven't run the full GPU test set with it.Tested
73dd5e5926(main8b7d6c183bcplus a commit that only adds native depth log lines), GCC 16.2.1, Release,BUILD_TESTING=ON.ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, withctest --no-tests=error.f32 denormal flush: emulated (6 of 5472 probe results differ from the emulated flush).hardware (0 of 5472 ...).main92d2fdc343in the GPU sweep I ran earlier today.AI-assisted: yes (Claude Code)