zink: flush gfx/compute batches when the other pipeline needs resource sync
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Wed, 12 Aug 2020 21:00:09 +0000 (17:00 -0400)
committerMarge Bot <eric+marge@anholt.net>
Wed, 10 Feb 2021 00:19:39 +0000 (00:19 +0000)
if compute or gfx use a resource which is already in use by the other pipeline,
we need to ensure tha we flush that pipeline now in order to have commands execute
in the expected order

Reviewed-by: Bas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8781>

src/gallium/drivers/zink/zink_draw.c

index d50aabb..9e97007 100644 (file)
@@ -456,13 +456,15 @@ update_descriptors(struct zink_context *ctx, struct zink_screen *screen, bool is
       }
    }
 
+   unsigned check_flush_id = is_compute ? 0 : ZINK_COMPUTE_BATCH_ID;
+   bool need_flush = false;
    if (num_wds > 0) {
       for (int i = 0; i < num_wds; ++i) {
          wds[i].dstSet = desc_set;
          if (read_desc_resources[i])
-            zink_batch_reference_resource_rw(batch, read_desc_resources[i], false);
+            need_flush |= zink_batch_reference_resource_rw(batch, read_desc_resources[i], false) == check_flush_id;
          else if (write_desc_resources[i])
-            zink_batch_reference_resource_rw(batch, write_desc_resources[i], true);
+            need_flush |= zink_batch_reference_resource_rw(batch, write_desc_resources[i], true) == check_flush_id;
       }
       vkUpdateDescriptorSets(screen->dev, num_wds, wds, 0, NULL);
       for (int i = 0; i < num_surface_refs; i++) {
@@ -477,6 +479,17 @@ update_descriptors(struct zink_context *ctx, struct zink_screen *screen, bool is
    else
       vkCmdBindDescriptorSets(batch->cmdbuf, VK_PIPELINE_BIND_POINT_GRAPHICS,
                               ctx->curr_program->layout, 0, 1, &desc_set, 0, NULL);
+   if (!need_flush)
+      return;
+
+   if (is_compute)
+      /* flush gfx batch */
+      ctx->base.flush(&ctx->base, NULL, PIPE_FLUSH_HINT_FINISH);
+   else {
+      /* flush compute batch */
+      zink_end_batch(ctx, &ctx->compute_batch);
+      zink_start_batch(ctx, &ctx->compute_batch);
+   }
 }
 
 static bool