From eb0cede5866f3cbd4b3e956b9670d61822b86e15 Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Fri, 6 Mar 2020 17:31:37 -0600 Subject: [PATCH] anv: Be more conservative about image view usage 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 Part-of: --- src/intel/vulkan/anv_image.c | 37 +++++++++++++++++++++++++++++++----- 1 file changed, 32 insertions(+), 5 deletions(-) diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c index 2baf93a6220..ac8514de942 100644 --- a/src/intel/vulkan/anv_image.c +++ b/src/intel/vulkan/anv_image.c @@ -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); -- 2.30.2