From cb95065dd122a09159ecf6f00d6ae03c6014fb10 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Thu, 1 Oct 2020 10:09:35 -0500 Subject: [PATCH] nir: Add lowering from regular ALU conversions to the intrinsic Reviewed-by: Jesse Natalie Part-of: --- src/compiler/nir/nir.h | 1 + src/compiler/nir/nir_lower_convert_alu_types.c | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index d102417..75da5ce 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -4388,6 +4388,7 @@ bool nir_opt_simplify_convert_alu_types(nir_shader *shader); bool nir_lower_convert_alu_types(nir_shader *shader, bool (*should_lower)(nir_intrinsic_instr *)); bool nir_lower_constant_convert_alu_types(nir_shader *shader); +bool nir_lower_alu_covnersion_to_intrinsic(nir_shader *shader); bool nir_lower_int_to_float(nir_shader *shader); bool nir_lower_load_const_to_scalar(nir_shader *shader); bool nir_lower_read_invocation_to_scalar(nir_shader *shader); diff --git a/src/compiler/nir/nir_lower_convert_alu_types.c b/src/compiler/nir/nir_lower_convert_alu_types.c index d2594b8..0e94949 100644 --- a/src/compiler/nir/nir_lower_convert_alu_types.c +++ b/src/compiler/nir/nir_lower_convert_alu_types.c @@ -180,3 +180,27 @@ nir_lower_constant_convert_alu_types(nir_shader *shader) { return nir_lower_convert_alu_types(shader, is_constant); } + +static bool +is_alu_conversion(const nir_instr *instr, UNUSED const void *_data) +{ + return instr->type == nir_instr_type_alu && + nir_op_infos[nir_instr_as_alu(instr)->op].is_conversion; +} + +static nir_ssa_def * +lower_alu_conversion(nir_builder *b, nir_instr *instr, UNUSED void *_data) +{ + nir_alu_instr *alu = nir_instr_as_alu(instr); + return nir_convert_alu_types(b, nir_ssa_for_alu_src(b, alu, 0), + nir_op_infos[alu->op].input_types[0], + nir_op_infos[alu->op].output_type, + nir_rounding_mode_undef, false); +} + +bool +nir_lower_alu_covnersion_to_intrinsic(nir_shader *shader) +{ + return nir_shader_lower_instructions(shader, is_alu_conversion, + lower_alu_conversion, NULL); +} -- 2.7.4