zink: add function for checking whether a batch is done
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Mon, 22 Mar 2021 14:33:34 +0000 (10:33 -0400)
committerMarge Bot <eric+marge@anholt.net>
Tue, 30 Mar 2021 15:12:58 +0000 (15:12 +0000)
this is like wait_on_batch, but without the waiting

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9885>

src/gallium/drivers/zink/zink_context.c
src/gallium/drivers/zink/zink_context.h

index a353d52..bd359fc 100644 (file)
@@ -1960,6 +1960,36 @@ zink_wait_on_batch(struct zink_context *ctx, uint32_t batch_id)
    simple_mtx_unlock(&ctx->batch_mtx);
 }
 
+bool
+zink_check_batch_completion(struct zink_context *ctx, uint32_t batch_id)
+{
+   assert(batch_id);
+   struct zink_batch_state *bs = ctx->batch.state;
+   assert(bs);
+   if (bs->fence.batch_id == batch_id)
+      /* not submitted yet */
+      return false;
+
+   struct zink_fence *fence;
+
+   simple_mtx_lock(&ctx->batch_mtx);
+
+   if (ctx->last_fence && batch_id == zink_batch_state(ctx->last_fence)->fence.batch_id)
+      fence = ctx->last_fence;
+   else {
+      struct hash_entry *he = _mesa_hash_table_search_pre_hashed(&ctx->batch_states, batch_id, (void*)(uintptr_t)batch_id);
+      /* if we can't find it, it must have finished already */
+      if (!he) {
+         simple_mtx_unlock(&ctx->batch_mtx);
+         return true;
+      }
+      fence = he->data;
+   }
+   simple_mtx_unlock(&ctx->batch_mtx);
+   assert(fence);
+   return ctx->base.screen->fence_finish(ctx->base.screen, &ctx->base, (struct pipe_fence_handle*)fence, 0);
+}
+
 static void
 zink_texture_barrier(struct pipe_context *pctx, unsigned flags)
 {
index 74ffad0..829fd42 100644 (file)
@@ -248,6 +248,9 @@ zink_fence_wait(struct pipe_context *ctx);
 void
 zink_wait_on_batch(struct zink_context *ctx, uint32_t batch_id);
 
+bool
+zink_check_batch_completion(struct zink_context *ctx, uint32_t batch_id);
+
 void
 zink_flush_queue(struct zink_context *ctx);