vulkan: make sure vk_image_view::format is never UNDEFINED
authorChia-I Wu <olvaffe@gmail.com>
Fri, 21 Apr 2023 05:09:26 +0000 (22:09 -0700)
committerMarge Bot <emma+marge@anholt.net>
Thu, 11 May 2023 22:18:02 +0000 (22:18 +0000)
Remove redundant override in anv and hasvk as well.

Fixed
android.graphics.cts.BasicVulkanGpuTest#testBasicBufferImportAndRenderingExternalFormat
for radv.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22619>

src/intel/vulkan/anv_image.c
src/intel/vulkan_hasvk/anv_image.c
src/vulkan/runtime/vk_image.c
src/vulkan/runtime/vk_image.h

index b74dda1..477fb08 100644 (file)
@@ -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.
     */
index 48b49ae..c14d34d 100644 (file)
@@ -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.
     */
index cd8d25b..e8af0e8 100644 (file)
@@ -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;
       }
    }
 
index 0b556f0..79541fb 100644 (file)
@@ -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