From bb4c5edda1986e226ee37b9ba3fc7bbc4fc4f2c9 Mon Sep 17 00:00:00 2001 From: Faith Ekstrand Date: Tue, 17 Jun 2025 14:03:23 -0400 Subject: [PATCH] nir: Add more tex_src helpers This adds a variant of nir_steal_tex_src() which is for derefs as well as versions that just return the source without removing it. Reviewed-by: Christian Gmeiner Part-of: --- src/compiler/nir/nir.h | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/compiler/nir/nir.h b/src/compiler/nir/nir.h index ab0cfae43a1..081eb78f6d7 100644 --- a/src/compiler/nir/nir.h +++ b/src/compiler/nir/nir.h @@ -2563,6 +2563,26 @@ void nir_tex_instr_add_src(nir_tex_instr *tex, /** Removes a source from a texture instruction */ void nir_tex_instr_remove_src(nir_tex_instr *tex, unsigned src_idx); +static inline nir_def * +nir_get_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; + + return tex->src[idx].src.ssa; +} + +static inline nir_deref_instr * +nir_get_tex_deref(nir_tex_instr *tex, nir_tex_src_type type_) +{ + int idx = nir_tex_instr_src_index(tex, type_); + if (idx < 0) + return NULL; + + return nir_src_as_deref(tex->src[idx].src); +} + /* * Find a texture source, remove it, and return its nir_def. If the texture * source does not exist, return NULL. This is useful for texture lowering pass @@ -2580,6 +2600,18 @@ nir_steal_tex_src(nir_tex_instr *tex, nir_tex_src_type type_) return ssa; } +static inline nir_deref_instr * +nir_steal_tex_deref(nir_tex_instr *tex, nir_tex_src_type type_) +{ + int idx = nir_tex_instr_src_index(tex, type_); + if (idx < 0) + return NULL; + + nir_deref_instr *deref = nir_src_as_deref(tex->src[idx].src); + nir_tex_instr_remove_src(tex, idx); + return deref; +} + bool nir_tex_instr_has_explicit_tg4_offsets(nir_tex_instr *tex); typedef struct nir_load_const_instr {