ac/nir/ngg: Move primitive ID workgroup barrier to proper place.
authorTimur Kristóf <timur.kristof@gmail.com>
Mon, 18 Jul 2022 13:42:57 +0000 (15:42 +0200)
committerMarge Bot <emma+marge@anholt.net>
Thu, 21 Jul 2022 21:53:29 +0000 (21:53 +0000)
Previously, it was in a divergent branch, therefore
it could hang the GPU when a workgroup had a primitive-only wave.

Signed-off-by: Timur Kristóf <timur.kristof@gmail.com>
Reviewed-by: Qiang Yu <yuq825@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17581>

src/amd/common/ac_nir_lower_ngg.c

index b7e7ec8..fdb3827 100644 (file)
@@ -480,10 +480,6 @@ emit_store_ngg_nogs_es_primitive_id(nir_builder *b)
    nir_ssa_def *prim_id = NULL;
 
    if (b->shader->info.stage == MESA_SHADER_VERTEX) {
-      /* Workgroup barrier - wait for GS threads to store primitive ID in LDS. */
-      nir_scoped_barrier(b, .execution_scope = NIR_SCOPE_WORKGROUP, .memory_scope = NIR_SCOPE_WORKGROUP,
-                            .memory_semantics = NIR_MEMORY_ACQ_REL, .memory_modes = nir_var_mem_shared);
-
       /* LDS address where the primitive ID is stored */
       nir_ssa_def *thread_id_in_threadgroup = nir_load_local_invocation_index(b);
       nir_ssa_def *addr =  pervertex_lds_addr(b, thread_id_in_threadgroup, 4u);
@@ -1466,6 +1462,10 @@ ac_nir_lower_ngg_nogs(nir_shader *shader,
       }
 
       emit_ngg_nogs_prim_id_store_shared(b, &state);
+
+      /* Wait for GS threads to store primitive ID in LDS. */
+      nir_scoped_barrier(b, .execution_scope = NIR_SCOPE_WORKGROUP, .memory_scope = NIR_SCOPE_WORKGROUP,
+                            .memory_semantics = NIR_MEMORY_ACQ_REL, .memory_modes = nir_var_mem_shared);
    }
 
    nir_intrinsic_instr *export_vertex_instr;