[Mesa-dev] [PATCH v13 11/36] st/dri: implement createImageWithModifiers in DRIimage

Daniel Stone daniels at collabora.com
Fri May 19 09:37:54 UTC 2017


From: Varad Gautam <varad.gautam at collabora.com>

adds a pscreen->resource_create_with_modifiers() to create textures
with modifier.

Signed-off-by: Varad Gautam <varad.gautam at collabora.com>
Signed-off-by: Daniel Stone <daniels at collabora.com>
---
 src/gallium/include/pipe/p_screen.h   | 18 ++++++++
 src/gallium/state_trackers/dri/dri2.c | 79 ++++++++++++++++++++++++++++-------
 2 files changed, 81 insertions(+), 16 deletions(-)

diff --git a/src/gallium/include/pipe/p_screen.h b/src/gallium/include/pipe/p_screen.h
index 8b4239c61a..8eddf355d7 100644
--- a/src/gallium/include/pipe/p_screen.h
+++ b/src/gallium/include/pipe/p_screen.h
@@ -328,6 +328,24 @@ struct pipe_screen {
     * driver doesn't support an on-disk shader cache.
     */
    struct disk_cache *(*get_disk_shader_cache)(struct pipe_screen *screen);
+
+   /**
+    * Create a new texture object from the given template info, taking
+    * format modifiers into account. \p modifiers specifies a list of format
+    * modifier tokens, as defined in drm_fourcc.h. The driver then picks the
+    * best modifier among these and creates the resource. \p count must
+    * contain the size of \p modifiers array. The selected modifier is
+    * returned via \p modifier after a successful call.
+    *
+    * Returns NULL if an entry in \p modifiers is unsupported by the driver,
+    * or if only DRM_FORMAT_MOD_INVALID is provided.
+    */
+   struct pipe_resource * (*resource_create_with_modifiers)(
+                           struct pipe_screen *,
+                           const struct pipe_resource *templat,
+                           const uint64_t *modifiers, int count,
+                           uint64_t *modifier);
+
 };
 
 
diff --git a/src/gallium/state_trackers/dri/dri2.c b/src/gallium/state_trackers/dri/dri2.c
index 7614474e4a..713f482181 100644
--- a/src/gallium/state_trackers/dri/dri2.c
+++ b/src/gallium/state_trackers/dri/dri2.c
@@ -977,27 +977,38 @@ dri2_create_image_from_renderbuffer(__DRIcontext *context,
 }
 
 static __DRIimage *
-dri2_create_image(__DRIscreen *_screen,
-                   int width, int height, int format,
-                   unsigned int use, void *loaderPrivate)
+dri2_create_image_common(__DRIscreen *_screen,
+                         int width, int height,
+                         int format, unsigned int use,
+                         const uint64_t *modifiers,
+                         const unsigned count,
+                         void *loaderPrivate)
 {
    struct dri_screen *screen = dri_screen(_screen);
    __DRIimage *img;
    struct pipe_resource templ;
    unsigned tex_usage;
    enum pipe_format pf;
+   uint64_t modifier = DRM_FORMAT_MOD_INVALID;
+
+   /* createImageWithModifiers doesn't supply usage, and we should not get
+    * here with both modifiers and a usage flag.
+    */
+   assert(!(use && (modifiers != NULL)));
 
    tex_usage = PIPE_BIND_RENDER_TARGET | PIPE_BIND_SAMPLER_VIEW;
-   if (use & __DRI_IMAGE_USE_SCANOUT)
-      tex_usage |= PIPE_BIND_SCANOUT;
-   if (use & __DRI_IMAGE_USE_SHARE)
-      tex_usage |= PIPE_BIND_SHARED;
-   if (use & __DRI_IMAGE_USE_LINEAR)
-      tex_usage |= PIPE_BIND_LINEAR;
-   if (use & __DRI_IMAGE_USE_CURSOR) {
-      if (width != 64 || height != 64)
-         return NULL;
-      tex_usage |= PIPE_BIND_CURSOR;
+   if (use) {
+      if (use & __DRI_IMAGE_USE_SCANOUT)
+         tex_usage |= PIPE_BIND_SCANOUT;
+      if (use & __DRI_IMAGE_USE_SHARE)
+         tex_usage |= PIPE_BIND_SHARED;
+      if (use & __DRI_IMAGE_USE_LINEAR)
+         tex_usage |= PIPE_BIND_LINEAR;
+      if (use & __DRI_IMAGE_USE_CURSOR) {
+         if (width != 64 || height != 64)
+            return NULL;
+         tex_usage |= PIPE_BIND_CURSOR;
+      }
    }
 
    pf = dri2_format_to_pipe_format (format);
@@ -1018,7 +1029,16 @@ dri2_create_image(__DRIscreen *_screen,
    templ.depth0 = 1;
    templ.array_size = 1;
 
-   img->texture = screen->base.screen->resource_create(screen->base.screen, &templ);
+   if (modifiers)
+      img->texture = screen->base.screen
+                        ->resource_create_with_modifiers(screen->base.screen,
+                                                         &templ,
+                                                         modifiers,
+                                                         count,
+                                                         &modifier);
+   else
+      img->texture = screen->base.screen
+                        ->resource_create(screen->base.screen, &templ);
    if (!img->texture) {
       FREE(img);
       return NULL;
@@ -1029,12 +1049,34 @@ dri2_create_image(__DRIscreen *_screen,
    img->dri_format = format;
    img->dri_components = 0;
    img->use = use;
-   img->modifier = DRM_FORMAT_MOD_INVALID;
+   img->modifier = modifier;
 
    img->loader_private = loaderPrivate;
    return img;
 }
 
+static __DRIimage *
+dri2_create_image(__DRIscreen *_screen,
+                   int width, int height, int format,
+                   unsigned int use, void *loaderPrivate)
+{
+   return dri2_create_image_common(_screen, width, height, format, use,
+                                   NULL /* modifiers */, 0 /* count */,
+                                   loaderPrivate);
+}
+
+static __DRIimage *
+dri2_create_image_with_modifiers(__DRIscreen *dri_screen,
+                                 int width, int height, int format,
+                                 const uint64_t *modifiers,
+                                 const unsigned count,
+                                 void *loaderPrivate)
+{
+   return dri2_create_image_common(dri_screen, width, height, format,
+                                   0 /* use */, modifiers, count,
+                                   loaderPrivate);
+}
+
 static GLboolean
 dri2_query_image(__DRIimage *image, int attrib, int *value)
 {
@@ -1432,7 +1474,7 @@ dri2_get_capabilities(__DRIscreen *_screen)
 
 /* The extension is modified during runtime if DRI_PRIME is detected */
 static __DRIimageExtension dri2ImageExtension = {
-    .base = { __DRI_IMAGE, 12 },
+    .base = { __DRI_IMAGE, 14 },
 
     .createImageFromName          = dri2_create_image_from_name,
     .createImageFromRenderbuffer  = dri2_create_image_from_renderbuffer,
@@ -1450,6 +1492,7 @@ static __DRIimageExtension dri2ImageExtension = {
     .getCapabilities              = dri2_get_capabilities,
     .mapImage                     = dri2_map_image,
     .unmapImage                   = dri2_unmap_image,
+    .createImageWithModifiers     = NULL,
 };
 
 
@@ -1998,6 +2041,10 @@ dri2_init_screen(__DRIscreen * sPriv)
       }
    }
 
+   if (pscreen->resource_create_with_modifiers)
+      dri2ImageExtension.createImageWithModifiers =
+         dri2_create_image_with_modifiers;
+
    if (pscreen->get_param(pscreen, PIPE_CAP_DEVICE_RESET_STATUS_QUERY)) {
       sPriv->extensions = dri_robust_screen_extensions;
       screen->has_reset_status_query = true;
-- 
2.13.0



More information about the mesa-dev mailing list