fix(shader): clamp f32 results to +0 for NaN and -0 #500
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/500"
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 adriadam10 on 2026-10-04T10:16:52Z.
What
The VOP3/SDWA
clampbit on f32 results (FPSaturate32) was emitted as GLSLFClamp(x, 0, 1). In SPIR-V that leaves NaN and −0 open: on RADV a NaN result stays NaN (0xffc00000) and lavapipe gives1.0, but the hardware gives+0for both. It is now done on the bits (1 <= bits <= 0x7f800000 ? umin(bits, 0x3f800000) : 0), so every driver gives the same result.FPSaturate64already works this way.Behaviour measured on HW (RDNA2, gfx1035, IEEE mode 0/1, f32 denormals on/off: all the same)
+0; −0 →+0; negatives and −inf →+0; > 1 and +inf →1.0.Tested
New execution test
agc_driver_f32_result_clamp_tests: 16 ops withclamp(add, sub, mul, mul with negated source, fma, fmac, min, max, med3, max3, floor, fract, trunc, ceil, rndne, cvt_f32_i32) over 32 rows covering each pre-clamp class (NaN, ±0, ±inf, negative, (0,1), 1, > 1). Expected values come from the hardware, and the Python model matches them in all 503 checked cells. Denormal rows and min/max rows with sNaN (where the result depends on IEEE mode) are left out. No row depends on whether the driver fusesfma.Passes on RADV, local lavapipe and CI's lavapipe (Mesa 25.2.8). The test fails without the fix on both drivers (going back to
FClamp, dropping the lower bound, or keeping NaN bits all fail). Full Release ctest is green exceptagc_driver_pixel_helper_lanes, which also fails onmainon local RADV.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T21:07:55Z.
Thanks, checked the bit rule (
1 <= bits <= 0x7f800000, then umin to 1.0) against the RDNA2 MODE description: NaN to +0 is the DX10_CLAMP behaviour, which LLVM also assumes by default for every calling convention, and it now matches whatFPSaturate64already does. One note for the record: on NVIDIA the new test already passes on main, because the driver lowersFClamp(x, 0, 1)to a saturate that gives +0 for NaN and -0, so the failure without the fix only shows on RADV and lavapipe, as you wrote. This touches every f32 clamp, so I'll run it through my PPSA21564 check before merging; ready to merge from my side otherwise.Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-05T08:31:16Z.
Gated on PPSA21564 with #508 on top: no visual or FPS change.