From b5fe1187ecaecdfdb5a9a3448725a54054b6e217 Mon Sep 17 00:00:00 2001 From: Georg Lehmann Date: Thu, 24 Feb 2022 21:35:43 +0100 Subject: [PATCH] nir/fold_16bit_sampler_conversions: Fix src type mismatches. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Gitlab: https://gitlab.freedesktop.org/mesa/mesa/-/issues/5996 Fixes: fb29cef8 ("nir: add many passes that lower and optimize 16-bit input/outputs and samplers") Signed-off-by: Georg Lehmann Reviewed-by: Daniel Schürmann Part-of: --- src/compiler/nir/nir_lower_mediump.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/compiler/nir/nir_lower_mediump.c b/src/compiler/nir/nir_lower_mediump.c index 3ebb6dcd06d..802661d9766 100644 --- a/src/compiler/nir/nir_lower_mediump.c +++ b/src/compiler/nir/nir_lower_mediump.c @@ -463,6 +463,8 @@ nir_fold_16bit_sampler_conversions(nir_shader *nir, src_alu = nir_instr_as_alu(src); b.cursor = nir_before_instr(src); + nir_alu_type src_type = nir_tex_instr_src_type(tex, i); + if (src_alu->op == nir_op_mov) { assert(!"The IR shouldn't contain any movs to make this pass" " effective."); @@ -473,8 +475,8 @@ nir_fold_16bit_sampler_conversions(nir_shader *nir, if (nir_op_is_vec(src_alu->op)) { /* See if the vector is made of f16->f32 opcodes. */ unsigned num = nir_dest_num_components(src_alu->dest.dest); - bool is_f16_to_f32 = true; - bool is_u16_to_u32 = true; + bool is_f16_to_f32 = src_type == nir_type_float; + bool is_u16_to_u32 = src_type & (nir_type_int | nir_type_uint); for (unsigned comp = 0; comp < num; comp++) { nir_instr *instr = src_alu->src[comp].src.ssa->parent_instr; @@ -507,9 +509,11 @@ nir_fold_16bit_sampler_conversions(nir_shader *nir, nir_instr_rewrite_src_ssa(&tex->instr, &tex->src[i].src, &new_vec->dest.dest.ssa); changed = true; - } else if (is_f16_to_f32_conversion(&src_alu->instr) || - is_u16_to_u32_conversion(&src_alu->instr) || - is_i16_to_i32_conversion(&src_alu->instr)) { + } else if ((is_f16_to_f32_conversion(&src_alu->instr) && + src_type == nir_type_float) || + ((is_u16_to_u32_conversion(&src_alu->instr) || + is_i16_to_i32_conversion(&src_alu->instr)) && + src_type & (nir_type_int | nir_type_uint))) { /* Handle scalar sources. */ replace_with_mov(&b, &tex->instr, &tex->src[i].src, src_alu); changed = true;