Module: Mesa
Branch: main
Commit: 0fa85b983f7fb0395d2ff8d7dc3a4c74baa75927
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=0fa85b983f7fb0395d2ff8d7dc3a4c74baa75927

Author: Sylvain Munaut <t...@246tnt.com>
Date:   Tue Nov 21 15:15:19 2023 +0100

mesa/st, dri2, wgl, glx: Restore flush_objects interop backward compat

In commit 1396dc1c a new output field was added as a parameter, but this
is a problem since the signature of the function are not versionned.

The flush function didn't have a versionned output struct. So what I'm
proposing here is that if the version of the input argument is new enough
(bumped to 2 here), then we re-use the existing argument, which until now
was directly a pointer to GLsync, and instead use it as a pointer to a
versioned struct.

We're just changing one pointer type to another, so in C, this should
be fine AFAIK.

Fixes: 1396dc1c

Signed-off-by: Sylvain Munaut <t...@246tnt.com>
Reviewed-by: Jesse Natalie <jenat...@microsoft.com>
Reviewed-by: Karol Herbst <kher...@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26315>

---

 include/GL/internal/dri_interface.h         |  3 +-
 include/GL/mesa_glinterop.h                 | 47 +++++++++++++++++++++++------
 src/egl/drivers/dri2/egl_dri2.c             |  4 +--
 src/egl/drivers/wgl/egl_wgl.c               |  4 +--
 src/egl/generate/egl_other.xml              |  3 +-
 src/egl/main/eglapi.c                       |  5 ++-
 src/egl/main/egldriver.h                    |  3 +-
 src/gallium/frontends/dri/dri2.c            |  4 +--
 src/gallium/frontends/rusticl/core/gl.rs    | 18 ++++++-----
 src/gallium/frontends/wgl/stw_ext_interop.c |  8 ++---
 src/gallium/frontends/wgl/stw_ext_interop.h |  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                         |  3 +-
 src/glx/glxcmds.c                           |  4 +--
 src/mesa/state_tracker/st_interop.c         | 35 ++++++++++++++-------
 src/mesa/state_tracker/st_interop.h         |  2 +-
 19 files changed, 104 insertions(+), 57 deletions(-)

diff --git a/include/GL/internal/dri_interface.h 
b/include/GL/internal/dri_interface.h
index 07e92fb15bc..a428e3c98fb 100644
--- a/include/GL/internal/dri_interface.h
+++ b/include/GL/internal/dri_interface.h
@@ -441,6 +441,7 @@ struct __DRI2fenceExtensionRec {
 struct mesa_glinterop_device_info;
 struct mesa_glinterop_export_in;
 struct mesa_glinterop_export_out;
+struct mesa_glinterop_flush_out;
 typedef struct __GLsync *GLsync;
 
 struct __DRI2interopExtensionRec {
@@ -462,7 +463,7 @@ struct __DRI2interopExtensionRec {
     */
    int (*flush_objects)(__DRIcontext *ctx,
                         unsigned count, struct mesa_glinterop_export_in 
*objects,
-                        GLsync *sync, int *fence_fd);
+                        struct mesa_glinterop_flush_out *out);
 };
 
 
diff --git a/include/GL/mesa_glinterop.h b/include/GL/mesa_glinterop.h
index 57edb674743..2c3b993183b 100644
--- a/include/GL/mesa_glinterop.h
+++ b/include/GL/mesa_glinterop.h
@@ -147,7 +147,7 @@ struct mesa_glinterop_device_info {
    /* Structure version 3 ends here. */
 };
 
-#define MESA_GLINTEROP_EXPORT_IN_VERSION 1
+#define MESA_GLINTEROP_EXPORT_IN_VERSION 2
 
 /**
  * Input parameters to Mesa interop export functions.
@@ -210,6 +210,12 @@ struct mesa_glinterop_export_in {
     */
    void *out_driver_data;
    /* Structure version 1 ends here. */
+
+   /* Structure version 2 starts here. */
+   /* NOTE: Version 2 doesn't add any fields to input but redefines the
+    *       argument to flush call to `struct mesa_glinterop_flush_out *`
+    *       instead of `GLsync *`  */
+   /* Structure version 2 ends here. */
 };
 
 #define MESA_GLINTEROP_EXPORT_OUT_VERSION 2
@@ -286,6 +292,28 @@ struct mesa_glinterop_export_out {
    /* Structure version 2 ends here. */
 };
 
+#define MESA_GLINTEROP_FLUSH_OUT_VERSION 1
+
+/**
+ * Outputs of Mesa interop flush functions.
+ */
+struct mesa_glinterop_flush_out {
+   /* The caller should set this to the version of the struct they support */
+   /* The callee will overwrite it if it supports a lower version.
+    *
+    * The caller should check the value and access up-to the version supported
+    * by the callee.
+    */
+   /* NOTE: Do not use the MESA_GLINTEROP_EXPORT_OUT_VERSION macro */
+   uint32_t version;
+
+   /* GLsync to map to CL event, caller set it non-NULL to be filled */
+   GLsync *sync;
+
+   /* fence_fd to use in CL, caller set it to non-NULL to be filled */
+   int *fence_fd;
+};
+
 
 /**
  * Query device information.
@@ -362,15 +390,14 @@ wglMesaGLInteropExportObject(HDC dpy, HGLRC context,
  * \param context    GLX 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
+ * \param out        return values
  *
  * \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, int *fence_fd);
+                             struct mesa_glinterop_flush_out *out);
 
 /**
 * Same as MesaGLInteropGLXFlushObjects except that it accepts
@@ -379,16 +406,16 @@ MesaGLInteropGLXFlushObjects(struct _XDisplay *dpy, 
struct __GLXcontextRec *cont
 int
 MesaGLInteropEGLFlushObjects(EGLDisplay dpy, EGLContext context,
                              unsigned count, struct mesa_glinterop_export_in 
*resources,
-                             GLsync *sync, int *fence_fd);
+                             struct mesa_glinterop_flush_out *out);
 
 /**
 * Same as MesaGLInteropGLXFlushObjects except that it accepts
-* HDC and HGLRC, and not a fence_fd.
+* HDC and HGLRC.
 */
 int
 wglMesaGLInteropFlushObjects(HDC dpy, HGLRC context,
                              unsigned count, struct mesa_glinterop_export_in 
*resources,
-                             GLsync *sync);
+                             struct mesa_glinterop_flush_out *out);
 
 
 typedef int (*PFNMESAGLINTEROPGLXQUERYDEVICEINFOPROC)(struct _XDisplay *dpy, 
struct __GLXcontextRec *context,
@@ -408,13 +435,13 @@ 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, int 
*fence_fd);
+                                                   struct 
mesa_glinterop_flush_out *out);
 typedef int (*PFNMESAGLINTEROPEGLFLUSHOBJECTSPROC)(EGLDisplay dpy, EGLContext 
context,
                                                    unsigned count, struct 
mesa_glinterop_export_in *resources,
-                                                   GLsync *sync, int 
*fence_fd);
+                                                   struct 
mesa_glinterop_flush_out *out);
 typedef int (*PFNWGLMESAGLINTEROPFLUSHOBJECTSPROC)(HDC dpy, HGLRC context,
                                                    unsigned count, struct 
mesa_glinterop_export_in *resources,
-                                                   GLsync *sync);
+                                                   struct 
mesa_glinterop_flush_out *out);
 
 #ifdef __cplusplus
 }
diff --git a/src/egl/drivers/dri2/egl_dri2.c b/src/egl/drivers/dri2/egl_dri2.c
index 96887aa8f09..bb75273ead9 100644
--- a/src/egl/drivers/dri2/egl_dri2.c
+++ b/src/egl/drivers/dri2/egl_dri2.c
@@ -3701,7 +3701,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, int *fence_fd)
+                           struct mesa_glinterop_flush_out *out)
 {
    struct dri2_egl_display *dri2_dpy = dri2_egl_display(disp);
    struct dri2_egl_context *dri2_ctx = dri2_egl_context(ctx);
@@ -3710,7 +3710,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, fence_fd);
+                                           objects, out);
 }
 
 const _EGLDriver _eglDriver = {
diff --git a/src/egl/drivers/wgl/egl_wgl.c b/src/egl/drivers/wgl/egl_wgl.c
index e708232a99e..83057183e69 100644
--- a/src/egl/drivers/wgl/egl_wgl.c
+++ b/src/egl/drivers/wgl/egl_wgl.c
@@ -1164,10 +1164,10 @@ 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, int *fence_fd)
+                          struct mesa_glinterop_flush_out *out)
 {
    struct wgl_egl_context *wgl_ctx = wgl_egl_context(ctx);
-   return stw_interop_flush_objects(wgl_ctx->ctx, count, objects, sync);
+   return stw_interop_flush_objects(wgl_ctx->ctx, count, objects, out);
 }
 
 struct _egl_driver _eglDriver = {
diff --git a/src/egl/generate/egl_other.xml b/src/egl/generate/egl_other.xml
index 5a7c4adbf4f..3c3588dbe9d 100644
--- a/src/egl/generate/egl_other.xml
+++ b/src/egl/generate/egl_other.xml
@@ -35,6 +35,7 @@
         <type>struct <name>mesa_glinterop_device_info</name>;</type>
         <type>struct <name>mesa_glinterop_export_in</name>;</type>
         <type>struct <name>mesa_glinterop_export_out</name>;</type>
+        <type>struct <name>mesa_glinterop_flush_out</name>;</type>
     </types>
     <commands namespace="EGL">
         <!-- EGL_WL_bind_wayland_display -->
@@ -103,7 +104,7 @@
             <param><ptype>EGLContext</ptype> <name>ctx</name></param>
             <param>unsigned <name>count</name></param>
             <param>struct <ptype>mesa_glinterop_export_in</ptype> 
*<name>objects</name></param>
-            <param>GLsync *<name>sync</name></param>
+            <param>struct <ptype>mesa_glinterop_flush_out</ptype> 
*<name>out</name></param>
         </command>
     </commands>
 </registry>
diff --git a/src/egl/main/eglapi.c b/src/egl/main/eglapi.c
index 65b76c811e1..88aa6c2ceba 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, int *fence_fd)
+                             struct mesa_glinterop_flush_out *out)
 {
    _EGLDisplay *disp;
    _EGLContext *ctx;
@@ -2910,8 +2910,7 @@ MesaGLInteropEGLFlushObjects(EGLDisplay dpy, EGLContext 
context, unsigned count,
       return ret;
 
    if (disp->Driver->GLInteropFlushObjects)
-      ret = disp->Driver->GLInteropFlushObjects(disp, ctx, count, objects, 
sync,
-                                                fence_fd);
+      ret = disp->Driver->GLInteropFlushObjects(disp, ctx, count, objects, 
out);
    else
       ret = MESA_GLINTEROP_UNSUPPORTED;
 
diff --git a/src/egl/main/egldriver.h b/src/egl/main/egldriver.h
index adae52cd950..89ac2473527 100644
--- a/src/egl/main/egldriver.h
+++ b/src/egl/main/egldriver.h
@@ -73,6 +73,7 @@ struct wl_display;
 struct mesa_glinterop_device_info;
 struct mesa_glinterop_export_in;
 struct mesa_glinterop_export_out;
+struct mesa_glinterop_flush_out;
 typedef struct __GLsync *GLsync;
 
 /**
@@ -208,7 +209,7 @@ struct _egl_driver {
    int (*GLInteropFlushObjects)(_EGLDisplay *disp, _EGLContext *ctx,
                                 unsigned count,
                                 struct mesa_glinterop_export_in *in,
-                                GLsync *sync, int *fence_fd);
+                                struct mesa_glinterop_flush_out *out);
 
    /* 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 3354a54b91d..ad68f3b08c0 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, int *fence_fd)
+                           struct mesa_glinterop_flush_out *out)
 {
-   return st_interop_flush_objects(dri_context(_ctx)->st, count, objects, 
sync, fence_fd);
+   return st_interop_flush_objects(dri_context(_ctx)->st, count, objects, out);
 }
 
 static const __DRI2interopExtension dri2InteropExtension = {
diff --git a/src/gallium/frontends/rusticl/core/gl.rs 
b/src/gallium/frontends/rusticl/core/gl.rs
index f2a2d3cc631..d65b8c78017 100644
--- a/src/gallium/frontends/rusticl/core/gl.rs
+++ b/src/gallium/frontends/rusticl/core/gl.rs
@@ -193,7 +193,7 @@ impl GLCtxManager {
     ) -> CLResult<GLExportManager> {
         let xplat_manager = &self.xplat_manager;
         let mut export_in = mesa_glinterop_export_in {
-            version: 1,
+            version: 2,
             target: target,
             obj: texture,
             miplevel: miplevel as u32,
@@ -206,6 +206,14 @@ impl GLCtxManager {
             ..Default::default()
         };
 
+        let mut fd = -1;
+
+        let mut flush_out = mesa_glinterop_flush_out {
+            version: 1,
+            fence_fd: &mut fd,
+            ..Default::default()
+        };
+
         let err = unsafe {
             match &self.gl_ctx {
                 GLCtx::EGL(disp, ctx) => {
@@ -217,14 +225,12 @@ impl GLCtxManager {
                         .MesaGLInteropEGLFlushObjects()?
                         .ok_or(CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR)?;
 
-                    let mut fd = -1;
                     let err_flush = egl_flush_objects_func(
                         disp.cast(),
                         ctx.cast(),
                         1,
                         &mut export_in,
-                        ptr::null_mut(),
-                        &mut fd,
+                        &mut flush_out,
                     );
                     // TODO: use fence_server_sync in ctx inside the queue 
thread
                     let fence_fd = FenceFd { fd };
@@ -253,14 +259,12 @@ impl GLCtxManager {
                         .MesaGLInteropGLXFlushObjects()?
                         .ok_or(CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR)?;
 
-                    let mut fd = -1;
                     let err_flush = glx_flush_objects_func(
                         disp.cast(),
                         ctx.cast(),
                         1,
                         &mut export_in,
-                        ptr::null_mut(),
-                        &mut fd,
+                        &mut flush_out,
                     );
                     // TODO: use fence_server_sync in ctx inside the queue 
thread
                     let fence_fd = FenceFd { fd };
diff --git a/src/gallium/frontends/wgl/stw_ext_interop.c 
b/src/gallium/frontends/wgl/stw_ext_interop.c
index 15582b42442..aaed245b2b2 100644
--- a/src/gallium/frontends/wgl/stw_ext_interop.c
+++ b/src/gallium/frontends/wgl/stw_ext_interop.c
@@ -88,7 +88,7 @@ stw_interop_export_object(struct stw_context *ctx,
 int
 wglMesaGLInteropFlushObjects(HDC dpy, HGLRC context,
                              unsigned count, struct mesa_glinterop_export_in 
*resources,
-                             GLsync *sync)
+                             struct mesa_glinterop_flush_out *out)
 {
    DHGLRC dhglrc = 0;
 
@@ -104,14 +104,14 @@ wglMesaGLInteropFlushObjects(HDC dpy, HGLRC context,
    if (!ctx)
       return MESA_GLINTEROP_INVALID_CONTEXT;
 
-   return stw_interop_flush_objects(ctx, count, resources, sync);
+   return stw_interop_flush_objects(ctx, count, resources, out);
 }
 
 int
 stw_interop_flush_objects(struct stw_context *ctx,
                           unsigned count, struct mesa_glinterop_export_in 
*objects,
-                          GLsync *sync)
+                          struct mesa_glinterop_flush_out *out)
 {
-   return st_interop_flush_objects(ctx->st, count, objects, sync, NULL);
+   return st_interop_flush_objects(ctx->st, count, objects, out);
 }
 
diff --git a/src/gallium/frontends/wgl/stw_ext_interop.h 
b/src/gallium/frontends/wgl/stw_ext_interop.h
index 1167d2c82af..c35417b25ce 100644
--- a/src/gallium/frontends/wgl/stw_ext_interop.h
+++ b/src/gallium/frontends/wgl/stw_ext_interop.h
@@ -40,6 +40,6 @@ stw_interop_export_object(struct stw_context *ctx,
 int
 stw_interop_flush_objects(struct stw_context *ctx,
                           unsigned count, struct mesa_glinterop_export_in 
*objects,
-                          GLsync *sync);
+                          struct mesa_glinterop_flush_out *out);
 
 #endif /* STW_EXT_INTEROP_H */
diff --git a/src/glx/dri2_priv.h b/src/glx/dri2_priv.h
index 2c26b544d12..4adf7c0f94b 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, int *fence_fd);
+                           struct mesa_glinterop_flush_out *out);
 
 #ifdef __cplusplus
 }
diff --git a/src/glx/dri3_priv.h b/src/glx/dri3_priv.h
index 6f523742f67..0a9c0a648f8 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, int *fence_fd);
+                           struct mesa_glinterop_flush_out *out);
diff --git a/src/glx/dri_common_interop.c b/src/glx/dri_common_interop.c
index e1c0fb928b7..c8038d60846 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, int *fence_fd)
+                           struct mesa_glinterop_flush_out *out)
 {
    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, 
fence_fd);
+   return psc->interop->flush_objects(ctx->driContext, count, objects, out);
 }
 
 #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, int *fence_fd)
+                           struct mesa_glinterop_flush_out *out)
 {
    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, 
fence_fd);
+   return psc->interop->flush_objects(ctx->driContext, count, objects, out);
 }
 
 #endif /* HAVE_DRI3 */
diff --git a/src/glx/g_glxglvnddispatchfuncs.c 
b/src/glx/g_glxglvnddispatchfuncs.c
index b583f838c82..a5d6f7d3360 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, int *fence_fd)
+                                              struct mesa_glinterop_flush_out 
*out)
 {
     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, 
fence_fd);
+    return pGLInteropFlushObjectsMESA(dpy, ctx, count, resources, out);
 }
 
 
diff --git a/src/glx/glxclient.h b/src/glx/glxclient.h
index b1c1fe574cf..38980d76ddf 100644
--- a/src/glx/glxclient.h
+++ b/src/glx/glxclient.h
@@ -208,6 +208,7 @@ typedef struct __GLXattributeMachineRec
 struct mesa_glinterop_device_info;
 struct mesa_glinterop_export_in;
 struct mesa_glinterop_export_out;
+struct mesa_glinterop_flush_out;
 
 struct glx_context_vtable {
    void (*destroy)(struct glx_context *ctx);
@@ -222,7 +223,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, int *fence_fd);
+                                struct mesa_glinterop_flush_out *out);
 };
 
 /**
diff --git a/src/glx/glxcmds.c b/src/glx/glxcmds.c
index 7ecf5daef96..295fd1836c7 100644
--- a/src/glx/glxcmds.c
+++ b/src/glx/glxcmds.c
@@ -2458,7 +2458,7 @@ PUBLIC int
 MesaGLInteropGLXFlushObjects(Display *dpy, GLXContext context,
                              unsigned count,
                              struct mesa_glinterop_export_in *resources,
-                             GLsync *sync, int *fence_fd)
+                             struct mesa_glinterop_flush_out *out)
 {
    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, 
fence_fd);
+   ret = gc->vtable->interop_flush_objects(gc, count, resources, out);
    __glXUnlock();
    return ret;
 }
diff --git a/src/mesa/state_tracker/st_interop.c 
b/src/mesa/state_tracker/st_interop.c
index de555c5b9cc..8b7c7afaef3 100644
--- a/src/mesa/state_tracker/st_interop.c
+++ b/src/mesa/state_tracker/st_interop.c
@@ -341,8 +341,8 @@ st_interop_export_object(struct st_context *st,
    if (res->target == PIPE_BUFFER)
       out->buf_offset += whandle.offset;
 
-   /* Instruct the caller that we support up-to version one of the interface */
-   in->version = MIN2(in->version, 1);
+   /* Instruct the caller of the version of the interface we support */
+   in->version = MIN2(in->version, 2);
    out->version = MIN2(out->version, 2);
 
    return MESA_GLINTEROP_SUCCESS;
@@ -363,8 +363,8 @@ flush_object(struct gl_context *ctx,
 
    ctx->pipe->flush_resource(ctx->pipe, res);
 
-   /* Instruct the caller that we support up-to version one of the interface */
-   in->version = 1;
+   /* Instruct the caller of the version of the interface we support */
+   in->version = MIN2(in->version, 2);
 
    return MESA_GLINTEROP_SUCCESS;
 }
@@ -372,9 +372,10 @@ 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, int *fence_fd)
+                         struct mesa_glinterop_flush_out *out)
 {
    struct gl_context *ctx = st->ctx;
+   bool flush_out_struct = false;
 
    /* Wait for glthread to finish to get up-to-date GL object lookups. */
    _mesa_glthread_finish(st->ctx);
@@ -384,6 +385,9 @@ st_interop_flush_objects(struct st_context *st,
    for (unsigned i = 0; i < count; ++i) {
       int ret = flush_object(ctx, &objects[i]);
 
+      if (objects[i].version >= 2)
+         flush_out_struct = true;
+
       if (ret != MESA_GLINTEROP_SUCCESS) {
          simple_mtx_unlock(&ctx->Shared->Mutex);
          return ret;
@@ -392,12 +396,21 @@ st_interop_flush_objects(struct st_context *st,
 
    simple_mtx_unlock(&ctx->Shared->Mutex);
 
-   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);
+   if (count > 0 && out) {
+      if (flush_out_struct) {
+         if (out->sync) {
+            *out->sync = _mesa_fence_sync(ctx, GL_SYNC_GPU_COMMANDS_COMPLETE, 
0);
+         }
+         if (out->fence_fd) {
+            struct pipe_fence_handle *fence = NULL;
+            ctx->pipe->flush(ctx->pipe, &fence, PIPE_FLUSH_FENCE_FD | 
PIPE_FLUSH_ASYNC);
+            *out->fence_fd = ctx->screen->fence_get_fd(ctx->screen, fence);
+         }
+         out->version = MIN2(out->version, 1);
+      } else {
+         GLsync *sync = (GLsync *)out;
+         *sync = _mesa_fence_sync(ctx, GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
+      }
    }
 
    return MESA_GLINTEROP_SUCCESS;
diff --git a/src/mesa/state_tracker/st_interop.h 
b/src/mesa/state_tracker/st_interop.h
index 1e83f4b2582..635d0c971c3 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, int *fence_fd);
+                         struct mesa_glinterop_flush_out *out);
 
 #endif /* ST_INTEROP_H */

Reply via email to