anv/image: Fix usage for depthstencil images
authorChad Versace <chad.versace@intel.com>
Tue, 9 Feb 2016 20:41:08 +0000 (12:41 -0800)
committerChad Versace <chad.versace@intel.com>
Tue, 9 Feb 2016 20:54:30 +0000 (12:54 -0800)
The tests assertion-failed in vkCmdClearDepthStencilImage because the
isl surface lacked ISL_SURF_USAGE_DEPTH_BIT.

Fixes: https://gitlab.khronos.org/vulkan/mesa/issues/26
Fixes: dEQP-VK.pipeline.timestamp.transfer_tests.host_stage_with_clear_depth_stencil_image_method
Fixes: dEQP-VK.pipeline.timestamp.transfer_tests.transfer_stage_with_clear_depth_stencil_image_method
src/vulkan/anv_image.c

index 2cf9de7d18469c45bc9e3ec5d4eb1241d25b7818..4ce997589c500283b4e82c9746d4f04c57494dcf 100644 (file)
@@ -151,8 +151,12 @@ make_surface(const struct anv_device *dev,
    return VK_SUCCESS;
 }
 
+/**
+ * Parameter @a format is required and overrides VkImageCreateInfo::format.
+ */
 static VkImageUsageFlags
-anv_image_get_full_usage(const VkImageCreateInfo *info)
+anv_image_get_full_usage(const VkImageCreateInfo *info,
+                         const struct anv_format *format)
 {
    VkImageUsageFlags usage = info->usage;
 
@@ -168,10 +172,21 @@ anv_image_get_full_usage(const VkImageCreateInfo *info)
    }
 
    if (usage & VK_IMAGE_USAGE_TRANSFER_DST_BIT) {
-      /* Meta will transfer to the image by binding it as a color attachment,
-       * even if the image format is not a color format.
+      /* For non-clear transfer operations, meta will transfer to the image by
+       * binding it as a color attachment, even if the image format is not
+       * a color format.
        */
       usage |= VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT;
+
+      if (anv_format_is_depth_or_stencil(format)) {
+         /* vkCmdClearDepthStencilImage() only requires that
+          * VK_IMAGE_USAGE_TRANSFER_SRC_BIT be set. In particular, it does
+          * not require VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT. Meta
+          * clears the image, though, by binding it as a depthstencil
+          * attachment.
+          */
+         usage |= VK_IMAGE_USAGE_DEPTH_STENCIL_ATTACHMENT_BIT;
+      }
    }
 
    return usage;
@@ -186,6 +201,7 @@ anv_image_create(VkDevice _device,
    ANV_FROM_HANDLE(anv_device, device, _device);
    const VkImageCreateInfo *pCreateInfo = create_info->vk_info;
    struct anv_image *image = NULL;
+   const struct anv_format *format = anv_format_for_vk_format(pCreateInfo->format);
    VkResult r;
 
    assert(pCreateInfo->sType == VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO);
@@ -206,14 +222,14 @@ anv_image_create(VkDevice _device,
    image->type = pCreateInfo->imageType;
    image->extent = pCreateInfo->extent;
    image->vk_format = pCreateInfo->format;
-   image->format = anv_format_for_vk_format(pCreateInfo->format);
+   image->format = format;
    image->levels = pCreateInfo->mipLevels;
    image->array_size = pCreateInfo->arrayLayers;
    image->samples = pCreateInfo->samples;
-   image->usage = anv_image_get_full_usage(pCreateInfo);
+   image->usage = anv_image_get_full_usage(pCreateInfo, format);
    image->tiling = pCreateInfo->tiling;
 
-   if (likely(anv_format_is_color(image->format))) {
+   if (likely(anv_format_is_color(format))) {
       r = make_surface(device, image, create_info,
                        VK_IMAGE_ASPECT_COLOR_BIT);
       if (r != VK_SUCCESS)