aco: Assert that workgroup barriers are not used inappropriately.

Example:
It is possible for some NGG GS waves to have 0 ES and/or GS invocations,
and in that case having an s_barrier inside divergent control flow can
very possibly hang the GPU.

Signed-off-by: Timur Kristóf <timur.kristof@gmail.com>
Reviewed-by: Rhys Perry <pendingchaos02@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7232>
diff --git a/src/amd/compiler/aco_instruction_selection.cpp b/src/amd/compiler/aco_instruction_selection.cpp
index 3b1d8ab..6717c6e 100644
--- a/src/amd/compiler/aco_instruction_selection.cpp
+++ b/src/amd/compiler/aco_instruction_selection.cpp
@@ -6559,6 +6559,11 @@
 
    assert(!(nir_semantics & (NIR_MEMORY_MAKE_AVAILABLE | NIR_MEMORY_MAKE_VISIBLE)));
 
+   /* Workgroup barriers can hang merged shaders that can potentially have 0 threads in either half. */
+   assert(exec_scope != scope_workgroup ||
+          ctx->shader->info.stage == MESA_SHADER_COMPUTE ||
+          ctx->shader->info.stage == MESA_SHADER_TESS_CTRL);
+
    bld.barrier(aco_opcode::p_barrier,
                memory_sync_info((storage_class)storage, (memory_semantics)semantics, mem_scope),
                exec_scope);