Module: Mesa Branch: main Commit: 1396dc1c387a9f9a8b16ad358ee12a025159cc98 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=1396dc1c387a9f9a8b16ad358ee12a025159cc98
Author: Antonio Gomes <antoniospg...@gmail.com> Date: Tue Oct 24 17:31:15 2023 -0300 mesa/st, dri2, wgl, glx: Modify flush_objects interop func to export a fence_fd Reviewed-by: Marek Olšák <marek.ol...@amd.com> Acked-by: Jesse Natalie <jenat...@microsoft.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21305> --- include/GL/internal/dri_interface.h | 16 ++++++++-------- include/GL/mesa_glinterop.h | 11 ++++++----- src/egl/drivers/dri2/egl_dri2.c | 4 ++-- src/egl/drivers/wgl/egl_wgl.c | 2 +- src/egl/main/eglapi.c | 6 +++--- src/egl/main/egldriver.h | 2 +- src/gallium/frontends/dri/dri2.c | 4 ++-- src/gallium/frontends/wgl/stw_ext_interop.c | 2 +- src/glx/dri2_priv.h | 2 +- src/glx/dri3_priv.h | 2 +- src/glx/dri_common_interop.c | 8 ++++---- src/glx/g_glxglvnddispatchfuncs.c | 4 ++-- src/glx/glxclient.h | 4 ++-- src/glx/glxcmds.c | 8 ++++---- src/mesa/state_tracker/st_interop.c | 7 ++++++- src/mesa/state_tracker/st_interop.h | 2 +- 16 files changed, 45 insertions(+), 39 deletions(-) diff --git a/include/GL/internal/dri_interface.h b/include/GL/internal/dri_interface.h index ad3ce1cfed4..07e92fb15bc 100644 --- a/include/GL/internal/dri_interface.h +++ b/include/GL/internal/dri_interface.h @@ -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 <ke...@precisioninsight.com> * \author Ian Romanick <i...@us.ibm.com> * \author Kristian Høgsberg <k...@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. * diff --git a/include/GL/mesa_glinterop.h b/include/GL/mesa_glinterop.h index 571ed26a5be..57edb674743 100644 --- a/include/GL/mesa_glinterop.h +++ b/include/GL/mesa_glinterop.h @@ -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); diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c index 50d7dfe0d1f..c3fb706bff1 100644 --- a/src/egl/drivers/dri2/egl_dri2.c +++ b/src/egl/drivers/dri2/egl_dri2.c @@ -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 = { diff --git a/src/egl/drivers/wgl/egl_wgl.c b/src/egl/drivers/wgl/egl_wgl.c index 498496417c2..e708232a99e 100644 --- a/src/egl/drivers/wgl/egl_wgl.c +++ b/src/egl/drivers/wgl/egl_wgl.c @@ -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); diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c index b9f179c2ce3..65b76c811e1 100644 --- a/src/egl/main/eglapi.c +++ b/src/egl/main/eglapi.c @@ -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; diff --git a/src/egl/main/egldriver.h b/src/egl/main/egldriver.h index 6bea4fb3d6b..adae52cd950 100644 --- a/src/egl/main/egldriver.h +++ b/src/egl/main/egldriver.h @@ -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, diff --git a/src/gallium/frontends/dri/dri2.c b/src/gallium/frontends/dri/dri2.c index a018ef70437..3354a54b91d 100644 --- a/src/gallium/frontends/dri/dri2.c +++ b/src/gallium/frontends/dri/dri2.c @@ -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 = { diff --git a/src/gallium/frontends/wgl/stw_ext_interop.c b/src/gallium/frontends/wgl/stw_ext_interop.c index b58ab71b4e1..15582b42442 100644 --- a/src/gallium/frontends/wgl/stw_ext_interop.c +++ b/src/gallium/frontends/wgl/stw_ext_interop.c @@ -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); } diff --git a/src/glx/dri2_priv.h b/src/glx/dri2_priv.h index 837709fa5ec..2c26b544d12 100644 --- a/src/glx/dri2_priv.h +++ b/src/glx/dri2_priv.h @@ -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 } diff --git a/src/glx/dri3_priv.h b/src/glx/dri3_priv.h index c76fdf7df5a..6f523742f67 100644 --- a/src/glx/dri3_priv.h +++ b/src/glx/dri3_priv.h @@ -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); diff --git a/src/glx/dri_common_interop.c b/src/glx/dri_common_interop.c index cce3776a35c..e1c0fb928b7 100644 --- a/src/glx/dri_common_interop.c +++ b/src/glx/dri_common_interop.c @@ -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 */ diff --git a/src/glx/g_glxglvnddispatchfuncs.c b/src/glx/g_glxglvnddispatchfuncs.c index bafe41cc337..b583f838c82 100644 --- a/src/glx/g_glxglvnddispatchfuncs.c +++ b/src/glx/g_glxglvnddispatchfuncs.c @@ -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); } diff --git a/src/glx/glxclient.h b/src/glx/glxclient.h index f884a18f205..b1c1fe574cf 100644 --- a/src/glx/glxclient.h +++ b/src/glx/glxclient.h @@ -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, diff --git a/src/glx/glxcmds.c b/src/glx/glxcmds.c index 7ce8aba22f9..7ecf5daef96 100644 --- a/src/glx/glxcmds.c +++ b/src/glx/glxcmds.c @@ -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; } diff --git a/src/mesa/state_tracker/st_interop.c b/src/mesa/state_tracker/st_interop.c index 1762fae821a..de555c5b9cc 100644 --- a/src/mesa/state_tracker/st_interop.c +++ b/src/mesa/state_tracker/st_interop.c @@ -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; diff --git a/src/mesa/state_tracker/st_interop.h b/src/mesa/state_tracker/st_interop.h index 70bae553ec3..1e83f4b2582 100644 --- a/src/mesa/state_tracker/st_interop.h +++ b/src/mesa/state_tracker/st_interop.h @@ -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 */