From 2a4b1ea69b8587188da599d5f0991c19a17e192e Mon Sep 17 00:00:00 2001 From: Konstantin Seurer Date: Wed, 10 Sep 2025 22:15:47 +0200 Subject: [PATCH] nir/opt_ray_queries: Cleanup and return if functions is not singular Reviewed-by: Lionel Landwerlin Part-of: --- src/compiler/nir/nir_opt_ray_queries.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/compiler/nir/nir_opt_ray_queries.c b/src/compiler/nir/nir_opt_ray_queries.c index 6d98cc73338..aeeb05b29a7 100644 --- a/src/compiler/nir/nir_opt_ray_queries.c +++ b/src/compiler/nir/nir_opt_ray_queries.c @@ -213,11 +213,12 @@ get_parent_loop(nir_cf_node *node) bool nir_opt_ray_query_ranges(nir_shader *shader) { - assert(exec_list_length(&shader->functions) == 1); + if (!exec_list_is_singular(&shader->functions)) { + nir_shader_preserve_all_metadata(shader); + return false; + } - struct nir_function *func = - (struct nir_function *)exec_list_get_head_const(&shader->functions); - assert(func->impl); + nir_function_impl *impl = nir_shader_get_entrypoint(shader); uint32_t ray_query_count = 0; nir_foreach_variable_in_shader(var, shader) { @@ -225,19 +226,19 @@ nir_opt_ray_query_ranges(nir_shader *shader) continue; ray_query_count++; } - nir_foreach_function_temp_variable(var, func->impl) { + nir_foreach_function_temp_variable(var, impl) { if (!var->data.ray_query || glsl_type_is_array(var->type)) continue; ray_query_count++; } if (ray_query_count <= 1) { - return nir_no_progress(func->impl); + return nir_no_progress(impl); } void *mem_ctx = ralloc_context(NULL); - nir_metadata_require(func->impl, nir_metadata_instr_index | nir_metadata_dominance); + nir_metadata_require(impl, nir_metadata_instr_index | nir_metadata_dominance); nir_variable **ray_queries = ralloc_array(mem_ctx, nir_variable *, ray_query_count); ray_query_count = 0; @@ -250,7 +251,7 @@ nir_opt_ray_query_ranges(nir_shader *shader) ray_query_count++; } - nir_foreach_function_temp_variable(var, func->impl) { + nir_foreach_function_temp_variable(var, impl) { if (!var->data.ray_query || glsl_type_is_array(var->type)) continue; @@ -267,7 +268,7 @@ nir_opt_ray_query_ranges(nir_shader *shader) struct hash_table *range_indices = _mesa_pointer_hash_table_create(mem_ctx); uint32_t target_index = 0; - nir_foreach_block(block, func->impl) { + nir_foreach_block(block, impl) { nir_cf_node *parent_loop = get_parent_loop(&block->cf_node); nir_foreach_instr(instr, block) { @@ -404,7 +405,7 @@ nir_opt_ray_query_ranges(nir_shader *shader) } } - nir_no_progress(func->impl); + nir_no_progress(impl); /* Remove dead ray queries. */ if (progress) {