anv: Stop assuming planes are in aspect-bit-order
authorJason Ekstrand <jason@jlekstrand.net>
Fri, 30 Jul 2021 21:58:22 +0000 (16:58 -0500)
committerMarge Bot <eric+marge@anholt.net>
Mon, 9 Aug 2021 16:07:23 +0000 (16:07 +0000)
Previously, we initialized vplane in anv_CreateImageView to 0 and
incremented it every iteration of the aspect loop.  This only works
because planes are guaranteed to be in aspect-bit-order which wasn't
documented anywhere.  Instead, drop this assumption and burn a couple
CPU cycles properly calculating vplane.

While we're here, make iplane const as well.

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

index ffb618d..5c2c682 100644 (file)
@@ -2812,10 +2812,11 @@ anv_CreateImageView(VkDevice _device,
    /* Now go through the underlying image selected planes (computed in
     * expanded_aspects) and map them to planes in the image view.
     */
-   uint32_t vplane = 0;
    anv_foreach_image_aspect_bit(iaspect_bit, image, expanded_aspects) {
-      uint32_t iplane =
+      const uint32_t iplane =
          anv_image_aspect_to_plane(image->aspects, 1UL << iaspect_bit);
+      const uint32_t vplane =
+         anv_image_aspect_to_plane(expanded_aspects, 1UL << iaspect_bit);
       struct anv_format_plane format;
       if (image->aspects & (VK_IMAGE_ASPECT_DEPTH_BIT |
                             VK_IMAGE_ASPECT_STENCIL_BIT)) {
@@ -2946,8 +2947,6 @@ anv_CreateImageView(VkDevice _device,
                                       &iview->planes[vplane].writeonly_storage_surface_state,
                                       NULL);
       }
-
-      vplane++;
    }
 
    *pView = anv_image_view_to_handle(iview);