anv: Be more conservative about image view usage
authorJason Ekstrand <jason@jlekstrand.net>
Fri, 6 Mar 2020 23:31:37 +0000 (17:31 -0600)
committerMarge Bot <eric+marge@anholt.net>
Fri, 24 Apr 2020 16:17:44 +0000 (16:17 +0000)
We were ORing together the image and stencil usage rather than actually
following the formula in the spec.  This can lead to assertions in other
parts of the driver if we're not careful.

Reviewed-by: Rafael Antognolli <rafael.antognolli@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4100>

src/intel/vulkan/anv_image.c

index 2baf93a6220d6653713c0be586b765d8a1ccb55e..ac8514de942c0c22ac439e3b3dc3deb972939bb7 100644 (file)
@@ -1898,11 +1898,38 @@ anv_CreateImageView(VkDevice _device,
       conv_format = conversion->format;
    }
 
-   VkImageUsageFlags image_usage = 0;
-   if (range->aspectMask & ~VK_IMAGE_ASPECT_STENCIL_BIT)
-      image_usage |= image->usage;
-   if (range->aspectMask & VK_IMAGE_ASPECT_STENCIL_BIT)
-      image_usage |= image->stencil_usage;
+   VkImageUsageFlags image_usage = image->usage;
+   if (range->aspectMask & (VK_IMAGE_ASPECT_DEPTH_BIT |
+                            VK_IMAGE_ASPECT_STENCIL_BIT)) {
+      assert(!(range->aspectMask & VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV));
+      /* From the Vulkan 1.2.131 spec:
+       *
+       *    "If the image was has a depth-stencil format and was created with
+       *    a VkImageStencilUsageCreateInfo structure included in the pNext
+       *    chain of VkImageCreateInfo, the usage is calculated based on the
+       *    subresource.aspectMask provided:
+       *
+       *     - If aspectMask includes only VK_IMAGE_ASPECT_STENCIL_BIT, the
+       *       implicit usage is equal to
+       *       VkImageStencilUsageCreateInfo::stencilUsage.
+       *
+       *     - If aspectMask includes only VK_IMAGE_ASPECT_DEPTH_BIT, the
+       *       implicit usage is equal to VkImageCreateInfo::usage.
+       *
+       *     - If both aspects are included in aspectMask, the implicit usage
+       *       is equal to the intersection of VkImageCreateInfo::usage and
+       *       VkImageStencilUsageCreateInfo::stencilUsage.
+       */
+      if (range->aspectMask == VK_IMAGE_ASPECT_STENCIL_BIT) {
+         image_usage = image->stencil_usage;
+      } else if (range->aspectMask == VK_IMAGE_ASPECT_DEPTH_BIT) {
+         image_usage = image->usage;
+      } else {
+         assert(range->aspectMask == (VK_IMAGE_ASPECT_DEPTH_BIT |
+                                      VK_IMAGE_ASPECT_STENCIL_BIT));
+         image_usage = image->usage & image->stencil_usage;
+      }
+   }
 
    const VkImageViewUsageCreateInfo *usage_info =
       vk_find_struct_const(pCreateInfo, IMAGE_VIEW_USAGE_CREATE_INFO);