From d4bcfed42234f9263c99936c87772c6e7f22739e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=A4in=C3=B6=20M=C3=A4kel=C3=A4?= Date: Fri, 18 Nov 2022 08:56:46 +0200 Subject: [PATCH] hasvk: Allow aliasing with modifiers for WSI images Ignore ALIAS_BIT when format comes from WSI because we have the ability to bind the MEMORY_BINDING_PRIVATE from the other WSI image. This commit is the same as f350b78b but for hasvk. Reviewed-by: Lionel Landwerlin --- src/intel/vulkan_hasvk/anv_formats.c | 18 +++++++++++++----- src/intel/vulkan_hasvk/anv_image.c | 5 ++++- src/intel/vulkan_hasvk/anv_private.h | 5 +++++ 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/intel/vulkan_hasvk/anv_formats.c b/src/intel/vulkan_hasvk/anv_formats.c index dbd42261834..8c54f7bddc7 100644 --- a/src/intel/vulkan_hasvk/anv_formats.c +++ b/src/intel/vulkan_hasvk/anv_formats.c @@ -984,7 +984,8 @@ anv_get_image_format_properties( struct anv_physical_device *physical_device, const VkPhysicalDeviceImageFormatInfo2 *info, VkImageFormatProperties *pImageFormatProperties, - VkSamplerYcbcrConversionImageFormatProperties *pYcbcrImageFormatProperties) + VkSamplerYcbcrConversionImageFormatProperties *pYcbcrImageFormatProperties, + bool from_wsi) { VkFormatFeatureFlags2 format_feature_flags; VkExtent3D maxExtent; @@ -1216,7 +1217,7 @@ anv_get_image_format_properties( } } - if (info->flags & VK_IMAGE_CREATE_ALIAS_BIT) { + if (info->flags & VK_IMAGE_CREATE_ALIAS_BIT && !from_wsi) { /* Reject aliasing of images with non-linear DRM format modifiers because: * * 1. For modifiers with compression, we store aux tracking state in @@ -1226,6 +1227,9 @@ anv_get_image_format_properties( * 2. For tiled modifiers without compression, we may attempt to compress * them behind the scenes, in which case both the aux tracking state * and the CCS data are bound to ANV_IMAGE_MEMORY_BINDING_PRIVATE. + * + * 3. For WSI we should ignore ALIAS_BIT because we have the ability to + * bind the ANV_MEMORY_BINDING_PRIVATE from the other WSI image. */ if (info->tiling == VK_IMAGE_TILING_DRM_FORMAT_MODIFIER_EXT && isl_mod_info->modifier != DRM_FORMAT_MOD_LINEAR) { @@ -1309,7 +1313,7 @@ VkResult anv_GetPhysicalDeviceImageFormatProperties( }; return anv_get_image_format_properties(physical_device, &info, - pImageFormatProperties, NULL); + pImageFormatProperties, NULL, false); } @@ -1375,10 +1379,11 @@ VkResult anv_GetPhysicalDeviceImageFormatProperties2( VkSamplerYcbcrConversionImageFormatProperties *ycbcr_props = NULL; VkAndroidHardwareBufferUsageANDROID *android_usage = NULL; VkResult result; + bool from_wsi = false; /* Extract input structs */ vk_foreach_struct_const(s, base_info->pNext) { - switch (s->sType) { + switch ((unsigned)s->sType) { case VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_IMAGE_FORMAT_INFO: external_info = (const void *) s; break; @@ -1389,6 +1394,9 @@ VkResult anv_GetPhysicalDeviceImageFormatProperties2( case VK_STRUCTURE_TYPE_IMAGE_STENCIL_USAGE_CREATE_INFO: /* Ignore but don't warn */ break; + case VK_STRUCTURE_TYPE_WSI_IMAGE_CREATE_INFO_MESA: + from_wsi = true; + break; default: anv_debug_ignored_stype(s->sType); break; @@ -1414,7 +1422,7 @@ VkResult anv_GetPhysicalDeviceImageFormatProperties2( } result = anv_get_image_format_properties(physical_device, base_info, - &base_props->imageFormatProperties, ycbcr_props); + &base_props->imageFormatProperties, ycbcr_props, from_wsi); if (result != VK_SUCCESS) goto fail; diff --git a/src/intel/vulkan_hasvk/anv_image.c b/src/intel/vulkan_hasvk/anv_image.c index a065330f469..9d10a1ac8f9 100644 --- a/src/intel/vulkan_hasvk/anv_image.c +++ b/src/intel/vulkan_hasvk/anv_image.c @@ -627,7 +627,7 @@ add_aux_surface_if_supported(struct anv_device *device, return VK_SUCCESS; } - if ((image->vk.create_flags & VK_IMAGE_CREATE_ALIAS_BIT)) { + if ((image->vk.create_flags & VK_IMAGE_CREATE_ALIAS_BIT) && !image->from_wsi) { /* The image may alias a plane of a multiplanar image. Above we ban * CCS on multiplanar images. * @@ -855,6 +855,7 @@ check_memory_bindings(const struct anv_device *device, * live in a VkDeviceMemory. The one exception is swapchain images. */ assert(!(image->vk.create_flags & VK_IMAGE_CREATE_ALIAS_BIT) || + image->from_wsi || image->bindings[ANV_IMAGE_MEMORY_BINDING_PRIVATE].memory_range.size == 0); /* Check primary surface */ @@ -1277,6 +1278,8 @@ anv_image_init(struct anv_device *device, struct anv_image *image, } image->n_planes = anv_get_format_planes(image->vk.format); + image->from_wsi = + vk_find_struct_const(pCreateInfo->pNext, WSI_IMAGE_CREATE_INFO_MESA) != NULL; /* The Vulkan 1.2.165 glossary says: * diff --git a/src/intel/vulkan_hasvk/anv_private.h b/src/intel/vulkan_hasvk/anv_private.h index f82e6acd8e4..cae98d2513e 100644 --- a/src/intel/vulkan_hasvk/anv_private.h +++ b/src/intel/vulkan_hasvk/anv_private.h @@ -3239,6 +3239,11 @@ struct anv_image { */ bool disjoint; + /** + * Image is a WSI image + */ + bool from_wsi; + /** * Image was imported from an struct AHardwareBuffer. We have to delay * final image creation until bind time.