minigbm: amdgpu: Update plane count in bo_import

This is required for importing multi-plane modifiers where the
format plane count is lower (usually `1`). It will be used
by Exo for v3/4 of the `zwp_linux_dmabuf_v1` Wayland potocol,
allowing Wayland clients (and thus all clients that build on
the Wayland support) to use explicit modifiers which again
can increase performance on many GPUs.

Also add another fallback path to `dri_num_planes_from_modifier()`
for cases when `queryDmaBufFormatModifierAttribs()` fails and do
some refactoring there. Without this, some test apparently fail.

This includes the amdgpu part of
commit 1a733377e91b9e714541ea1f51e1f5808b32897c, partially reverting
commit 853b8542fbf5711cca4b00d0e30cd3e559c925fd.

Bug:b:224580219
Change-Id: I93b64123420b39f3b83ff1bbbb9c59ddf4bc6105
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/minigbm/+/3568489
Reviewed-by: Bas Nieuwenhuizen <basni@chromium.org>
Tested-by: Robert Mader <robert.mader@collabora.com>
Commit-Queue: Robert Mader <robert.mader@collabora.com>
diff --git a/amdgpu.c b/amdgpu.c
index f0053d6..700a8c7 100644
--- a/amdgpu.c
+++ b/amdgpu.c
@@ -625,6 +625,9 @@
 		dri_tiling = combo->metadata.tiling != TILE_TYPE_LINEAR;
 	}
 
+	bo->meta.num_planes = dri_num_planes_from_modifier(bo->drv, data->format,
+		data->format_modifier);
+
 	if (dri_tiling)
 		return dri_bo_import(bo, data);
 	else
diff --git a/dri.c b/dri.c
index ea8c757..7257c31 100644
--- a/dri.c
+++ b/dri.c
@@ -452,19 +452,18 @@
 size_t dri_num_planes_from_modifier(struct driver *drv, uint32_t format, uint64_t modifier)
 {
 	struct dri_driver *dri = drv->priv;
-	if (!dri->image_extension->queryDmaBufFormatModifierAttribs) {
-		/* We do not do any modifier checks here. The create will fail
-		 * later if the modifier is not supported. */
-		return drv_num_planes_from_format(format);
-	}
+	uint64_t planes = 0;
 
-	uint64_t planes;
-	unsigned char ret = dri->image_extension->queryDmaBufFormatModifierAttribs(
-	    dri->device, format, modifier, __DRI_IMAGE_FORMAT_MODIFIER_ATTRIB_PLANE_COUNT, &planes);
-	if (!ret)
-		return 0;
+	/* We do not do any modifier checks here. The create will fail later if the modifier is not
+	 * supported.
+	 */
+	if (dri->image_extension->queryDmaBufFormatModifierAttribs &&
+	    dri->image_extension->queryDmaBufFormatModifierAttribs(
+		dri->device, format, modifier, __DRI_IMAGE_FORMAT_MODIFIER_ATTRIB_PLANE_COUNT,
+		&planes))
+		return planes;
 
-	return planes;
+	return drv_num_planes_from_format(format);
 }
 
 bool dri_query_modifiers(struct driver *drv, uint32_t format, int max, uint64_t *modifiers,