agc_driver_f32_fma_denormal_mode2 fails on RADV before RDNA2: Mesa splits GLSL Fma, even with NoContraction #15316

Open
opened 2026-11-02 23:37:04 +00:00 by ryanc2112 · 0 comments
ryanc2112 commented 2026-11-02 23:37:04 +00:00 (Migrated from github.com)
Contributor

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).

AGC graphics: v_fmamk_f32 v12, v4, 0x3f7fffff, v6 f32 denormal mode 2, IEEE=0 with v4 0x00800000, v5 0x00000000, v6 0x80800001 is 0x80000001, expected 0x80000002

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. 0x80000001 is what you get by rounding the product first, to 2^-126, and then adding. So the RX 570 runs this Fma unfused.

Why

  • The split: Mesa's vtn_glsl450.c turns GLSLstd450Fma into nir_op_ffma_weak, whatever the decorations. EmitFPFma32 already decorates the Fma with NoContraction, but that doesn't stop it.
  • Where it happens: nir_opt_algebraic.py rewrites ffma_weak as fadd(fmul) when the backend sets prefers_split. ac_nir.c sets prefers_split for f32 when has_mad32, which ac_gpu_info.c gives 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 real ffma, which matches the Deck passing.
  • What I saw: with RADV_DEBUG=shaders, the RX 570's NIR for this test has no ffma left (154 fmul, 59 fadd). The ISA is mostly v_mad_f32/v_mul_f32.
  • Spec: Vulkan allows this. The precision of GLSL Fma is "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.c maps it to nir_op_ffma, which isn't split. The RX 570 offers it (shaderFmaFloat32 = true, shaderFmaFloat64 = true, shaderFmaFloat16 = false). #11265 already enables the extension and emits OpFmaKHR for the packed f16 forms. Doing the same in EmitFPFma32 when shaderFmaFloat32 is 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 main 9090972b7e with #11265 merged in, plus about 20 lines on top:

  • Device setup: when shaderFmaFloat32 is offered, enable it, and add FMAKHR/SPV_KHR_fma to the device's capabilities.
  • Emitter: EmitFPFma32 emits OpFmaKHR (still with NoContraction) when FMAKHR is supported. An environment variable switches this on, so both sides come from one build.
Without OpFmaKHR With OpFmaKHR
agc_driver_f32_fma_denormal_mode2 fails 3/3 passes 3/3
^agc_driver_(f32|f64|f16|packed|float) (61 tests) 60 pass, 1 fails (the one above) 61 pass

The same 5 tests skip on both sides (the native f16 ones, because this device has no shaderFloat16), and there are no VUID- errors. It's a prototype, not a PR. Notably, #11265's fmaFloat16 gate would need splitting so that f32-only devices don't advertise f16 OpFmaKHR. I haven't run the full GPU test set with it.

Tested

  • Builds: clean build at 73dd5e5926 (main 8b7d6c183bc plus a commit that only adds native depth log lines), GCC 16.2.1, Release, BUILD_TESTING=ON.
  • Environment: ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, with ctest --no-tests=error.
  • RX 570: fails 3/3. The startup probe reports f32 denormal flush: emulated (6 of 5472 probe results differ from the emulated flush).
  • Steam Deck: passes 3/3. Its probe reports hardware (0 of 5472 ...).
  • Same failure on main 92d2fdc343 in the GPU sweep I ran earlier today.
  • Not tested: other pre-RDNA2 chips, and the PS5.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:6173061630 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/15316). Originally posted by [ryanc2112](https://github.com/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). ``` AGC graphics: v_fmamk_f32 v12, v4, 0x3f7fffff, v6 f32 denormal mode 2, IEEE=0 with v4 0x00800000, v5 0x00000000, v6 0x80800001 is 0x80000001, expected 0x80000002 ``` 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`. `0x80000001` is what you get by rounding the product first, to 2^-126, and then adding. So the RX 570 runs this `Fma` unfused. ### Why - **The split:** Mesa's `vtn_glsl450.c` turns `GLSLstd450Fma` into `nir_op_ffma_weak`, whatever the decorations. `EmitFPFma32` already decorates the `Fma` with `NoContraction`, but that doesn't stop it. - **Where it happens:** `nir_opt_algebraic.py` rewrites `ffma_weak` as `fadd(fmul)` when the backend sets `prefers_split`. `ac_nir.c` sets `prefers_split` for f32 when `has_mad32`, which `ac_gpu_info.c` gives 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 real `ffma`, which matches the Deck passing. - **What I saw:** with `RADV_DEBUG=shaders`, the RX 570's NIR for this test has no `ffma` left (154 `fmul`, 59 `fadd`). The ISA is mostly `v_mad_f32`/`v_mul_f32`. - **Spec:** Vulkan allows this. The precision of GLSL `Fma` is "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.c` maps it to `nir_op_ffma`, which isn't split. The RX 570 offers it (`shaderFmaFloat32 = true`, `shaderFmaFloat64 = true`, `shaderFmaFloat16 = false`). #11265 already enables the extension and emits `OpFmaKHR` for the packed f16 forms. Doing the same in `EmitFPFma32` when `shaderFmaFloat32` is 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 `main` `9090972b7e` with #11265 merged in, plus about 20 lines on top: - **Device setup:** when `shaderFmaFloat32` is offered, enable it, and add `FMAKHR`/`SPV_KHR_fma` to the device's capabilities. - **Emitter:** `EmitFPFma32` emits `OpFmaKHR` (still with `NoContraction`) when `FMAKHR` is supported. An environment variable switches this on, so both sides come from one build. | | Without `OpFmaKHR` | With `OpFmaKHR` | |---|---|---| | `agc_driver_f32_fma_denormal_mode2` | fails 3/3 | passes 3/3 | | `^agc_driver_(f32\|f64\|f16\|packed\|float)` (61 tests) | 60 pass, 1 fails (the one above) | 61 pass | The same 5 tests skip on both sides (the native f16 ones, because this device has no `shaderFloat16`), and there are no `VUID-` errors. It's a prototype, not a PR. Notably, #11265's `fmaFloat16` gate would need splitting so that f32-only devices don't advertise f16 `OpFmaKHR`. I haven't run the full GPU test set with it. ### Tested - **Builds:** clean build at `73dd5e5926` (`main` `8b7d6c183bc` plus a commit that only adds native depth log lines), GCC 16.2.1, Release, `BUILD_TESTING=ON`. - **Environment:** `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, with `ctest --no-tests=error`. - **RX 570:** fails 3/3. The startup probe reports `f32 denormal flush: emulated (6 of 5472 probe results differ from the emulated flush)`. - **Steam Deck:** passes 3/3. Its probe reports `hardware (0 of 5472 ...)`. - **Same failure on `main` `92d2fdc343`** in the GPU sweep I ran earlier today. - **Not tested:** other pre-RDNA2 chips, and the PS5. AI-assisted: yes (Claude Code)
Sign in to join this conversation.
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5#15316
No description provided.