Skip to content

asahi/compiler: keep unmodified scalar f16 FFMA GPR sources native on AGX3C compute - #1191

Merged
RyanTheTide merged 1 commit into
aurora-silicon:aurora-wipfrom
oreater:pr/agx3c-compute-native-f16-ffma
Nov 27, 2026
Merged

RyanTheTide merged 1 commit into
aurora-silicon:aurora-wipfrom
oreater:pr/agx3c-compute-native-f16-ffma

Conversation

@oreater

@oreater oreater commented Nov 27, 2026

Copy link
Copy Markdown

What: Keep unmodified all-scalar-register F32 FFMA half-GPR sources native in agx_lower_agx3_fma_sources() on AGX3C (non-emit_agx3d) compute shaders, matching AGX3B and eliminating redundant f16->f32 widening moves on normflt.f16 byte-unpack and single-use f16-source compute loops.

Tested: J716c Apple M5 Max at 088d165: 334/334 asahi+poly debug CI tests pass (incl. updated NativeForms.Agx3bFfmaKeepsUnmodifiedHalfGprNative covering AGX3C compute vs vertex); 3-round ABBA vs 41fe336dffa wins -19.2% (1.24x) on serial single-use f16->f32 FFMA, -12.7% (1.15x) on 8-wide dense f16->f32 FFMA (-31 ALU instrs, -3 GPRs), and -8.3% (1.09x) on 15-tap u8 byte-unpack blur (-56 ALU instrs, -302 B), all bit-exact; Vulkan CTS precision_fp16_storage16b.fma + float16 + 16bit/8bit_storage A/B 135/154 pass (0 fail, 0 status diffs).

Risk: two-way door · M5 Macs (AGX3C non-emit_agx3d) — scoped strictly to unmodified all-scalar-register F32 FFMA in compute shaders on AGX_ISA_ENCODING_AGX3C && !emit_agx3d; AGX3C graphics stages, modified/uniform-mixed forms, AGX2, AGX3B, and G18G (emit_agx3d) are unchanged.

Not yet: Not yet hardware-tested on M5 Pro/Base variants beyond J716c Apple M5 Max.

Benchmarks, shaderdb stats, and CTS details

3-round ABBA vs 41fe336dffa (J716c Apple M5 Max, G17C B1, MESA_SHADER_CACHE_DISABLE=1)

Workload Instrs (Base->Head) Code Size GPRs Base (ms) Head (ms) Delta Speedup
serial_f16_fma (single-chain f16->f32 FFMA) 79 -> 70 694 -> 640 B 31 -> 31 0.248 0.201 -19.15% 1.24x
dense_f16_fma (8-wide f16->f32 FFMA loop) 247 -> 216 1654 -> 1450 B 57 -> 54 0.922 0.805 -12.69% 1.15x
u8_blur_15tap (u8 byte-unpack + dynamic weight) 344 -> 288 2362 -> 2060 B 39 -> 39 1.085 0.994 -8.34% 1.09x
  • All outputs verified bit-exact (FNV-1a 64-bit hash identical across every ABBA round).
  • Local CI-matching Clang debugoptimized build: meson test --suite asahi --suite poly 334/334 PASS, 0 FAIL.
  • Live Vulkan CTS A/B (deqp-vk, precision_fp16_storage16b.fma, compute.float16, compute.16bit_storage, compute.8bit_storage): 135/154 PASS, 19 NotSupported, 0 FAIL, 0 status diffs vs 41fe336dffa.

… AGX3C compute

Extend unmodified all-scalar-register F32 FFMA half-GPR preservation in
agx_lower_agx3_fma_sources() from AGX3B to AGX3C (non-emit_agx3d) compute
shaders.

Previously single-use f16 GPR sources (such as normflt.f16 + hmul from
agx_opt_agx3_normflt_byte_pairs or dense f16-source F32-accum loops) were
re-widened via fmov/fadd before every FFMA even though AGX3C encodes
unmodified all-scalar-register mixed-width F32 FFMA natively via
agx3_falu_fma_mod_runtime(). Keeping those sources native eliminates the
extra widening instructions and reduces ALU pressure and code size on
compute inner loops while preserving explicit widening on non-compute
stages, modified/uniform-mixed forms, and emit_agx3d devices.

Update NativeForms.Agx3bFfmaKeepsUnmodifiedHalfGprNative to cover both
AGX3C compute (kept native) and AGX3C vertex (widened).

Signed-off-by: oreater <145754695+oreater@users.noreply.github.com>
@oreater
oreater requested review from a team and DjDeveloperr as code owners November 27, 2026 01:33

@DjDeveloperr DjDeveloperr 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.

Verdict at 088d165da4f4: ready on the code; CI and hardware rows still owed

I found no code blocker. The new path keeps half GPR sources only in a form AGX3C already encodes today. Widening an f16 to f32 is exact, so results don't change. The gate is narrow: only the encoding and the stage decide it.

Blockers

none

Checked

  • The gate (agx_lower_agx3_fma_sources()). The new all_scalar_regs term needs all of these:

    • AGX_ISA_ENCODING_AGX3C, with !g18g, where agx_is_g18g() is AGX3C && emit_agx3d, so it is the PR's "non-emit_agx3d";
    • a compute stage;
    • a scalar 32-bit destination that isn't memory;
    • every source a scalar NORMAL or REGISTER operand, so no immediates, uniforms, memory or vectors;
    • no abs/neg on any source (native_scalar_half_gpr = all_scalar_regs && !src_modifier).

    Saturating FFMAs return earlier (I->saturate) and don't reach this test. AGX2 returns at the top, and AGX3B and G18G behave as before.

  • Encoding. On AGX3C, agx3c_native_half_gpr already keeps halves read by two or more FFMAs. So an FFMA with an f32 destination and half GPR operands in any slot is already emitted there, and packed by agx3_falu_fma_mod_runtime() with per-operand width bits (agx3_pack_binary.c).

    • The new path extends that to single-use values, and to precoloured AGX_INDEX_REGISTER halves, which become the same 16-bit register operand after register allocation.
    • The packer refuses a combination it can't encode (it returns -1) and doesn't mis-encode it.
  • Precision. The widening move it drops is an exact f16-to-f32 conversion, and the AGX3C operand slot widens exactly too (the comment in the pass says so). The single rounding of the FFMA is unchanged, and the bit-exact hashes in Tested agree.

  • Stage split. Graphics stages keep the old single-use widening, with its stated reason (an FFMA on a half register being slower). That's a measured heuristic, not a correctness rule. The compute side is supported by the J716c ABBA numbers.

  • Build and tests, in a separate shallow clone (aarch64 host, debugoptimized, -Dvulkan-drivers=asahi -Dbuild-tests=true):

    • it builds, with no warnings on the changed lines; the 4 -Wdangling-else warnings in test-native-form-regressions.cpp (6342, 8280) come from other commits;
    • meson test --suite asahi: 212/212 OK; --suite poly: 5/5 OK;
    • NativeForms.Agx3bFfmaKeepsUnmodifiedHalfGprNative passes.
    • Each of two mutations fails the test:
      • dropping the compute-stage condition fails agx3c_vertex_src0_widened;
      • removing the AGX3C clause fails agx3c_compute_src0_native.
  • Small test gap (not blocking). The precoloured-register case exists only for AGX3B (agx3b_src0_precoloured). An AGX3C compute precoloured case, and one with a modifier (e.g. agx3c_compute_neg_widened), would pin the new path's other two conditions.

  • Merge and text. It merges cleanly with the current aurora-wip (8ac326f31d4f). The commit is signed off and carries no attribution.

Owed before merge

  • CI. No checks are reported on this head yet.
  • Hardware rows. Only J716c (G17C) is listed. The change covers every AGX3C part, so a G17S (J714s) row, which Not yet already names, and ideally a G17G row are owed. Each should repeat the CTS groups (precision_fp16_storage16b.fma, compute.float16, compute.16bit_storage, compute.8bit_storage) and the bit-exact compute set.
Evidence
head 088d165da4f4958c73a9a1d8d41693e725b7fee6, base 41fe336dffae, merge-tree clean with aurora-wip 8ac326f31d4f

agx_compile.h:560   agx_is_g18g(dev) = encoding == AGX3C && emit_agx3d
agx_compile.c       all_scalar_regs = (AGX3B || (AGX3C && !g18g && compute)) && 1 dest, !memory, 32-bit, 1 channel
                    + every src NORMAL/REGISTER, !memory, 1 channel; native only if no src abs/neg
                    existing: agx3c_native_half_gpr keeps halves with ffma_reads >= 2 (same FFMA form)
agx3_pack_binary.c  AGX3B/AGX3C FFMA -> agx3_falu_fma_mod_runtime(enc, d, s0, s1, addend, &m{src*_16, addend_16}, ...)

meson test --suite asahi   -> Ok: 212, Fail: 0
meson test --suite poly    -> Ok: 5, Fail: 0
mutation: no compute-stage condition -> agx3c_vertex_src0_widened FAILED
mutation: no AGX3C clause            -> agx3c_compute_src0_native FAILED
CI checks on this head: none reported

@DjDeveloperr

Copy link
Copy Markdown

J714s (MacBook Pro 14" M5 Pro, G17S B1) row at 088d165da4f4 against its merge base 41fe336dffae: PASS. No CTS differences, compute rows neutral.

Setup:

  • Isolated Mesa kits built on the M5 from one warm tree:
    • A = 41fe336dffae, this PR's merge base with aurora-wip.
    • C = 088d165da4f4, this PR's head.
  • Both kits were confirmed loaded for Vulkan and GL (git-41fe336dff / git-088d165da4).
  • The default kernel 7.3.0-m5-cdirect16 with the default command line, headless. The system Mesa and the kernel were not changed.
  • MESA_SHADER_CACHE_DISABLE=1 throughout.

1. Vulkan CTS (deqp-vk 1.4.7.1, 16 jobs), the same 995 cases on both kits:

  • Selection: glsl.builtin.precision_fp16_storage16b.fma.* plus spirv_assembly.instruction.compute.{float16,16bit_storage,8bit_storage}.*.
  • A: 963 Pass and 32 NotSupported. C: the same.
  • 0 Fail, and 0 per-case status differences between A and C.

2. gpubench-vk compute.* at depths 1 and 2: 5 × 400 ms runs after a 300 ms warm-up, in the order A C C A.

Row A GPU µs C GPU µs Δ GPU
light d1 / d2 3.0 / 2.8 3.0 / 2.9 —
heavy d1 / d2 269.8 / 269.5 269.8 / 269.4 0.0 % / 0.0 %
uber d1 / d2 253.2 / 252.6 252.9 / 252.6 −0.1 % / 0.0 %
conv2d d1 / d2 239.4 / 239.2 238.9 / 238.6 −0.2 % / −0.3 %
edge d1 / d2 140.6 / 140.2 141.2 / 141.3 +0.4 % / +0.8 %
cull_mdi d1 / d2 410.8 / 405.1 407.4 / 407.0 −0.8 % / +0.5 %
fp16 d1 / d2 40.5 / 40.1 40.6 / 40.3 +0.3 % / +0.6 %
stereo d1 / d2 3,666.3 / 3,665.9 3,666.3 / 3,665.9 0.0 % / 0.0 %
  • GPU time: within ±0.8 % on every row. These rows don't have this PR's single-use f16→f32 FFMA pattern, so they show no gain here.
  • light d2: µs per submit was noisy on the base (39.7 and 32.1) against 30.3 and 28.8 on C. That is submission timing on a 3 µs kernel and is not counted as a result.

3. Kernel log for the slot: 0 GPU faults, 0 WARN and 0 error lines. The GPU was online with 0 crashed and 0 quarantined owners before and after.

This was referenced Nov 27, 2026

@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.

Verdict: MERGE at 088d165da4f4

Blockers: none

Checked: Read the diff. Keeping unmodified all-scalar-register f16 FFMA sources native on AGX3C compute uses the encoding AGX3B already emits and agx3_falu_fma_mod_runtime packs; widening f16 to f32 is exact, so results do not change. Gated on encoding and stage only. M5-only; J716c and Dj's J714s rows are on the PR at this head. Gate green.

Evidence

Local Mesa gate (stands in for CI; buildbox x86 docker aurora/hk6356-mesa-x86-tests:local, clang release with asserts, -Dbuild-tests=true -Dtools=asahi,drm-shim, meson test --suite asahi --suite poly):

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