nir/opt_ray_queries: Cleanup and return if functions is not singular

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/37283>
This commit is contained in:
Konstantin Seurer 2025-09-10 22:15:47 +02:00 committed by Marge Bot
parent 39a5e80a7a
commit 2a4b1ea69b

View file

@ -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) {