diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index d1024175838..75da5ce43cb 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 d2594b8a50d..0e94949cef8 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); +}