Skip to contentSkip to conversation

dri: Rework planar image interface

PATCH New Jakob Bornecrantz 1 participant 1 message Aug 25, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 dri: Rework planar image interface

As discussed with Kristian on #wayland. Pushes the decision of components into the dri driver giving it greater freedom to allow t to implement YUV samplers in hardware, and which mode to use.

This interface will also allow drivers like SVGA to implement YUV surfaces without the need to sub-allocate and instead send 3 seperate buffers for each channel, currently not implemented.

This is only the dri interface and gallium dri state tracker parts of the changes needed to make this change work, I haven't done the intel parts of them and I'll do these tomorrow or monday, I wanted to get the dri- interface changes out as fast as possible for review.

I have tested these changes on SVGA with the previus patch series I sent out (mines the last one), and everything seem to work just as before.

Cheers, Jakob.

---
 include/GL/internal/dri_interface.h                |   67 +++++++++-
 src/egl/drivers/dri2/egl_dri2.c                    |  128 ++++++--------------
 src/gallium/state_trackers/dri/common/dri_screen.h |    1 +
 src/gallium/state_trackers/dri/drm/dri2.c          |   79 +++++++++++-
 src/gbm/backends/dri/gbm_dri.c                     |   33 ++---
 5 files changed, 193 insertions(+), 115 deletions(-)
include/GL/internal/dri_interface.h +63 -4
index 09f63ff..1e0f1d0 100644
@@ -923,6 +923,10 @@ struct __DRIdri2ExtensionRec {
  * __DRI_IMAGE_FORMAT_NONE is for images that aren't directly usable
  * by the driver (YUV planar formats) but serve as a base image for
  * creating sub-images for the different planes within the image.
+ *
+ * R8, GR88 and NONE should not be used with createImageFormName or
+ * createImage, and are returned by query from sub images created with
+ * createImageFromNames (NONE, see above) and fromPlane (R8 & GR88).
  */
 #define __DRI_IMAGE_FORMAT_RGB565       0x1001
 #define __DRI_IMAGE_FORMAT_XRGB8888     0x1002
@@ -937,6 +941,49 @@ struct __DRIdri2ExtensionRec {
 #define __DRI_IMAGE_USE_SCANOUT		0x0002
 #define __DRI_IMAGE_USE_CURSOR		0x0004 /* Depricated */
 
+
+/**
+ * Four CC formats that matches with WL_DRM_FORMAT_* from wayland_drm.h
+ * and GBM_FORMAT_* from gbm.h, used with createImageFromNames.
+ *
+ * \since 5
+ */
+
+#define __DRI_IMAGE_FOURCC_RGB565	0x36314752
+#define __DRI_IMAGE_FOURCC_ARGB8888	0x34325241
+#define __DRI_IMAGE_FOURCC_XRGB8888	0x34325258
+#define __DRI_IMAGE_FOURCC_ABGR8888	0x34324241
+#define __DRI_IMAGE_FOURCC_XBGR8888	0x34324258
+#define __DRI_IMAGE_FOURCC_YUV410	0x39565559
+#define __DRI_IMAGE_FOURCC_YUV411	0x31315559
+#define __DRI_IMAGE_FOURCC_YUV420	0x32315559
+#define __DRI_IMAGE_FOURCC_YUV422	0x36315559
+#define __DRI_IMAGE_FOURCC_YUV444	0x34325559
+#define __DRI_IMAGE_FOURCC_NV12		0x3231564e
+#define __DRI_IMAGE_FOURCC_NV16		0x3631564e
+#define __DRI_IMAGE_FOURCC_YUYV		0x56595559
+
+
+/**
+ * Queryable on images created by createImageFromNames.
+ *
+ * RGB and RGBA are may be usable directly as images but its still
+ * recommended to call fromPlanar with plane == 0.
+ *
+ * Y_U_V, Y_UV and Y_XUXV all requires call to fromPlanar to create
+ * usable sub-images, sampling from images return raw YUV data and
+ * color conversion needs to be done in the shader.
+ *
+ * \since 5
+ */
+
+#define __DRI_IMAGE_COMPONENTS_RGB	0x3001
+#define __DRI_IMAGE_COMPONENTS_RGBA	0x3002
+#define __DRI_IMAGE_COMPONENTS_Y_U_V	0x3003
+#define __DRI_IMAGE_COMPONENTS_Y_UV	0x3004
+#define __DRI_IMAGE_COMPONENTS_Y_XUXV	0x3005
+
+
 /**
  * queryImage attributes
  */
@@ -947,6 +994,7 @@ struct __DRIdri2ExtensionRec {
 #define __DRI_IMAGE_ATTRIB_FORMAT	0x2003 /* available in versions 3+ */
 #define __DRI_IMAGE_ATTRIB_WIDTH	0x2004 /* available in versions 4+ */
 #define __DRI_IMAGE_ATTRIB_HEIGHT	0x2005
+#define __DRI_IMAGE_ATTRIB_COMPONENTS	0x2006 /* available in versions 5+ */
 
 typedef struct __DRIimageRec          __DRIimage;
 typedef struct __DRIimageExtensionRec __DRIimageExtension;
@@ -984,6 +1032,19 @@ struct __DRIimageExtensionRec {
    GLboolean (*validateUsage)(__DRIimage *image, unsigned int use);
 
    /**
+    * Unlike createImageFromName __DRI_IMAGE_FORMAT is not but instead
+    * __DRI_IMAGE_FOURCC and strides are in bytes not pixels. Stride is
+    * also per block and not per pixel (for non-RGB, see gallium blocks).
+    *
+    * \since 5
+    */
+   __DRIimage *(*createImageFromNames)(__DRIscreen *screen,
+                                       int width, int height, int fourcc,
+                                       int *names, int num_names,
+                                       int *strides, int *offsets,
+                                       void *loaderPrivate);
+
+   /**
     * Create an image out of a sub-region of a parent image.  This
     * entry point lets us create individual __DRIimages for different
     * planes in a planar buffer (typically yuv), for example.  While a
@@ -998,10 +1059,8 @@ struct __DRIimageExtensionRec {
     *
     * \since 5
     */
-    __DRIimage *(*createSubImage)(__DRIimage *image,
-                                  int width, int height, int format,
-                                  int offset, int pitch,
-                                  void *loaderPrivate);
+    __DRIimage *(*fromPlanar)(__DRIimage *image, int plane,
+                              void *loaderPrivate);
 };
 
 
src/egl/drivers/dri2/egl_dri2.c +38 -90

167 lines not on this page · raw message

src/gallium/state_trackers/dri/common/dri_screen.h +1 -0
index 2818e9c..ff48b02 100644
@@ -86,6 +86,7 @@ struct __DRIimageRec {
    unsigned level;
    unsigned layer;
    uint32_t dri_format;
+   uint32_t dri_components;
 
    void *loader_private;
 };
src/gallium/state_trackers/dri/drm/dri2.c +78 -1

115 lines not on this page · raw message

src/gbm/backends/dri/gbm_dri.c +13 -20
index 1831f13..d8b1cc7 100644
@@ -363,7 +363,7 @@ gbm_dri_bo_import(struct gbm_device *gbm,
    struct gbm_dri_bo *bo;
    __DRIimage *image;
    unsigned dri_use = 0;
-   int dri_format, width, height, gbm_format, stride, cpp, offset;
+   int gbm_format;
 
    /* Required for query image WIDTH & HEIGHT */
    if (dri->image->base.version < 4)
@@ -376,20 +376,15 @@ gbm_dri_bo_import(struct gbm_device *gbm,
       struct wl_drm_buffer *wb = (struct wl_drm_buffer *) buffer;
 
       image = wb->driver_buffer;
-      stride = wb->stride[0];
-      offset = wb->offset[0];
-      cpp = 4;
+
       switch (wb->format) {
       case WL_DRM_FORMAT_XRGB8888:
-         dri_format = __DRI_IMAGE_FORMAT_XRGB8888;
          gbm_format = GBM_FORMAT_XRGB8888;
          break;
       case WL_DRM_FORMAT_ARGB8888:
-         dri_format = __DRI_IMAGE_FORMAT_ARGB8888;
          gbm_format = GBM_FORMAT_ARGB8888;
          break;
       case WL_DRM_FORMAT_YUYV:
-         dri_format = __DRI_IMAGE_FORMAT_ARGB8888;
          gbm_format = GBM_FORMAT_YUYV;
          break;
       default:
@@ -401,15 +396,15 @@ gbm_dri_bo_import(struct gbm_device *gbm,
 
    case GBM_BO_IMPORT_EGL_IMAGE:
    {
+      int dri_format;
       if (dri->lookup_image == NULL)
          return NULL;
 
       image = dri->lookup_image(dri->screen, buffer, dri->lookup_user_data);
       dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_FORMAT, &dri_format);
       gbm_format = gbm_dri_to_gbm_format(dri_format);
-      dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_STRIDE, &stride);
-      offset = 0;
-      cpp = 4;
+      if (gbm_format == 0)
+         return NULL;
       break;
    }
 
@@ -422,13 +417,7 @@ gbm_dri_bo_import(struct gbm_device *gbm,
    if (bo == NULL)
       return NULL;
 
-   dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_WIDTH, &width);
-   dri->image->queryImage(image, __DRI_IMAGE_ATTRIB_HEIGHT, &height);
-
-   bo->image = dri->image->createSubImage(image,
-                                          width, height, dri_format,
-                                          offset, stride / cpp, NULL);
-
+   bo->image = dri->image->dupImage(image, NULL);
 
    if (usage & GBM_BO_USE_SCANOUT)
       dri_use |= __DRI_IMAGE_USE_SCANOUT;
@@ -441,10 +430,14 @@ gbm_dri_bo_import(struct gbm_device *gbm,
    }
 
    bo->base.base.gbm = gbm;
-   bo->base.base.width = width;
-   bo->base.base.height = height;
-   bo->base.base.stride = stride;
    bo->base.base.format = gbm_format;
+
+   dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_WIDTH,
+                          (int*)&bo->base.base.width);
+   dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_HEIGHT,
+                          (int*)&bo->base.base.height);
+   dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_STRIDE,
+                          (int*)&bo->base.base.stride);
    dri->image->queryImage(bo->image, __DRI_IMAGE_ATTRIB_HANDLE,
                           &bo->base.base.handle.s32);
 
Signature · 1 line
1.7.9.5