From 5561abcb2cbda8b90bdad592d128d3703b6e01c0 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Thu, 20 Apr 2023 22:09:26 -0700 Subject: [PATCH] vulkan: make sure vk_image_view::format is never UNDEFINED Remove redundant override in anv and hasvk as well. Fixed android.graphics.cts.BasicVulkanGpuTest#testBasicBufferImportAndRenderingExternalFormat for radv. Part-of: --- src/intel/vulkan/anv_image.c | 16 ---------------- src/intel/vulkan_hasvk/anv_image.c | 16 ---------------- src/vulkan/runtime/vk_image.c | 17 ++++++++++------- src/vulkan/runtime/vk_image.h | 5 +++-- 4 files changed, 13 insertions(+), 41 deletions(-) diff --git a/src/intel/vulkan/anv_image.c b/src/intel/vulkan/anv_image.c index b74dda1..477fb08 100644 --- a/src/intel/vulkan/anv_image.c +++ b/src/intel/vulkan/anv_image.c @@ -2649,22 +2649,6 @@ anv_CreateImageView(VkDevice _device, iview->image = image; iview->n_planes = anv_image_aspect_get_planes(iview->vk.aspects); - /* Check if a conversion info was passed. */ - VkFormat conv_format = VK_FORMAT_UNDEFINED; - const VkSamplerYcbcrConversionInfo *conv_info = - vk_find_struct_const(pCreateInfo->pNext, SAMPLER_YCBCR_CONVERSION_INFO); - - if (conv_info) { - VK_FROM_HANDLE(vk_ycbcr_conversion, conversion, conv_info->conversion); - conv_format = conversion->state.format; - } - - /* Format is undefined, this can happen when using external formats. Set - * view format from the passed conversion info. - */ - if (iview->vk.view_format == VK_FORMAT_UNDEFINED && conv_format) - iview->vk.view_format = conv_format; - /* Now go through the underlying image selected planes and map them to * planes in the image view. */ diff --git a/src/intel/vulkan_hasvk/anv_image.c b/src/intel/vulkan_hasvk/anv_image.c index 48b49ae..c14d34d 100644 --- a/src/intel/vulkan_hasvk/anv_image.c +++ b/src/intel/vulkan_hasvk/anv_image.c @@ -2404,22 +2404,6 @@ anv_CreateImageView(VkDevice _device, iview->image = image; iview->n_planes = anv_image_aspect_get_planes(iview->vk.aspects); - /* Check if a conversion info was passed. */ - VkFormat conv_format = VK_FORMAT_UNDEFINED; - const VkSamplerYcbcrConversionInfo *conv_info = - vk_find_struct_const(pCreateInfo->pNext, SAMPLER_YCBCR_CONVERSION_INFO); - - if (conv_info) { - VK_FROM_HANDLE(vk_ycbcr_conversion, conversion, conv_info->conversion); - conv_format = conversion->state.format; - } - - /* Format is undefined, this can happen when using external formats. Set - * view format from the passed conversion info. - */ - if (iview->vk.view_format == VK_FORMAT_UNDEFINED && conv_format) - iview->vk.view_format = conv_format; - /* Now go through the underlying image selected planes and map them to * planes in the image view. */ diff --git a/src/vulkan/runtime/vk_image.c b/src/vulkan/runtime/vk_image.c index cd8d25b..e8af0e8 100644 --- a/src/vulkan/runtime/vk_image.c +++ b/src/vulkan/runtime/vk_image.c @@ -323,7 +323,10 @@ vk_image_view_init(struct vk_device *device, image_view->create_flags = pCreateInfo->flags; image_view->image = image; image_view->view_type = pCreateInfo->viewType; + image_view->format = pCreateInfo->format; + if (image_view->format == VK_FORMAT_UNDEFINED) + image_view->format = image->format; if (!driver_internal) { switch (image_view->view_type) { @@ -356,7 +359,7 @@ vk_image_view_init(struct vk_device *device, if (driver_internal) { image_view->aspects = range->aspectMask; - image_view->view_format = pCreateInfo->format; + image_view->view_format = image_view->format; } else { image_view->aspects = vk_image_expand_aspect_mask(image, range->aspectMask); @@ -382,7 +385,7 @@ vk_image_view_init(struct vk_device *device, */ if ((image->aspects & VK_IMAGE_ASPECT_PLANE_1_BIT) && (range->aspectMask == VK_IMAGE_ASPECT_COLOR_BIT)) - assert(pCreateInfo->format == image->format); + assert(image_view->format == image->format); /* From the Vulkan 1.2.184 spec: * @@ -390,10 +393,10 @@ vk_image_view_init(struct vk_device *device, */ if (image_view->aspects & (VK_IMAGE_ASPECT_DEPTH_BIT | VK_IMAGE_ASPECT_STENCIL_BIT)) - assert(pCreateInfo->format == image->format); + assert(image_view->format == image->format); if (!(image->create_flags & VK_IMAGE_CREATE_MUTABLE_FORMAT_BIT)) - assert(pCreateInfo->format == image->format); + assert(image_view->format == image->format); /* Restrict the format to only the planes chosen. * @@ -416,11 +419,11 @@ vk_image_view_init(struct vk_device *device, * enable sampler Y′CBCR conversion." */ if (image_view->aspects == VK_IMAGE_ASPECT_STENCIL_BIT) { - image_view->view_format = vk_format_stencil_only(pCreateInfo->format); + image_view->view_format = vk_format_stencil_only(image_view->format); } else if (image_view->aspects == VK_IMAGE_ASPECT_DEPTH_BIT) { - image_view->view_format = vk_format_depth_only(pCreateInfo->format); + image_view->view_format = vk_format_depth_only(image_view->format); } else { - image_view->view_format = pCreateInfo->format; + image_view->view_format = image_view->format; } } diff --git a/src/vulkan/runtime/vk_image.h b/src/vulkan/runtime/vk_image.h index 0b556f0..79541fb 100644 --- a/src/vulkan/runtime/vk_image.h +++ b/src/vulkan/runtime/vk_image.h @@ -219,7 +219,7 @@ struct vk_image_view { struct vk_image *image; VkImageViewType view_type; - /** VkImageViewCreateInfo::format */ + /** VkImageViewCreateInfo::format or vk_image::format */ VkFormat format; /** Image view format, relative to the selected aspects @@ -235,7 +235,8 @@ struct vk_image_view { * For color images, we have three cases: * * 1. It's a single-plane image in which case this is the unmodified - * format provided to VkImageViewCreateInfo::format. + * format provided to VkImageViewCreateInfo::format or + * vk_image::format. * * 2. It's a YCbCr view of a multi-plane image in which case the * client will have asked for VK_IMAGE_ASPECT_COLOR_BIT and the -- 2.7.4