From cb558b2b88c28fe6b617c59d66cd28f2c3e17dfd Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Fri, 25 Jul 2025 13:19:32 +1000 Subject: [PATCH] glsl: add mark_array_elements_referenced() fast path MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a fast path for single dimension arrays. This is around 3x faster on large arrays. For example when testing a shader from issue 9953 compile time went from ~12 seconds down to ~4 seconds. Issue: https://gitlab.freedesktop.org/mesa/mesa/-/issues/9953 Acked-by: Marek Olšák Reviewed-by: Alyssa Rosenzweig Part-of: --- src/compiler/glsl/gl_nir_link_uniforms.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/compiler/glsl/gl_nir_link_uniforms.c b/src/compiler/glsl/gl_nir_link_uniforms.c index 127a6bfa51a..db51c0fe3e3 100644 --- a/src/compiler/glsl/gl_nir_link_uniforms.c +++ b/src/compiler/glsl/gl_nir_link_uniforms.c @@ -129,6 +129,24 @@ mark_array_elements_referenced(const struct array_deref_range *dr, if (count != array_depth) return; + /* Single dimension array fast path. This is the most common path as most + * arrays are only one dimension. This path is around 3x faster on large + * arrays than _mark_array_elements_referenced(). + */ + if (count == 1) { + if (dr[0].size == 0) + return; + + if (dr[0].index < dr[0].size) { + BITSET_SET(bits, dr[0].index); + } else { + /* Accessed by non-constant index so set everything as referenced */ + BITSET_SET_RANGE(bits, 0, dr[0].size - 1); + } + + return; + } + _mark_array_elements_referenced(dr, count, 1, 0, bits); }