anv: Add a usage parameter to anv_layout_to_aux_usage
authorJason Ekstrand <jason@jlekstrand.net>
Tue, 19 Nov 2019 23:51:20 +0000 (17:51 -0600)
committerMarge Bot <eric+marge@anholt.net>
Fri, 24 Jan 2020 17:42:36 +0000 (17:42 +0000)
Most places we actually know the usage and can provide it.  There are
two exceptions to this:

 1. We pass 0 into get_blorp_surf_for_anv_image when we use
    ANV_IMAGE_LAYOUT_EXPLICIT_AUX because anv_layout_to_aux_usage is
    never actually called so it doesn't matter.

 2. We pass 0 into anv_layout_to_aux_usage in transition_color_buffer.
    However, the coming commits which will begin using the usage
    parameter only care about depth.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Nanley Chery <nanley.g.chery@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/2605>

src/intel/vulkan/anv_blorp.c
src/intel/vulkan/anv_image.c
src/intel/vulkan/anv_private.h
src/intel/vulkan/genX_cmd_buffer.c

index 135768e8e623399dddd4289fdfed998491cbe07c..f2554e04df9762a7b9a501e43a1e1d36d3ceffea 100644 (file)
@@ -199,14 +199,18 @@ static void
 get_blorp_surf_for_anv_image(const struct anv_device *device,
                              const struct anv_image *image,
                              VkImageAspectFlags aspect,
+                             VkImageUsageFlags usage,
                              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 (layout != ANV_IMAGE_LAYOUT_EXPLICIT_AUX)
-      aux_usage = anv_layout_to_aux_usage(&device->info, image, aspect, layout);
+   if (layout != ANV_IMAGE_LAYOUT_EXPLICIT_AUX) {
+      assert(usage != 0);
+      aux_usage = anv_layout_to_aux_usage(&device->info, image,
+                                          aspect, usage, layout);
+   }
 
    const struct anv_surface *surface = &image->planes[plane].surface;
    *blorp_surf = (struct blorp_surf) {
@@ -339,10 +343,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,
+                                         VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
                                          srcImageLayout, ISL_AUX_USAGE_NONE,
                                          &src_surf);
             get_blorp_surf_for_anv_image(cmd_buffer->device,
                                          dst_image, 1UL << aspect_bit,
+                                         VK_IMAGE_USAGE_TRANSFER_DST_BIT,
                                          dstImageLayout, ISL_AUX_USAGE_NONE,
                                          &dst_surf);
             anv_cmd_buffer_mark_image_written(cmd_buffer, dst_image,
@@ -375,9 +381,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,
+                                      VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
                                       srcImageLayout, ISL_AUX_USAGE_NONE,
                                       &src_surf);
          get_blorp_surf_for_anv_image(cmd_buffer->device, dst_image, dst_mask,
+                                      VK_IMAGE_USAGE_TRANSFER_DST_BIT,
                                       dstImageLayout, ISL_AUX_USAGE_NONE,
                                       &dst_surf);
          anv_cmd_buffer_mark_image_written(cmd_buffer, dst_image, dst_mask,
@@ -461,6 +469,9 @@ 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,
+                                   buffer_to_image ?
+                                      VK_IMAGE_USAGE_TRANSFER_DST_BIT :
+                                      VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
                                    image_layout, ISL_AUX_USAGE_NONE,
                                    &image.surf);
       image.offset =
@@ -655,9 +666,11 @@ void anv_CmdBlitImage(
       anv_foreach_image_aspect_bit(aspect_bit, src_image, src_res->aspectMask) {
          get_blorp_surf_for_anv_image(cmd_buffer->device,
                                       src_image, 1U << aspect_bit,
+                                      VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
                                       srcImageLayout, ISL_AUX_USAGE_NONE, &src);
          get_blorp_surf_for_anv_image(cmd_buffer->device,
                                       dst_image, 1U << aspect_bit,
+                                      VK_IMAGE_USAGE_TRANSFER_DST_BIT,
                                       dstImageLayout, ISL_AUX_USAGE_NONE, &dst);
 
          struct anv_format_plane src_format =
@@ -960,6 +973,7 @@ void anv_CmdClearColorImage(
       struct blorp_surf surf;
       get_blorp_surf_for_anv_image(cmd_buffer->device,
                                    image, pRanges[r].aspectMask,
+                                   VK_IMAGE_USAGE_TRANSFER_DST_BIT,
                                    imageLayout, ISL_AUX_USAGE_NONE, &surf);
 
       struct anv_format_plane src_format =
@@ -1013,6 +1027,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,
+                                   VK_IMAGE_USAGE_TRANSFER_DST_BIT,
                                    imageLayout, ISL_AUX_USAGE_NONE, &depth);
    } else {
       memset(&depth, 0, sizeof(depth));
@@ -1022,6 +1037,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,
+                                   VK_IMAGE_USAGE_TRANSFER_DST_BIT,
                                    imageLayout, ISL_AUX_USAGE_NONE, &stencil);
 
       has_stencil_shadow =
@@ -1327,7 +1343,7 @@ anv_image_msaa_resolve(struct anv_cmd_buffer *cmd_buffer,
 
    struct blorp_surf src_surf, dst_surf;
    get_blorp_surf_for_anv_image(cmd_buffer->device, src_image, aspect,
-                                ANV_IMAGE_LAYOUT_EXPLICIT_AUX,
+                                0, ANV_IMAGE_LAYOUT_EXPLICIT_AUX,
                                 src_aux_usage, &src_surf);
    if (src_aux_usage == ISL_AUX_USAGE_MCS) {
       src_surf.clear_color_addr = anv_to_blorp_address(
@@ -1335,7 +1351,7 @@ anv_image_msaa_resolve(struct anv_cmd_buffer *cmd_buffer,
                                         VK_IMAGE_ASPECT_COLOR_BIT));
    }
    get_blorp_surf_for_anv_image(cmd_buffer->device, dst_image, aspect,
-                                ANV_IMAGE_LAYOUT_EXPLICIT_AUX,
+                                0, ANV_IMAGE_LAYOUT_EXPLICIT_AUX,
                                 dst_aux_usage, &dst_surf);
    anv_cmd_buffer_mark_image_written(cmd_buffer, dst_image,
                                      aspect, dst_aux_usage,
@@ -1397,10 +1413,14 @@ void anv_CmdResolveImage(
                                    pRegions[r].srcSubresource.aspectMask) {
          enum isl_aux_usage src_aux_usage =
             anv_layout_to_aux_usage(&cmd_buffer->device->info, src_image,
-                                    (1 << aspect_bit), srcImageLayout);
+                                    (1 << aspect_bit),
+                                    VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
+                                    srcImageLayout);
          enum isl_aux_usage dst_aux_usage =
             anv_layout_to_aux_usage(&cmd_buffer->device->info, dst_image,
-                                    (1 << aspect_bit), dstImageLayout);
+                                    (1 << aspect_bit),
+                                    VK_IMAGE_USAGE_TRANSFER_DST_BIT,
+                                    dstImageLayout);
 
          anv_image_msaa_resolve(cmd_buffer,
                                 src_image, src_aux_usage,
@@ -1454,6 +1474,7 @@ 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, aspect,
+                                VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
                                 VK_IMAGE_LAYOUT_GENERAL,
                                 ISL_AUX_USAGE_NONE, &surf);
    assert(surf.aux_usage == ISL_AUX_USAGE_NONE);
@@ -1509,7 +1530,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,
+                                0, 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);
@@ -1544,7 +1565,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,
+                                   0, ANV_IMAGE_LAYOUT_EXPLICIT_AUX,
                                    depth_aux_usage, &depth);
       depth.clear_color.f32[0] = ANV_HZ_FC_VAL;
    }
@@ -1553,7 +1574,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,
+                                   0, ANV_IMAGE_LAYOUT_EXPLICIT_AUX,
                                    ISL_AUX_USAGE_NONE, &stencil);
    }
 
@@ -1619,7 +1640,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,
+                                0, ANV_IMAGE_LAYOUT_EXPLICIT_AUX,
                                 ISL_AUX_USAGE_HIZ, &surf);
    surf.clear_color.f32[0] = ANV_HZ_FC_VAL;
 
@@ -1648,7 +1669,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,
+                                   0, ANV_IMAGE_LAYOUT_EXPLICIT_AUX,
                                    ISL_AUX_USAGE_HIZ, &depth);
       depth.clear_color.f32[0] = ANV_HZ_FC_VAL;
    }
@@ -1657,7 +1678,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,
+                                   0, ANV_IMAGE_LAYOUT_EXPLICIT_AUX,
                                    ISL_AUX_USAGE_NONE, &stencil);
    }
 
@@ -1734,7 +1755,7 @@ 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_IMAGE_LAYOUT_EXPLICIT_AUX,
+                                0, ANV_IMAGE_LAYOUT_EXPLICIT_AUX,
                                 ISL_AUX_USAGE_MCS, &surf);
 
    /* Blorp will store the clear color for us if we provide the clear color
@@ -1814,7 +1835,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,
+                                0, ANV_IMAGE_LAYOUT_EXPLICIT_AUX,
                                 fast_clear_aux_usage(image, aspect),
                                 &surf);
 
index 996954d2817209eab9f111649f58f35216626ab0..957276c306247ec0a850fb7278513d4b159a9d5e 100644 (file)
@@ -1249,6 +1249,7 @@ anv_layout_to_aux_state(const struct gen_device_info * const devinfo,
  * @param devinfo The device information of the Intel GPU.
  * @param image The image that may contain a collection of buffers.
  * @param aspect The aspect of the image to be accessed.
+ * @param usage The usage which describes how the image will be accessed.
  * @param layout The current layout of the image aspect(s).
  *
  * @return The primary buffer that should be used for the given layout.
@@ -1257,6 +1258,7 @@ enum isl_aux_usage
 anv_layout_to_aux_usage(const struct gen_device_info * const devinfo,
                         const struct anv_image * const image,
                         const VkImageAspectFlagBits aspect,
+                        const VkImageUsageFlagBits usage,
                         const VkImageLayout layout)
 {
    uint32_t plane = anv_image_aspect_to_plane(image->aspects, aspect);
@@ -1305,6 +1307,7 @@ anv_layout_to_aux_usage(const struct gen_device_info * const devinfo,
  * @param devinfo The device information of the Intel GPU.
  * @param image The image that may contain a collection of buffers.
  * @param aspect The aspect of the image to be accessed.
+ * @param usage The usage which describes how the image will be accessed.
  * @param layout The current layout of the image aspect(s).
  */
 enum anv_fast_clear_type
@@ -1791,9 +1794,11 @@ anv_CreateImageView(VkDevice _device,
 
          enum isl_aux_usage general_aux_usage =
             anv_layout_to_aux_usage(&device->info, image, 1UL << iaspect_bit,
+                                    VK_IMAGE_USAGE_SAMPLED_BIT,
                                     VK_IMAGE_LAYOUT_GENERAL);
          enum isl_aux_usage optimal_aux_usage =
             anv_layout_to_aux_usage(&device->info, image, 1UL << iaspect_bit,
+                                    VK_IMAGE_USAGE_SAMPLED_BIT,
                                     VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL);
 
          anv_image_fill_surface_state(device, image, 1ULL << iaspect_bit,
index 8350e9fe8f7eaf0e3ec2a6f00022daa0740de2cc..55b06ef6db991be48125008959c02db8be3db0d4 100644 (file)
@@ -3700,6 +3700,7 @@ enum isl_aux_usage
 anv_layout_to_aux_usage(const struct gen_device_info * const devinfo,
                         const struct anv_image *image,
                         const VkImageAspectFlagBits aspect,
+                        const VkImageUsageFlagBits usage,
                         const VkImageLayout layout);
 
 enum anv_fast_clear_type
index 9af5e9c8f5b5ea9b5a64911eed94d63e1e99051b..c8ec8697b956483f6e5274d0cee8f7a361eeeb15 100644 (file)
@@ -308,6 +308,7 @@ color_attachment_compute_aux_usage(struct anv_device * device,
    att_state->aux_usage =
       anv_layout_to_aux_usage(&device->info, iview->image,
                               VK_IMAGE_ASPECT_COLOR_BIT,
+                              VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT,
                               VK_IMAGE_LAYOUT_COLOR_ATTACHMENT_OPTIMAL);
 
    /* If we don't have aux, then we should have returned early in the layer
@@ -465,6 +466,7 @@ depth_stencil_attachment_compute_aux_usage(struct anv_device *device,
    const enum isl_aux_usage first_subpass_aux_usage =
       anv_layout_to_aux_usage(&device->info, iview->image,
                               VK_IMAGE_ASPECT_DEPTH_BIT,
+                              VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
                               pass_att->first_subpass_layout);
    if (!blorp_can_hiz_clear_depth(&device->info,
                                   &iview->image->planes[0].surface.isl,
@@ -1139,9 +1141,9 @@ transition_color_buffer(struct anv_cmd_buffer *cmd_buffer,
    }
 
    const enum isl_aux_usage initial_aux_usage =
-      anv_layout_to_aux_usage(devinfo, image, aspect, initial_layout);
+      anv_layout_to_aux_usage(devinfo, image, aspect, 0, initial_layout);
    const enum isl_aux_usage final_aux_usage =
-      anv_layout_to_aux_usage(devinfo, image, aspect, final_layout);
+      anv_layout_to_aux_usage(devinfo, image, aspect, 0, final_layout);
 
    /* The current code assumes that there is no mixing of CCS_E and CCS_D.
     * We can handle transitions between CCS_D/E to and from NONE.  What we
@@ -1490,7 +1492,9 @@ genX(BeginCommandBuffer)(
 
             enum isl_aux_usage aux_usage =
                anv_layout_to_aux_usage(&cmd_buffer->device->info, iview->image,
-                                       VK_IMAGE_ASPECT_DEPTH_BIT, layout);
+                                       VK_IMAGE_ASPECT_DEPTH_BIT,
+                                       VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
+                                       layout);
 
             cmd_buffer->state.hiz_enabled = aux_usage == ISL_AUX_USAGE_HIZ;
          }
@@ -4658,7 +4662,9 @@ cmd_buffer_begin_subpass(struct anv_cmd_buffer *cmd_buffer,
                                  att_state->current_layout, target_layout);
          att_state->aux_usage =
             anv_layout_to_aux_usage(&cmd_buffer->device->info, image,
-                                    VK_IMAGE_ASPECT_DEPTH_BIT, target_layout);
+                                    VK_IMAGE_ASPECT_DEPTH_BIT,
+                                    VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT,
+                                    target_layout);
       }
 
       if (image->aspects & VK_IMAGE_ASPECT_STENCIL_BIT) {
@@ -5047,6 +5053,7 @@ cmd_buffer_end_subpass(struct anv_cmd_buffer *cmd_buffer)
          src_state->aux_usage =
             anv_layout_to_aux_usage(&cmd_buffer->device->info, src_iview->image,
                                     VK_IMAGE_ASPECT_DEPTH_BIT,
+                                    VK_IMAGE_USAGE_TRANSFER_SRC_BIT,
                                     VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL);
          src_state->current_layout = VK_IMAGE_LAYOUT_TRANSFER_SRC_OPTIMAL;
 
@@ -5071,6 +5078,7 @@ cmd_buffer_end_subpass(struct anv_cmd_buffer *cmd_buffer)
          dst_state->aux_usage =
             anv_layout_to_aux_usage(&cmd_buffer->device->info, dst_iview->image,
                                     VK_IMAGE_ASPECT_DEPTH_BIT,
+                                    VK_IMAGE_USAGE_TRANSFER_DST_BIT,
                                     VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL);
          dst_state->current_layout = VK_IMAGE_LAYOUT_TRANSFER_DST_OPTIMAL;