From 2527900bbc273b3109b3c037d7eb550638d3f885 Mon Sep 17 00:00:00 2001 From: Georg Lehmann Date: Thu, 26 Mar 2026 15:44:59 +0100 Subject: [PATCH] nir/lower_non_uniform_access: fix fusing loops for same index but different array variable struct nu_handle is hashed and deduplicated using struct nu_handle_key, which ignored parent_deref. That means all instructions will use the first parent_deref when rewriting the sources. Avoid this by not including the parent deref in the struct, and instead querying it when needed. Fixes: 4d09cd7fa59 ("nir/lower_non_uniform_access: Group accesses using the same resource") Closes: https://gitlab.freedesktop.org/mesa/mesa/-/work_items/15173 Reviewed-by: Konstantin Seurer (cherry picked from commit e7077e8f5c7943d0f70a94dd268ea0ca9cf33ec3) Part-of: --- .pick_status.json | 2 +- src/compiler/nir/nir_lower_non_uniform_access.c | 15 ++++++++------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/.pick_status.json b/.pick_status.json index 26a4c5499d6..7c9d3b340fa 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -1274,7 +1274,7 @@ "description": "nir/lower_non_uniform_access: fix fusing loops for same index but different array variable", "nominated": true, "nomination_type": 2, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "4d09cd7fa590cbd52d8772d5a251fab8b0874ab7", "notes": null diff --git a/src/compiler/nir/nir_lower_non_uniform_access.c b/src/compiler/nir/nir_lower_non_uniform_access.c index bdaffcb5508..e7afd3216f1 100644 --- a/src/compiler/nir/nir_lower_non_uniform_access.c +++ b/src/compiler/nir/nir_lower_non_uniform_access.c @@ -29,7 +29,6 @@ struct nu_handle { nir_def *handle; - nir_deref_instr *parent_deref; nir_def *first; }; @@ -81,7 +80,6 @@ nu_handle_init(struct nu_handle *h, nir_src *src) return false; h->handle = deref->arr.index.ssa; - h->parent_deref = parent; return true; } else { @@ -89,7 +87,6 @@ nu_handle_init(struct nu_handle *h, nir_src *src) return false; h->handle = src->ssa; - h->parent_deref = NULL; return true; } @@ -123,11 +120,15 @@ nu_handle_compare(const nir_lower_non_uniform_access_options *options, static void nu_handle_rewrite(nir_builder *b, struct nu_handle *h, nir_src *src) { - if (h->parent_deref) { + if (nir_src_is_deref(*src)) { + nir_deref_instr *deref = nir_src_as_deref(*src); + assert(deref->deref_type == nir_deref_type_array); + nir_deref_instr *parent = nir_deref_instr_parent(deref); + /* Replicate the deref. */ - nir_deref_instr *deref = - nir_build_deref_array(b, h->parent_deref, h->first); - nir_src_rewrite(src, &deref->def); + nir_deref_instr *new_deref = + nir_build_deref_array(b, parent, h->first); + nir_src_rewrite(src, &new_deref->def); } else { nir_src_rewrite(src, h->first); }