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: b154a4154b ("nir/lower_tex: rewrite tex/txb -> txd/txl before saturating srcs")
Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26012>
This commit is contained in:
antonino
2023-11-02 18:03:41 +01:00
committed by Marge Bot
parent 28b79b2ea5
commit 4a627af0e3

View File

@@ -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);