[Mesa-dev,1/2] dri: add support for "compute" (tuple-based) formats.

Submitted by Gwenole Beauchesne on March 14, 2014, 6:06 p.m.

Details

Message ID 1394820419-22031-1-git-send-email-gwenole.beauchesne@intel.com
State New
Headers show

Not browsing as part of any series.

Commit Message

Gwenole Beauchesne March 14, 2014, 6:06 p.m.
DRM tuple-based formats are useful to express non-presentable memory
used with dma_buf sharing for EGL or OpenCL interop, but also for planar
YUV surfaces when it is desired to map each of their individual plane
separately.

Note: this also fixes the case where an EGL image is the storage of a
renderbuffer, and that EGL image was created from a texture with a non
traditional format, e.g. GL_RGBA8UI.

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
---
 include/GL/internal/dri_interface.h    |   22 +++++++++
 src/egl/drivers/dri2/egl_dri2.c        |    5 ++
 src/mesa/drivers/dri/common/dri_util.c |   85 ++++++++++++++++++++++++++++++++
 3 files changed, 112 insertions(+)

Patch hide | download patch | download mbox

diff --git a/include/GL/internal/dri_interface.h b/include/GL/internal/dri_interface.h
index d028d05..51c5864 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -1033,6 +1033,17 @@  struct __DRIdri2ExtensionRec {
 #define __DRI_IMAGE_FORMAT_ARGB2101010  0x100a
 #define __DRI_IMAGE_FORMAT_SARGB8       0x100b
 
+#define __DRI_IMAGE_FORMAT_T_UNORM      0x0100
+#define __DRI_IMAGE_FORMAT_T_SINT       0x0200
+#define __DRI_IMAGE_FORMAT_T_UINT       0x0300
+#define __DRI_IMAGE_FORMAT_T_FLOAT      0x0400
+
+/** Generates a DRI image format value for a tuple */
+#define __DRI_IMAGE_FORMAT_TUPLE_I(num_elements, type, size) \
+   (0x2000|(type)|((size)<<4)|(num_elements))
+#define __DRI_IMAGE_FORMAT_TUPLE(num_elements, type, size) \
+   __DRI_IMAGE_FORMAT_TUPLE_I(num_elements, __DRI_IMAGE_FORMAT_T_##type, size)
+
 #define __DRI_IMAGE_USE_SHARE		0x0001
 #define __DRI_IMAGE_USE_SCANOUT		0x0002
 #define __DRI_IMAGE_USE_CURSOR		0x0004 /* Depricated */
@@ -1061,6 +1072,13 @@  struct __DRIdri2ExtensionRec {
 #define __DRI_IMAGE_FOURCC_NV16		0x3631564e
 #define __DRI_IMAGE_FOURCC_YUYV		0x56595559
 
+/** Generates a DRI image FOURCC value for a tuple */
+#define __DRI_IMAGE_FOURCC_TUPLE(num_elements, type, size)      \
+   ((uint32_t)('T') |                                           \
+    ((uint32_t)('0'+(num_elements)) << 8) |                     \
+    ((uint32_t)(type) << 16) |                                  \
+    ((uint32_t)('0'+(size)) << 24))
+
 
 /**
  * Queryable on images created by createImageFromNames.
@@ -1080,6 +1098,10 @@  struct __DRIdri2ExtensionRec {
 #define __DRI_IMAGE_COMPONENTS_Y_U_V	0x3003
 #define __DRI_IMAGE_COMPONENTS_Y_UV	0x3004
 #define __DRI_IMAGE_COMPONENTS_Y_XUXV	0x3005
+#define __DRI_IMAGE_COMPONENTS_X	0x3006
+#define __DRI_IMAGE_COMPONENTS_XY	0x3007
+#define __DRI_IMAGE_COMPONENTS_XYZ	0x3008
+#define __DRI_IMAGE_COMPONENTS_XYZW	0x3009
 
 
 /**
diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 892f1f4..c9878e3 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -1500,6 +1500,11 @@  dri2_check_dma_buf_format(const _EGLImageAttribs *attrs)
       plane_n = 3;
       break;
    default:
+      /* Special formats for compute */
+      if ((attrs->DMABufFourCC.Value & 0xff) == 'T') {
+         plane_n = 1;
+         break;
+      }
       _eglError(EGL_BAD_ATTRIBUTE, "invalid format");
       return 0;
    }
diff --git a/src/mesa/drivers/dri/common/dri_util.c b/src/mesa/drivers/dri/common/dri_util.c
index aed73c7..8e9b425 100644
--- a/src/mesa/drivers/dri/common/dri_util.c
+++ b/src/mesa/drivers/dri/common/dri_util.c
@@ -836,6 +836,46 @@  driGLFormatToImageFormat(mesa_format format)
       return __DRI_IMAGE_FORMAT_NONE;
    case MESA_FORMAT_B8G8R8A8_SRGB:
       return __DRI_IMAGE_FORMAT_SARGB8;
+
+   /* Compute formats */
+   case MESA_FORMAT_R_UNORM16:      return __DRI_IMAGE_FORMAT_TUPLE(1,UNORM,2);
+#if MESA_LITTLE_ENDIAN
+   case MESA_FORMAT_R16G16_UNORM:   return __DRI_IMAGE_FORMAT_TUPLE(2,UNORM,2);
+#else
+   case MESA_FORMAT_G16R16_UNORM:   return __DRI_IMAGE_FORMAT_TUPLE(2,UNORM,2);
+#endif
+   case MESA_FORMAT_R_SINT8:        return __DRI_IMAGE_FORMAT_TUPLE(1,SINT,1);
+   case MESA_FORMAT_R_SINT16:       return __DRI_IMAGE_FORMAT_TUPLE(1,SINT,2);
+   case MESA_FORMAT_R_SINT32:       return __DRI_IMAGE_FORMAT_TUPLE(1,SINT,4);
+   case MESA_FORMAT_RG_SINT8:       return __DRI_IMAGE_FORMAT_TUPLE(2,SINT,1);
+   case MESA_FORMAT_RG_SINT16:      return __DRI_IMAGE_FORMAT_TUPLE(2,SINT,2);
+   case MESA_FORMAT_RG_SINT32:      return __DRI_IMAGE_FORMAT_TUPLE(2,SINT,4);
+   case MESA_FORMAT_RGB_SINT8:      return __DRI_IMAGE_FORMAT_TUPLE(3,SINT,1);
+   case MESA_FORMAT_RGB_SINT16:     return __DRI_IMAGE_FORMAT_TUPLE(3,SINT,2);
+   case MESA_FORMAT_RGB_SINT32:     return __DRI_IMAGE_FORMAT_TUPLE(3,SINT,4);
+   case MESA_FORMAT_RGBA_SINT8:     return __DRI_IMAGE_FORMAT_TUPLE(4,SINT,1);
+   case MESA_FORMAT_RGBA_SINT16:    return __DRI_IMAGE_FORMAT_TUPLE(4,SINT,2);
+   case MESA_FORMAT_RGBA_SINT32:    return __DRI_IMAGE_FORMAT_TUPLE(4,SINT,4);
+   case MESA_FORMAT_R_UINT8:        return __DRI_IMAGE_FORMAT_TUPLE(1,UINT,1);
+   case MESA_FORMAT_R_UINT16:       return __DRI_IMAGE_FORMAT_TUPLE(1,UINT,2);
+   case MESA_FORMAT_R_UINT32:       return __DRI_IMAGE_FORMAT_TUPLE(1,UINT,4);
+   case MESA_FORMAT_RG_UINT8:       return __DRI_IMAGE_FORMAT_TUPLE(2,UINT,1);
+   case MESA_FORMAT_RG_UINT16:      return __DRI_IMAGE_FORMAT_TUPLE(2,UINT,2);
+   case MESA_FORMAT_RG_UINT32:      return __DRI_IMAGE_FORMAT_TUPLE(2,UINT,4);
+   case MESA_FORMAT_RGB_UINT8:      return __DRI_IMAGE_FORMAT_TUPLE(3,UINT,1);
+   case MESA_FORMAT_RGB_UINT16:     return __DRI_IMAGE_FORMAT_TUPLE(3,UINT,2);
+   case MESA_FORMAT_RGB_UINT32:     return __DRI_IMAGE_FORMAT_TUPLE(3,UINT,4);
+   case MESA_FORMAT_RGBA_UINT8:     return __DRI_IMAGE_FORMAT_TUPLE(4,UINT,1);
+   case MESA_FORMAT_RGBA_UINT16:    return __DRI_IMAGE_FORMAT_TUPLE(4,UINT,2);
+   case MESA_FORMAT_RGBA_UINT32:    return __DRI_IMAGE_FORMAT_TUPLE(4,UINT,4);
+   case MESA_FORMAT_R_FLOAT16:      return __DRI_IMAGE_FORMAT_TUPLE(1,FLOAT,2);
+   case MESA_FORMAT_R_FLOAT32:      return __DRI_IMAGE_FORMAT_TUPLE(1,FLOAT,4);
+   case MESA_FORMAT_RG_FLOAT16:     return __DRI_IMAGE_FORMAT_TUPLE(2,FLOAT,2);
+   case MESA_FORMAT_RG_FLOAT32:     return __DRI_IMAGE_FORMAT_TUPLE(2,FLOAT,4);
+   case MESA_FORMAT_RGB_FLOAT16:    return __DRI_IMAGE_FORMAT_TUPLE(3,FLOAT,2);
+   case MESA_FORMAT_RGB_FLOAT32:    return __DRI_IMAGE_FORMAT_TUPLE(3,FLOAT,4);
+   case MESA_FORMAT_RGBA_FLOAT16:   return __DRI_IMAGE_FORMAT_TUPLE(4,FLOAT,2);
+   case MESA_FORMAT_RGBA_FLOAT32:   return __DRI_IMAGE_FORMAT_TUPLE(4,FLOAT,4);
    default:
       return 0;
    }
@@ -867,6 +907,51 @@  driImageFormatToGLFormat(uint32_t image_format)
       return MESA_FORMAT_B8G8R8A8_SRGB;
    case __DRI_IMAGE_FORMAT_NONE:
       return MESA_FORMAT_NONE;
+
+   /* Compute formats */
+   case __DRI_IMAGE_FORMAT_TUPLE(1,UNORM,1): return MESA_FORMAT_R_UNORM8;
+   case __DRI_IMAGE_FORMAT_TUPLE(1,UNORM,2): return MESA_FORMAT_R_UNORM16;
+#if MESA_LITTLE_ENDIAN
+   case __DRI_IMAGE_FORMAT_TUPLE(2,UNORM,1): return MESA_FORMAT_R8G8_UNORM;
+   case __DRI_IMAGE_FORMAT_TUPLE(2,UNORM,2): return MESA_FORMAT_R16G16_UNORM;
+   case __DRI_IMAGE_FORMAT_TUPLE(4,UNORM,1): return MESA_FORMAT_R8G8B8A8_UNORM;
+#else
+   case __DRI_IMAGE_FORMAT_TUPLE(2,UNORM,1): return MESA_FORMAT_G8R8_UNORM;
+   case __DRI_IMAGE_FORMAT_TUPLE(2,UNORM,2): return MESA_FORMAT_G16R16_UNORM;
+   case __DRI_IMAGE_FORMAT_TUPLE(4,UNORM,1): return MESA_FORMAT_A8B8G8R8_UNORM;
+#endif
+   case __DRI_IMAGE_FORMAT_TUPLE(1,SINT,1):     return MESA_FORMAT_R_SINT8;
+   case __DRI_IMAGE_FORMAT_TUPLE(1,SINT,2):     return MESA_FORMAT_R_SINT16;
+   case __DRI_IMAGE_FORMAT_TUPLE(1,SINT,4):     return MESA_FORMAT_R_SINT32;
+   case __DRI_IMAGE_FORMAT_TUPLE(2,SINT,1):     return MESA_FORMAT_RG_SINT8;
+   case __DRI_IMAGE_FORMAT_TUPLE(2,SINT,2):     return MESA_FORMAT_RG_SINT16;
+   case __DRI_IMAGE_FORMAT_TUPLE(2,SINT,4):     return MESA_FORMAT_RG_SINT32;
+   case __DRI_IMAGE_FORMAT_TUPLE(3,SINT,1):     return MESA_FORMAT_RGB_SINT8;
+   case __DRI_IMAGE_FORMAT_TUPLE(3,SINT,2):     return MESA_FORMAT_RGB_SINT16;
+   case __DRI_IMAGE_FORMAT_TUPLE(3,SINT,4):     return MESA_FORMAT_RGB_SINT32;
+   case __DRI_IMAGE_FORMAT_TUPLE(4,SINT,1):     return MESA_FORMAT_RGBA_SINT8;
+   case __DRI_IMAGE_FORMAT_TUPLE(4,SINT,2):     return MESA_FORMAT_RGBA_SINT16;
+   case __DRI_IMAGE_FORMAT_TUPLE(4,SINT,4):     return MESA_FORMAT_RGBA_SINT32;
+   case __DRI_IMAGE_FORMAT_TUPLE(1,UINT,1):     return MESA_FORMAT_R_UINT8;
+   case __DRI_IMAGE_FORMAT_TUPLE(1,UINT,2):     return MESA_FORMAT_R_UINT16;
+   case __DRI_IMAGE_FORMAT_TUPLE(1,UINT,4):     return MESA_FORMAT_R_UINT32;
+   case __DRI_IMAGE_FORMAT_TUPLE(2,UINT,1):     return MESA_FORMAT_RG_UINT8;
+   case __DRI_IMAGE_FORMAT_TUPLE(2,UINT,2):     return MESA_FORMAT_RG_UINT16;
+   case __DRI_IMAGE_FORMAT_TUPLE(2,UINT,4):     return MESA_FORMAT_RG_UINT32;
+   case __DRI_IMAGE_FORMAT_TUPLE(3,UINT,1):     return MESA_FORMAT_RGB_UINT8;
+   case __DRI_IMAGE_FORMAT_TUPLE(3,UINT,2):     return MESA_FORMAT_RGB_UINT16;
+   case __DRI_IMAGE_FORMAT_TUPLE(3,UINT,4):     return MESA_FORMAT_RGB_UINT32;
+   case __DRI_IMAGE_FORMAT_TUPLE(4,UINT,1):     return MESA_FORMAT_RGBA_UINT8;
+   case __DRI_IMAGE_FORMAT_TUPLE(4,UINT,2):     return MESA_FORMAT_RGBA_UINT16;
+   case __DRI_IMAGE_FORMAT_TUPLE(4,UINT,4):     return MESA_FORMAT_RGBA_UINT32;
+   case __DRI_IMAGE_FORMAT_TUPLE(1,FLOAT,2):    return MESA_FORMAT_R_FLOAT16;
+   case __DRI_IMAGE_FORMAT_TUPLE(1,FLOAT,4):    return MESA_FORMAT_R_FLOAT32;
+   case __DRI_IMAGE_FORMAT_TUPLE(2,FLOAT,2):    return MESA_FORMAT_RG_FLOAT16;
+   case __DRI_IMAGE_FORMAT_TUPLE(2,FLOAT,4):    return MESA_FORMAT_RG_FLOAT32;
+   case __DRI_IMAGE_FORMAT_TUPLE(3,FLOAT,2):    return MESA_FORMAT_RGB_FLOAT16;
+   case __DRI_IMAGE_FORMAT_TUPLE(3,FLOAT,4):    return MESA_FORMAT_RGB_FLOAT32;
+   case __DRI_IMAGE_FORMAT_TUPLE(4,FLOAT,2):    return MESA_FORMAT_RGBA_FLOAT16;
+   case __DRI_IMAGE_FORMAT_TUPLE(4,FLOAT,4):    return MESA_FORMAT_RGBA_FLOAT32;
    default:
       return MESA_FORMAT_NONE;
    }