From 59d994c8ca507021a22a9162e023bb684e5c4328 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Fri, 24 Apr 2026 02:02:32 +0200 Subject: [PATCH] agx: port over to nir_op_ffma Reviewed-by: Alyssa Rosenzweig Reviewed-by: Georg Lehmann Part-of: --- src/asahi/compiler/agx_compile.c | 3 ++- src/asahi/compiler/agx_compile.h | 2 ++ src/asahi/compiler/agx_nir_lower_interpolation.c | 6 +++--- src/asahi/compiler/agx_nir_opt_preamble.c | 1 + src/gallium/drivers/asahi/agx_blit.c | 2 +- 5 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/asahi/compiler/agx_compile.c b/src/asahi/compiler/agx_compile.c index c2ef0471aca..62eb16c3b13 100644 --- a/src/asahi/compiler/agx_compile.c +++ b/src/asahi/compiler/agx_compile.c @@ -1906,6 +1906,7 @@ agx_emit_alu(agx_builder *b, nir_alu_instr *instr) else return agx_fmul_to(b, dst, s0, s1); + case nir_op_ffma: case nir_op_ffma_old: if (instr->def.bit_size == 16) return agx_hfma_to(b, dst, s0, s1, s2); @@ -3559,7 +3560,7 @@ libagx_frcp(nir_builder *b, nir_def *x) * = fma(fma(-x, u, 1), u, u) */ nir_def *one = nir_imm_float(b, 1.0); - nir_def *u_2 = nir_ffma_old(b, nir_ffma_old(b, nir_fneg(b, x), u, one), u, u); + nir_def *u_2 = nir_ffma(b, nir_ffma(b, nir_fneg(b, x), u, one), u, u); /* If the original value was infinite, frcp will generate the correct zero. * However, the Newton-Raphson step would multiply 0 * Inf and get a NaN. So diff --git a/src/asahi/compiler/agx_compile.h b/src/asahi/compiler/agx_compile.h index feb801496f6..ff4cf05b00f 100644 --- a/src/asahi/compiler/agx_compile.h +++ b/src/asahi/compiler/agx_compile.h @@ -350,6 +350,8 @@ static const nir_shader_compiler_options agx_nir_options = { .lower_fdiv = true, .fuse_ffma16 = true, .fuse_ffma32 = true, + .float_mul_add16 = nir_float_muladd_support_has_ffma | nir_float_muladd_support_fuse, + .float_mul_add32 = nir_float_muladd_support_has_ffma | nir_float_muladd_support_fuse, .lower_flrp16 = true, .lower_flrp32 = true, .lower_fpow = true, diff --git a/src/asahi/compiler/agx_nir_lower_interpolation.c b/src/asahi/compiler/agx_nir_lower_interpolation.c index d7ed4fe0845..8280a374cf0 100644 --- a/src/asahi/compiler/agx_nir_lower_interpolation.c +++ b/src/asahi/compiler/agx_nir_lower_interpolation.c @@ -55,10 +55,10 @@ interpolate_at_offset(nir_builder *b, nir_def *cf, nir_def *offset, nir_def *pos = nir_fadd(b, center, nir_f2f32(b, offset)); /* Interpolate with the given coefficients */ - nir_def *interp = nir_ffma_old(b, nir_channel(b, pos, 1), nir_channel(b, cf, 1), - nir_channel(b, cf, 2)); + nir_def *interp = nir_ffma_weak(b, nir_channel(b, pos, 1), nir_channel(b, cf, 1), + nir_channel(b, cf, 2)); - interp = nir_ffma_old(b, nir_channel(b, pos, 0), nir_channel(b, cf, 0), interp); + interp = nir_ffma_weak(b, nir_channel(b, pos, 0), nir_channel(b, cf, 0), interp); /* Divide by RHW. This load will be lowered recursively. */ if (perspective) { diff --git a/src/asahi/compiler/agx_nir_opt_preamble.c b/src/asahi/compiler/agx_nir_opt_preamble.c index 49d30c8b0df..85a20df4c64 100644 --- a/src/asahi/compiler/agx_nir_opt_preamble.c +++ b/src/asahi/compiler/agx_nir_opt_preamble.c @@ -89,6 +89,7 @@ alu_cost(nir_alu_instr *alu) case nir_op_f2f16_rtne: case nir_op_fadd: case nir_op_fmul: + case nir_op_ffma: case nir_op_ffma_old: case nir_op_iadd: case nir_op_inot: diff --git a/src/gallium/drivers/asahi/agx_blit.c b/src/gallium/drivers/asahi/agx_blit.c index 6adba875bbe..fb9cb78b6cf 100644 --- a/src/gallium/drivers/asahi/agx_blit.c +++ b/src/gallium/drivers/asahi/agx_blit.c @@ -116,7 +116,7 @@ asahi_blit_compute_shader(struct pipe_context *ctx, struct asahi_blit_key *key) { /* For pixels within the copy area, texture from the source */ nir_def *coords_el_2d = - nir_ffma_old(b, nir_u2f32(b, logical_id_el_2d), trans_scale, trans_offs); + nir_ffma_weak(b, nir_u2f32(b, logical_id_el_2d), trans_scale, trans_offs); nir_def *coords_el_nd = coords_el_2d; if (layer) {