Module: Mesa Branch: main Commit: 663cef26d0ba93dc3237b950046bc7fa48a879d8 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=663cef26d0ba93dc3237b950046bc7fa48a879d8
Author: Antonio Gomes <antoniospg...@gmail.com> Date: Sat Apr 22 17:00:56 2023 -0300 mesa/st: Add new data to mesa_glinterop * Version 3 of mesa_glinterop_device_info * Export device uuid * Version 2 of mesa_glinterop_export_out * Export texture sizes * Export whandle.modifier * Export whandle.stride * Add PIPE_HANDLE_USAGE_EXPLICIT_FLUSH in interop_export_objects Reviewed-by: Marek Olšák <marek.ol...@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21305> --- include/GL/mesa_glinterop.h | 26 +++++++++++++++++++++---- src/mesa/state_tracker/st_interop.c | 38 ++++++++++++++++++++++++++++++++----- 2 files changed, 55 insertions(+), 9 deletions(-) diff --git a/include/GL/mesa_glinterop.h b/include/GL/mesa_glinterop.h index 886448f63a2..571ed26a5be 100644 --- a/include/GL/mesa_glinterop.h +++ b/include/GL/mesa_glinterop.h @@ -101,7 +101,9 @@ enum { MESA_GLINTEROP_ACCESS_WRITE_ONLY }; -#define MESA_GLINTEROP_DEVICE_INFO_VERSION 2 +#define MESA_GLINTEROP_DEVICE_INFO_VERSION 3 + +#define UUID_SIZE 16 /** * Device information returned by Mesa. @@ -139,6 +141,10 @@ struct mesa_glinterop_device_info { void *driver_data; /* Structure version 2 ends here. */ + + char device_uuid[UUID_SIZE]; + + /* Structure version 3 ends here. */ }; #define MESA_GLINTEROP_EXPORT_IN_VERSION 1 @@ -206,7 +212,7 @@ struct mesa_glinterop_export_in { /* Structure version 1 ends here. */ }; -#define MESA_GLINTEROP_EXPORT_OUT_VERSION 1 +#define MESA_GLINTEROP_EXPORT_OUT_VERSION 2 /** * Outputs of Mesa interop export functions. @@ -266,6 +272,18 @@ struct mesa_glinterop_export_out { /* The number of bytes written to out_driver_data. */ uint32_t out_driver_data_written; /* Structure version 1 ends here. */ + + /* Structure version 2 starts here. */ + /* Texture sizes. If the object is not a texture, default parameters will + * be returned. + */ + uint32_t width; + uint32_t height; + uint32_t depth; + uint32_t stride; + /* the modifier to use when reimporting the fd */ + uint64_t modifier; + /* Structure version 2 ends here. */ }; @@ -339,13 +357,13 @@ wglMesaGLInteropExportObject(HDC dpy, HGLRC context, /** * Prepare OpenGL resources for being accessed by OpenCL. - * + * * \param dpy GLX display * \param context GLX context * \param count number of resources * \param resources resources to flush * \param sync optional GLsync to map to CL event - * + * * \return MESA_GLINTEROP_SUCCESS or MESA_GLINTEROP_* != 0 on error */ int diff --git a/src/mesa/state_tracker/st_interop.c b/src/mesa/state_tracker/st_interop.c index f84ffa1a275..1762fae821a 100644 --- a/src/mesa/state_tracker/st_interop.c +++ b/src/mesa/state_tracker/st_interop.c @@ -29,6 +29,7 @@ #include "bufferobj.h" #include "texobj.h" +#include "teximage.h" #include "syncobj.h" int @@ -54,8 +55,11 @@ st_interop_query_device_info(struct st_context *st, out->driver_data_size, out->driver_data); - /* Instruct the caller that we support up-to version two of the interface */ - out->version = MIN2(out->version, 2); + if (out->version >= 3 && screen->get_device_uuid) + screen->get_device_uuid(screen, out->device_uuid); + + /* Instruct the caller that we support up-to version three of the interface */ + out->version = MIN2(out->version, 3); return MESA_GLINTEROP_SUCCESS; } @@ -163,6 +167,12 @@ lookup_object(struct gl_context *ctx, out->view_numlevels = 1; out->view_minlayer = 0; out->view_numlayers = 1; + + if (out->version >= 2) { + out->width = rb->Width; + out->height = rb->Height; + out->depth = MAX2(1, rb->Depth); + } } } else { /* Texture objects. @@ -230,6 +240,15 @@ lookup_object(struct gl_context *ctx, out->view_numlevels = obj->Attrib.NumLevels; out->view_minlayer = obj->Attrib.MinLayer; out->view_numlayers = obj->Attrib.NumLayers; + + if (out->version >= 2) { + const GLuint face = _mesa_tex_target_to_face(in->target);; + struct gl_texture_image *image = obj->Image[face][in->miplevel]; + + out->width = image->Width; + out->height = image->Height; + out->depth = image->Depth; + } } } } @@ -288,10 +307,14 @@ st_interop_export_object(struct st_context *st, } memset(&whandle, 0, sizeof(whandle)); - + if (need_export_dmabuf) { whandle.type = WINSYS_HANDLE_TYPE_FD; + /* OpenCL requires explicit flushes. */ + if (out->version >= 2) + usage |= PIPE_HANDLE_USAGE_EXPLICIT_FLUSH; + success = screen->resource_get_handle(screen, st->pipe, res, &whandle, usage); @@ -305,6 +328,11 @@ st_interop_export_object(struct st_context *st, #else out->win32_handle = whandle.handle; #endif + + if (out->version >= 2) { + out->modifier = whandle.modifier; + out->stride = whandle.stride; + } } simple_mtx_unlock(&ctx->Shared->Mutex); @@ -313,8 +341,8 @@ st_interop_export_object(struct st_context *st, out->buf_offset += whandle.offset; /* Instruct the caller that we support up-to version one of the interface */ - in->version = 1; - out->version = 1; + in->version = MIN2(in->version, 1); + out->version = MIN2(out->version, 2); return MESA_GLINTEROP_SUCCESS; }