Skip to content

fix(shader): keep f32 denormals in compares when denormals are kept - #3895

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
CouchRiv:fix-shader-vcmpx-f32-family
Oct 12, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
CouchRiv:fix-shader-vcmpx-f32-family

Conversation

@CouchRiv

Copy link
Copy Markdown
Contributor

What

With the f32 denormal field of FLOAT_MODE set to keep denormals, v_cmp_X_f32 and v_cmpx_X_f32 read a denormal operand as zero:

v_cmp_eq_f32 0x00000000, 0x00000001   ->  1   (RDNA2: 0)
v_cmp_lg_f32 0x00000000, 0x00000001   ->  0   (RDNA2: 1)

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

  • Red on main: agc_driver_vcmp_f32_denormals fails on all three drivers (v_cmpx_eq_f32 of 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:
    • nvidia: 100% tests passed out of 9
    • radeon: 100% tests passed out of 9
    • lavapipe: 100% tests passed out of 9
  • tools/check_conventions.py --base origin/main and git diff --check: clean.
  • Windows and macOS not run. Denormal modes 1 and 2 still throw, as before.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source (none in this change)
  • Generic behaviour, not specific to one title
  • Depends on: none
    AI-assisted: yes

@LeandroLP23

Copy link
Copy Markdown
Contributor

Windows run of this head (124bfde44, on main a11c8f7f7): 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 (Vulkan 24.30.58.08, LLPC). Shader cache cleared before each run.

@github-actions github-actions Bot added needs rebase Conflicts with main, rebase needed labels Oct 11, 2026
With the f32 denormal field of FLOAT_MODE set to keep, v_cmp_X_f32 and
v_cmpx_X_f32 read a denormal operand as zero: NVIDIA, RADV and lavapipe
all flush denormals in their float compares. Compare the operands as
sign-magnitude integers instead, with NaN handled apart. Compares with
flushed denormals are unchanged. This matches RDNA2 (gfx1036) on 256
operand pairs per opcode, with f32 denormals kept and flushed.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@CouchRiv
CouchRiv force-pushed the fix-shader-vcmpx-f32-family branch from 124bfde to de54527 Compare October 11, 2026 23:22
@github-actions github-actions Bot removed the needs rebase Conflicts with main, rebase needed label Oct 11, 2026
@oneandonlydean oneandonlydean self-assigned this Oct 12, 2026
@oneandonlydean
oneandonlydean merged commit d06c065 into boykopovar:main Oct 12, 2026
14 checks passed
@CouchRiv
CouchRiv deleted the fix-shader-vcmpx-f32-family branch October 29, 2026 18:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* docs shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants