Skip to content

fix(shader): return src0 when both f32 min/max sources are NaN - #568

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
adriadam10:fix/f32-minmax-nan
Oct 5, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
adriadam10:fix/f32-minmax-nan

Conversation

@adriadam10

Copy link
Copy Markdown
Collaborator

What

v_min_f32/v_max_f32 with two NaN sources returned src1. On hardware they return src0, so v_min3_f32, v_max3_f32 and v_med3_f32 (built from the same helper) gave the wrong NaN too. EmitMinMaxF32Value now picks src0 when both sources are NaN; every other case is unchanged.

f16 min/max go through the same helper on main, so their both-NaN result is now src0 too. That is the f16 hardware rule (#533).

Behaviour measured on HW (RDNA2 gfx1035 compute kernel, MODE IEEE=0 DENORM=0, the mode the recompiler assumes): all 4913 triples of 17 values (±0, ±1, 2.5, -3, ±inf, max float, min normal, ±qNaN with payloads, ±sNaN) through v_min_f32, v_max_f32 (e32 and e64), v_min3_f32, v_max3_f32 and v_med3_f32. A model matches all 34391 results:

  • one source NaN: return the other source
  • both NaN: return src0 unchanged (sNaN isn't quieted)
  • ±0 pair: min returns -0, max returns +0
  • med3 with any NaN returns min3
    Only the both-NaN row differs from main. With IEEE=1 the hardware quiets sNaN, which the recompiler doesn't model (same as before this PR).

Tested

New execution test agc_driver_f32_min_max_nan (F32MinMaxNan.cpp): 128 rows (all 100 ordered pairs of ±0, 1, -3, ±inf, ±qNaN, ±sNaN, plus rows picked to cover the remaining class combinations) × 7 ops, expected values taken from the hardware, compared bit for bit. All result bits are picked by selects, so the driver's NaN handling doesn't affect them. It fails on main (row 67 v_min_f32 v10, v4, v5 is 0xffd54321, expected 0x7fc12345) and passes with the change on RADV, local lavapipe and CI's lavapipe (Mesa 25.2.8). Full Release ctest on Linux/RADV: only the three tests that already fail on main locally (agc_driver_pixel_helper_lanes, agc_driver_global_load_addtid, agc_driver_vop3_carry_out, wave32 lane 32 on RADV's 64-wide subgroup) fail. The agc_driver suite passes on CI's lavapipe.

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

Co-Authored-By: Claude <noreply@anthropic.com>
@github-actions github-actions Bot added shader core/shader agc libSceAgc* labels Oct 4, 2026
@oneandonlydean

Copy link
Copy Markdown
Collaborator

Thanks. The change is exactly the select order: the rhs-NaN select now wins last, so two NaNs give src0 unchanged and a single NaN still gives the other source; the ±0 and numeric paths are untouched. All callers pass src0 as lhs (min, max, and min3/max3/med3 built from them), so the nested forms follow. src0 for two NaNs also matches the packed f16 rule from #533, and since every result bit comes from a select, the test doesn't depend on the driver's NaN handling.

agc_driver_f32_min_max_nan passes on my NVIDIA machine at this head, and on main's code it fails at row 67 (v_min_f32 gives 0xffd54321 where 0x7fc12345 is expected).

It changes v_min_f32/v_max_f32 results that PPSA21564's shaders produce (only in the both-NaN case), so I'll run it through my PPSA21564 check before merging; otherwise it's ready from my side.

@oneandonlydean

Copy link
Copy Markdown
Collaborator

Gated on PPSA21564: no visual or FPS change.

@oneandonlydean
oneandonlydean merged commit 71f248a into boykopovar:main Oct 5, 2026
3 checks passed
@adriadam10
adriadam10 deleted the fix/f32-minmax-nan branch October 5, 2026 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants