zink: break out barrier struct initializing into helper funcs
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Mon, 30 Nov 2020 17:36:24 +0000 (12:36 -0500)
committerMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Mon, 29 Mar 2021 02:17:57 +0000 (22:17 -0400)
make this and the no-op handling reusable for future extension

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

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

index d479a3a..2fbe9f6 100644 (file)
@@ -1592,23 +1592,20 @@ zink_resource_image_needs_barrier(struct zink_resource *res, VkImageLayout new_l
           zink_resource_access_is_write(flags);
 }
 
-void
-zink_resource_image_barrier(struct zink_context *ctx, struct zink_batch *batch, struct zink_resource *res,
-                      VkImageLayout new_layout, VkAccessFlags flags, VkPipelineStageFlags pipeline)
+bool
+zink_resource_image_barrier_init(VkImageMemoryBarrier *imb, struct zink_resource *res, VkImageLayout new_layout, VkAccessFlags flags, VkPipelineStageFlags pipeline)
 {
    if (!pipeline)
       pipeline = pipeline_dst_stage(new_layout);
    if (!flags)
       flags = access_dst_flags(new_layout);
-   if (!zink_resource_image_needs_barrier(res, new_layout, flags, pipeline))
-      return;
+
    VkImageSubresourceRange isr = {
       res->aspect,
       0, VK_REMAINING_MIP_LEVELS,
       0, VK_REMAINING_ARRAY_LAYERS
    };
-
-   VkImageMemoryBarrier imb = {
+   *imb = (VkImageMemoryBarrier){
       VK_STRUCTURE_TYPE_IMAGE_MEMORY_BARRIER,
       NULL,
       res->access ? res->access : access_src_flags(res->layout),
@@ -1620,6 +1617,18 @@ zink_resource_image_barrier(struct zink_context *ctx, struct zink_batch *batch,
       res->obj->image,
       isr
    };
+   return zink_resource_image_needs_barrier(res, new_layout, flags, pipeline);
+}
+
+void
+zink_resource_image_barrier(struct zink_context *ctx, struct zink_batch *batch, struct zink_resource *res,
+                      VkImageLayout new_layout, VkAccessFlags flags, VkPipelineStageFlags pipeline)
+{
+   VkImageMemoryBarrier imb;
+   if (!zink_resource_image_barrier_init(&imb, res, new_layout, flags, pipeline))
+      return;
+   if (!pipeline)
+      pipeline = pipeline_dst_stage(new_layout);
    /* only barrier if we're changing layout or doing something besides read -> read */
    batch = zink_batch_no_rp(ctx);
    assert(!batch->in_rp);
@@ -1635,7 +1644,7 @@ zink_resource_image_barrier(struct zink_context *ctx, struct zink_batch *batch,
 
    res->layout = new_layout;
    res->access_stage = pipeline;
-   res->access = flags;
+   res->access = imb.dstAccessMask;
 }
 
 
@@ -1688,14 +1697,12 @@ zink_resource_buffer_needs_barrier(struct zink_resource *res, VkAccessFlags flag
           zink_resource_access_is_write(flags);
 }
 
-void
-zink_resource_buffer_barrier(struct zink_context *ctx, struct zink_batch *batch, struct zink_resource *res, VkAccessFlags flags, VkPipelineStageFlags pipeline)
+bool
+zink_resource_buffer_barrier_init(VkBufferMemoryBarrier *bmb, struct zink_resource *res, VkAccessFlags flags, VkPipelineStageFlags pipeline)
 {
    if (!pipeline)
       pipeline = pipeline_access_stage(flags);
-   if (!zink_resource_buffer_needs_barrier(res, flags, pipeline))
-      return;
-   VkBufferMemoryBarrier bmb = {
+   *bmb = (VkBufferMemoryBarrier){
       VK_STRUCTURE_TYPE_BUFFER_MEMORY_BARRIER,
       NULL,
       res->access,
@@ -1706,6 +1713,17 @@ zink_resource_buffer_barrier(struct zink_context *ctx, struct zink_batch *batch,
       res->obj->offset,
       res->base.width0
    };
+   return zink_resource_buffer_needs_barrier(res, flags, pipeline);
+}
+
+void
+zink_resource_buffer_barrier(struct zink_context *ctx, struct zink_batch *batch, struct zink_resource *res, VkAccessFlags flags, VkPipelineStageFlags pipeline)
+{
+   VkBufferMemoryBarrier bmb;
+   if (!zink_resource_buffer_barrier_init(&bmb, res, flags, pipeline))
+      return;
+   if (!pipeline)
+      pipeline = pipeline_access_stage(flags);
    /* only barrier if we're changing layout or doing something besides read -> read */
    batch = zink_batch_no_rp(ctx);
    assert(!batch->in_rp);
@@ -1718,7 +1736,7 @@ zink_resource_buffer_barrier(struct zink_context *ctx, struct zink_batch *batch,
       1, &bmb,
       0, NULL
    );
-   res->access = flags;
+   res->access = bmb.dstAccessMask;
    res->access_stage = pipeline;
 }
 
index 396c680..81912b4 100644 (file)
@@ -266,11 +266,16 @@ zink_resource_access_is_write(VkAccessFlags flags);
 bool
 zink_resource_buffer_needs_barrier(struct zink_resource *res, VkAccessFlags flags, VkPipelineStageFlags pipeline);
 
+bool
+zink_resource_buffer_barrier_init(VkBufferMemoryBarrier *bmb, struct zink_resource *res, VkAccessFlags flags, VkPipelineStageFlags pipeline);
+
 void
 zink_resource_buffer_barrier(struct zink_context *ctx, struct zink_batch *batch, struct zink_resource *res, VkAccessFlags flags, VkPipelineStageFlags pipeline);
 
 bool
 zink_resource_image_needs_barrier(struct zink_resource *res, VkImageLayout new_layout, VkAccessFlags flags, VkPipelineStageFlags pipeline);
+bool
+zink_resource_image_barrier_init(VkImageMemoryBarrier *imb, struct zink_resource *res, VkImageLayout new_layout, VkAccessFlags flags, VkPipelineStageFlags pipeline);
 void
 zink_resource_image_barrier(struct zink_context *ctx, struct zink_batch *batch, struct zink_resource *res,
                       VkImageLayout new_layout, VkAccessFlags flags, VkPipelineStageFlags pipeline);