From 204af7e09fb93b7c808871d9d5616064d4e2993c Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Sat, 21 Mar 2026 00:34:00 -0700 Subject: [PATCH] intel/nir: Replace tg4 with txl/txb/tex when splitting texture residency textureGather() returns the four taps that would have been filtered together to produce the value that ordinary texturing operations would return. As such, it should access the same data, so we can use either interchangeably when we're only checking for residency and not returning the actual data. This allows us to mask out some unneeded registers. Reviewed-by: Lionel Landwerlin Part-of: --- src/intel/compiler/intel_nir_lower_sparse.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/intel/compiler/intel_nir_lower_sparse.c b/src/intel/compiler/intel_nir_lower_sparse.c index e4c6ecd4dd4..ba5e56cb1f6 100644 --- a/src/intel/compiler/intel_nir_lower_sparse.c +++ b/src/intel/compiler/intel_nir_lower_sparse.c @@ -130,6 +130,22 @@ split_tex_residency(nir_builder *b, nir_tex_instr *tex, int compare_idx) tex->def.num_components, tex->def.bit_size); nir_builder_instr_insert(b, &sparse_tex->instr); + /* txl/txb/tex and tg4 both access the same pixels for residency checking + * purposes, but using the former for residency-only queries lets us mask + * out unwanted color components, using fewer registers. + */ + if (sparse_tex->op == nir_texop_tg4) { + if (nir_tex_instr_src_index(sparse_tex, nir_tex_src_bias) >= 0) + sparse_tex->op = nir_texop_txb; + else if (sparse_tex->is_gather_implicit_lod) + sparse_tex->op = nir_texop_tex; + else + sparse_tex->op = nir_texop_txl; + + sparse_tex->component = 0; + sparse_tex->is_gather_implicit_lod = false; + } + /* Drop the compare source on the cloned instruction */ if (compare_idx != -1) nir_tex_instr_remove_src(sparse_tex, compare_idx);