From d4b4d69d4dc387a3d999f4d820fe9471dd9cf8b9 Mon Sep 17 00:00:00 2001 From: Lionel Landwerlin Date: Mon, 4 Jan 2021 13:47:37 +0100 Subject: [PATCH] anv: add transfer usage for color/depth/stencil attachments MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 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 (v1) Reviewed-by: Jason Ekstrand Part-of: --- src/intel/vulkan/anv_image.c | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c index fcebe0f770f..21c5d5c3eef 100644 --- a/src/intel/vulkan/anv_image.c +++ b/src/intel/vulkan/anv_image.c @@ -733,6 +733,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, @@ -782,7 +801,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; @@ -795,8 +814,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,