Re: [Mesa-dev] [RFC PATCH] include/GL: add mesa_glinterop.h for OpenGL-OpenCL interop

2016-03-01 Thread Marek Olšák
On Tue, Mar 1, 2016 at 3:29 AM, Michel Dänzer  wrote:
> On 01.03.2016 03:11, Marek Olšák wrote:
>> From: Marek Olšák 
>
> [...]
>
>> +/**
>> + * Device information returned by Mesa.
>> + */
>> +typedef struct {
>> +   uint32_t size; /* size of this structure */
>> +
>> +   /* PCI location */
>> +   uint32_t pci_segment_group;
>> +   uint32_t pci_bus;
>> +   uint32_t pci_device;
>> +   uint32_t pci_function;
>> +
>> +   /* Device identification */
>> +   uint32_t vendor_id;
>> +   uint32_t device_id;
>> +} mesa_glinterop_device_info;
>> +
>> +
>> +/**
>> + * Input parameters to Mesa interop export functions.
>> + */
>> +typedef struct {
>> +   uint32_t size; /* size of this structure */
>> +
>> +   /* One of the following:
>> +* - GL_TEXTURE_BUFFER
>> +* - GL_TEXTURE_1D
>> +* - GL_TEXTURE_2D
>> +* - GL_TEXTURE_3D
>> +* - GL_TEXTURE_RECTANGLE
>> +* - GL_TEXTURE_1D_ARRAY
>> +* - GL_TEXTURE_2D_ARRAY
>> +* - GL_TEXTURE_CUBE_MAP_ARRAY
>> +* - GL_TEXTURE_CUBE_MAP
>> +* - GL_TEXTURE_CUBE_MAP_POSITIVE_X
>> +* - GL_TEXTURE_CUBE_MAP_NEGATIVE_X
>> +* - GL_TEXTURE_CUBE_MAP_POSITIVE_Y
>> +* - GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
>> +* - GL_TEXTURE_CUBE_MAP_POSITIVE_Z
>> +* - GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
>> +* - GL_TEXTURE_2D_MULTISAMPLE
>> +* - GL_TEXTURE_2D_MULTISAMPLE_ARRAY
>> +* - GL_TEXTURE_EXTERNAL_OES
>> +* - GL_RENDERBUFFER
>> +* - GL_ARRAY_BUFFER
>> +*/
>> +   GLenum target;
>> +
>> +   /* If target is GL_ARRAY_BUFFER, it's a buffer object.
>> +* If target is GL_RENDERBUFFER, it's a renderbuffer object.
>> +* If target is GL_TEXTURE_*, it's a texture object.
>> +*/
>> +   GLuint obj;
>> +
>> +   /* Mipmap level. Ignored for non-texture objects. */
>> +   GLuint miplevel;
>> +
>> +   /* One of MESA_GLINTEROP_ACCESS_* flags. This describes how the exported
>> +* object is going to be used.
>> +*/
>> +   uint32_t access;
>> +
>> +   /* Size of memory pointed to by out_driver_data. */
>> +   uint32_t out_driver_data_size;
>> +
>> +   /* If the caller wants to query driver-specific data about the OpenGL
>> +* object, this should point to the memory where that dta will be stored.
>
> Typo: "dta"
>
>
>> +*/
>> +   void *out_driver_data;
>> +} mesa_glinterop_export_in;
>> +
>> +
>> +/**
>> + * Outputs of Mesa interop export functions.
>> + */
>> +typedef struct {
>> +   uint32_t size; /* size of this structure */
>> +
>> +   /* The DMABUF handle. It must closed by the caller using the POSIX 
>> close()
>> +* function when it's not needed anymore. Mesa is not responsible for
>> +* closing the handle.
>> +*/
>> +   int dmabuf_fd;
>> +
>> +   /* The mutable OpenGL internal format specified by glTextureView or
>> +* glTexBuffer. If the object is not one of those, the original internal
>> +* format specified by glTexStorage, glTexImage, or glRenderbufferStorage
>> +* will be returned.
>> +*/
>> +   GLenum internalformat;
>> +
>> +   /* Parameters specified by glTexBufferRange for GL_TEXTURE_BUFFER. */
>> +   GLintptr buf_offset;
>> +   GLsizeiptr buf_size;
>> +
>> +   /* Parameters specified by glTextureView. If the object is not a texture
>> +* view, default parameters covering the whole texture will be returned.
>> +*/
>> +   GLuint view_minlevel;
>> +   GLuint view_numlevels;
>> +   GLuint view_minlayer;
>> +   GLuint view_numlayers;
>> +} mesa_glinterop_export_out;
>> +
>> +
>> +/**
>> + * Query device information.
>> + *
>> + * \param dpyGLX display
>> + * \param contextGLX context
>> + * \param outwhere to return the information
>> + *
>> + * \return MESA_GLINTEROP_SUCCESS or MESA_GLINTEROP_* != 0 on error
>> + */
>> +GLAPI int GLAPIENTRY
>> +MesaGLInteropGLXQueryDeviceInfo(Display *dpy, GLXContext context,
>> +mesa_glinterop_device_info *out);
>> +
>> +
>> +/**
>> + * Same as MesaGLInteropGLXQueryDeviceInfo except that it accepts EGLDisplay
>> + * and EGLContext.
>> + */
>> +GLAPI int GLAPIENTRY
>> +MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy, EGLContext context,
>> +mesa_glinterop_device_info *out);
>> +
>> +
>> +/**
>> + * Create and return a DMABUF handle corresponding to the given OpenGL
>> + * object, and return other parameters about the OpenGL object.
>> + *
>> + * \param dpyGLX display
>> + * \param contextGLX context
>> + * \param in input parameters
>> + * \param outreturn values
>> + *
>> + * \return MESA_GLINTEROP_SUCCESS or MESA_GLINTEROP_* != 0 on error
>> + */
>> +GLAPI int GLAPIENTRY
>> +MesaGLInteropGLXExportObject(Display *dpy, GLXContext context,
>> + mesa_glinterop_export_in *in,
>> + mesa_glinterop_export_out *out);
>> +
>> +
>> +/**
>> + * Same as MesaGLInteropGLXExportGLObject except that it accepts
>> + * EGLDisplay and EGLContext.
>> + */
>> 

Re: [Mesa-dev] [RFC PATCH] include/GL: add mesa_glinterop.h for OpenGL-OpenCL interop

2016-02-29 Thread Michel Dänzer
On 01.03.2016 03:11, Marek Olšák wrote:
> From: Marek Olšák 

[...]

> +/**
> + * Device information returned by Mesa.
> + */
> +typedef struct {
> +   uint32_t size; /* size of this structure */
> +
> +   /* PCI location */
> +   uint32_t pci_segment_group;
> +   uint32_t pci_bus;
> +   uint32_t pci_device;
> +   uint32_t pci_function;
> +
> +   /* Device identification */
> +   uint32_t vendor_id;
> +   uint32_t device_id;
> +} mesa_glinterop_device_info;
> +
> +
> +/**
> + * Input parameters to Mesa interop export functions.
> + */
> +typedef struct {
> +   uint32_t size; /* size of this structure */
> +
> +   /* One of the following:
> +* - GL_TEXTURE_BUFFER
> +* - GL_TEXTURE_1D
> +* - GL_TEXTURE_2D
> +* - GL_TEXTURE_3D
> +* - GL_TEXTURE_RECTANGLE
> +* - GL_TEXTURE_1D_ARRAY
> +* - GL_TEXTURE_2D_ARRAY
> +* - GL_TEXTURE_CUBE_MAP_ARRAY
> +* - GL_TEXTURE_CUBE_MAP
> +* - GL_TEXTURE_CUBE_MAP_POSITIVE_X
> +* - GL_TEXTURE_CUBE_MAP_NEGATIVE_X
> +* - GL_TEXTURE_CUBE_MAP_POSITIVE_Y
> +* - GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
> +* - GL_TEXTURE_CUBE_MAP_POSITIVE_Z
> +* - GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
> +* - GL_TEXTURE_2D_MULTISAMPLE
> +* - GL_TEXTURE_2D_MULTISAMPLE_ARRAY
> +* - GL_TEXTURE_EXTERNAL_OES
> +* - GL_RENDERBUFFER
> +* - GL_ARRAY_BUFFER
> +*/
> +   GLenum target;
> +
> +   /* If target is GL_ARRAY_BUFFER, it's a buffer object.
> +* If target is GL_RENDERBUFFER, it's a renderbuffer object.
> +* If target is GL_TEXTURE_*, it's a texture object.
> +*/
> +   GLuint obj;
> +
> +   /* Mipmap level. Ignored for non-texture objects. */
> +   GLuint miplevel;
> +
> +   /* One of MESA_GLINTEROP_ACCESS_* flags. This describes how the exported
> +* object is going to be used.
> +*/
> +   uint32_t access;
> +
> +   /* Size of memory pointed to by out_driver_data. */
> +   uint32_t out_driver_data_size;
> +
> +   /* If the caller wants to query driver-specific data about the OpenGL
> +* object, this should point to the memory where that dta will be stored.

Typo: "dta"


> +*/
> +   void *out_driver_data;
> +} mesa_glinterop_export_in;
> +
> +
> +/**
> + * Outputs of Mesa interop export functions.
> + */
> +typedef struct {
> +   uint32_t size; /* size of this structure */
> +
> +   /* The DMABUF handle. It must closed by the caller using the POSIX close()
> +* function when it's not needed anymore. Mesa is not responsible for
> +* closing the handle.
> +*/
> +   int dmabuf_fd;
> +
> +   /* The mutable OpenGL internal format specified by glTextureView or
> +* glTexBuffer. If the object is not one of those, the original internal
> +* format specified by glTexStorage, glTexImage, or glRenderbufferStorage
> +* will be returned.
> +*/
> +   GLenum internalformat;
> +
> +   /* Parameters specified by glTexBufferRange for GL_TEXTURE_BUFFER. */
> +   GLintptr buf_offset;
> +   GLsizeiptr buf_size;
> +
> +   /* Parameters specified by glTextureView. If the object is not a texture
> +* view, default parameters covering the whole texture will be returned.
> +*/
> +   GLuint view_minlevel;
> +   GLuint view_numlevels;
> +   GLuint view_minlayer;
> +   GLuint view_numlayers;
> +} mesa_glinterop_export_out;
> +
> +
> +/**
> + * Query device information.
> + *
> + * \param dpyGLX display
> + * \param contextGLX context
> + * \param outwhere to return the information
> + *
> + * \return MESA_GLINTEROP_SUCCESS or MESA_GLINTEROP_* != 0 on error
> + */
> +GLAPI int GLAPIENTRY
> +MesaGLInteropGLXQueryDeviceInfo(Display *dpy, GLXContext context,
> +mesa_glinterop_device_info *out);
> +
> +
> +/**
> + * Same as MesaGLInteropGLXQueryDeviceInfo except that it accepts EGLDisplay
> + * and EGLContext.
> + */
> +GLAPI int GLAPIENTRY
> +MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy, EGLContext context,
> +mesa_glinterop_device_info *out);
> +
> +
> +/**
> + * Create and return a DMABUF handle corresponding to the given OpenGL
> + * object, and return other parameters about the OpenGL object.
> + *
> + * \param dpyGLX display
> + * \param contextGLX context
> + * \param in input parameters
> + * \param outreturn values
> + *
> + * \return MESA_GLINTEROP_SUCCESS or MESA_GLINTEROP_* != 0 on error
> + */
> +GLAPI int GLAPIENTRY
> +MesaGLInteropGLXExportObject(Display *dpy, GLXContext context,
> + mesa_glinterop_export_in *in,
> + mesa_glinterop_export_out *out);
> +
> +
> +/**
> + * Same as MesaGLInteropGLXExportGLObject except that it accepts
> + * EGLDisplay and EGLContext.
> + */
> +GLAPI int GLAPIENTRY
> +MesaGLInteropEGLExportObject(EGLDisplay dpy, EGLContext context,
> + mesa_glinterop_export_in *in,
> + mesa_glinterop_export_out *out);

The caller doesn't know 

[Mesa-dev] [RFC PATCH] include/GL: add mesa_glinterop.h for OpenGL-OpenCL interop

2016-02-29 Thread Marek Olšák
From: Marek Olšák 

---
 include/GL/mesa_glinterop.h | 226 
 1 file changed, 226 insertions(+)
 create mode 100644 include/GL/mesa_glinterop.h

diff --git a/include/GL/mesa_glinterop.h b/include/GL/mesa_glinterop.h
new file mode 100644
index 000..ecb5459
--- /dev/null
+++ b/include/GL/mesa_glinterop.h
@@ -0,0 +1,226 @@
+/*
+ * Mesa 3-D graphics library
+ *
+ * Copyright 2016 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+ * OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+/* Mesa OpenGL inter-driver interoperability interface. */
+
+#ifndef MESA_GLINTEROP_H
+#define MESA_GLINTEROP_H
+
+#include 
+#include 
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define MESA_GLINTEROP_VERSION 1
+
+/** Returned error codes. */
+#define MESA_GLINTEROP_SUCCESS  0
+#define MESA_GLINTEROP_OUT_OF_RESOURCES 1
+#define MESA_GLINTEROP_INVALID_OPERATION2
+#define MESA_GLINTEROP_INVALID_VALUE3
+#define MESA_GLINTEROP_INVALID_DISPLAY  4
+#define MESA_GLINTEROP_INVALID_CONTEXT  5
+#define MESA_GLINTEROP_INVALID_TARGET   6
+#define MESA_GLINTEROP_INVALID_OBJECT   7
+#define MESA_GLINTEROP_INVALID_MIP_LEVEL8
+
+/** Access flags. */
+#define MESA_GLINTEROP_ACCESS_READ_WRITE0
+#define MESA_GLINTEROP_ACCESS_READ_ONLY 1
+#define MESA_GLINTEROP_ACCESS_WRITE_ONLY2
+
+
+/**
+ * Device information returned by Mesa.
+ */
+typedef struct {
+   uint32_t size; /* size of this structure */
+
+   /* PCI location */
+   uint32_t pci_segment_group;
+   uint32_t pci_bus;
+   uint32_t pci_device;
+   uint32_t pci_function;
+
+   /* Device identification */
+   uint32_t vendor_id;
+   uint32_t device_id;
+} mesa_glinterop_device_info;
+
+
+/**
+ * Input parameters to Mesa interop export functions.
+ */
+typedef struct {
+   uint32_t size; /* size of this structure */
+
+   /* One of the following:
+* - GL_TEXTURE_BUFFER
+* - GL_TEXTURE_1D
+* - GL_TEXTURE_2D
+* - GL_TEXTURE_3D
+* - GL_TEXTURE_RECTANGLE
+* - GL_TEXTURE_1D_ARRAY
+* - GL_TEXTURE_2D_ARRAY
+* - GL_TEXTURE_CUBE_MAP_ARRAY
+* - GL_TEXTURE_CUBE_MAP
+* - GL_TEXTURE_CUBE_MAP_POSITIVE_X
+* - GL_TEXTURE_CUBE_MAP_NEGATIVE_X
+* - GL_TEXTURE_CUBE_MAP_POSITIVE_Y
+* - GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
+* - GL_TEXTURE_CUBE_MAP_POSITIVE_Z
+* - GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
+* - GL_TEXTURE_2D_MULTISAMPLE
+* - GL_TEXTURE_2D_MULTISAMPLE_ARRAY
+* - GL_TEXTURE_EXTERNAL_OES
+* - GL_RENDERBUFFER
+* - GL_ARRAY_BUFFER
+*/
+   GLenum target;
+
+   /* If target is GL_ARRAY_BUFFER, it's a buffer object.
+* If target is GL_RENDERBUFFER, it's a renderbuffer object.
+* If target is GL_TEXTURE_*, it's a texture object.
+*/
+   GLuint obj;
+
+   /* Mipmap level. Ignored for non-texture objects. */
+   GLuint miplevel;
+
+   /* One of MESA_GLINTEROP_ACCESS_* flags. This describes how the exported
+* object is going to be used.
+*/
+   uint32_t access;
+
+   /* Size of memory pointed to by out_driver_data. */
+   uint32_t out_driver_data_size;
+
+   /* If the caller wants to query driver-specific data about the OpenGL
+* object, this should point to the memory where that dta will be stored.
+*/
+   void *out_driver_data;
+} mesa_glinterop_export_in;
+
+
+/**
+ * Outputs of Mesa interop export functions.
+ */
+typedef struct {
+   uint32_t size; /* size of this structure */
+
+   /* The DMABUF handle. It must closed by the caller using the POSIX close()
+* function when it's not needed anymore. Mesa is not responsible for
+* closing the handle.
+*/
+   int dmabuf_fd;
+
+   /* The mutable OpenGL internal format specified by glTextureView or
+* glTexBuffer. If the object is not one of those, the original internal
+* format specified by glTexStorage, glTexImage, or glRenderbufferStorage
+* will be returned.
+*/
+   GLenum internalformat;
+
+   /*