From a2e96a86e1c3fa1dd28e480733cd0a8085208de6 Mon Sep 17 00:00:00 2001 From: antonino Date: Mon, 9 Oct 2023 16:51:11 +0200 Subject: [PATCH] nir: fix several crashes in `nir_lower_tex` This patch fixes the following issues that lead to crashes in some cases: * an instruction is inserted to get texture lod that depends on a texture instruction that hasn't been inserted yet. * this code tries to read channel 1 of the lod, but lod is scalar * the code assumed there would only be 2 srcs, this isn't the case when bindless is used. Fixes: b154a4154b4 ("nir/lower_tex: rewrite tex/txb -> txd/txl before saturating srcs") Reviewed-by: Faith Ekstrand Reviewed-by: Emma Anholt Part-of: --- src/compiler/nir/nir_lower_tex.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/compiler/nir/nir_lower_tex.c b/src/compiler/nir/nir_lower_tex.c index 432eaccd5e3..c454018c57f 100644 --- a/src/compiler/nir/nir_lower_tex.c +++ b/src/compiler/nir/nir_lower_tex.c @@ -906,17 +906,17 @@ lower_txb_to_txl(nir_builder *b, nir_tex_instr *tex) txl->is_new_style_shadow = tex->is_new_style_shadow; /* reuse all but bias src */ - for (int i = 0; i < 2; i++) { + for (int i = 0; i < tex->num_srcs; i++) { if (tex->src[i].src_type != nir_tex_src_bias) { txl->src[i].src = nir_src_for_ssa(tex->src[i].src.ssa); txl->src[i].src_type = tex->src[i].src_type; } } - nir_def *lod = nir_get_texture_lod(b, txl); + nir_def *lod = nir_get_texture_lod(b, tex); int bias_idx = nir_tex_instr_src_index(tex, nir_tex_src_bias); assert(bias_idx >= 0); - lod = nir_fadd(b, nir_channel(b, lod, 1), tex->src[bias_idx].src.ssa); + lod = nir_fadd(b, lod, tex->src[bias_idx].src.ssa); txl->src[tex->num_srcs - 1] = nir_tex_src_for_ssa(nir_tex_src_lod, lod); nir_def_init(&txl->instr, &txl->def,