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@intel.com>
Fixes: 54b525caf0 ("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@intel.com> (v1)
Reviewed-by: Jason Ekstrand <jason@jlekstrand.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/8307>
This commit is contained in:
Lionel Landwerlin 2021-01-04 13:47:37 +01:00
parent ad098553ee
commit d4b4d69d4d
1 changed files with 25 additions and 3 deletions

View File

@ -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,