zink: use res->queue to auto-handle queue transitions back to gfx queue
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Mon, 19 Sep 2022 19:23:44 +0000 (15:23 -0400)
committerMarge Bot <emma+marge@anholt.net>
Fri, 17 Mar 2023 07:25:04 +0000 (07:25 +0000)
much simpler

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21733>

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

index a363643..c181f22 100644 (file)
@@ -3744,10 +3744,10 @@ zink_resource_image_barrier(struct zink_context *ctx, struct zink_resource *res,
    if (res->obj->needs_zs_evaluate)
       imb.pNext = &res->obj->zs_evaluate;
    res->obj->needs_zs_evaluate = false;
-   if (res->dmabuf_acquire) {
-      imb.srcQueueFamilyIndex = VK_QUEUE_FAMILY_FOREIGN_EXT;
+   if (res->queue != zink_screen(ctx->base.screen)->gfx_queue && res->queue != VK_QUEUE_FAMILY_IGNORED) {
+      imb.srcQueueFamilyIndex = res->queue;
       imb.dstQueueFamilyIndex = zink_screen(ctx->base.screen)->gfx_queue;
-      res->dmabuf_acquire = false;
+      res->queue = VK_QUEUE_FAMILY_IGNORED;
    }
    bool marker = zink_cmd_debug_marker_begin(ctx, cmdbuf, "image_barrier(%s->%s)", vk_ImageLayout_to_str(res->layout), vk_ImageLayout_to_str(new_layout));
    VKCTX(CmdPipelineBarrier)(
@@ -3791,10 +3791,10 @@ zink_resource_image_barrier2(struct zink_context *ctx, struct zink_resource *res
    if (res->obj->needs_zs_evaluate)
       imb.pNext = &res->obj->zs_evaluate;
    res->obj->needs_zs_evaluate = false;
-   if (res->dmabuf_acquire) {
-      imb.srcQueueFamilyIndex = VK_QUEUE_FAMILY_FOREIGN_EXT;
+   if (res->queue != zink_screen(ctx->base.screen)->gfx_queue && res->queue != VK_QUEUE_FAMILY_IGNORED) {
+      imb.srcQueueFamilyIndex = res->queue;
       imb.dstQueueFamilyIndex = zink_screen(ctx->base.screen)->gfx_queue;
-      res->dmabuf_acquire = false;
+      res->queue = VK_QUEUE_FAMILY_IGNORED;
    }
    VkDependencyInfo dep = {
       VK_STRUCTURE_TYPE_DEPENDENCY_INFO,
@@ -4366,7 +4366,7 @@ zink_flush_resource(struct pipe_context *pctx,
       }
       ctx->batch.swapchain = res;
    } else if (res->dmabuf)
-      res->dmabuf_acquire = true;
+      res->queue = VK_QUEUE_FAMILY_FOREIGN_EXT;
 }
 
 static struct pipe_stream_output_target *
index e41ce7f..c379a67 100644 (file)
@@ -1232,8 +1232,10 @@ resource_create(struct pipe_screen *pscreen,
          res->need_2D = (screen->need_2D_zs && util_format_is_depth_or_stencil(templ->format)) ||
                         (screen->need_2D_sparse && (templ->flags & PIPE_RESOURCE_FLAG_SPARSE));
       }
-      res->dmabuf = res->dmabuf_acquire = whandle && whandle->type == WINSYS_HANDLE_TYPE_FD;
-      res->layout = res->dmabuf_acquire ? VK_IMAGE_LAYOUT_PREINITIALIZED : VK_IMAGE_LAYOUT_UNDEFINED;
+      res->dmabuf = whandle && whandle->type == WINSYS_HANDLE_TYPE_FD;
+      if (res->dmabuf)
+         res->queue = VK_QUEUE_FAMILY_FOREIGN_EXT;
+      res->layout = res->dmabuf ? VK_IMAGE_LAYOUT_PREINITIALIZED : VK_IMAGE_LAYOUT_UNDEFINED;
       res->linear = linear;
       res->aspect = aspect_from_format(templ->format);
    }
index 2eee620..4f5251c 100644 (file)
@@ -1236,7 +1236,6 @@ struct zink_resource {
    };
 
    bool swapchain;
-   bool dmabuf_acquire;
    bool dmabuf;
    unsigned dt_stride;