From f3ee9be836bf3d00a51f6b58300c383c4d269309 Mon Sep 17 00:00:00 2001 From: M Henning Date: Sat, 12 Nov 2022 15:53:30 -0500 Subject: [PATCH] glsl: Drop borrow/carry lowerings in favor of nir Unconditionally lowering prevents GL drivers from natively implementing these ops. Drivers that need lowering should set lower_uadd_carry and lower_usub_borrow on nir_shader_compiler_options to get the nir lowerings. Tested with dEQP-GLES31.functional.shaders.builtin_functions.integer.* Reviewed-by: Alyssa Rosenzweig Reviewed-by: Emma Anholt Part-of: --- src/compiler/glsl/lower_instructions.cpp | 48 -------------------------- src/gallium/auxiliary/nir/nir_to_tgsi.c | 6 ++++ src/gallium/drivers/etnaviv/etnaviv_compiler.c | 1 + src/gallium/drivers/r600/r600_pipe_common.c | 2 ++ src/gallium/drivers/zink/zink_compiler.c | 1 + src/microsoft/compiler/nir_to_dxil.c | 1 + src/panfrost/midgard/midgard_compile.h | 2 ++ 7 files changed, 13 insertions(+), 48 deletions(-) diff --git a/src/compiler/glsl/lower_instructions.cpp b/src/compiler/glsl/lower_instructions.cpp index 16d691e..b657f5a 100644 --- a/src/compiler/glsl/lower_instructions.cpp +++ b/src/compiler/glsl/lower_instructions.cpp @@ -89,8 +89,6 @@ private: void dldexp_to_arith(ir_expression *); void dfrexp_sig_to_arith(ir_expression *); void dfrexp_exp_to_arith(ir_expression *); - void carry_to_arith(ir_expression *); - void borrow_to_arith(ir_expression *); void double_dot_to_fma(ir_expression *); void double_lrp(ir_expression *); void dceil_to_dfrac(ir_expression *); @@ -581,44 +579,6 @@ lower_instructions_visitor::dfrexp_exp_to_arith(ir_expression *ir) } void -lower_instructions_visitor::carry_to_arith(ir_expression *ir) -{ - /* Translates - * ir_binop_carry x y - * into - * sum = ir_binop_add x y - * bcarry = ir_binop_less sum x - * carry = ir_unop_b2i bcarry - */ - - ir_rvalue *x_clone = ir->operands[0]->clone(ir, NULL); - ir->operation = ir_unop_i2u; - ir->init_num_operands(); - ir->operands[0] = b2i(less(add(ir->operands[0], ir->operands[1]), x_clone)); - ir->operands[1] = NULL; - - this->progress = true; -} - -void -lower_instructions_visitor::borrow_to_arith(ir_expression *ir) -{ - /* Translates - * ir_binop_borrow x y - * into - * bcarry = ir_binop_less x y - * carry = ir_unop_b2i bcarry - */ - - ir->operation = ir_unop_i2u; - ir->init_num_operands(); - ir->operands[0] = b2i(less(ir->operands[0], ir->operands[1])); - ir->operands[1] = NULL; - - this->progress = true; -} - -void lower_instructions_visitor::double_dot_to_fma(ir_expression *ir) { ir_variable *temp = new(ir) ir_variable(ir->operands[0]->type->get_base_type(), "dot_res", @@ -1467,14 +1427,6 @@ lower_instructions_visitor::visit_leave(ir_expression *ir) dfrexp_sig_to_arith(ir); break; - case ir_binop_carry: - carry_to_arith(ir); - break; - - case ir_binop_borrow: - borrow_to_arith(ir); - break; - case ir_unop_trunc: if (lowering(DOPS_TO_DFRAC) && ir->type->is_double()) dtrunc_to_dfrac(ir); diff --git a/src/gallium/auxiliary/nir/nir_to_tgsi.c b/src/gallium/auxiliary/nir/nir_to_tgsi.c index 479bdf8..ba1dbc0 100644 --- a/src/gallium/auxiliary/nir/nir_to_tgsi.c +++ b/src/gallium/auxiliary/nir/nir_to_tgsi.c @@ -3656,6 +3656,8 @@ ntt_fix_nir_options(struct pipe_screen *screen, struct nir_shader *s, !options->lower_flrp64 || !options->lower_fmod || !options->lower_rotate || + !options->lower_uadd_carry || + !options->lower_usub_borrow || !options->lower_uadd_sat || !options->lower_usub_sat || !options->lower_uniforms_to_ubo || @@ -3674,6 +3676,8 @@ ntt_fix_nir_options(struct pipe_screen *screen, struct nir_shader *s, new_options->lower_flrp64 = true; new_options->lower_fmod = true; new_options->lower_rotate = true; + new_options->lower_uadd_carry = true; + new_options->lower_usub_borrow = true; new_options->lower_uadd_sat = true; new_options->lower_usub_sat = true; new_options->lower_uniforms_to_ubo = true; @@ -4030,6 +4034,8 @@ static const nir_shader_compiler_options nir_to_tgsi_compiler_options = { .lower_fmod = true, .lower_rotate = true, .lower_uniforms_to_ubo = true, + .lower_uadd_carry = true, + .lower_usub_borrow = true, .lower_uadd_sat = true, .lower_usub_sat = true, .lower_vector_cmp = true, diff --git a/src/gallium/drivers/etnaviv/etnaviv_compiler.c b/src/gallium/drivers/etnaviv/etnaviv_compiler.c index b51312a..26b30f6 100644 --- a/src/gallium/drivers/etnaviv/etnaviv_compiler.c +++ b/src/gallium/drivers/etnaviv/etnaviv_compiler.c @@ -42,6 +42,7 @@ etna_compiler_create(const char *renderer, const struct etna_specs *specs) .fuse_ffma32 = true, .fuse_ffma64 = true, .lower_uadd_carry = true, + .lower_usub_borrow = true, .lower_mul_high = true, .lower_bitops = true, .lower_all_io_to_temps = true, diff --git a/src/gallium/drivers/r600/r600_pipe_common.c b/src/gallium/drivers/r600/r600_pipe_common.c index 51b045a..d25708e 100644 --- a/src/gallium/drivers/r600/r600_pipe_common.c +++ b/src/gallium/drivers/r600/r600_pipe_common.c @@ -1334,6 +1334,8 @@ bool r600_common_screen_init(struct r600_common_screen *rscreen, .lower_isign = true, .lower_fsign = true, .lower_fmod = true, + .lower_uadd_carry = true, + .lower_usub_borrow = true, .lower_extract_byte = true, .lower_extract_word = true, .lower_insert_byte = true, diff --git a/src/gallium/drivers/zink/zink_compiler.c b/src/gallium/drivers/zink/zink_compiler.c index c59c4d5..8e12996 100644 --- a/src/gallium/drivers/zink/zink_compiler.c +++ b/src/gallium/drivers/zink/zink_compiler.c @@ -338,6 +338,7 @@ zink_screen_init_compiler(struct zink_screen *screen) .lower_mul_high = true, .lower_rotate = true, .lower_uadd_carry = true, + .lower_usub_borrow = true, .lower_uadd_sat = true, .lower_usub_sat = true, .lower_vector_cmp = true, diff --git a/src/microsoft/compiler/nir_to_dxil.c b/src/microsoft/compiler/nir_to_dxil.c index 8f46a52..ed3cb06 100644 --- a/src/microsoft/compiler/nir_to_dxil.c +++ b/src/microsoft/compiler/nir_to_dxil.c @@ -115,6 +115,7 @@ nir_options = { .lower_usub_sat = true, .lower_iadd_sat = true, .lower_uadd_carry = true, + .lower_usub_borrow = true, .lower_mul_high = true, .lower_rotate = true, .lower_pack_half_2x16 = true, diff --git a/src/panfrost/midgard/midgard_compile.h b/src/panfrost/midgard/midgard_compile.h index 5d1f3fc..bced01d 100644 --- a/src/panfrost/midgard/midgard_compile.h +++ b/src/panfrost/midgard/midgard_compile.h @@ -55,6 +55,8 @@ static const nir_shader_compiler_options midgard_nir_options = { .lower_find_lsb = true, .lower_ifind_msb = true, .lower_fdph = true, + .lower_uadd_carry = true, + .lower_usub_borrow = true, /* TODO: We have native ops to help here, which we'll want to look into * eventually */ -- 2.7.4