spirv: Call repair SSA for OpTerminateInvocation
authorJason Ekstrand <jason.ekstrand@intel.com>
Mon, 23 Nov 2020 16:07:17 +0000 (10:07 -0600)
committerMarge Bot <eric+marge@anholt.net>
Tue, 24 Nov 2020 15:47:06 +0000 (15:47 +0000)
Fixes: 886d2d1a9abcb "spirv: Handle SpvOpTerminateInvocation"

Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/7734>

src/compiler/spirv/vtn_cfg.c
src/compiler/spirv/vtn_private.h

index 4162275..4d68f8f 100644 (file)
@@ -687,11 +687,12 @@ vtn_process_block(struct vtn_builder *b,
       return NULL;
 
    case SpvOpKill:
-      b->has_kill = true;
+      b->has_early_terminate = true;
       block->branch_type = vtn_branch_type_discard;
       return NULL;
 
    case SpvOpTerminateInvocation:
+      b->has_early_terminate = true;
       block->branch_type = vtn_branch_type_terminate;
       return NULL;
 
@@ -1377,7 +1378,8 @@ vtn_function_emit(struct vtn_builder *b, struct vtn_function *func,
     * but instructions in the continue may use SSA defs in the loop body.
     * Therefore, we need to repair SSA to insert the needed phi nodes.
     */
-   if (b->func->impl->structured && (b->has_loop_continue || b->has_kill))
+   if (b->func->impl->structured &&
+       (b->has_loop_continue || b->has_early_terminate))
       nir_repair_ssa_impl(func->impl);
 
    func->emitted = true;
index 97fc67f..3d32db8 100644 (file)
@@ -702,7 +702,19 @@ struct vtn_builder {
    unsigned func_param_idx;
 
    bool has_loop_continue;
-   bool has_kill;
+
+   /** True if this shader has any early termination instructions like OpKill
+    *
+    * In the SPIR-V, the following instructions are block terminators:
+    *
+    *  - OpKill
+    *  - OpTerminateInvocation
+    *
+    * However, in NIR, they're represented by regular intrinsics with no
+    * control-flow semantics.  This means that the SSA form from the SPIR-V
+    * may not 100% match NIR and we have to fix it up at the end.
+    */
+   bool has_early_terminate;
 
    /* false by default, set to true by the ContractionOff execution mode */
    bool exact;