Module: Mesa
Branch: main
Commit: ee524e198b54a1acb762f9be7ec47160bb9fde37
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=ee524e198b54a1acb762f9be7ec47160bb9fde37

Author: Nanley Chery <[email protected]>
Date:   Wed Dec 27 17:06:52 2023 -0500

iris: Fix lowered images in get_main_plane_for_plane

This function was recently simplified based on the idea that if a
modifier is not present, then the plane count should not exceed the
plane count of the resource's external format. This seems to be true
except for lowered images. We don't enable compression modifiers on
lowered images, so this case was not handled during the transition.

As an example of the lowering that may occur: PIPE_FORMAT_YVYU is a
single plane, subsampled format that the gallium layer lowers to two
planes/formats (R8G8_UNORM and B8G8R8A8_UNORM) if not natively supported
by the hardware.

Fixes the assert failure when running the piglit test case:

   ext_image_dma_buf_import-sample_yuv -fmt=YVYU -auto

   ext_image_dma_buf_import-sample_yuv:
      ../../src/gallium/drivers/iris/iris_resource.c:1384:
   iris_resource_from_handle:
      Assertion `main_res->aux.surf.row_pitch_B ==
                 plane_res->surf.row_pitch_B' failed.

Also, replaces it with a new one in case this fails again:

   ext_image_dma_buf_import-sample_yuv:
      ../../src/gallium/drivers/iris/iris_resource.c:1381:
   iris_resource_from_handle:
      Assertion `isl_drm_modifier_has_aux(whandle->modifier)' failed.

Fixes: 79222e5884f ("iris: Simplify get_main_plane_for_plane")
Reviewed-by: Lionel Landwerlin <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26826>

---

 src/gallium/drivers/iris/iris_resource.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/src/gallium/drivers/iris/iris_resource.c 
b/src/gallium/drivers/iris/iris_resource.c
index f3cc5cdf248..6c3ffefa7d5 100644
--- a/src/gallium/drivers/iris/iris_resource.c
+++ b/src/gallium/drivers/iris/iris_resource.c
@@ -1315,8 +1315,19 @@ static unsigned
 get_main_plane_for_plane(enum pipe_format format,
                          unsigned plane)
 {
-   unsigned int n_planes = util_format_get_num_planes(format);
-   return plane % n_planes;
+   if (format == PIPE_FORMAT_NONE) {
+      /* Created dmabuf resources have this format. */
+      return 0;
+   } else if (isl_format_for_pipe_format(format) == ISL_FORMAT_UNSUPPORTED) {
+      /* This format has been lowered to more planes than are native to it.
+       * So, compression modifiers are not enabled and the plane index is used
+       * as-is.
+       */
+      return plane;
+   } else {
+      unsigned int n_planes = util_format_get_num_planes(format);
+      return plane % n_planes;
+   }
 }
 
 static struct pipe_resource *
@@ -1378,6 +1389,7 @@ iris_resource_from_handle(struct pipe_screen *pscreen,
             main_res->aux.clear_color_unknown = true;
          } else if (plane > main_plane) {
             /* Fill out some aux surface fields. */
+            assert(isl_drm_modifier_has_aux(whandle->modifier));
             assert(!devinfo->has_flat_ccs);
             assert(plane_res->bo->size >= plane_res->offset +
                    main_res->aux.surf.size_B);

Reply via email to