agx: fix 1D texture sampling
fixes texwrap 1d bordercolor cases. Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> Reviewed-by: Faith Ekstrand <faith.ekstrand@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26377>
This commit is contained in:
committed by
Marge Bot
parent
e14633fa7d
commit
d5e0901fd5
@@ -130,25 +130,6 @@ lower_buffer_texture(nir_builder *b, nir_tex_instr *tex)
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
* Given a 1D texture coordinate, calculate the 2D coordinate vector that
|
||||
* will be used to access the linear 2D texture bound to the 1D texture.
|
||||
*/
|
||||
static nir_def *
|
||||
coords_for_1d_texture(nir_builder *b, nir_def *coord, bool is_array)
|
||||
{
|
||||
/* Add a zero Y component to the coordinate */
|
||||
if (is_array) {
|
||||
assert(coord->num_components >= 2);
|
||||
return nir_vec3(b, nir_channel(b, coord, 0),
|
||||
nir_imm_intN_t(b, 0, coord->bit_size),
|
||||
nir_channel(b, coord, 1));
|
||||
} else {
|
||||
assert(coord->num_components >= 1);
|
||||
return nir_vec2(b, coord, nir_imm_intN_t(b, 0, coord->bit_size));
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* NIR indexes into array textures with unclamped floats (integer for txf). AGX
|
||||
* requires the index to be a clamped integer. Lower tex_src_coord into
|
||||
@@ -177,34 +158,6 @@ lower_regular_texture(nir_builder *b, nir_instr *instr, UNUSED void *data)
|
||||
nir_def *coord = nir_steal_tex_src(tex, nir_tex_src_coord);
|
||||
nir_def *ms_idx = nir_steal_tex_src(tex, nir_tex_src_ms_index);
|
||||
|
||||
/* It's unclear if mipmapped 1D textures work in the hardware. For now, we
|
||||
* always lower to 2D.
|
||||
*/
|
||||
if (tex->sampler_dim == GLSL_SAMPLER_DIM_1D) {
|
||||
coord = coords_for_1d_texture(b, coord, tex->is_array);
|
||||
|
||||
/* Add a zero Y component to other sources */
|
||||
nir_tex_src_type other_srcs[] = {
|
||||
nir_tex_src_ddx,
|
||||
nir_tex_src_ddy,
|
||||
nir_tex_src_offset,
|
||||
};
|
||||
|
||||
for (unsigned i = 0; i < ARRAY_SIZE(other_srcs); ++i) {
|
||||
nir_def *src = nir_steal_tex_src(tex, other_srcs[i]);
|
||||
|
||||
if (!src)
|
||||
continue;
|
||||
|
||||
assert(src->num_components == 1);
|
||||
src = nir_vec2(b, src, nir_imm_intN_t(b, 0, src->bit_size));
|
||||
nir_tex_instr_add_src(tex, other_srcs[i], src);
|
||||
}
|
||||
|
||||
tex->sampler_dim = GLSL_SAMPLER_DIM_2D;
|
||||
tex->coord_components++;
|
||||
}
|
||||
|
||||
/* The layer is always the last component of the NIR coordinate, split it off
|
||||
* because we'll need to swizzle.
|
||||
*/
|
||||
@@ -465,9 +418,18 @@ lower_1d_image(nir_builder *b, nir_intrinsic_instr *intr)
|
||||
{
|
||||
nir_def *coord = intr->src[1].ssa;
|
||||
bool is_array = nir_intrinsic_image_array(intr);
|
||||
nir_def *coord2d = coords_for_1d_texture(b, coord, is_array);
|
||||
nir_def *zero = nir_imm_intN_t(b, 0, coord->bit_size);
|
||||
|
||||
nir_src_rewrite(&intr->src[1], nir_pad_vector(b, coord2d, 4));
|
||||
if (is_array) {
|
||||
assert(coord->num_components >= 2);
|
||||
coord =
|
||||
nir_vec3(b, nir_channel(b, coord, 0), zero, nir_channel(b, coord, 1));
|
||||
} else {
|
||||
assert(coord->num_components >= 1);
|
||||
coord = nir_vec2(b, coord, zero);
|
||||
}
|
||||
|
||||
nir_src_rewrite(&intr->src[1], nir_pad_vector(b, coord, 4));
|
||||
nir_intrinsic_set_image_dim(intr, GLSL_SAMPLER_DIM_2D);
|
||||
}
|
||||
|
||||
@@ -560,6 +522,9 @@ agx_nir_lower_texture_early(nir_shader *s, bool support_lod_bias)
|
||||
.lower_tg4_offsets = true,
|
||||
.lower_index_to_offset = true,
|
||||
|
||||
/* Unclear if/how mipmapped 1D textures work in the hardware. */
|
||||
.lower_1d = true,
|
||||
|
||||
/* XXX: Metal seems to handle just like 3D txd, so why doesn't it work?
|
||||
* TODO: Stop using this lowering
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user