From 89868d37cedd59c119ae1da1deb8f40ba130c8e8 Mon Sep 17 00:00:00 2001 From: Karol Herbst Date: Fri, 24 Apr 2026 01:52:26 +0200 Subject: [PATCH] r600,sfn: support new multadd opcodes Reviewed-by: Georg Lehmann Part-of: --- src/gallium/drivers/r600/r600_pipe_common.c | 3 +++ src/gallium/drivers/r600/sfn/sfn_instr_alu.cpp | 3 +++ src/gallium/drivers/r600/sfn/sfn_nir_lower_64bit.cpp | 1 + src/gallium/drivers/r600/sfn/sfn_nir_lower_tex.cpp | 4 ++-- 4 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/gallium/drivers/r600/r600_pipe_common.c b/src/gallium/drivers/r600/r600_pipe_common.c index e274633282b..c3fe7cbb517 100644 --- a/src/gallium/drivers/r600/r600_pipe_common.c +++ b/src/gallium/drivers/r600/r600_pipe_common.c @@ -1087,6 +1087,9 @@ bool r600_common_screen_init(struct r600_common_screen *rscreen, .fuse_ffma16 = true, .fuse_ffma32 = true, .fuse_ffma64 = true, + .float_mul_add16 = nir_float_muladd_support_has_fmad | nir_float_muladd_support_fuse, + .float_mul_add32 = nir_float_muladd_support_has_fmad | nir_float_muladd_support_fuse, + .float_mul_add64 = nir_float_muladd_support_has_ffma | nir_float_muladd_support_fuse, .lower_flrp32 = true, .lower_flrp64 = true, .lower_fdiv = true, diff --git a/src/gallium/drivers/r600/sfn/sfn_instr_alu.cpp b/src/gallium/drivers/r600/sfn/sfn_instr_alu.cpp index 8fc7ba1f338..8d295463cb3 100644 --- a/src/gallium/drivers/r600/sfn/sfn_instr_alu.cpp +++ b/src/gallium/drivers/r600/sfn/sfn_instr_alu.cpp @@ -1639,6 +1639,7 @@ AluInstr::from_nir(nir_alu_instr *alu, Shader& shader) return emit_alu_op2_64bit_one_dst(*alu, op2_setgt_64, shader, true); case nir_op_fneu32: return emit_alu_op2_64bit_one_dst(*alu, op2_setne_64, shader, false); + case nir_op_ffma: case nir_op_ffma_old: return emit_alu_fma_64bit(*alu, op3_fma_64, shader); @@ -1956,10 +1957,12 @@ AluInstr::from_nir(nir_alu_instr *alu, Shader& shader) case nir_op_unpack_64_2x32_split_y: return emit_unpack_64_2x32_split(*alu, 1, shader); + case nir_op_fmad: case nir_op_ffma_old: if (!shader.has_flag(Shader::sh_legacy_math_rules)) return emit_alu_op3(*alu, op3_muladd_ieee, shader); FALLTHROUGH; + case nir_op_fmadz: case nir_op_ffmaz_old: return emit_alu_op3(*alu, op3_muladd, shader); diff --git a/src/gallium/drivers/r600/sfn/sfn_nir_lower_64bit.cpp b/src/gallium/drivers/r600/sfn/sfn_nir_lower_64bit.cpp index 9306c132ead..fc717c8a0b0 100644 --- a/src/gallium/drivers/r600/sfn/sfn_nir_lower_64bit.cpp +++ b/src/gallium/drivers/r600/sfn/sfn_nir_lower_64bit.cpp @@ -1033,6 +1033,7 @@ Lower64BitToVec2::support_fp64_op(nir_op op) const case nir_op_fge32: case nir_op_flt32: case nir_op_fneu32: + case nir_op_ffma: case nir_op_ffma_old: case nir_op_fadd: case nir_op_fmul: diff --git a/src/gallium/drivers/r600/sfn/sfn_nir_lower_tex.cpp b/src/gallium/drivers/r600/sfn/sfn_nir_lower_tex.cpp index bd67f224ddd..b9e0a576e96 100644 --- a/src/gallium/drivers/r600/sfn/sfn_nir_lower_tex.cpp +++ b/src/gallium/drivers/r600/sfn/sfn_nir_lower_tex.cpp @@ -257,7 +257,7 @@ r600_nir_lower_cube_to_2darray_impl(nir_builder *b, nir_instr *instr, void *_opt auto cubed = nir_cube_amd(b, nir_trim_vector(b, tex->src[coord_idx].src.ssa, 3)); - auto xy = nir_fmad_old(b, + auto xy = nir_fmad(b, nir_vec2(b, nir_channel(b, cubed, 1), nir_channel(b, cubed, 0)), nir_frcp(b, nir_fabs(b, nir_channel(b, cubed, 2))), nir_imm_float(b, 1.5)); @@ -266,7 +266,7 @@ r600_nir_lower_cube_to_2darray_impl(nir_builder *b, nir_instr *instr, void *_opt if (tex->is_array && tex->op != nir_texop_lod) { auto slice = nir_fround_even(b, nir_channel(b, tex->src[coord_idx].src.ssa, 3)); z = - nir_fmad_old(b, nir_fmax(b, slice, nir_imm_float(b, 0.0)), nir_imm_float(b, 8.0), z); + nir_fmad(b, nir_fmax(b, slice, nir_imm_float(b, 0.0)), nir_imm_float(b, 8.0), z); } if (tex->op == nir_texop_txd) {