From 35d5e903acf5eb8d5240c6aa2d62a6eca3b0b26f Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Wed, 8 Oct 2025 10:02:07 +1100 Subject: [PATCH] util/range_remap: dont overwrite entry if ptr is NULL MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the ptr value is NULL and we match an existing entry during an insert call we now just return the existing value. This allows us to drop an extra lookup, this will become important as the following patches change `util_range_remap()` lookups to use a sorted array that is not created until after we have added all entries to our linked list. Reviewed-by: Marek Olšák Part-of: --- src/compiler/glsl/gl_nir_linker.c | 29 +++++++++++++---------------- src/util/u_range_remap.c | 10 +++++++--- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/compiler/glsl/gl_nir_linker.c b/src/compiler/glsl/gl_nir_linker.c index 4689f275344..ed627cc039e 100644 --- a/src/compiler/glsl/gl_nir_linker.c +++ b/src/compiler/glsl/gl_nir_linker.c @@ -2975,23 +2975,20 @@ reserve_explicit_locations(struct gl_shader_program *prog, unsigned return_value = slots; struct range_entry *re = - util_range_remap(location, prog->UniformRemapTable); + util_range_insert_remap(location, max_loc, prog->UniformRemapTable, + NULL); if (!re) { - re = util_range_insert_remap(location, max_loc, - prog->UniformRemapTable, NULL); - if (!re) { - /* ARB_explicit_uniform_location specification states: - * - * "No two default-block uniform variables in the program can have - * the same location, even if they are unused, otherwise a compiler - * or linker error will be generated." - */ - linker_error(prog, - "location qualifier for uniform %s overlaps " - "previously used location\n", - *var_name); - return -1; - } + /* ARB_explicit_uniform_location specification states: + * + * "No two default-block uniform variables in the program can have + * the same location, even if they are unused, otherwise a compiler + * or linker error will be generated." + */ + linker_error(prog, + "location qualifier for uniform %s overlaps " + "previously used location\n", + *var_name); + return -1; } /* Check if location is already used. */ diff --git a/src/util/u_range_remap.c b/src/util/u_range_remap.c index b3a1cd0ce61..d56367497a0 100644 --- a/src/util/u_range_remap.c +++ b/src/util/u_range_remap.c @@ -83,9 +83,10 @@ get_range_entry(unsigned n, const struct list_head *r_list) return NULL; } -/* Insert a new range entry or update an existing entries pointer value if - * start and end match exactly. If the range overlaps an existing entry we - * return NULL. +/* Insert a new range entry or if ptr is non-null update an existing entries + * pointer value if start and end match exactly. If the range overlaps an + * existing entry we return NULL or if start and end match an entry exactly + * but ptr is null we return the existing entry. */ struct range_entry * util_range_insert_remap(unsigned start, unsigned end, @@ -148,6 +149,9 @@ util_range_insert_remap(unsigned start, unsigned end, mid++; } } else if (mid_entry->start == start && mid_entry->end == end) { + if (!ptr) + return mid_entry; + entry = mid_entry; goto insert_end; } else {