anv: Use anv_get_format_plane for color image view setup
authorJason Ekstrand <jason@jlekstrand.net>
Fri, 30 Jul 2021 11:59:53 +0000 (06:59 -0500)
committerMarge Bot <eric+marge@anholt.net>
Mon, 9 Aug 2021 16:07:23 +0000 (16:07 +0000)
When creating a single-plane view of a multi-plane image, we were
relying on vplane_aspect to be VK_IMAGE_ASPECT_COLOR_BIT so that
anv_get_format_plane of the single-plane view format would work.
Instead of relying on this quirk, we can drop vplane_aspect and rely
entirely on vplane to only be 0 in this case.  In the case of depth or
stencil images, we still need to grab the format aspect but we can use
the actual aspect and don't need the vplane_aspect trickery.

Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12141>

src/intel/vulkan/anv_image.c
src/intel/vulkan/anv_private.h

index bd8e674..ffb618d 100644 (file)
@@ -2816,11 +2816,37 @@ anv_CreateImageView(VkDevice _device,
    anv_foreach_image_aspect_bit(iaspect_bit, image, expanded_aspects) {
       uint32_t iplane =
          anv_image_aspect_to_plane(image->aspects, 1UL << iaspect_bit);
-      VkImageAspectFlags vplane_aspect =
-         anv_plane_to_aspect(iview->aspect_mask, vplane);
-      struct anv_format_plane format =
-         anv_get_format_aspect(&device->info, iview->vk_format,
-                               vplane_aspect, image->tiling);
+      struct anv_format_plane format;
+      if (image->aspects & (VK_IMAGE_ASPECT_DEPTH_BIT |
+                            VK_IMAGE_ASPECT_STENCIL_BIT)) {
+         /* With depth/stencil images, we're always given the full
+          * depth/stencil format even if we're only taking one aspect.
+          */
+         assert(iview->vk_format == image->vk_format);
+         format = anv_get_format_aspect(&device->info, iview->vk_format,
+                                        1u << iaspect_bit, image->tiling);
+      } else {
+         /* With color images, we have three cases:
+          *
+          *  1. It's a single-plane image in which case vplane=0.
+          *
+          *  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
+          *     format provided will be the full planar format.  In this case,
+          *     we want all the planes.
+          *
+          *  3. It's a single-plane view of a multi-plane image in which case
+          *     the client will have asked for VK_IMAGE_ASPECT_PLANE_N_BIT and
+          *     will have provided a format compatible with that specific
+          *     plane of the multi-planar format.
+          *
+          * In all three cases, the format provided by the client corresponds
+          * to exactly the planes we have in the view so we can just grab the
+          * format plane based on vplane.
+          */
+         format = anv_get_format_plane(&device->info, iview->vk_format,
+                                       vplane, image->tiling);
+      }
 
       iview->planes[vplane].image_plane = iplane;
 
index 8e7909c..e89bdd5 100644 (file)
@@ -3809,21 +3809,6 @@ anv_image_aspect_to_plane(VkImageAspectFlags image_aspects,
    }
 }
 
-static inline VkImageAspectFlags
-anv_plane_to_aspect(VkImageAspectFlags image_aspects,
-                    uint32_t plane)
-{
-   if (image_aspects & VK_IMAGE_ASPECT_ANY_COLOR_BIT_ANV) {
-      if (util_bitcount(image_aspects) > 1)
-         return VK_IMAGE_ASPECT_PLANE_0_BIT << plane;
-      return VK_IMAGE_ASPECT_COLOR_BIT;
-   }
-   if (image_aspects & VK_IMAGE_ASPECT_DEPTH_BIT)
-      return VK_IMAGE_ASPECT_DEPTH_BIT << plane;
-   assert(image_aspects == VK_IMAGE_ASPECT_STENCIL_BIT);
-   return VK_IMAGE_ASPECT_STENCIL_BIT;
-}
-
 #define anv_foreach_image_aspect_bit(b, image, aspects) \
    u_foreach_bit(b, anv_image_expand_aspects(image, aspects))