Skip to content

fix(shader): flush f16 min/max denormal inputs - #2876

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
CouchRiv:fix-shader-minmax-f16-denorm-flush
Oct 10, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
CouchRiv:fix-shader-minmax-f16-denorm-flush

Conversation

@CouchRiv

@CouchRiv CouchRiv commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

What

v_min_f16 and v_max_f16 keep denormal inputs when the shader asks to flush them, so their selected result differs from RDNA2. #2036 fixed their IEEE NaN handling but left this gap in TechnicalDebt.

The binary forms now flush each half input to its signed zero when denorm16 bit 0 is clear. Output flushing alone preserves the selected input. This applies to the comparison value and the bits returned for a NaN fallback. The second commit applies the same rule to v_min3_f16, v_max3_f16 and v_med3_f16, which share minMaxF16: on gfx1036 they flush the same way (8,024 operand triples in each of the eight IEEE 0/1 x denorm16 0-3 modes, every row matching the rule, changes only at denorm16 0 and 2). The debt entry retains the f64 gap.

Measured with the hardware oracle on gfx1036 (Radeon 610M), at IEEE=0/1 and denorm16=0/1/2/3. Other controls: DX10 clamp enabled, f32 denormals flushed, both rounding fields nearest even, FP16_OVFL=0. These example half results are at IEEE=1:

Instruction / operands denorm16 Hardware and fix main
min 0x3c01, 0x03ff 0 0x0000 0x03ff
max 0xbc01, 0x03ff 2 0x0000 0x03ff
min 0x3c01, 0x03ff 1 0x03ff 0x03ff

Tested

CachyOS Linux, Release build; RTX 4070 Ti (NVIDIA), Radeon 610M (RADV), and lavapipe, including the pinned CI driver.

  • Extended agc_driver_f16_min_max_nan: 32 measured operand pairs, eight IEEE/denormal modes, plain and neg/abs forms, and SDWA WORD_0/WORD_1 sources. Includes signed zeros, NaNs, denormals and minimum normals. Main fails with 0x03ff instead of 0x0000; the fix passes on all three drivers. Original NaN/ternary tables still pass. The ternary rows fail on the first commit (v_min3_f16 v12, v4, v5, v6 is 0x000003ff, expected 0x00000000) and pass with the second. Runtime below 1.2 s.
  • Build, the execution test plus shader checks (22/22 per driver), check_conventions.py, and git diff --check pass.
  • Not tested: gfx1013 hardware, Windows, titles, or a replay of every sweep row. Packed f16 and f64 lowering are unchanged; backend half conversion is unchanged.

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 (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes

RDNA2 min/max flush half inputs to signed zero when input
preservation is disabled, while output flushing alone keeps them.
Apply this to the measured binary forms and pin the hardware rows.

Co-Authored-By: GPT-6.1 Sol <noreply@openai.com>
@github-actions github-actions Bot added shader core/shader docs agc libSceAgc* labels Oct 10, 2026
The ternary forms share minMaxF16 with v_min_f16 and v_max_f16 and follow
the same rule on gfx1036: a subnormal half input becomes a signed zero when
bit 0 of the f16 denormal field is clear, at IEEE=0 and IEEE=1.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked on the HW oracle (gfx1035): 2048 operand triples (signed zeros, denormals, min normals, ±1, ±inf, quiet/signaling NaNs) at IEEE=0/1 × denorm16 0–3 for v_min/max/min3/max3/med3_f16, neg/abs, SDWA and clamp all match "flush inputs when denorm16 bit 0 is clear". Also ran the AGC driver ctest scope (agc_driver_f16_min_max_nan fails without the change). Merging.

@adriadam10
adriadam10 merged commit 0d2546e into boykopovar:main Oct 10, 2026
14 of 15 checks passed
@CouchRiv
CouchRiv deleted the fix-shader-minmax-f16-denorm-flush 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.

2 participants