<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Jan 2, 2017 at 6:37 PM, Ben Widawsky <span dir="ltr"><<a href="mailto:ben@bwidawsk.net" target="_blank">ben@bwidawsk.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">The idea behind modifiers like this is that the user of GBM will have<br>
some mechanism to query what properties the hardware supports for its BO<br>
or surface. This information is directly passed in (and stored) so that<br>
the DRI implementation can create an image with the appropriate<br>
attributes.<br>
<br>
A getter() will be added later so that the user GBM will be able to<br>
query what modifier should be used.<br>
<br>
I've opted to store all modifiers passed in during creation and to make<br>
the determination happen at actual creation time for no reason other<br>
than it seems more flexible.<br>
<br>
v2: Make sure to check if count is non-zero in addition to testing if<br>
calloc fails. (Daniel)<br>
<br>
v3: Remove "usage" and "flags" from modifier creation. Requested by<br>
Kristian.<br>
<br>
Cc: Kristian Høgsberg <<a href="mailto:krh@bitplanet.net">krh@bitplanet.net</a>><br>
Cc: Daniel Stone <<a href="mailto:daniel@fooishbar.org">daniel@fooishbar.org</a>><br>
Signed-off-by: Ben Widawsky <<a href="mailto:ben@bwidawsk.net">ben@bwidawsk.net</a>><br>
Reviewed-by: Eric Engestrom <<a href="mailto:eric.engestrom@imgtec.com">eric.engestrom@imgtec.com</a>><br>
Acked-by: Daniel Stone <<a href="mailto:daniels@collabora.com">daniels@collabora.com</a>><br>
---<br>
 src/egl/drivers/dri2/platform_<wbr>drm.c | 19 +++++++++++++----<br>
 src/gbm/backends/dri/gbm_dri.c      | 41 ++++++++++++++++++++++++++++++<wbr>+------<br>
 src/gbm/gbm-symbols-check           |  2 ++<br>
 src/gbm/main/gbm.c                  | 28 +++++++++++++++++++++++--<br>
 src/gbm/main/gbm.h                  | 12 +++++++++++<br>
 src/gbm/main/gbmint.h               | 16 +++++++++++++--<br>
 6 files changed, 104 insertions(+), 14 deletions(-)<br>
<br>
diff --git a/src/egl/drivers/dri2/<wbr>platform_drm.c b/src/egl/drivers/dri2/<wbr>platform_drm.c<br>
index 20993147c8..86247ecaf3 100644<br>
--- a/src/egl/drivers/dri2/<wbr>platform_drm.c<br>
+++ b/src/egl/drivers/dri2/<wbr>platform_drm.c<br>
@@ -228,10 +228,21 @@ get_back_bo(struct dri2_egl_surface *dri2_surf)<br>
<br>
    if (dri2_surf->back == NULL)<br>
       return -1;<br>
-   if (dri2_surf->back->bo == NULL)<br>
-      dri2_surf->back->bo = gbm_bo_create(&dri2_dpy->gbm_<wbr>dri->base.base,<br>
-                                         surf->base.width, surf->base.height,<br>
-                                         surf->base.format, surf->base.flags);<br>
+   if (dri2_surf->back->bo == NULL) {<br>
+      if (surf->base.modifiers)<br>
+         dri2_surf->back->bo = gbm_bo_create_with_modifiers(&<wbr>dri2_dpy->gbm_dri->base.base,<br>
+                                                            surf->base.width, surf->base.height,<br>
+                                                            surf->base.format,<br>
+                                                            surf->base.modifiers,<br>
+                                                            surf->base.count);<br>
+      else<br>
+         dri2_surf->back->bo = gbm_bo_create(&dri2_dpy->gbm_<wbr>dri->base.base,<br>
+                                             surf->base.width,<br>
+                                             surf->base.height,<br>
+                                             surf->base.format,<br>
+                                             surf->base.flags);<br>
+<br>
+   }<br>
    if (dri2_surf->back->bo == NULL)<br>
       return -1;<br>
<br>
diff --git a/src/gbm/backends/dri/gbm_<wbr>dri.c b/src/gbm/backends/dri/gbm_<wbr>dri.c<br>
index 20bbf27cc3..f0e67b081e 100644<br>
--- a/src/gbm/backends/dri/gbm_<wbr>dri.c<br>
+++ b/src/gbm/backends/dri/gbm_<wbr>dri.c<br>
@@ -958,13 +958,21 @@ free_bo:<br>
 static struct gbm_bo *<br>
 gbm_dri_bo_create(struct gbm_device *gbm,<br>
                   uint32_t width, uint32_t height,<br>
-                  uint32_t format, uint32_t usage)<br>
+                  uint32_t format, uint32_t usage,<br>
+                  const uint64_t *modifiers,<br>
+                  const unsigned int count)<br>
 {<br>
    struct gbm_dri_device *dri = gbm_dri_device(gbm);<br>
    struct gbm_dri_bo *bo;<br>
    int dri_format;<br>
    unsigned dri_use = 0;<br>
<br>
+   /* Callers of this may specify a modifier, or a dri usage, but not both. The<br>
+    * newer modifier interface deprecates the older usage flags. This is the<br>
+    * equivalent of usage NAND count.<br>
+    */<br>
+   assert(~(usage & count));<br></blockquote><div><br></div><div>Again, I don't think this is what you want.  You want "assert(!(usage && count));"<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+<br>
    if (usage & GBM_BO_USE_WRITE || dri->image == NULL)<br>
       return create_dumb(gbm, width, height, format, usage);<br>
<br>
@@ -1023,13 +1031,23 @@ gbm_dri_bo_create(struct gbm_device *gbm,<br>
    dri_use |= __DRI_IMAGE_USE_SHARE;<br>
<br>
    bo->image =<br>
-      dri->image->createImage(dri-><wbr>screen,<br>
-                              width, height,<br>
-                              dri_format, dri_use,<br>
-                              bo);<br>
+      dri->image-><wbr>createImageWithModifiers(dri-><wbr>screen,<br>
+                                           width, height,<br>
+                                           dri_format,<br>
+                                           modifiers, count,<br>
+                                           bo);<br></blockquote><div><br></div><div>Do we want to handle the case where your DRI is too old to have createImageWithModifiers?<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
    if (bo->image == NULL)<br>
       goto failed;<br>
<br>
+   bo->base.base.modifiers = calloc(count, sizeof(*modifiers));<br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+   if (count && !bo->base.base.modifiers) {<br>
+      dri->image->destroyImage(bo-><wbr>image);<br>
+      goto failed;<br>
+   }<br>
+<br>
+   bo->base.base.count = count;<br>
+   memcpy(bo->base.base.<wbr>modifiers, modifiers, count * sizeof(*modifiers));<br>
+<br>
    dri->image->queryImage(bo-><wbr>image, __DRI_IMAGE_ATTRIB_HANDLE,<br>
                           &bo->base.base.handle.s32);<br>
    dri->image->queryImage(bo-><wbr>image, __DRI_IMAGE_ATTRIB_STRIDE,<br>
@@ -1100,7 +1118,8 @@ gbm_dri_bo_unmap(struct gbm_bo *_bo, void *map_data)<br>
 static struct gbm_surface *<br>
 gbm_dri_surface_create(struct gbm_device *gbm,<br>
                        uint32_t width, uint32_t height,<br>
-                      uint32_t format, uint32_t flags)<br>
+                      uint32_t format, uint32_t flags,<br>
+                       const uint64_t *modifiers, const unsigned count)<br>
 {<br>
    struct gbm_dri_surface *surf;<br>
<br>
@@ -1114,6 +1133,15 @@ gbm_dri_surface_create(struct gbm_device *gbm,<br>
    surf->base.format = format;<br>
    surf->base.flags = flags;<br>
<br>
+   surf->base.modifiers = calloc(count, sizeof(*modifiers));<br>
+   if (count && !surf->base.modifiers) {<br></blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+      free(surf);<br>
+      return NULL;<br>
+   }<br>
+<br>
+   surf->base.count = count;<br>
+   memcpy(surf->base.modifiers, modifiers, count * sizeof(*modifiers));<br>
+<br>
    return &surf->base;<br>
 }<br>
<br>
@@ -1122,6 +1150,7 @@ gbm_dri_surface_destroy(struct gbm_surface *_surf)<br>
 {<br>
    struct gbm_dri_surface *surf = gbm_dri_surface(_surf);<br>
<br>
+   free(surf->base.modifiers);<br>
    free(surf);<br>
 }<br>
<br>
diff --git a/src/gbm/gbm-symbols-check b/src/gbm/gbm-symbols-check<br>
index 7ff78ab400..c137c6cd93 100755<br>
--- a/src/gbm/gbm-symbols-check<br>
+++ b/src/gbm/gbm-symbols-check<br>
@@ -8,6 +8,7 @@ gbm_device_is_format_supported<br>
 gbm_device_destroy<br>
 gbm_create_device<br>
 gbm_bo_create<br>
+gbm_bo_create_with_modifiers<br>
 gbm_bo_import<br>
 gbm_bo_map<br>
 gbm_bo_unmap<br>
@@ -27,6 +28,7 @@ gbm_bo_set_user_data<br>
 gbm_bo_get_user_data<br>
 gbm_bo_destroy<br>
 gbm_surface_create<br>
+gbm_surface_create_with_<wbr>modifiers<br>
 gbm_surface_needs_lock_front_<wbr>buffer<br>
 gbm_surface_lock_front_buffer<br>
 gbm_surface_release_buffer<br>
diff --git a/src/gbm/main/gbm.c b/src/gbm/main/gbm.c<br>
index 295f6894eb..64da03b0da 100644<br>
--- a/src/gbm/main/gbm.c<br>
+++ b/src/gbm/main/gbm.c<br>
@@ -369,9 +369,23 @@ gbm_bo_create(struct gbm_device *gbm,<br>
       return NULL;<br>
    }<br>
<br>
-   return gbm->bo_create(gbm, width, height, format, usage);<br>
+   return gbm->bo_create(gbm, width, height, format, usage, NULL, 0);<br>
 }<br>
<br>
+GBM_EXPORT struct gbm_bo *<br>
+gbm_bo_create_with_modifiers(<wbr>struct gbm_device *gbm,<br>
+                             uint32_t width, uint32_t height,<br>
+                             uint32_t format,<br>
+                             const uint64_t *modifiers,<br>
+                             const unsigned int count)<br>
+{<br>
+   if (width == 0 || height == 0) {<br>
+      errno = EINVAL;<br>
+      return NULL;<br>
+   }<br>
+<br>
+   return gbm->bo_create(gbm, width, height, format, 0, modifiers, count);<br>
+}<br>
 /**<br>
  * Create a gbm buffer object from an foreign object<br>
  *<br>
@@ -477,7 +491,17 @@ gbm_surface_create(struct gbm_device *gbm,<br>
                    uint32_t width, uint32_t height,<br>
                   uint32_t format, uint32_t flags)<br>
 {<br>
-   return gbm->surface_create(gbm, width, height, format, flags);<br>
+   return gbm->surface_create(gbm, width, height, format, flags, NULL, 0);<br>
+}<br>
+<br>
+GBM_EXPORT struct gbm_surface *<br>
+gbm_surface_create_with_<wbr>modifiers(struct gbm_device *gbm,<br>
+                                  uint32_t width, uint32_t height,<br>
+                                  uint32_t format, uint32_t flags,<br>
+                                  const uint64_t *modifiers, const unsigned int count)<br>
+{<br>
+   return gbm->surface_create(gbm, width, height, format, flags,<br>
+                              modifiers, count);<br>
 }<br>
<br>
 /**<br>
diff --git a/src/gbm/main/gbm.h b/src/gbm/main/gbm.h<br>
index b089359b01..6390e60d04 100644<br>
--- a/src/gbm/main/gbm.h<br>
+++ b/src/gbm/main/gbm.h<br>
@@ -243,6 +243,12 @@ gbm_bo_create(struct gbm_device *gbm,<br>
               uint32_t width, uint32_t height,<br>
               uint32_t format, uint32_t flags);<br>
<br>
+struct gbm_bo *<br>
+gbm_bo_create_with_modifiers(<wbr>struct gbm_device *gbm,<br>
+                             uint32_t width, uint32_t height,<br>
+                             uint32_t format,<br>
+                             const uint64_t *modifiers,<br>
+                             const unsigned int count);<br>
 #define GBM_BO_IMPORT_WL_BUFFER         0x5501<br>
 #define GBM_BO_IMPORT_EGL_IMAGE         0x5502<br>
 #define GBM_BO_IMPORT_FD                0x5503<br>
@@ -345,6 +351,12 @@ gbm_surface_create(struct gbm_device *gbm,<br>
                    uint32_t width, uint32_t height,<br>
                   uint32_t format, uint32_t flags);<br>
<br>
+struct gbm_surface *<br>
+gbm_surface_create_with_<wbr>modifiers(struct gbm_device *gbm,<br>
+                                  uint32_t width, uint32_t height,<br>
+                                  uint32_t format, uint32_t flags,<br>
+                                  const uint64_t *modifiers,<br>
+                                  const unsigned int count);<br>
 int<br>
 gbm_surface_needs_lock_front_<wbr>buffer(struct gbm_surface *surface);<br>
<br>
diff --git a/src/gbm/main/gbmint.h b/src/gbm/main/gbmint.h<br>
index ac6078361a..cd437df021 100644<br>
--- a/src/gbm/main/gbmint.h<br>
+++ b/src/gbm/main/gbmint.h<br>
@@ -65,7 +65,9 @@ struct gbm_device {<br>
    struct gbm_bo *(*bo_create)(struct gbm_device *gbm,<br>
                                uint32_t width, uint32_t height,<br>
                                uint32_t format,<br>
-                               uint32_t usage);<br>
+                               uint32_t usage,<br>
+                               const uint64_t *modifiers,<br>
+                               const unsigned int count);<br>
    struct gbm_bo *(*bo_import)(struct gbm_device *gbm, uint32_t type,<br>
                                void *buffer, uint32_t usage);<br>
    void *(*bo_map)(struct gbm_bo *bo,<br>
@@ -84,7 +86,9 @@ struct gbm_device {<br>
<br>
    struct gbm_surface *(*surface_create)(struct gbm_device *gbm,<br>
                                          uint32_t width, uint32_t height,<br>
-                                         uint32_t format, uint32_t flags);<br>
+                                         uint32_t format, uint32_t flags,<br>
+                                         const uint64_t *modifiers,<br>
+                                         const unsigned count);<br>
    struct gbm_bo *(*surface_lock_front_buffer)(<wbr>struct gbm_surface *surface);<br>
    void (*surface_release_buffer)(<wbr>struct gbm_surface *surface,<br>
                                   struct gbm_bo *bo);<br>
@@ -103,6 +107,10 @@ struct gbm_bo {<br>
    uint32_t height;<br>
    uint32_t stride;<br>
    uint32_t format;<br>
+   struct {<br>
+      uint64_t *modifiers;<br>
+      unsigned int count;<br>
+   };<br>
    union gbm_bo_handle  handle;<br>
    void *user_data;<br>
    void (*destroy_user_data)(struct gbm_bo *, void *);<br>
@@ -114,6 +122,10 @@ struct gbm_surface {<br>
    uint32_t height;<br>
    uint32_t format;<br>
    uint32_t flags;<br>
+   struct {<br>
+      uint64_t *modifiers;<br>
+      unsigned count;<br>
+   };<br>
 };<br>
<br>
 struct gbm_backend {<br>
<span class="gmail-HOEnZb"><font color="#888888">--<br>
2.11.0<br>
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>