spirv: Fix order of barriers in SpvOpControlBarrier
authorDaniel Schürmann <daniel@schuermann.dev>
Thu, 18 Jul 2019 18:48:14 +0000 (20:48 +0200)
committerCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Fri, 19 Jul 2019 17:37:37 +0000 (10:37 -0700)
Semantically, the memory barrier has to come first to wait
for the completion of pending memory requests.
Afterwards, the workgroups can be synchronized.

Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
src/compiler/spirv/spirv_to_nir.c

index ea4aebb767c8cc1481ae91b9318ce2164c5e8dc2..76ccbfad514d6adba2ff677120f3b5a24400c8c0 100644 (file)
@@ -3360,13 +3360,13 @@ vtn_handle_barrier(struct vtn_builder *b, SpvOp opcode,
    }
 
    case SpvOpControlBarrier: {
-      SpvScope execution_scope = vtn_constant_uint(b, w[1]);
-      if (execution_scope == SpvScopeWorkgroup)
-         vtn_emit_barrier(b, nir_intrinsic_barrier);
-
       SpvScope memory_scope = vtn_constant_uint(b, w[2]);
       SpvMemorySemanticsMask memory_semantics = vtn_constant_uint(b, w[3]);
       vtn_emit_memory_barrier(b, memory_scope, memory_semantics);
+
+      SpvScope execution_scope = vtn_constant_uint(b, w[1]);
+      if (execution_scope == SpvScopeWorkgroup)
+         vtn_emit_barrier(b, nir_intrinsic_barrier);
       break;
    }