From e2b7a736a47960e4270cd93797b054e2ca9c7bbb Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Wed, 7 May 2025 16:49:11 -0400 Subject: [PATCH] nak/nir/lower_tex: Use nir_tex_instr_add_src() This is slightly less efficient but way safer than trying to mangle the sources array that's already in the tex instruction. Part-of: --- src/nouveau/compiler/nak_nir_lower_tex.c | 29 +++++++++--------------- 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/src/nouveau/compiler/nak_nir_lower_tex.c b/src/nouveau/compiler/nak_nir_lower_tex.c index 3e1d60a1820..4a1ba988450 100644 --- a/src/nouveau/compiler/nak_nir_lower_tex.c +++ b/src/nouveau/compiler/nak_nir_lower_tex.c @@ -70,7 +70,10 @@ lower_tex(nir_builder *b, nir_tex_instr *tex, const struct nak_compiler *nak) default: unreachable("Unsupported texture source"); } + /* Remove sources as we walk them. We'll add them back later */ + nir_instr_clear_src(&tex->instr, &tex->src[i].src); } + tex->num_srcs = 0; /* Combine sampler and texture into one if needed */ if (samp_h != NULL && samp_h != tex_h) { @@ -176,7 +179,6 @@ lower_tex(nir_builder *b, nir_tex_instr *tex, const struct nak_compiler *nak) a[a##_comps++] = val; \ } while(0) - unsigned num_backend_srcs = 0; if (nak->sm >= 50) { nir_def *src0[4] = { NULL, }; nir_def *src1[4] = { NULL, }; @@ -232,16 +234,14 @@ lower_tex(nir_builder *b, nir_tex_instr *tex, const struct nak_compiler *nak) PUSH(src1, z_cmpr); } - num_backend_srcs = 1; - tex->src[0].src_type = nir_tex_src_backend1; - nir_src_rewrite(&tex->src[0].src, nir_vec(b, src0, src0_comps)); + nir_tex_instr_add_src(tex, nir_tex_src_backend1, + nir_vec(b, src0, src0_comps)); if (src1_comps > 0) { while (src1_comps < 4) PUSH(src1, nir_undef(b, 1, 32)); - num_backend_srcs = 2; - tex->src[1].src_type = nir_tex_src_backend2; - nir_src_rewrite(&tex->src[1].src, nir_vec(b, src1, src1_comps)); + nir_tex_instr_add_src(tex, nir_tex_src_backend2, + nir_vec(b, src1, src1_comps)); } } else if (nak->sm >= 30) { nir_def *src[8] = { NULL, }; @@ -292,23 +292,16 @@ lower_tex(nir_builder *b, nir_tex_instr *tex, const struct nak_compiler *nak) while (src_comps % 4) PUSH(src, nir_undef(b, 1, 32)); - num_backend_srcs = 1; - tex->src[0].src_type = nir_tex_src_backend1; - nir_src_rewrite(&tex->src[0].src, nir_vec(b, src, 4)); - + nir_tex_instr_add_src(tex, nir_tex_src_backend1, + nir_vec(b, src, 4)); if (src_comps > 4) { - num_backend_srcs = 2; - tex->src[1].src_type = nir_tex_src_backend2; - nir_src_rewrite(&tex->src[1].src, nir_vec(b, src + 4, 4)); + nir_tex_instr_add_src(tex, nir_tex_src_backend2, + nir_vec(b, src + 4, 4)); } } else { unreachable("Unsupported shader model"); } - /* Remove any extras */ - while (tex->num_srcs > num_backend_srcs) - nir_tex_instr_remove_src(tex, tex->num_srcs - 1); - tex->sampler_dim = remap_sampler_dim(tex->sampler_dim); struct nak_nir_tex_flags flags = {