From 9a52b9372cc412f4582613e32b5c88f3250b1fd2 Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Mon, 16 Jun 2025 12:02:12 -0400 Subject: [PATCH] nir/lower_input_attachments: Stop assuming tex src indices There's nothing in NIR which guarantees that the deref is the first source or that the coordinate is the second. Use nir_tex_instr_src_index() to get the actual indices. Fixes: 84b08971fbdc ("nir/lower_input_attachments: lower nir_texop_fragment_{mask}_fetch") Reviewed-by: Alyssa Rosenzweig Part-of: --- src/compiler/nir/nir_lower_input_attachments.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/compiler/nir/nir_lower_input_attachments.c b/src/compiler/nir/nir_lower_input_attachments.c index af21c3e12f5..1bfac8c3fe2 100644 --- a/src/compiler/nir/nir_lower_input_attachments.c +++ b/src/compiler/nir/nir_lower_input_attachments.c @@ -159,11 +159,19 @@ static bool try_lower_input_texop(nir_builder *b, nir_tex_instr *tex, const nir_input_attachment_options *options) { - nir_deref_instr *deref = nir_src_as_deref(tex->src[0].src); + const int texture_src_idx = + nir_tex_instr_src_index(tex, nir_tex_src_texture_deref); + if (texture_src_idx < 0) + return false; + + nir_deref_instr *deref = nir_src_as_deref(tex->src[texture_src_idx].src); if (glsl_get_sampler_dim(deref->type) != GLSL_SAMPLER_DIM_SUBPASS_MS) return false; + const int coord_src_idx = nir_tex_instr_src_index(tex, nir_tex_src_coord); + assert(coord_src_idx >= 0); + b->cursor = nir_before_instr(&tex->instr); nir_def *frag_coord = load_frag_coord(b, deref, options); @@ -175,7 +183,7 @@ try_lower_input_texop(nir_builder *b, nir_tex_instr *tex, tex->coord_components = 3; - nir_src_rewrite(&tex->src[1].src, coord); + nir_src_rewrite(&tex->src[coord_src_idx].src, coord); return true; }