blob: 7e57dda2d5a289387a445587be818ab6eb15df37 [file] [log] [blame]
Marek Olšák6eeb7292016-02-26 21:21:31 +01001/*
2 * Mesa 3-D graphics library
3 *
4 * Copyright 2016 Advanced Micro Devices, Inc.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25/* Mesa OpenGL inter-driver interoperability interface designed for but not
26 * limited to OpenCL.
27 *
28 * This is a driver-agnostic, backward-compatible interface. The structures
29 * are only allowed to grow. They can never shrink and their members can
30 * never be removed, renamed, or redefined.
31 *
32 * The interface doesn't return a lot of static texture parameters like
33 * width, height, etc. It mainly returns mutable buffer and texture view
34 * parameters that can't be part of the texture allocation (because they are
35 * mutable). If drivers want to return more data or want to return static
36 * allocation parameters, they can do it in one of these two ways:
37 * - attaching the data to the DMABUF handle in a driver-specific way
38 * - passing the data via "out_driver_data" in the "in" structure.
39 *
40 * Mesa is expected to do a lot of error checking on behalf of OpenCL, such
41 * as checking the target, miplevel, and texture completeness.
42 *
43 * OpenCL, on the other hand, needs to check if the display+context combo
44 * is compatible with the OpenCL driver by querying the device information.
45 * It also needs to check if the texture internal format and channel ordering
46 * (returned in a driver-specific way) is supported by OpenCL, among other
47 * things.
48 */
49
50#ifndef MESA_GLINTEROP_H
51#define MESA_GLINTEROP_H
52
Emil Velikovbcf9e472016-05-03 12:13:43 +010053#include <stddef.h>
Marek Olšák6eeb7292016-02-26 21:21:31 +010054#include <GL/glx.h>
55#include <EGL/egl.h>
56
57#ifdef __cplusplus
58extern "C" {
59#endif
60
61/** Returned error codes. */
62enum {
63 MESA_GLINTEROP_SUCCESS = 0,
64 MESA_GLINTEROP_OUT_OF_RESOURCES,
65 MESA_GLINTEROP_OUT_OF_HOST_MEMORY,
66 MESA_GLINTEROP_INVALID_OPERATION,
67 MESA_GLINTEROP_INVALID_VALUE,
68 MESA_GLINTEROP_INVALID_DISPLAY,
69 MESA_GLINTEROP_INVALID_CONTEXT,
70 MESA_GLINTEROP_INVALID_TARGET,
71 MESA_GLINTEROP_INVALID_OBJECT,
72 MESA_GLINTEROP_INVALID_MIP_LEVEL,
73 MESA_GLINTEROP_UNSUPPORTED
74};
75
76/** Access flags. */
77enum {
78 MESA_GLINTEROP_ACCESS_READ_WRITE = 0,
79 MESA_GLINTEROP_ACCESS_READ_ONLY,
80 MESA_GLINTEROP_ACCESS_WRITE_ONLY
81};
82
83#define MESA_GLINTEROP_DEVICE_INFO_VERSION 1
84
85/**
86 * Device information returned by Mesa.
87 */
88typedef struct _mesa_glinterop_device_info {
89 /* The caller should set this to: MESA_GLINTEROP_DEVICE_INFO_VERSION */
90 uint32_t struct_version;
91
92 /* PCI location */
93 uint32_t pci_segment_group;
94 uint32_t pci_bus;
95 uint32_t pci_device;
96 uint32_t pci_function;
97
98 /* Device identification */
99 uint32_t vendor_id;
100 uint32_t device_id;
101
102 /* The interop version determines what behavior the caller should expect
103 * out of all functions.
104 *
105 * Interop version 1:
106 * - mesa_glinterop_export_in is not read beyond "out_driver_data"
107 * - mesa_glinterop_export_out is not written beyond "out_driver_data_written"
108 * - mesa_glinterop_device_info is not written beyond "interop_version"
109 */
110 uint32_t interop_version;
111 /* Structure version 1 ends here. */
112} mesa_glinterop_device_info;
113
114#define MESA_GLINTEROP_EXPORT_IN_VERSION 1
115
116/**
117 * Input parameters to Mesa interop export functions.
118 */
119typedef struct _mesa_glinterop_export_in {
120 /* The caller should set this to: MESA_GLINTEROP_EXPORT_IN_VERSION */
121 uint32_t struct_version;
122
123 /* One of the following:
124 * - GL_TEXTURE_BUFFER
125 * - GL_TEXTURE_1D
126 * - GL_TEXTURE_2D
127 * - GL_TEXTURE_3D
128 * - GL_TEXTURE_RECTANGLE
129 * - GL_TEXTURE_1D_ARRAY
130 * - GL_TEXTURE_2D_ARRAY
131 * - GL_TEXTURE_CUBE_MAP_ARRAY
132 * - GL_TEXTURE_CUBE_MAP
133 * - GL_TEXTURE_CUBE_MAP_POSITIVE_X
134 * - GL_TEXTURE_CUBE_MAP_NEGATIVE_X
135 * - GL_TEXTURE_CUBE_MAP_POSITIVE_Y
136 * - GL_TEXTURE_CUBE_MAP_NEGATIVE_Y
137 * - GL_TEXTURE_CUBE_MAP_POSITIVE_Z
138 * - GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
139 * - GL_TEXTURE_2D_MULTISAMPLE
140 * - GL_TEXTURE_2D_MULTISAMPLE_ARRAY
141 * - GL_TEXTURE_EXTERNAL_OES
142 * - GL_RENDERBUFFER
143 * - GL_ARRAY_BUFFER
144 */
Emil Velikov2e726142016-04-21 16:36:01 +0100145 unsigned target;
Marek Olšák6eeb7292016-02-26 21:21:31 +0100146
147 /* If target is GL_ARRAY_BUFFER, it's a buffer object.
148 * If target is GL_RENDERBUFFER, it's a renderbuffer object.
149 * If target is GL_TEXTURE_*, it's a texture object.
150 */
Emil Velikov2e726142016-04-21 16:36:01 +0100151 unsigned obj;
Marek Olšák6eeb7292016-02-26 21:21:31 +0100152
153 /* Mipmap level. Ignored for non-texture objects. */
Emil Velikov2e726142016-04-21 16:36:01 +0100154 unsigned miplevel;
Marek Olšák6eeb7292016-02-26 21:21:31 +0100155
156 /* One of MESA_GLINTEROP_ACCESS_* flags. This describes how the exported
157 * object is going to be used.
158 */
159 uint32_t access;
160
161 /* Size of memory pointed to by out_driver_data. */
162 uint32_t out_driver_data_size;
163
164 /* If the caller wants to query driver-specific data about the OpenGL
165 * object, this should point to the memory where that data will be stored.
166 * This is expected to be a temporary staging memory. The pointer is not
167 * allowed to be saved for later use by Mesa.
168 */
169 void *out_driver_data;
170 /* Structure version 1 ends here. */
171} mesa_glinterop_export_in;
172
173#define MESA_GLINTEROP_EXPORT_OUT_VERSION 1
174
175/**
176 * Outputs of Mesa interop export functions.
177 */
178typedef struct _mesa_glinterop_export_out {
179 /* The caller should set this to: MESA_GLINTEROP_EXPORT_OUT_VERSION */
180 uint32_t struct_version;
181
182 /* The DMABUF handle. It must be closed by the caller using the POSIX
183 * close() function when it's not needed anymore. Mesa is not responsible
184 * for closing the handle.
185 *
186 * Not closing the handle by the caller will lead to a resource leak,
187 * will prevent releasing the GPU buffer, and may prevent creating new
188 * DMABUF handles within the process.
189 */
190 int dmabuf_fd;
191
192 /* The mutable OpenGL internal format specified by glTextureView or
193 * glTexBuffer. If the object is not one of those, the original internal
194 * format specified by glTexStorage, glTexImage, or glRenderbufferStorage
195 * will be returned.
196 */
Emil Velikov2e726142016-04-21 16:36:01 +0100197 unsigned internal_format;
Marek Olšák6eeb7292016-02-26 21:21:31 +0100198
199 /* Buffer offset and size for GL_ARRAY_BUFFER and GL_TEXTURE_BUFFER.
200 * This allows interop with suballocations (a buffer allocated within
201 * a larger buffer).
202 *
203 * Parameters specified by glTexBufferRange for GL_TEXTURE_BUFFER are
204 * applied to these and can shrink the range further.
205 */
Emil Velikovbcf9e472016-05-03 12:13:43 +0100206 ptrdiff_t buf_offset;
207 ptrdiff_t buf_size;
Marek Olšák6eeb7292016-02-26 21:21:31 +0100208
209 /* Parameters specified by glTextureView. If the object is not a texture
210 * view, default parameters covering the whole texture will be returned.
211 */
Emil Velikov2e726142016-04-21 16:36:01 +0100212 unsigned view_minlevel;
213 unsigned view_numlevels;
214 unsigned view_minlayer;
215 unsigned view_numlayers;
Marek Olšák6eeb7292016-02-26 21:21:31 +0100216
217 /* The number of bytes written to out_driver_data. */
218 uint32_t out_driver_data_written;
219 /* Structure version 1 ends here. */
220} mesa_glinterop_export_out;
221
222
223/**
224 * Query device information.
225 *
226 * \param dpy GLX display
227 * \param context GLX context
228 * \param out where to return the information
229 *
230 * \return MESA_GLINTEROP_SUCCESS or MESA_GLINTEROP_* != 0 on error
231 */
232GLAPI int GLAPIENTRY
233MesaGLInteropGLXQueryDeviceInfo(Display *dpy, GLXContext context,
234 mesa_glinterop_device_info *out);
235
236
237/**
238 * Same as MesaGLInteropGLXQueryDeviceInfo except that it accepts EGLDisplay
239 * and EGLContext.
240 */
241GLAPI int GLAPIENTRY
242MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy, EGLContext context,
243 mesa_glinterop_device_info *out);
244
245
246/**
247 * Create and return a DMABUF handle corresponding to the given OpenGL
248 * object, and return other parameters about the OpenGL object.
249 *
250 * \param dpy GLX display
251 * \param context GLX context
252 * \param in input parameters
253 * \param out return values
254 *
255 * \return MESA_GLINTEROP_SUCCESS or MESA_GLINTEROP_* != 0 on error
256 */
257GLAPI int GLAPIENTRY
258MesaGLInteropGLXExportObject(Display *dpy, GLXContext context,
259 const mesa_glinterop_export_in *in,
260 mesa_glinterop_export_out *out);
261
262
263/**
264 * Same as MesaGLInteropGLXExportObject except that it accepts
265 * EGLDisplay and EGLContext.
266 */
267GLAPI int GLAPIENTRY
268MesaGLInteropEGLExportObject(EGLDisplay dpy, EGLContext context,
269 const mesa_glinterop_export_in *in,
270 mesa_glinterop_export_out *out);
271
Emil Velikov0d31bfd2016-05-24 14:21:31 +0100272
Marek Olšák6eeb7292016-02-26 21:21:31 +0100273typedef int (APIENTRYP PFNMESAGLINTEROPGLXQUERYDEVICEINFOPROC)(Display *dpy, GLXContext context,
274 mesa_glinterop_device_info *out);
275typedef int (APIENTRYP PFNMESAGLINTEROPEGLQUERYDEVICEINFOPROC)(EGLDisplay dpy, EGLContext context,
276 mesa_glinterop_device_info *out);
277typedef int (APIENTRYP PFNMESAGLINTEROPGLXEXPORTOBJECTPROC)(Display *dpy, GLXContext context,
278 const mesa_glinterop_export_in *in,
279 mesa_glinterop_export_out *out);
Marek Olšák6eeb7292016-02-26 21:21:31 +0100280typedef int (APIENTRYP PFNMESAGLINTEROPEGLEXPORTOBJECTPROC)(EGLDisplay dpy, EGLContext context,
281 const mesa_glinterop_export_in *in,
282 mesa_glinterop_export_out *out);
283
284#ifdef __cplusplus
285}
286#endif
287
288#endif /* MESA_GLINTEROP_H */