From 36e779e4a9ab7266025e8720f51e965fcc454d94 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Wed, 7 Jun 2023 17:55:10 -0400 Subject: [PATCH] nir/builder: Add steal_tex_src helper MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit I have this in the AGX compiler but I want to use it in more places. Signed-off-by: Alyssa Rosenzweig Reviewed-by: Timur Kristóf Reviewed-by: Rhys Perry Part-of: --- src/compiler/nir/nir_builder.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/compiler/nir/nir_builder.h b/src/compiler/nir/nir_builder.h index db09e88..9c0d64d 100644 --- a/src/compiler/nir/nir_builder.h +++ b/src/compiler/nir/nir_builder.h @@ -1650,6 +1650,24 @@ nir_tex_src_for_ssa(nir_tex_src_type src_type, nir_ssa_def *def) return src; } +/* + * Find a texture source, remove it, and return its nir_ssa_def. If the texture + * source does not exist, return NULL. This is useful for texture lowering pass + * that consume their input sources and produce a new lowered source. + */ +static inline nir_ssa_def * +nir_steal_tex_src(nir_tex_instr *tex, nir_tex_src_type type_) +{ + int idx = nir_tex_instr_src_index(tex, type_); + if (idx < 0) + return NULL; + + assert(tex->src[idx].src.is_ssa); + nir_ssa_def *ssa = tex->src[idx].src.ssa; + nir_tex_instr_remove_src(tex, idx); + return ssa; +} + static inline nir_ssa_def * nir_tex_deref(nir_builder *b, nir_deref_instr *t, nir_deref_instr *s, nir_ssa_def *coord) -- 2.7.4