From ec60ee3b56cbcc470e2cf0602adfe1424a1c3aab 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: (cherry picked from commit b5fe1187ecaecdfdb5a9a3448725a54054b6e217) --- .pick_status.json | 2 +- src/compiler/nir/nir_lower_mediump.c | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index db78a4d6ec0..8d116fe0629 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -1980,7 +1980,7 @@ "description": "nir/fold_16bit_sampler_conversions: Fix src type mismatches.", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "because_sha": "fb29cef8ddabdd05aeddc5220017bb28a83bb19c" }, { diff --git a/src/compiler/nir/nir_lower_mediump.c b/src/compiler/nir/nir_lower_mediump.c index 5bbbe20b5c4..0ceb8562a7e 100644 --- a/src/compiler/nir/nir_lower_mediump.c +++ b/src/compiler/nir/nir_lower_mediump.c @@ -460,6 +460,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."); @@ -470,8 +472,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; @@ -504,9 +506,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;