Path: blob/21.2-virgl/include/GL/mesa_glinterop.h
4547 views
/*1* Mesa 3-D graphics library2*3* Copyright 2016 Advanced Micro Devices, Inc.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the "Software"),7* to deal in the Software without restriction, including without limitation8* the rights to use, copy, modify, merge, publish, distribute, sublicense,9* and/or sell copies of the Software, and to permit persons to whom the10* Software is furnished to do so, subject to the following conditions:11*12* The above copyright notice and this permission notice shall be included13* in all copies or substantial portions of the Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS16* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL18* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR19* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,20* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR21* OTHER DEALINGS IN THE SOFTWARE.22*/2324/* Mesa OpenGL inter-driver interoperability interface designed for but not25* limited to OpenCL.26*27* This is a driver-agnostic, backward-compatible interface. The structures28* are only allowed to grow. They can never shrink and their members can29* never be removed, renamed, or redefined.30*31* The interface doesn't return a lot of static texture parameters like32* width, height, etc. It mainly returns mutable buffer and texture view33* parameters that can't be part of the texture allocation (because they are34* mutable). If drivers want to return more data or want to return static35* allocation parameters, they can do it in one of these two ways:36* - attaching the data to the DMABUF handle in a driver-specific way37* - passing the data via "out_driver_data" in the "in" structure.38*39* Mesa is expected to do a lot of error checking on behalf of OpenCL, such40* as checking the target, miplevel, and texture completeness.41*42* OpenCL, on the other hand, needs to check if the display+context combo43* is compatible with the OpenCL driver by querying the device information.44* It also needs to check if the texture internal format and channel ordering45* (returned in a driver-specific way) is supported by OpenCL, among other46* things.47*/4849#ifndef MESA_GLINTEROP_H50#define MESA_GLINTEROP_H5152#include <stddef.h>53#include <stdint.h>5455#ifdef __cplusplus56extern "C" {57#endif5859/* Forward declarations to avoid inclusion of GL/glx.h */60#ifndef GLX_H61struct _XDisplay;62struct __GLXcontextRec;63#endif6465/* Forward declarations to avoid inclusion of EGL/egl.h */66#ifndef __egl_h_67typedef void *EGLDisplay;68typedef void *EGLContext;69#endif7071/** Returned error codes. */72enum {73MESA_GLINTEROP_SUCCESS = 0,74MESA_GLINTEROP_OUT_OF_RESOURCES,75MESA_GLINTEROP_OUT_OF_HOST_MEMORY,76MESA_GLINTEROP_INVALID_OPERATION,77MESA_GLINTEROP_INVALID_VERSION,78MESA_GLINTEROP_INVALID_DISPLAY,79MESA_GLINTEROP_INVALID_CONTEXT,80MESA_GLINTEROP_INVALID_TARGET,81MESA_GLINTEROP_INVALID_OBJECT,82MESA_GLINTEROP_INVALID_MIP_LEVEL,83MESA_GLINTEROP_UNSUPPORTED84};8586/** Access flags. */87enum {88MESA_GLINTEROP_ACCESS_READ_WRITE = 0,89MESA_GLINTEROP_ACCESS_READ_ONLY,90MESA_GLINTEROP_ACCESS_WRITE_ONLY91};9293#define MESA_GLINTEROP_DEVICE_INFO_VERSION 19495/**96* Device information returned by Mesa.97*/98struct mesa_glinterop_device_info {99/* The caller should set this to the version of the struct they support */100/* The callee will overwrite it if it supports a lower version.101*102* The caller should check the value and access up-to the version supported103* by the callee.104*/105/* NOTE: Do not use the MESA_GLINTEROP_DEVICE_INFO_VERSION macro */106uint32_t version;107108/* PCI location */109uint32_t pci_segment_group;110uint32_t pci_bus;111uint32_t pci_device;112uint32_t pci_function;113114/* Device identification */115uint32_t vendor_id;116uint32_t device_id;117118/* Structure version 1 ends here. */119};120121#define MESA_GLINTEROP_EXPORT_IN_VERSION 1122123/**124* Input parameters to Mesa interop export functions.125*/126struct mesa_glinterop_export_in {127/* The caller should set this to the version of the struct they support */128/* The callee will overwrite it if it supports a lower version.129*130* The caller should check the value and access up-to the version supported131* by the callee.132*/133/* NOTE: Do not use the MESA_GLINTEROP_EXPORT_IN_VERSION macro */134uint32_t version;135136/* One of the following:137* - GL_TEXTURE_BUFFER138* - GL_TEXTURE_1D139* - GL_TEXTURE_2D140* - GL_TEXTURE_3D141* - GL_TEXTURE_RECTANGLE142* - GL_TEXTURE_1D_ARRAY143* - GL_TEXTURE_2D_ARRAY144* - GL_TEXTURE_CUBE_MAP_ARRAY145* - GL_TEXTURE_CUBE_MAP146* - GL_TEXTURE_CUBE_MAP_POSITIVE_X147* - GL_TEXTURE_CUBE_MAP_NEGATIVE_X148* - GL_TEXTURE_CUBE_MAP_POSITIVE_Y149* - GL_TEXTURE_CUBE_MAP_NEGATIVE_Y150* - GL_TEXTURE_CUBE_MAP_POSITIVE_Z151* - GL_TEXTURE_CUBE_MAP_NEGATIVE_Z152* - GL_TEXTURE_2D_MULTISAMPLE153* - GL_TEXTURE_2D_MULTISAMPLE_ARRAY154* - GL_TEXTURE_EXTERNAL_OES155* - GL_RENDERBUFFER156* - GL_ARRAY_BUFFER157*/158unsigned target;159160/* If target is GL_ARRAY_BUFFER, it's a buffer object.161* If target is GL_RENDERBUFFER, it's a renderbuffer object.162* If target is GL_TEXTURE_*, it's a texture object.163*/164unsigned obj;165166/* Mipmap level. Ignored for non-texture objects. */167unsigned miplevel;168169/* One of MESA_GLINTEROP_ACCESS_* flags. This describes how the exported170* object is going to be used.171*/172uint32_t access;173174/* Size of memory pointed to by out_driver_data. */175uint32_t out_driver_data_size;176177/* If the caller wants to query driver-specific data about the OpenGL178* object, this should point to the memory where that data will be stored.179* This is expected to be a temporary staging memory. The pointer is not180* allowed to be saved for later use by Mesa.181*/182void *out_driver_data;183/* Structure version 1 ends here. */184};185186#define MESA_GLINTEROP_EXPORT_OUT_VERSION 1187188/**189* Outputs of Mesa interop export functions.190*/191struct mesa_glinterop_export_out {192/* The caller should set this to the version of the struct they support */193/* The callee will overwrite it if it supports a lower version.194*195* The caller should check the value and access up-to the version supported196* by the callee.197*/198/* NOTE: Do not use the MESA_GLINTEROP_EXPORT_OUT_VERSION macro */199uint32_t version;200201/* The DMABUF handle. It must be closed by the caller using the POSIX202* close() function when it's not needed anymore. Mesa is not responsible203* for closing the handle.204*205* Not closing the handle by the caller will lead to a resource leak,206* will prevent releasing the GPU buffer, and may prevent creating new207* DMABUF handles within the process.208*/209int dmabuf_fd;210211/* The mutable OpenGL internal format specified by glTextureView or212* glTexBuffer. If the object is not one of those, the original internal213* format specified by glTexStorage, glTexImage, or glRenderbufferStorage214* will be returned.215*/216unsigned internal_format;217218/* Buffer offset and size for GL_ARRAY_BUFFER and GL_TEXTURE_BUFFER.219* This allows interop with suballocations (a buffer allocated within220* a larger buffer).221*222* Parameters specified by glTexBufferRange for GL_TEXTURE_BUFFER are223* applied to these and can shrink the range further.224*/225ptrdiff_t buf_offset;226ptrdiff_t buf_size;227228/* Parameters specified by glTextureView. If the object is not a texture229* view, default parameters covering the whole texture will be returned.230*/231unsigned view_minlevel;232unsigned view_numlevels;233unsigned view_minlayer;234unsigned view_numlayers;235236/* The number of bytes written to out_driver_data. */237uint32_t out_driver_data_written;238/* Structure version 1 ends here. */239};240241242/**243* Query device information.244*245* \param dpy GLX display246* \param context GLX context247* \param out where to return the information248*249* \return MESA_GLINTEROP_SUCCESS or MESA_GLINTEROP_* != 0 on error250*/251int252MesaGLInteropGLXQueryDeviceInfo(struct _XDisplay *dpy, struct __GLXcontextRec *context,253struct mesa_glinterop_device_info *out);254255256/**257* Same as MesaGLInteropGLXQueryDeviceInfo except that it accepts EGLDisplay258* and EGLContext.259*/260int261MesaGLInteropEGLQueryDeviceInfo(EGLDisplay dpy, EGLContext context,262struct mesa_glinterop_device_info *out);263264265/**266* Create and return a DMABUF handle corresponding to the given OpenGL267* object, and return other parameters about the OpenGL object.268*269* \param dpy GLX display270* \param context GLX context271* \param in input parameters272* \param out return values273*274* \return MESA_GLINTEROP_SUCCESS or MESA_GLINTEROP_* != 0 on error275*/276int277MesaGLInteropGLXExportObject(struct _XDisplay *dpy, struct __GLXcontextRec *context,278struct mesa_glinterop_export_in *in,279struct mesa_glinterop_export_out *out);280281282/**283* Same as MesaGLInteropGLXExportObject except that it accepts284* EGLDisplay and EGLContext.285*/286int287MesaGLInteropEGLExportObject(EGLDisplay dpy, EGLContext context,288struct mesa_glinterop_export_in *in,289struct mesa_glinterop_export_out *out);290291292typedef int (PFNMESAGLINTEROPGLXQUERYDEVICEINFOPROC)(struct _XDisplay *dpy, struct __GLXcontextRec *context,293struct mesa_glinterop_device_info *out);294typedef int (PFNMESAGLINTEROPEGLQUERYDEVICEINFOPROC)(EGLDisplay dpy, EGLContext context,295struct mesa_glinterop_device_info *out);296typedef int (PFNMESAGLINTEROPGLXEXPORTOBJECTPROC)(struct _XDisplay *dpy, struct __GLXcontextRec *context,297struct mesa_glinterop_export_in *in,298struct mesa_glinterop_export_out *out);299typedef int (PFNMESAGLINTEROPEGLEXPORTOBJECTPROC)(EGLDisplay dpy, EGLContext context,300struct mesa_glinterop_export_in *in,301struct mesa_glinterop_export_out *out);302303#ifdef __cplusplus304}305#endif306307#endif /* MESA_GLINTEROP_H */308309310