From 4a627af0e3670d409d8140c1f9ee1c7ac86b5ddf Mon Sep 17 00:00:00 2001 From: antonino Date: Thu, 2 Nov 2023 18:03:41 +0100 Subject: [PATCH] nir: don't take the derivative of the array index in `nir_lower_tex` Previosuly when lowering to txd for sampler array the index would be derived as well, therefore the resulting derivative would have been a vec with one more component than what the txd instruction expects. This patch truncates the coordinate vector in this case to make sure the index is not derived. Fixes: b154a4154b4 ("nir/lower_tex: rewrite tex/txb -> txd/txl before saturating srcs") Reviewed-by: Faith Ekstrand Part-of: --- src/compiler/nir/nir_lower_tex.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/compiler/nir/nir_lower_tex.c b/src/compiler/nir/nir_lower_tex.c index 83f3ebb5c9e..716c5dda7a8 100644 --- a/src/compiler/nir/nir_lower_tex.c +++ b/src/compiler/nir/nir_lower_tex.c @@ -872,10 +872,14 @@ lower_tex_to_txd(nir_builder *b, nir_tex_instr *tex) txd->src[i].src = nir_src_for_ssa(tex->src[i].src.ssa); txd->src[i].src_type = tex->src[i].src_type; } - int coord = nir_tex_instr_src_index(tex, nir_tex_src_coord); - assert(coord >= 0); - nir_def *dfdx = nir_fddx(b, tex->src[coord].src.ssa); - nir_def *dfdy = nir_fddy(b, tex->src[coord].src.ssa); + int coord_idx = nir_tex_instr_src_index(tex, nir_tex_src_coord); + assert(coord_idx >= 0); + nir_def *coord = tex->src[coord_idx].src.ssa; + /* don't take the derivative of the array index */ + if (tex->is_array) + coord = nir_channels(b, coord, nir_component_mask(coord->num_components - 1)); + nir_def *dfdx = nir_fddx(b, coord); + nir_def *dfdy = nir_fddy(b, coord); txd->src[tex->num_srcs] = nir_tex_src_for_ssa(nir_tex_src_ddx, dfdx); txd->src[tex->num_srcs + 1] = nir_tex_src_for_ssa(nir_tex_src_ddy, dfdy);