From 7ddfc43fdffb4b38f721c7449fd0c9dcf29749b7 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Wed, 21 Jun 2023 18:16:07 -0400 Subject: [PATCH] nir: Remove integer and 64-bit modifiers Now that Intel and R600 both do their own modifier propagation, the only backends that still lower modifiers in NIR are: * nir-to-tgsi * lima * etnaviv * a2xx The latter 3 backends do not support integers, and certainly do not support fp64. So they don't use these. TGSI in theory supports integer negate modifiers but NTT doesn't use them, so they're unused there too. Since they're unused, we remove NIR support for integer and 64-bit modifiers, leaving only 16/32-bit float modifiers. This will reduce the scope needed for a replacement to NIR modifiers, being pursued in !23089. Signed-off-by: Alyssa Rosenzweig Reviewed-by: Faith Ekstrand Reviewed-by: Christian Gmeiner Part-of: --- src/compiler/nir/nir.h | 12 +++---- src/compiler/nir/nir_lower_to_source_mods.c | 40 ++++++---------------- src/gallium/auxiliary/nir/nir_to_tgsi.c | 6 ++-- src/gallium/drivers/etnaviv/etnaviv_compiler_nir.c | 3 +- 4 files changed, 18 insertions(+), 43 deletions(-) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index 56f4618..93c25f1 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -5682,16 +5682,12 @@ void nir_lower_bitmap(nir_shader *shader, const nir_lower_bitmap_options *option bool nir_lower_atomics_to_ssbo(nir_shader *shader, unsigned offset_align_state); typedef enum { - nir_lower_int_source_mods = 1 << 0, - nir_lower_fabs_source_mods = 1 << 1, - nir_lower_fneg_source_mods = 1 << 2, - nir_lower_64bit_source_mods = 1 << 3, - nir_lower_triop_abs = 1 << 4, - nir_lower_all_source_mods = (1 << 5) - 1 + nir_lower_fabs_source_mods = 1 << 0, + nir_lower_fneg_source_mods = 1 << 1, + nir_lower_triop_abs = 1 << 2, + nir_lower_all_source_mods = (1 << 3) - 1 } nir_lower_to_source_mods_flags; -#define nir_lower_float_source_mods (nir_lower_fabs_source_mods | nir_lower_fneg_source_mods) - bool nir_lower_to_source_mods(nir_shader *shader, nir_lower_to_source_mods_flags options); typedef enum { diff --git a/src/compiler/nir/nir_lower_to_source_mods.c b/src/compiler/nir/nir_lower_to_source_mods.c index b94ec14..a41fba3 100644 --- a/src/compiler/nir/nir_lower_to_source_mods.c +++ b/src/compiler/nir/nir_lower_to_source_mods.c @@ -73,30 +73,17 @@ nir_lower_to_source_mods_instr(nir_builder *b, nir_instr *instr, if (parent->dest.saturate) continue; - switch (nir_alu_type_get_base_type(nir_op_infos[alu->op].input_types[i])) { - case nir_type_float: - if (!(options & nir_lower_float_source_mods)) - continue; - if (!(parent->op == nir_op_fabs && (options & nir_lower_fabs_source_mods)) && - !(parent->op == nir_op_fneg && (options & nir_lower_fneg_source_mods))) { - continue; - } - break; - case nir_type_int: - if (!(options & nir_lower_int_source_mods)) - continue; - if (parent->op != nir_op_iabs && parent->op != nir_op_ineg) - continue; - break; - default: + if (nir_alu_type_get_base_type(nir_op_infos[alu->op].input_types[i]) != nir_type_float) continue; - } - if (nir_src_bit_size(alu->src[i].src) == 64 && - !(options & nir_lower_64bit_source_mods)) { + if (!(parent->op == nir_op_fabs && (options & nir_lower_fabs_source_mods)) && + !(parent->op == nir_op_fneg && (options & nir_lower_fneg_source_mods))) { continue; } + if (nir_src_bit_size(alu->src[i].src) == 64) + continue; + /* We can only do a rewrite if the source we are copying is SSA. * Otherwise, moving the read might invalidly reorder reads/writes * on a register. @@ -104,17 +91,15 @@ nir_lower_to_source_mods_instr(nir_builder *b, nir_instr *instr, if (!parent->src[0].src.is_ssa) continue; - if (!lower_abs && (parent->op == nir_op_fabs || - parent->op == nir_op_iabs || - parent->src[0].abs)) + if (!lower_abs && (parent->op == nir_op_fabs || parent->src[0].abs)) continue; nir_instr_rewrite_src(instr, &alu->src[i].src, parent->src[0].src); /* Apply any modifiers that come from the parent opcode */ - if (parent->op == nir_op_fneg || parent->op == nir_op_ineg) + if (parent->op == nir_op_fneg) alu_src_consume_negate(&alu->src[i]); - if (parent->op == nir_op_fabs || parent->op == nir_op_iabs) + if (parent->op == nir_op_fabs) alu_src_consume_abs(&alu->src[i]); /* Apply modifiers from the parent source */ @@ -142,19 +127,14 @@ nir_lower_to_source_mods_instr(nir_builder *b, nir_instr *instr, if (!alu->dest.dest.is_ssa) return progress; - if (nir_dest_bit_size(alu->dest.dest) == 64 && - !(options & nir_lower_64bit_source_mods)) { + if (nir_dest_bit_size(alu->dest.dest) == 64) return progress; - } /* We can only saturate float destinations */ if (nir_alu_type_get_base_type(nir_op_infos[alu->op].output_type) != nir_type_float) return progress; - if (!(options & nir_lower_float_source_mods)) - return progress; - bool all_children_are_sat = true; nir_foreach_use_including_if(child_src, &alu->dest.dest.ssa) { if (child_src->is_if) { diff --git a/src/gallium/auxiliary/nir/nir_to_tgsi.c b/src/gallium/auxiliary/nir/nir_to_tgsi.c index 9ca1af8..947ed28 100644 --- a/src/gallium/auxiliary/nir/nir_to_tgsi.c +++ b/src/gallium/auxiliary/nir/nir_to_tgsi.c @@ -3855,9 +3855,9 @@ const void *nir_to_tgsi_options(struct nir_shader *s, NIR_PASS_V(s, nir_opt_move, move_all); - /* Only lower 32-bit floats. The only other modifier type officially - * supported by TGSI is 32-bit integer negates, but even those are broken on - * virglrenderer, so skip lowering all integer and f64 float mods. + /* We're fine lowering only 32-bit floats. TGSI officially supports 32-bit + * integer negates, but even those are broken on virglrenderer, so we don't + * use integer or f64 float mods. * * The options->lower_fabs requests that we not have native source modifiers * for fabs, and instead emit MAX(a,-a) for nir_op_fabs. diff --git a/src/gallium/drivers/etnaviv/etnaviv_compiler_nir.c b/src/gallium/drivers/etnaviv/etnaviv_compiler_nir.c index 1bf098e..048279e 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_compiler_nir.c +++ b/src/gallium/drivers/etnaviv/etnaviv_compiler_nir.c @@ -1180,8 +1180,7 @@ etna_compile_shader(struct etna_shader_variant *v) NIR_PASS_V(s, nir_move_vec_src_uses_to_dest); NIR_PASS_V(s, nir_copy_prop); - /* only HW supported integer source mod is ineg for iadd instruction (?) */ - NIR_PASS_V(s, nir_lower_to_source_mods, ~nir_lower_int_source_mods); + NIR_PASS_V(s, nir_lower_to_source_mods, nir_lower_all_source_mods); /* need copy prop after uses_to_dest, and before src mods: see * dEQP-GLES2.functional.shaders.random.all_features.fragment.95 */ -- 2.7.4