Mesa (staging/20.3): anv: add transfer usage for color/depth/stencil attachments

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Thu Jan 14 18:43:15 UTC 2021


Module: Mesa
Branch: staging/20.3
Commit: bfb6f66934f5881c94d0d2044a5db12a23306df8
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=bfb6f66934f5881c94d0d2044a5db12a23306df8

Author: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Date:   Mon Jan  4 13:47:37 2021 +0100

anv: add transfer usage for color/depth/stencil attachments

We sometimes use anv_layout_to_aux_state() to compute the aux state of
an image during the resolve operations at the end of a render
(sub)pass.

If we're dealing with a multisampled image that is created without a
transfer usage, our internal code might trigger a resolve using the
transfer layout (see genX_cmd_buffer.c:cmd_buffer_end_subpass), for
which the image doesn't the usage bit. The current code tries to AND
the 2 usages which won't have any bit in common, thus skipping all
checks below.

v2: Add the transfer usages depending on attachment usage (Lionel)

v3: Limit to samples > 1 (Jason) && DEPTH_STENCIL_ATTACHMENT_BIT (Lionel)

v4: Add transfer usage at image creation (Jason)

Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>
Fixes: 54b525caf0aa99 ("anv: Rework anv_layout_to_aux_state")
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/4037
Reviewed-by: Reviewed-by: Tapani Pälli <tapani.palli at intel.com> (v1)
Reviewed-by: Jason Ekstrand <jason at jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8307>
(cherry picked from commit d4b4d69d4dc387a3d999f4d820fe9471dd9cf8b9)

---

 .pick_status.json            |  2 +-
 src/intel/vulkan/anv_image.c | 28 +++++++++++++++++++++++++---
 2 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/.pick_status.json b/.pick_status.json
index dae7d8bb116..f4a1c41128d 100644
--- a/.pick_status.json
+++ b/.pick_status.json
@@ -76,7 +76,7 @@
         "description": "anv: add transfer usage for color/depth/stencil attachments",
         "nominated": true,
         "nomination_type": 1,
-        "resolution": 0,
+        "resolution": 1,
         "master_sha": null,
         "because_sha": "54b525caf0aa9966f5c0aa359709f43038bbd5ca"
     },
diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c
index 0290431f145..80307cd612f 100644
--- a/src/intel/vulkan/anv_image.c
+++ b/src/intel/vulkan/anv_image.c
@@ -684,6 +684,25 @@ choose_drm_format_mod(const struct anv_physical_device *device,
       return NULL;
 }
 
+static VkImageUsageFlags
+anv_image_create_usage(const VkImageCreateInfo *pCreateInfo,
+                       VkImageUsageFlags usage)
+{
+   /* Add TRANSFER_SRC usage for multisample attachment images. This is
+    * because we might internally use the TRANSFER_SRC layout on them for
+    * blorp operations associated with resolving those into other attachments
+    * at the end of a subpass.
+    *
+    * Without this additional usage, we compute an incorrect AUX state in
+    * anv_layout_to_aux_state().
+    */
+   if (pCreateInfo->samples > VK_SAMPLE_COUNT_1_BIT &&
+       (usage & (VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT |
+                 VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT)))
+      usage |= VK_IMAGE_USAGE_TRANSFER_SRC_BIT;
+   return usage;
+}
+
 VkResult
 anv_image_create(VkDevice _device,
                  const struct anv_image_create_info *create_info,
@@ -732,7 +751,7 @@ anv_image_create(VkDevice _device,
    image->levels = pCreateInfo->mipLevels;
    image->array_size = pCreateInfo->arrayLayers;
    image->samples = pCreateInfo->samples;
-   image->usage = pCreateInfo->usage;
+   image->usage = anv_image_create_usage(pCreateInfo, pCreateInfo->usage);
    image->create_flags = pCreateInfo->flags;
    image->tiling = pCreateInfo->tiling;
    image->disjoint = pCreateInfo->flags & VK_IMAGE_CREATE_DISJOINT_BIT;
@@ -745,8 +764,11 @@ anv_image_create(VkDevice _device,
       const VkImageStencilUsageCreateInfoEXT *stencil_usage_info =
          vk_find_struct_const(pCreateInfo->pNext,
                               IMAGE_STENCIL_USAGE_CREATE_INFO_EXT);
-      if (stencil_usage_info)
-         image->stencil_usage = stencil_usage_info->stencilUsage;
+      if (stencil_usage_info) {
+         image->stencil_usage =
+            anv_image_create_usage(pCreateInfo,
+                                   stencil_usage_info->stencilUsage);
+      }
    }
 
    /* In case of external format, We don't know format yet,



More information about the mesa-commit mailing list