Skip to content

agx, borealis: handle fmin/fmax/fsat in FP32 denorm preserve lowering and unify exposure - #813

Merged
DjDeveloperr merged 1 commit into
aurora-wipfrom
feat/borealis-m5-denorm-preserve-fp32
Nov 24, 2026
Merged

DjDeveloperr merged 1 commit into
aurora-wipfrom
feat/borealis-m5-denorm-preserve-fp32

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 23, 2026 •

Copy link
Copy Markdown

Summary

Fixes FP32 denormal preservation for min/nmin/max/nmax/clamp/nclamp/fsat on AGX3B/AGX3C and ties Vulkan shaderDenormPreserveFloat32 exposure directly to the lowering capability:

  • src/asahi/compiler/agx_nir_lower_denorm_preserve.c: hardware fmin/fmax (fcmpsel) can flush denormal inputs during comparison on AGX3B chips (G15/G16), and nir_op_fsat lowers to fadd.sat(x, -0.0) which flushes positive denormals to zero. Adds exact integer-ordered lowering (order_key() + is_nan()) for nir_op_fmin, nir_op_fmax, nir_op_fmin_agx, nir_op_fmax_agx (preserving IEEE 754 minNum/maxNum NaN semantics and -0 < +0 ordering) and nir_op_fsat when an operand is denormal.
  • src/asahi/lib/agx_chip.h & src/asahi/vulkan/hk_physical_device.c: derives shaderDenormPreserveFloat32 from agx_chip_has_fp32_denorm_preserve(dev->chip), tying Vulkan exposure directly to the AGX3B/AGX3C lowering capability across native AGX3 and M5 (leaving AGX2 and G18G disabled).
  • src/asahi/compiler/test/test-denorm-preserve-fma.cpp: adds bit-exact unit tests covering fmin, fmax, fmin_agx, fmax_agx, clamp (fmin(fmax(x, lo), hi)), and fsat across denormal/signed-zero/inf/NaN combinations, plus multi-stage (VS/FS/CS) compilation coverage for both AGX3B (G15G, G16G, G17P) and AGX3C (G17S).

Verification (R2 — 1b34640bb383)

  • Full asahi unit suite (-Db_ndebug=false, mirror asahi CI): PASS — run 45143319073 (241/241 tests OK, including new DenormPreserveMinMax.DirectMinMaxClampAndSat and DenormPreserveLowering.CapabilityStagesAndEncodings).
  • Policy gate: DEFAULT_BRANCH=aurora-wip bash .github/aurora/agent-policy.sh pr feat/borealis-m5-denorm-preserve-fp32 PASS (PR is clean).
  • M5 R2 hardware CTS (G17S B1, covering denormal inputs & results across stages including min/nmin/max/nmax/clamp/nclamp): pending hardware lock release; will be posted on exact head 1b34640bb383 before merge.

Assisted-by: LLM (Google:Gemini 4 Neon)

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CHANGES · source review of 1c16f85af871

The rationale says FP32 preservation is supplied by software lowering, but the exposed property is still selected by chip family and the published row is M5 Pro only. Please derive the property from the stage/encoding capability that guarantees the lowering for every advertised path, and provide native AGX3 rows for every newly advertised encoding. In particular, report denormal input and result cases across the supported stages.

Verification here was by source inspection.

@RyanTheTide

Copy link
Copy Markdown

@DjDeveloperr Could you tie exposure to the lowering capability and include denormal input and result coverage by stage and encoding? In a separate exposure trial, both Airs failed the same three runtime-input cases for clamp, min and nmin. Direct fmin/fmax were absent from the exact lowering in that trial.

… and unify exposure

Hardware fmin/fmax (fcmpsel) can flush denormal inputs during comparison on
AGX3B chips (G15/G16), and fsat lowers to fadd.sat(x, -0.0) which flushes
positive denormals to zero.

- agx_nir_lower_denorm_preserve.c: add exact integer-ordered lowering for
  nir_op_fmin, nir_op_fmax, nir_op_fmin_agx, nir_op_fmax_agx (preserving
  IEEE 754 minNum/maxNum NaN semantics and signed-zero ordering) and
  nir_op_fsat when an operand is denormal.
- agx_chip.h / hk_physical_device.c: derive shaderDenormPreserveFloat32 from
  agx_chip_has_fp32_denorm_preserve(dev->chip), tying Vulkan exposure to the
  AGX3B/AGX3C lowering capability across native AGX3 and M5.
- test-denorm-preserve-fma.cpp: add bit-exact fmin/fmax/fclamp/fsat denormal
  tests and multi-stage (VS/FS/CS) compilation coverage for both AGX3B
  (G15G, G16G, G17P) and AGX3C (G17S).

Signed-off-by: Diljit Singh <hey@djdev.me>
@DjDeveloperr
DjDeveloperr force-pushed the feat/borealis-m5-denorm-preserve-fp32 branch from 1c16f85 to 1b34640 Compare November 23, 2026 09:11
@DjDeveloperr DjDeveloperr changed the title borealis: advertise shaderDenormPreserveFloat32 on native AGX3 and M5 agx, borealis: handle fmin/fmax/fsat in FP32 denorm preserve lowering and unify exposure Nov 23, 2026
@DjDeveloperr

Copy link
Copy Markdown
Author

Pushed R2 (1b34640bb383f664dfa3a4fa00da3438ccfcd92a) on aurora-wip (efabab38502d) addressing all review points from @RyanTheTide:

  1. Root cause of the 3 runtime-input clamp/min/nmin failures on J615 (G15G) and J713 (G16G):
    • agx_nir_lower_denorm_preserve.c lowered fadd/fmul/ffma/fneg/fabs/comparisons/fsign, but did not lower nir_op_fmin, nir_op_fmax, nir_op_fmin_agx, nir_op_fmax_agx, or nir_op_fsat.
    • On AGX3B (G15/G16), hardware fcmpsel (fmin_agx/fmax_agx) flushes denormal operands during comparison, and nir_op_fsat lowers to fadd.sat(x, -0.0) which flushes positive denormals to zero.
    • Added exact integer-ordered lowering (lower_minmax() using order_key() + is_nan() with IEEE 754 minNum/maxNum NaN semantics and -0 < +0, and lower_fsat()) when any operand is denormal.
  2. Unified capability exposure:
    • Added agx_chip_has_fp32_denorm_preserve() in src/asahi/lib/agx_chip.h and wired hk_physical_device.c (shaderDenormPreserveFloat32) directly from it across native AGX3 and M5.
  3. Unit tests:
    • Added DenormPreserveMinMax.DirectMinMaxClampAndSat (bit-exact denormal folding for fmin, fmax, fmin_agx, fmax_agx, clamp, fsat across denorms, signed zeros, infinities, and NaN) and DenormPreserveLowering.CapabilityStagesAndEncodings (VS/FS/CS compilation on G15G, G16G, G17P, G17S) in src/asahi/compiler/test/test-denorm-preserve-fma.cpp.
  4. Verification so far:
    • Full asahi unit suite (-Db_ndebug=false) PASS on exact head 1b34640bb383: run 45143319073.
    • Non-LOCAL=1 agent-policy.sh pr feat/borealis-m5-denorm-preserve-fp32: PR is clean.
    • M5 (G17S B1) R2 hardware CTS has not run yet and will be posted once the M5 hardware lock is free.

Assisted-by: LLM (Google:Gemini 4 Neon)

@DjDeveloperr

Copy link
Copy Markdown
Author

@RyanTheTide Fresh exact-head R2 hardware row on G17S B1 (m5-ssd), including full stage coverage (VS/FS/CS) and all 18 runtime-input clamp/min/nmin/max/nmax cases:

G17S B1 (Apple M5 Pro / m5-ssd) Exact-Head R2 Hardware Verification

  • Hardware / Kernel: Apple M5 Pro (G17S B1), Linux 7.3.0-m5-cdirect2 (+ 16-plane SLC)
  • Environment: MESA_SHADER_CACHE_DISABLE=1, no ASAHI_M5_BRINGUP
  • HEAD SHA: 1b34640bb383f664dfa3a4fa00da3438ccfcd92a (R2, mirror asahi CI 45143319073 PASS)
  • ICD: Mesa 26.3.0-devel (git-1b34640bb3), Borealis, derived from Honeykrisp
  • Full FP32 denorm_preserve CTS (216/222 passed, 0 failed, 6 not supported):
    • compute.generated_args: 37/38 passed (0 failed, 1 NS)
    • compute.input_args: 35/36 passed (0 failed, 1 NS)
    • graphics.generated_args (VS/FS): 74/76 passed (0 failed, 2 NS)
    • graphics.input_args (VS/FS): 70/72 passed (0 failed, 2 NS)
  • Runtime-input clamp / nclamp / min / nmin / max / nmax (input_args.*denorm_preserve* across CS, VS, FS): 18/18 passed (0 failed)
  • Kernel GPU faults: 0 (dmesg delta 0)

@joshuaswarren joshuaswarren left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Head 1b34640bb383f664dfa3a4fa00da3438ccfcd92a, base efabab38502dc32302a058503231b12e815a21f9 (the head's parent = merge-base with aurora-wip; diff reviewed is base..head).

Read the whole diff.

  • lower_minmax: when either operand is denormal it computes the result as an exact integer-ordered comparison via order_key (so -0 < +0 correctly), and layers IEEE 754 minNum/maxNum NaN handling on top (is_nan(x) → y, is_nan(y) → x) — matching what fcmpsel does for the non-flushing cases. Non-denormal inputs take the native instruction unchanged, so the added work only runs where the flush could occur. Covers fmin/fmax/fmin_agx/fmax_agx.
  • lower_fsat: fadd.sat(x, -0.0) flushes positive denormals; the guard returns x for x >= 0 and 0 below — exact for the denormal range, native path otherwise.
  • hk_physical_device.c: shaderDenormPreserveFloat32 moves from a chip == AGX_CHIP_G17P literal to agx_chip_has_fp32_denorm_preserve() — AGX3B/AGX3C encoding + agx_chip_native_or_m5. On our AGX2 chips (G13G/G13X) the predicate is false, so the advertised feature set is unchanged; the widening only lands where the unconditional lowering actually runs.
  • New test-denorm-preserve-fma.cpp cases (208 lines, inside the existing test binary): bit-exact min/max/clamp/sat denormal vectors plus multi-stage compile coverage across G15G/G16G/G17P (AGX3B) and G17S (AGX3C).

Built and ran at this head (aarch64):

  • release build clean; full asahi suite 164/164 (169/169 with the poly suite).

Hardware rows — deqp-vk 1.4.7.1, 13,781 dEQP-VK.compute.* cases (cooperative_matrix excluded), per-case status vs the aurora-wip b10c5d3f build:

  • 13-inch M1 MacBook Pro: 0 diffs of 13,781
  • 16-inch M1 Max MacBook Pro: 0 diffs of 13,781

(Also 0 diffs of 13,781 on both laptops vs the efabab38 merge-base build.)

On these chips the pass never engages for FP32 DenormPreserve (the feature stays unexposed and the lowering is gated to the AGX3 encodings), so the change is a no-op on our hardware by construction — the rows verify nothing else moved.

Approving.

@DjDeveloperr
DjDeveloperr merged commit 0edb84f into aurora-wip Nov 24, 2026
@DjDeveloperr

Copy link
Copy Markdown
Author

Merged into aurora-wip at 0edb84f85fd6 (exact head 1b34640bb383, verified merge tree 670f5c9da3be).

  • Review: @joshuaswarren exact-head APPROVED (asahi 164/164, 169/169 w/ poly; 13,781 dEQP-VK.compute.* cases with 0 diffs on M1 & M1 Max).
  • CI: Exact-head asahi (45143319073) & aurora-agent-policy (45143319071) PASS; Gate-3 clean (1/1 SOB, empty .github/ diff, agent-policy clean).

Assisted-by: LLM (Google:Gemini 4 Neon)

@RyanTheTide RyanTheTide left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Post-merge source review of 1b34640bb383 (merged as 0edb84f85fd6). I found no defect in the new lowering. One coverage gap remains open on the chips this change newly exposes.

Checked. lower_minmax(): integer order keys give -0 < +0. A NaN operand returns the other operand, and two NaNs return NaN. The exact path is taken only when an operand is denormal, so normal and inf operands keep the native fcmpsel. lower_fsat(): a negative denormal gives +0 and a positive denormal is returned unchanged. NaN is not denormal, so it stays on the native path. The newly built native min/max/sat are inserted before the instruction being lowered, so they are not revisited.

  1. Exposure moved to G15G/G16G with no M3/M4 row at this head. Before this change, shaderDenormPreserveFloat32 was true on G17P only. agx_chip_has_fp32_denorm_preserve() now also turns it on for G15G/G15S/G15C/G16G (M3, M4) and M5. The R2 hardware row is G17S only, at 216/222 pass and 0 fail. The pre-R2 Air trial that found the min/clamp/nmin failures ran on G15G/G16G, and the "J615/J713 known-failure controls" are still marked queued. Please post the same float_controls.fp32 denorm_preserve set (compute and graphics, input_args and generated_args) at 0edb84f85fd6 on one G15G and one G16G Mac. Those two are what the merge newly advertises.
  2. Ops the pass still leaves native. The pass lowers add/mul/fma/neg/abs/compares/min/max/sat/sign. Rounding and fraction ops are not lowered: ffloor, fceil, ftrunc, fround_even, ffract. If AGX3B flushes their inputs the way it flushes fcmpsel, floor(-denorm) gives -0 instead of -1, and fract(denorm) gives 0. Neither has a unit test here, and M5 passing CTS does not show how G15/G16 behave. The G15G/G16G row in item 1 settles it: if any of these fail there, they need the same integer lowering, or the exposure stays G17P/M5-only until they are lowered.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants