From a9d230077f08955f97fddac84b4014d2131c8917 Mon Sep 17 00:00:00 2001 From: Caio Marcelo de Oliveira Filho Date: Tue, 7 Jul 2020 17:38:03 -0700 Subject: [PATCH] nir: Two shared memory *blocks* may alias each other Reviewed-by: Jason Ekstrand Reviewed-by: Bas Nieuwenhuizen Part-of: --- src/compiler/nir/nir_deref.c | 12 ++++++++++++ src/compiler/nir/nir_remove_dead_variables.c | 12 ++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/compiler/nir/nir_deref.c b/src/compiler/nir/nir_deref.c index 4735175..f406c87 100644 --- a/src/compiler/nir/nir_deref.c +++ b/src/compiler/nir/nir_deref.c @@ -492,6 +492,18 @@ nir_compare_deref_paths(nir_deref_path *a_path, deref_path_contains_coherent_decoration(b_path)) return nir_derefs_may_alias_bit; + /* Per SPV_KHR_workgroup_memory_explicit_layout and GL_EXT_shared_memory_block, + * shared blocks alias each other. + */ + if (a_path->path[0]->modes & nir_var_mem_shared && + b_path->path[0]->modes & nir_var_mem_shared && + (glsl_type_is_interface(a_path->path[0]->var->type) || + glsl_type_is_interface(b_path->path[0]->var->type))) { + assert(glsl_type_is_interface(a_path->path[0]->var->type) && + glsl_type_is_interface(b_path->path[0]->var->type)); + return nir_derefs_may_alias_bit; + } + /* If we can chase the deref all the way back to the variable and * they're not the same variable and at least one is not declared * coherent, we know they can't possibly alias. diff --git a/src/compiler/nir/nir_remove_dead_variables.c b/src/compiler/nir/nir_remove_dead_variables.c index 19e56d0..0182c98 100644 --- a/src/compiler/nir/nir_remove_dead_variables.c +++ b/src/compiler/nir/nir_remove_dead_variables.c @@ -71,8 +71,16 @@ add_var_use_deref(nir_deref_instr *deref, struct set *live) * make them live. Only keep them if they are used by some intrinsic. */ if ((deref->var->data.mode & (nir_var_function_temp | - nir_var_shader_temp | - nir_var_mem_shared)) && + nir_var_shader_temp)) && + !deref_used_for_not_store(deref)) + return; + + /* + * Shared memory blocks (interface type) alias each other, so be + * conservative in that case. + */ + if ((deref->var->data.mode & nir_var_mem_shared) && + !glsl_type_is_interface(deref->var->type) && !deref_used_for_not_store(deref)) return; -- 2.7.4