fix(shader): flush f16 denormals in unary, frexp and conversion ops per the float mode #3932
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3932"
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-11T19:17:54Z.
What
With the f16 denormal field of FLOAT_MODE set to flush (what most titles use), RDNA2 turns a denormal half operand into its signed zero before these instructions use it, and turns a denormal half result into its signed zero. The recompiler read denormal halves as they are and wrote denormal results as they are, so for example
v_ceil_f16 0x0001gave 0x3c00 where the hardware gives 0, andv_rcp_f16 0x7bffgave the denormal 0x0100 where the hardware gives 0.The affected instructions are
v_ceil_f16,v_floor_f16,v_fract_f16,v_rcp_f16,v_rsq_f16,v_sqrt_f16,v_log_f16,v_exp_f16,v_sin_f16,v_frexp_mant_f16,v_frexp_exp_i16_f16,v_cvt_norm_i16_f16,v_cvt_norm_u16_f16andv_cvt_f32_f16. They now share one rule driven by the float mode: bit 0 of the denormal field clear flushes a denormal half input, bit 1 clear flushes a denormal half result.v_ldexp_f16uses the same helper for its input instead of its own copy. A shader without a known float mode, and every mode that keeps denormals, compile as before. The pknorm packs are not measured and keep their old lowering (listed in TechnicalDebt).On
main, 310 of 1,456 checks of the new test differ (14 of 14 instructions); with this change none do.Tested
Linux (CachyOS), GCC; RTX 4070 Ti (NVIDIA), Radeon 610M (RADV) and lavapipe (Mesa 26.2.4). Expected values were measured on a Radeon 610M (gfx1036).
agc_driver_f16_denormal_flush: 182 input rows over the 14 instructions, each in all four denorm16 modes and with IEEE on and off. Red onmain, green with this change on NVIDIA, RADV and lavapipe.v_exp_f16andv_sin_f16, which are the same with denormals kept.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