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 <cgmeiner@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/35623>
This commit is contained in:
Faith Ekstrand
2025-06-17 14:03:23 -04:00
committed by Marge Bot
parent 2b40fa09f2
commit bb4c5edda1
+32
View File
@@ -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 {