mesa/st, dri2, wgl, glx: Modify flush_objects interop func to export a fence_fd

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Acked-by: Jesse Natalie <jenatali@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21305>
This commit is contained in:
Antonio Gomes 2023-10-24 17:31:15 -03:00 committed by Marge Bot
parent 663cef26d0
commit 1396dc1c38
16 changed files with 45 additions and 39 deletions

View File

@ -31,7 +31,7 @@
* between a DRI driver and driver loader. Currently, the most common driver
* loader is the XFree86 libGL.so. However, other loaders do exist, and in
* the future the server-side libglx.a will also be a loader.
*
*
* \author Kevin E. Martin <kevin@precisioninsight.com>
* \author Ian Romanick <idr@us.ibm.com>
* \author Kristian Høgsberg <krh@redhat.com>
@ -190,7 +190,7 @@ struct __DRItexBufferExtensionRec {
/**
* Method to override base texture image with the contents of a
* __DRIdrawable.
* __DRIdrawable.
*
* For GLX_EXT_texture_from_pixmap with AIGLX. Deprecated in favor of
* setTexBuffer2 in version 2 of this interface. Not used by post-2011 X.
@ -457,12 +457,12 @@ struct __DRI2interopExtensionRec {
/**
* Same as MesaGLInterop*FlushObjects.
*
*
* \since 2
*/
int (*flush_objects)(__DRIcontext *ctx,
unsigned count, struct mesa_glinterop_export_in *objects,
GLsync *sync);
GLsync *sync, int *fence_fd);
};
@ -544,7 +544,7 @@ struct __DRIsystemTimeExtensionRec {
/**
* Get the media stream counter (MSC) rate.
*
*
* Matching the definition in GLX_OML_sync_control, this function returns
* the rate of the "media stream counter". In practical terms, this is
* the frame refresh rate of the display.
@ -759,7 +759,7 @@ struct __DRIuseInvalidateExtensionRec {
#define __DRI_ATTRIB_MAX 54
/* __DRI_ATTRIB_RENDER_TYPE */
#define __DRI_ATTRIB_RGBA_BIT 0x01
#define __DRI_ATTRIB_RGBA_BIT 0x01
#define __DRI_ATTRIB_COLOR_INDEX_BIT 0x02
#define __DRI_ATTRIB_LUMINANCE_BIT 0x04
#define __DRI_ATTRIB_FLOAT_BIT 0x08
@ -862,7 +862,7 @@ struct __DRIcoreExtensionRec {
/**
* Stored version of some component (i.e., server-side DRI module, kernel-side
* DRM, etc.).
*
*
* \todo
* There are several data structures that explicitly store a major version,
* minor version, and patch level. These structures should be modified to
@ -879,7 +879,7 @@ struct __DRIversionRec {
/**
* Framebuffer information record. Used by libGL to communicate information
* about the framebuffer to the driver's \c __driCreateNewScreen function.
*
*
* In XFree86, most of this information is derrived from data returned by
* calling \c XF86DRIGetDeviceInfo.
*

View File

@ -363,13 +363,14 @@ wglMesaGLInteropExportObject(HDC dpy, HGLRC context,
* \param count number of resources
* \param resources resources to flush
* \param sync optional GLsync to map to CL event
* \param fence_fd optional fence_fd to use in CL
*
* \return MESA_GLINTEROP_SUCCESS or MESA_GLINTEROP_* != 0 on error
*/
int
MesaGLInteropGLXFlushObjects(struct _XDisplay *dpy, struct __GLXcontextRec *context,
unsigned count, struct mesa_glinterop_export_in *resources,
GLsync *sync);
GLsync *sync, int *fence_fd);
/**
* Same as MesaGLInteropGLXFlushObjects except that it accepts
@ -378,11 +379,11 @@ MesaGLInteropGLXFlushObjects(struct _XDisplay *dpy, struct __GLXcontextRec *cont
int
MesaGLInteropEGLFlushObjects(EGLDisplay dpy, EGLContext context,
unsigned count, struct mesa_glinterop_export_in *resources,
GLsync *sync);
GLsync *sync, int *fence_fd);
/**
* Same as MesaGLInteropGLXFlushObjects except that it accepts
* HDC and HGLRC.
* HDC and HGLRC, and not a fence_fd.
*/
int
wglMesaGLInteropFlushObjects(HDC dpy, HGLRC context,
@ -407,10 +408,10 @@ typedef int (*PFNWGLMESAGLINTEROPEXPORTOBJECTPROC)(HDC dpy, HGLRC context,
struct mesa_glinterop_export_out *out);
typedef int (*PFNMESAGLINTEROPGLXFLUSHOBJECTSPROC)(struct _XDisplay *dpy, struct __GLXcontextRec *context,
unsigned count, struct mesa_glinterop_export_in *resources,
GLsync *sync);
GLsync *sync, int *fence_fd);
typedef int (*PFNMESAGLINTEROPEGLFLUSHOBJECTSPROC)(EGLDisplay dpy, EGLContext context,
unsigned count, struct mesa_glinterop_export_in *resources,
GLsync *sync);
GLsync *sync, int *fence_fd);
typedef int (*PFNWGLMESAGLINTEROPFLUSHOBJECTSPROC)(HDC dpy, HGLRC context,
unsigned count, struct mesa_glinterop_export_in *resources,
GLsync *sync);

View File

@ -3664,7 +3664,7 @@ dri2_interop_export_object(_EGLDisplay *disp, _EGLContext *ctx,
static int
dri2_interop_flush_objects(_EGLDisplay *disp, _EGLContext *ctx, unsigned count,
struct mesa_glinterop_export_in *objects,
GLsync *sync)
GLsync *sync, int *fence_fd)
{
struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
@ -3673,7 +3673,7 @@ dri2_interop_flush_objects(_EGLDisplay *disp, _EGLContext *ctx, unsigned count,
return MESA_GLINTEROP_UNSUPPORTED;
return dri2_dpy->interop->flush_objects(dri2_ctx->dri_context, count,
objects, sync);
objects, sync, fence_fd);
}
const _EGLDriver _eglDriver = {

View File

@ -1164,7 +1164,7 @@ wgl_interop_export_object(_EGLDisplay *disp, _EGLContext *ctx,
static int
wgl_interop_flush_objects(_EGLDisplay *disp, _EGLContext *ctx, unsigned count,
struct mesa_glinterop_export_in *objects,
GLsync *sync)
GLsync *sync, int *fence_fd)
{
struct wgl_egl_context *wgl_ctx = wgl_egl_context(ctx);
return stw_interop_flush_objects(wgl_ctx->ctx, count, objects, sync);

View File

@ -2899,7 +2899,7 @@ MesaGLInteropEGLExportObject(EGLDisplay dpy, EGLContext context,
PUBLIC int
MesaGLInteropEGLFlushObjects(EGLDisplay dpy, EGLContext context, unsigned count,
struct mesa_glinterop_export_in *objects,
GLsync *sync)
GLsync *sync, int *fence_fd)
{
_EGLDisplay *disp;
_EGLContext *ctx;
@ -2910,8 +2910,8 @@ MesaGLInteropEGLFlushObjects(EGLDisplay dpy, EGLContext context, unsigned count,
return ret;
if (disp->Driver->GLInteropFlushObjects)
ret =
disp->Driver->GLInteropFlushObjects(disp, ctx, count, objects, sync);
ret = disp->Driver->GLInteropFlushObjects(disp, ctx, count, objects, sync,
fence_fd);
else
ret = MESA_GLINTEROP_UNSUPPORTED;

View File

@ -208,7 +208,7 @@ struct _egl_driver {
int (*GLInteropFlushObjects)(_EGLDisplay *disp, _EGLContext *ctx,
unsigned count,
struct mesa_glinterop_export_in *in,
GLsync *sync);
GLsync *sync, int *fence_fd);
/* for EGL_EXT_image_dma_buf_import_modifiers */
EGLBoolean (*QueryDmaBufFormatsEXT)(_EGLDisplay *disp, EGLint max_formats,

View File

@ -2098,9 +2098,9 @@ dri2_interop_export_object(__DRIcontext *_ctx,
static int
dri2_interop_flush_objects(__DRIcontext *_ctx,
unsigned count, struct mesa_glinterop_export_in *objects,
GLsync *sync)
GLsync *sync, int *fence_fd)
{
return st_interop_flush_objects(dri_context(_ctx)->st, count, objects, sync);
return st_interop_flush_objects(dri_context(_ctx)->st, count, objects, sync, fence_fd);
}
static const __DRI2interopExtension dri2InteropExtension = {

View File

@ -112,6 +112,6 @@ stw_interop_flush_objects(struct stw_context *ctx,
unsigned count, struct mesa_glinterop_export_in *objects,
GLsync *sync)
{
return st_interop_flush_objects(ctx->st, count, objects, sync);
return st_interop_flush_objects(ctx->st, count, objects, sync, NULL);
}

View File

@ -83,7 +83,7 @@ dri2_interop_export_object(struct glx_context *ctx,
_X_HIDDEN int
dri2_interop_flush_objects(struct glx_context *ctx,
unsigned count, struct mesa_glinterop_export_in *objects,
GLsync *sync);
GLsync *sync, int *fence_fd);
#ifdef __cplusplus
}

View File

@ -143,4 +143,4 @@ dri3_interop_export_object(struct glx_context *ctx,
_X_HIDDEN int
dri3_interop_flush_objects(struct glx_context *ctx,
unsigned count, struct mesa_glinterop_export_in *objects,
GLsync *sync);
GLsync *sync, int *fence_fd);

View File

@ -60,14 +60,14 @@ dri2_interop_export_object(struct glx_context *ctx,
_X_HIDDEN int
dri2_interop_flush_objects(struct glx_context *ctx,
unsigned count, struct mesa_glinterop_export_in *objects,
GLsync *sync)
GLsync *sync, int *fence_fd)
{
struct dri2_screen *psc = (struct dri2_screen*)ctx->psc;
if (!psc->interop || psc->interop->base.version < 2)
return MESA_GLINTEROP_UNSUPPORTED;
return psc->interop->flush_objects(ctx->driContext, count, objects, sync);
return psc->interop->flush_objects(ctx->driContext, count, objects, sync, fence_fd);
}
#if defined(HAVE_DRI3)
@ -100,14 +100,14 @@ dri3_interop_export_object(struct glx_context *ctx,
_X_HIDDEN int
dri3_interop_flush_objects(struct glx_context *ctx,
unsigned count, struct mesa_glinterop_export_in *objects,
GLsync *sync)
GLsync *sync, int *fence_fd)
{
struct dri3_screen *psc = (struct dri3_screen*)ctx->psc;
if (!psc->interop || psc->interop->base.version < 2)
return MESA_GLINTEROP_UNSUPPORTED;
return psc->interop->flush_objects(ctx->driContext, count, objects, sync);
return psc->interop->flush_objects(ctx->driContext, count, objects, sync, fence_fd);
}
#endif /* HAVE_DRI3 */

View File

@ -333,7 +333,7 @@ static int dispatch_GLInteropExportObjectMESA(Display *dpy, GLXContext ctx,
static int dispatch_GLInteropFlushObjectsMESA(Display *dpy, GLXContext ctx,
unsigned count,
struct mesa_glinterop_export_in *resources,
GLsync *sync)
GLsync *sync, int *fence_fd)
{
PFNMESAGLINTEROPGLXFLUSHOBJECTSPROC pGLInteropFlushObjectsMESA;
__GLXvendorInfo *dd;
@ -346,7 +346,7 @@ static int dispatch_GLInteropFlushObjectsMESA(Display *dpy, GLXContext ctx,
if (pGLInteropFlushObjectsMESA == NULL)
return 0;
return pGLInteropFlushObjectsMESA(dpy, ctx, count, resources, sync);
return pGLInteropFlushObjectsMESA(dpy, ctx, count, resources, sync, fence_fd);
}

View File

@ -222,7 +222,7 @@ struct glx_context_vtable {
struct mesa_glinterop_export_out *out);
int (*interop_flush_objects)(struct glx_context *ctx,
unsigned count, struct mesa_glinterop_export_in *objects,
GLsync *sync);
GLsync *sync, int *fence_fd);
};
/**
@ -457,7 +457,7 @@ struct glx_screen_vtable {
/* The error outparameter abuses the fact that the only possible errors are
* GLXBadContext (0), GLXBadFBConfig (9), GLXBadProfileARB (13), BadValue
* (2), BadMatch (8), and BadAlloc (11). Since those don't collide we just
* use them directly rather than try to offset or use a sign convention.
* use them directly rather than try to offset or use a sign convention.
*/
struct glx_context *(*create_context_attribs)(struct glx_screen *psc,
struct glx_config *config,

View File

@ -596,7 +596,7 @@ glXCopyContext(Display * dpy, GLXContext source_user,
mask, &errorcode, &x11error)) {
__glXSendError(dpy, errorcode, 0, X_GLXCopyContext, x11error);
}
#else
xGLXCopyContextReq *req;
struct glx_context *gc = __glXGetCurrentContext();
@ -1756,7 +1756,7 @@ glXWaitVideoSyncSGI(int divisor, int remainder, unsigned int *count)
/*
** GLX_SGIX_fbconfig
** Many of these functions are aliased to GLX 1.3 entry points in the
** Many of these functions are aliased to GLX 1.3 entry points in the
** GLX_functions table.
*/
@ -2458,7 +2458,7 @@ PUBLIC int
MesaGLInteropGLXFlushObjects(Display *dpy, GLXContext context,
unsigned count,
struct mesa_glinterop_export_in *resources,
GLsync *sync)
GLsync *sync, int *fence_fd)
{
struct glx_context *gc = (struct glx_context*)context;
int ret;
@ -2475,7 +2475,7 @@ MesaGLInteropGLXFlushObjects(Display *dpy, GLXContext context,
return MESA_GLINTEROP_UNSUPPORTED;
}
ret = gc->vtable->interop_flush_objects(gc, count, resources, sync);
ret = gc->vtable->interop_flush_objects(gc, count, resources, sync, fence_fd);
__glXUnlock();
return ret;
}

View File

@ -25,6 +25,7 @@
#include "st_interop.h"
#include "st_cb_texture.h"
#include "st_cb_flush.h"
#include "st_texture.h"
#include "bufferobj.h"
@ -371,7 +372,7 @@ flush_object(struct gl_context *ctx,
int
st_interop_flush_objects(struct st_context *st,
unsigned count, struct mesa_glinterop_export_in *objects,
GLsync *sync)
GLsync *sync, int *fence_fd)
{
struct gl_context *ctx = st->ctx;
@ -393,6 +394,10 @@ st_interop_flush_objects(struct st_context *st,
if (count > 0 && sync) {
*sync = _mesa_fence_sync(ctx, GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
} else if (count > 0 && fence_fd) {
struct pipe_fence_handle *fence = NULL;
ctx->pipe->flush(ctx->pipe, &fence, PIPE_FLUSH_FENCE_FD | PIPE_FLUSH_ASYNC);
*fence_fd = ctx->screen->fence_get_fd(ctx->screen, fence);
}
return MESA_GLINTEROP_SUCCESS;

View File

@ -41,6 +41,6 @@ st_interop_export_object(struct st_context *st,
int
st_interop_flush_objects(struct st_context *st,
unsigned count, struct mesa_glinterop_export_in *objects,
GLsync *sync);
GLsync *sync, int *fence_fd);
#endif /* ST_INTEROP_H */