radeonsi: fixup sampler desc for tg4 in nir

For ACO which won't do this for us. But we still can't
remove the same code in llvm because non-uniform sampler
is keept as index in nir.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Signed-off-by: Qiang Yu <yuq825@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22573>
This commit is contained in:
Qiang Yu
2023-04-24 16:42:11 +08:00
committed by Marge Bot
parent 521cbcb588
commit 288adae512
@@ -496,6 +496,23 @@ static nir_ssa_def *load_bindless_sampler_desc(nir_builder *b, nir_ssa_def *inde
return load_sampler_desc(b, list, index, desc_type);
}
static nir_ssa_def *fixup_sampler_desc(nir_builder *b,
nir_tex_instr *tex,
nir_ssa_def *sampler,
struct lower_resource_state *s)
{
const struct si_shader_selector *sel = s->shader->selector;
if (tex->op != nir_texop_tg4 || sel->screen->info.conformant_trunc_coord)
return sampler;
/* Set TRUNC_COORD=0 for textureGather(). */
nir_ssa_def *dword0 = nir_channel(b, sampler, 0);
dword0 = nir_iand_imm(b, dword0, C_008F30_TRUNC_COORD);
sampler = nir_vector_insert_imm(b, sampler, dword0, 0);
return sampler;
}
static bool lower_resource_tex(nir_builder *b, nir_tex_instr *tex,
struct lower_resource_state *s)
{
@@ -561,6 +578,9 @@ static bool lower_resource_tex(nir_builder *b, nir_tex_instr *tex,
else if (sampler_handle)
sampler = load_bindless_sampler_desc(b, sampler_handle, AC_DESC_SAMPLER, s);
if (sampler && sampler->num_components > 1)
sampler = fixup_sampler_desc(b, tex, sampler, s);
for (unsigned i = 0; i < tex->num_srcs; i++) {
switch (tex->src[i].src_type) {
case nir_tex_src_texture_deref: