[Mesa-dev] [PATCH 4/5] anv/blorp: Use layout_to_aux_usage when a layout is provided

Jason Ekstrand jason at jlekstrand.net
Tue Feb 20 21:52:43 UTC 2018


Instead of having aux usage and ANV_AUX_USAGE_DEFAULT to mean "give me
something reasonable" we now use anv_layout_to_aux_usage whenever a
layout is available.  If a layout is available, we ignore the aux_usage
parameter.  For the cases where we have an explicit aux usage such as
clears and aux ops, we have a new ANV_IMAGE_LAYOUT_EXPLICIT_AUX layout.
---
 src/intel/vulkan/anv_blorp.c | 71 ++++++++++++++++++++++++++++----------------
 1 file changed, 46 insertions(+), 25 deletions(-)

diff --git a/src/intel/vulkan/anv_blorp.c b/src/intel/vulkan/anv_blorp.c
index a3551fe..bee51e0 100644
--- a/src/intel/vulkan/anv_blorp.c
+++ b/src/intel/vulkan/anv_blorp.c
@@ -176,7 +176,10 @@ get_blorp_surf_for_anv_buffer(struct anv_device *device,
    assert(ok);
 }
 
-#define ANV_AUX_USAGE_DEFAULT ((enum isl_aux_usage)0xff)
+/* Pick something high enough that it won't be used in core and low enough it
+ * will never map to an extension.
+ */
+#define ANV_IMAGE_LAYOUT_EXPLICIT_AUX (VkImageLayout)10000000
 
 static struct blorp_address
 anv_to_blorp_address(struct anv_address addr)
@@ -191,18 +194,14 @@ static void
 get_blorp_surf_for_anv_image(const struct anv_device *device,
                              const struct anv_image *image,
                              VkImageAspectFlags aspect,
+                             VkImageLayout layout,
                              enum isl_aux_usage aux_usage,
                              struct blorp_surf *blorp_surf)
 {
    uint32_t plane = anv_image_aspect_to_plane(image->aspects, aspect);
 
-   if (aux_usage == ANV_AUX_USAGE_DEFAULT) {
-      aux_usage = image->planes[plane].aux_usage;
-
-      /* Blorp copies and blits can't handle HiZ so disable it by default */
-      if (aux_usage == ISL_AUX_USAGE_HIZ)
-         aux_usage = ISL_AUX_USAGE_NONE;
-   }
+   if (layout != ANV_IMAGE_LAYOUT_EXPLICIT_AUX)
+      aux_usage = anv_layout_to_aux_usage(&device->info, image, aspect, layout);
 
    const struct anv_surface *surface = &image->planes[plane].surface;
    *blorp_surf = (struct blorp_surf) {
@@ -282,10 +281,12 @@ void anv_CmdCopyImage(
             struct blorp_surf src_surf, dst_surf;
             get_blorp_surf_for_anv_image(cmd_buffer->device,
                                          src_image, 1UL << aspect_bit,
-                                         ANV_AUX_USAGE_DEFAULT, &src_surf);
+                                         srcImageLayout, ISL_AUX_USAGE_NONE,
+                                         &src_surf);
             get_blorp_surf_for_anv_image(cmd_buffer->device,
                                          dst_image, 1UL << aspect_bit,
-                                         ANV_AUX_USAGE_DEFAULT, &dst_surf);
+                                         dstImageLayout, ISL_AUX_USAGE_NONE,
+                                         &dst_surf);
             anv_cmd_buffer_mark_image_written(cmd_buffer, dst_image,
                                               1UL << aspect_bit,
                                               dst_surf.aux_usage, dst_level,
@@ -302,9 +303,11 @@ void anv_CmdCopyImage(
       } else {
          struct blorp_surf src_surf, dst_surf;
          get_blorp_surf_for_anv_image(cmd_buffer->device, src_image, src_mask,
-                                      ANV_AUX_USAGE_DEFAULT, &src_surf);
+                                      srcImageLayout, ISL_AUX_USAGE_NONE,
+                                      &src_surf);
          get_blorp_surf_for_anv_image(cmd_buffer->device, dst_image, dst_mask,
-                                      ANV_AUX_USAGE_DEFAULT, &dst_surf);
+                                      dstImageLayout, ISL_AUX_USAGE_NONE,
+                                      &dst_surf);
          anv_cmd_buffer_mark_image_written(cmd_buffer, dst_image, dst_mask,
                                            dst_surf.aux_usage, dst_level,
                                            dst_base_layer, layer_count);
@@ -326,6 +329,7 @@ static void
 copy_buffer_to_image(struct anv_cmd_buffer *cmd_buffer,
                      struct anv_buffer *anv_buffer,
                      struct anv_image *anv_image,
+                     VkImageLayout image_layout,
                      uint32_t regionCount,
                      const VkBufferImageCopy* pRegions,
                      bool buffer_to_image)
@@ -354,7 +358,8 @@ copy_buffer_to_image(struct anv_cmd_buffer *cmd_buffer,
       const VkImageAspectFlags aspect = pRegions[r].imageSubresource.aspectMask;
 
       get_blorp_surf_for_anv_image(cmd_buffer->device, anv_image, aspect,
-                                   ANV_AUX_USAGE_DEFAULT, &image.surf);
+                                   image_layout, ISL_AUX_USAGE_NONE,
+                                   &image.surf);
       image.offset =
          anv_sanitize_image_offset(anv_image->type, pRegions[r].imageOffset);
       image.level = pRegions[r].imageSubresource.mipLevel;
@@ -429,7 +434,7 @@ void anv_CmdCopyBufferToImage(
    ANV_FROM_HANDLE(anv_buffer, src_buffer, srcBuffer);
    ANV_FROM_HANDLE(anv_image, dst_image, dstImage);
 
-   copy_buffer_to_image(cmd_buffer, src_buffer, dst_image,
+   copy_buffer_to_image(cmd_buffer, src_buffer, dst_image, dstImageLayout,
                         regionCount, pRegions, true);
 }
 
@@ -445,7 +450,7 @@ void anv_CmdCopyImageToBuffer(
    ANV_FROM_HANDLE(anv_image, src_image, srcImage);
    ANV_FROM_HANDLE(anv_buffer, dst_buffer, dstBuffer);
 
-   copy_buffer_to_image(cmd_buffer, dst_buffer, src_image,
+   copy_buffer_to_image(cmd_buffer, dst_buffer, src_image, srcImageLayout,
                         regionCount, pRegions, false);
 }
 
@@ -508,10 +513,10 @@ void anv_CmdBlitImage(
 
       get_blorp_surf_for_anv_image(cmd_buffer->device,
                                    src_image, src_res->aspectMask,
-                                   ANV_AUX_USAGE_DEFAULT, &src);
+                                   srcImageLayout, ISL_AUX_USAGE_NONE, &src);
       get_blorp_surf_for_anv_image(cmd_buffer->device,
                                    dst_image, dst_res->aspectMask,
-                                   ANV_AUX_USAGE_DEFAULT, &dst);
+                                   dstImageLayout, ISL_AUX_USAGE_NONE, &dst);
 
       struct anv_format_plane src_format =
          anv_get_format_plane(&cmd_buffer->device->info, src_image->vk_format,
@@ -822,7 +827,7 @@ void anv_CmdClearColorImage(
       struct blorp_surf surf;
       get_blorp_surf_for_anv_image(cmd_buffer->device,
                                    image, pRanges[r].aspectMask,
-                                   ANV_AUX_USAGE_DEFAULT, &surf);
+                                   imageLayout, ISL_AUX_USAGE_NONE, &surf);
 
       struct anv_format_plane src_format =
          anv_get_format_plane(&cmd_buffer->device->info, image->vk_format,
@@ -875,7 +880,7 @@ void anv_CmdClearDepthStencilImage(
    if (image->aspects & VK_IMAGE_ASPECT_DEPTH_BIT) {
       get_blorp_surf_for_anv_image(cmd_buffer->device,
                                    image, VK_IMAGE_ASPECT_DEPTH_BIT,
-                                   ISL_AUX_USAGE_NONE, &depth);
+                                   imageLayout, ISL_AUX_USAGE_NONE, &depth);
    } else {
       memset(&depth, 0, sizeof(depth));
    }
@@ -883,7 +888,7 @@ void anv_CmdClearDepthStencilImage(
    if (image->aspects & VK_IMAGE_ASPECT_STENCIL_BIT) {
       get_blorp_surf_for_anv_image(cmd_buffer->device,
                                    image, VK_IMAGE_ASPECT_STENCIL_BIT,
-                                   ISL_AUX_USAGE_NONE, &stencil);
+                                   imageLayout, ISL_AUX_USAGE_NONE, &stencil);
    } else {
       memset(&stencil, 0, sizeof(stencil));
    }
@@ -1162,8 +1167,10 @@ static void
 resolve_image(struct anv_device *device,
               struct blorp_batch *batch,
               const struct anv_image *src_image,
+              VkImageLayout src_image_layout,
               uint32_t src_level, uint32_t src_layer,
               const struct anv_image *dst_image,
+              VkImageLayout dst_image_layout,
               uint32_t dst_level, uint32_t dst_layer,
               VkImageAspectFlags aspect_mask,
               uint32_t src_x, uint32_t src_y, uint32_t dst_x, uint32_t dst_y,
@@ -1182,9 +1189,11 @@ resolve_image(struct anv_device *device,
    anv_foreach_image_aspect_bit(aspect_bit, src_image, aspect_mask) {
       struct blorp_surf src_surf, dst_surf;
       get_blorp_surf_for_anv_image(device, src_image, 1UL << aspect_bit,
-                                   ANV_AUX_USAGE_DEFAULT, &src_surf);
+                                   src_image_layout, ISL_AUX_USAGE_NONE,
+                                   &src_surf);
       get_blorp_surf_for_anv_image(device, dst_image, 1UL << aspect_bit,
-                                   ANV_AUX_USAGE_DEFAULT, &dst_surf);
+                                   dst_image_layout, ISL_AUX_USAGE_NONE,
+                                   &dst_surf);
       anv_cmd_buffer_mark_image_written(cmd_buffer, dst_image,
                                         1UL << aspect_bit,
                                         dst_surf.aux_usage,
@@ -1232,10 +1241,10 @@ void anv_CmdResolveImage(
 
       for (uint32_t layer = 0; layer < layer_count; layer++) {
          resolve_image(cmd_buffer->device, &batch,
-                       src_image,
+                       src_image, srcImageLayout,
                        pRegions[r].srcSubresource.mipLevel,
                        pRegions[r].srcSubresource.baseArrayLayer + layer,
-                       dst_image,
+                       dst_image, dstImageLayout,
                        pRegions[r].dstSubresource.mipLevel,
                        pRegions[r].dstSubresource.baseArrayLayer + layer,
                        pRegions[r].dstSubresource.aspectMask,
@@ -1314,9 +1323,11 @@ anv_cmd_buffer_resolve_subpass(struct anv_cmd_buffer *cmd_buffer)
          struct blorp_surf src_surf, dst_surf;
          get_blorp_surf_for_anv_image(cmd_buffer->device, src_iview->image,
                                       VK_IMAGE_ASPECT_COLOR_BIT,
+                                      ANV_IMAGE_LAYOUT_EXPLICIT_AUX,
                                       src_aux_usage, &src_surf);
          get_blorp_surf_for_anv_image(cmd_buffer->device, dst_iview->image,
                                       VK_IMAGE_ASPECT_COLOR_BIT,
+                                      ANV_IMAGE_LAYOUT_EXPLICIT_AUX,
                                       dst_aux_usage, &dst_surf);
          anv_cmd_buffer_mark_image_written(cmd_buffer, dst_iview->image,
                                            VK_IMAGE_ASPECT_COLOR_BIT,
@@ -1357,7 +1368,9 @@ anv_image_copy_to_shadow(struct anv_cmd_buffer *cmd_buffer,
    struct blorp_surf surf;
    get_blorp_surf_for_anv_image(cmd_buffer->device,
                                 image, VK_IMAGE_ASPECT_COLOR_BIT,
+                                VK_IMAGE_LAYOUT_GENERAL,
                                 ISL_AUX_USAGE_NONE, &surf);
+   assert(surf.aux_usage == ISL_AUX_USAGE_NONE);
 
    struct blorp_surf shadow_surf = {
       .surf = &image->planes[0].shadow_surface.isl,
@@ -1412,6 +1425,7 @@ anv_image_clear_color(struct anv_cmd_buffer *cmd_buffer,
 
    struct blorp_surf surf;
    get_blorp_surf_for_anv_image(cmd_buffer->device, image, aspect,
+                                ANV_IMAGE_LAYOUT_EXPLICIT_AUX,
                                 aux_usage, &surf);
    anv_cmd_buffer_mark_image_written(cmd_buffer, image, aspect, aux_usage,
                                      level, base_layer, layer_count);
@@ -1446,6 +1460,7 @@ anv_image_clear_depth_stencil(struct anv_cmd_buffer *cmd_buffer,
    if (aspects & VK_IMAGE_ASPECT_DEPTH_BIT) {
       get_blorp_surf_for_anv_image(cmd_buffer->device,
                                    image, VK_IMAGE_ASPECT_DEPTH_BIT,
+                                   ANV_IMAGE_LAYOUT_EXPLICIT_AUX,
                                    depth_aux_usage, &depth);
       depth.clear_color.f32[0] = ANV_HZ_FC_VAL;
    }
@@ -1454,6 +1469,7 @@ anv_image_clear_depth_stencil(struct anv_cmd_buffer *cmd_buffer,
    if (aspects & VK_IMAGE_ASPECT_STENCIL_BIT) {
       get_blorp_surf_for_anv_image(cmd_buffer->device,
                                    image, VK_IMAGE_ASPECT_STENCIL_BIT,
+                                   ANV_IMAGE_LAYOUT_EXPLICIT_AUX,
                                    ISL_AUX_USAGE_NONE, &stencil);
    }
 
@@ -1488,6 +1504,7 @@ anv_image_hiz_op(struct anv_cmd_buffer *cmd_buffer,
    struct blorp_surf surf;
    get_blorp_surf_for_anv_image(cmd_buffer->device,
                                 image, VK_IMAGE_ASPECT_DEPTH_BIT,
+                                ANV_IMAGE_LAYOUT_EXPLICIT_AUX,
                                 ISL_AUX_USAGE_HIZ, &surf);
    surf.clear_color.f32[0] = ANV_HZ_FC_VAL;
 
@@ -1516,6 +1533,7 @@ anv_image_hiz_clear(struct anv_cmd_buffer *cmd_buffer,
              anv_image_aux_layers(image, VK_IMAGE_ASPECT_DEPTH_BIT, level));
       get_blorp_surf_for_anv_image(cmd_buffer->device,
                                    image, VK_IMAGE_ASPECT_DEPTH_BIT,
+                                   ANV_IMAGE_LAYOUT_EXPLICIT_AUX,
                                    ISL_AUX_USAGE_HIZ, &depth);
       depth.clear_color.f32[0] = ANV_HZ_FC_VAL;
    }
@@ -1524,6 +1542,7 @@ anv_image_hiz_clear(struct anv_cmd_buffer *cmd_buffer,
    if (aspects & VK_IMAGE_ASPECT_STENCIL_BIT) {
       get_blorp_surf_for_anv_image(cmd_buffer->device,
                                    image, VK_IMAGE_ASPECT_STENCIL_BIT,
+                                   ANV_IMAGE_LAYOUT_EXPLICIT_AUX,
                                    ISL_AUX_USAGE_NONE, &stencil);
    }
 
@@ -1575,7 +1594,8 @@ anv_image_mcs_op(struct anv_cmd_buffer *cmd_buffer,
 
    struct blorp_surf surf;
    get_blorp_surf_for_anv_image(cmd_buffer->device, image, aspect,
-                                ANV_AUX_USAGE_DEFAULT, &surf);
+                                ANV_IMAGE_LAYOUT_EXPLICIT_AUX,
+                                ISL_AUX_USAGE_MCS, &surf);
 
    /* From the Sky Lake PRM Vol. 7, "Render Target Fast Clear":
     *
@@ -1641,6 +1661,7 @@ anv_image_ccs_op(struct anv_cmd_buffer *cmd_buffer,
 
    struct blorp_surf surf;
    get_blorp_surf_for_anv_image(cmd_buffer->device, image, aspect,
+                                ANV_IMAGE_LAYOUT_EXPLICIT_AUX,
                                 fast_clear_aux_usage(image, aspect),
                                 &surf);
 
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list