From 605ef577b3f16aa9d93b8407fc28fcaf1651a314 Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Sat, 21 Mar 2026 00:37:04 -0700 Subject: [PATCH] intel/nir: Generalize lower_tex_compare to split_tex_residency This splits a single texture-with-residency operation into two halves, one which returns texture data, and another which queries residency. We're currently using this only for a shadow sampling workaround, but the technique is more broadly applicable, if we ever wanted. Reviewed-by: Lionel Landwerlin Part-of: --- src/intel/compiler/intel_nir_lower_sparse.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/intel/compiler/intel_nir_lower_sparse.c b/src/intel/compiler/intel_nir_lower_sparse.c index 9e2a5d79717..e4c6ecd4dd4 100644 --- a/src/intel/compiler/intel_nir_lower_sparse.c +++ b/src/intel/compiler/intel_nir_lower_sparse.c @@ -120,7 +120,7 @@ lower_sparse_image_load(nir_builder *b, nir_intrinsic_instr *intrin) } static void -lower_tex_compare(nir_builder *b, nir_tex_instr *tex, int compare_idx) +split_tex_residency(nir_builder *b, nir_tex_instr *tex, int compare_idx) { b->cursor = nir_after_instr(&tex->instr); @@ -131,7 +131,8 @@ lower_tex_compare(nir_builder *b, nir_tex_instr *tex, int compare_idx) nir_builder_instr_insert(b, &sparse_tex->instr); /* Drop the compare source on the cloned instruction */ - nir_tex_instr_remove_src(sparse_tex, compare_idx); + if (compare_idx != -1) + nir_tex_instr_remove_src(sparse_tex, compare_idx); /* Drop the residency query on the original tex instruction */ tex->is_sparse = false; @@ -177,7 +178,7 @@ lower_sparse_intrinsics(nir_builder *b, nir_instr *instr, void *cb_data) nir_tex_instr *tex = nir_instr_as_tex(instr); int comp_idx = nir_tex_instr_src_index(tex, nir_tex_src_comparator); if (comp_idx != -1 && tex->is_sparse) { - lower_tex_compare(b, tex, comp_idx); + split_tex_residency(b, tex, comp_idx); return true; } return false;