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

Jason Ekstrand jason at jlekstrand.net
Mon Feb 5 23:13:26 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 4018476..1cef587 100644
--- a/src/intel/vulkan/anv_blorp.c
+++ b/src/intel/vulkan/anv_blorp.c
@@ -173,7 +173,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)
@@ -188,18 +191,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) {
@@ -279,10 +278,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,
@@ -299,9 +300,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);
@@ -323,6 +326,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)
@@ -351,7 +355,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;
@@ -426,7 +431,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);
 }
 
@@ -442,7 +447,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);
 }
 
@@ -505,10 +510,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,
@@ -819,7 +824,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,
@@ -872,7 +877,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));
    }
@@ -880,7 +885,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));
    }
@@ -1159,8 +1164,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,
@@ -1179,9 +1186,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,
@@ -1229,10 +1238,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,
@@ -1311,9 +1320,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,
@@ -1354,7 +1365,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,
@@ -1409,6 +1422,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);
@@ -1443,6 +1457,7 @@ anv_image_clear_depth_stencil(struct anv_cmd_buffer *cmd_buffer,
    if (image->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;
    } else {
@@ -1452,6 +1467,7 @@ anv_image_clear_depth_stencil(struct anv_cmd_buffer *cmd_buffer,
    if (image->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);
    } else {
       memset(&stencil, 0, sizeof(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;
 
@@ -1515,6 +1532,7 @@ anv_image_hiz_clear(struct anv_cmd_buffer *cmd_buffer,
    struct blorp_surf depth;
    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;
 
@@ -1522,6 +1540,7 @@ anv_image_hiz_clear(struct anv_cmd_buffer *cmd_buffer,
    if (image->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);
    } else {
       memset(&stencil, 0, sizeof(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