gbm: Don't pass default usage flags on ABIs < 1
authorJames Jones <jajones@nvidia.com>
Fri, 19 Nov 2021 19:50:18 +0000 (11:50 -0800)
committerMarge Bot <emma+marge@anholt.net>
Wed, 8 Dec 2021 09:49:47 +0000 (09:49 +0000)
Older drivers will not expect any flags from the
GBM front-end when modifiers are in use, and will
likely fail the allocation or handle them
incorrectly as a result. Only specify usage flags
when allocating from a backend with an ABI >= 1,
as that's the ABI version that added support for
specifying usage flags along with modifiers.

Fixes: ad50b47a14e9 ("gbm: assume USE_SCANOUT in create_with_modifiers")
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/5709
Signed-off-by: James Jones <jajones@nvidia.com>
Reviewed-by: Simon Ser <contact@emersion.fr>
Tested-by: Olivier Fourdan <ofourdan@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/14049>

src/gbm/main/gbm.c

index 476a03c..6b1b324 100644 (file)
@@ -500,8 +500,22 @@ gbm_bo_create_with_modifiers(struct gbm_device *gbm,
                              const uint64_t *modifiers,
                              const unsigned int count)
 {
+   uint32_t flags = 0;
+
+   /*
+    * ABI version 1 added the modifiers+flags capability. Backends from
+    * prior versions may fail if "unknown" flags are provided along with
+    * modifiers, but assume scanout is required when modifiers are used.
+    * Newer backends expect scanout to be explicitly requested if required,
+    * but applications using this older interface rely on the older implied
+    * requirement, so that behavior must be preserved.
+    */
+   if (gbm->v0.backend_version >= 1) {
+      flags |= GBM_BO_USE_SCANOUT;
+   }
+
    return gbm_bo_create_with_modifiers2(gbm, width, height, format, modifiers,
-                                        count, GBM_BO_USE_SCANOUT);
+                                        count, flags);
 }
 
 GBM_EXPORT struct gbm_bo *
@@ -651,9 +665,23 @@ gbm_surface_create_with_modifiers(struct gbm_device *gbm,
                                   const uint64_t *modifiers,
                                   const unsigned int count)
 {
+   uint32_t flags = 0;
+
+   /*
+    * ABI version 1 added the modifiers+flags capability. Backends from
+    * prior versions may fail if "unknown" flags are provided along with
+    * modifiers, but assume scanout is required when modifiers are used.
+    * Newer backends expect scanout to be explicitly requested if required,
+    * but applications using this older interface rely on the older implied
+    * requirement, so that behavior must be preserved.
+    */
+   if (gbm->v0.backend_version >= 1) {
+      flags |= GBM_BO_USE_SCANOUT;
+   }
+
    return gbm_surface_create_with_modifiers2(gbm, width, height, format,
                                              modifiers, count,
-                                             GBM_BO_USE_SCANOUT);
+                                             flags);
 }
 
 GBM_EXPORT struct gbm_surface *