fix(shader): keep f32 denormals in compares when denormals are kept #3895
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3895"
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 CouchRiv on 2026-10-11T18:58:05Z.
What
With the f32 denormal field of
FLOAT_MODEset to keep denormals,v_cmp_X_f32andv_cmpx_X_f32read a denormal operand as zero:The compares are emitted as the SPIR-V float compares, and NVIDIA, RADV and lavapipe all flush denormals in those. With denormals flushed the hardware does the same, so that case was right.
When denormals are kept, the operands are now compared as sign-magnitude integers (so +0 and -0 still compare equal) and a NaN in either operand gives the ordered or unordered result. Compares with flushed denormals, f16 and f64 compares and the constant-operand paths are untouched. Only shaders that keep f32 denormals pay the extra integer ops.
On RDNA2 (gfx1036, Radeon 610M) the IEEE mode makes no difference to these compares; the f32 denormal mode does. 256 operand pairs per opcode (zeros, denormals including the largest, the smallest normal, ±1, infinities, quiet and signalling NaNs, the largest finite value) for the 12 conditions
eq ge gt le lg lt neq nge ngt nle nlg nltin both encodings, in IEEE 0 and 1 with denormals kept and flushed: 24,576 rows measured, 0 differing after this change.Tested
Linux (CachyOS), GCC; RTX 4070 Ti (NVIDIA), Radeon 610M (RADV) and lavapipe (Mesa 26.2.4).
main:agc_driver_vcmp_f32_denormalsfails on all three drivers (v_cmpx_eq_f32of 0x00000000 and 0x00000001 is 1, expected 0). Green with this change on every driver below.ctest -R "agc_driver_(vcmp_f32_denormals|f32_compare_constant|f32_denormal_flush|vop3_compare_modifiers|vopc_compare|vopc_compare_table|f32_min_max_nan|f32_arithmetic_nan|f32_result_clamp)$"after a clean build:tools/check_conventions.py --base origin/mainandgit diff --check: clean.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 repositoryAI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by LeandroLP23 on 2026-10-11T19:41:17Z.
Windows run of this head (
124bfde44, onmaina11c8f7f7): Windows 11 (26300), WinLibs GCC 15.2.0 r7, Release, full build. GPU: Radeon 860M (RDNA 3.5), AMD's Windows driver 32.0.13058.8001 (Vulkan24.30.58.08, LLPC). Shader cache cleared before each run.agc_driver_vcmp_f32_denormals.agc_driver_f32_compare_constantfails with the same message as onmain(v_cmp_lt_f32 0x7fc00000, 0x7f800000 is 1, expected 0). That's #3536 on this driver, fixed by #3541, not this change.CompareInstructions.cppandTranslationContext.hppreverted tomain,agc_driver_vcmp_f32_denormalsfails as on your drivers:v_cmpx_eq_f32 denormals kept, IEEE mode on of 0x00000000 and 0x00000001 is 1, expected 0. So AMD's Windows driver reads a kept denormal as zero in the float compares as well.d668b7c2b): no conflicts (TechnicalDebt.mdauto-merges), 9/9 pass in 3 runs.