From 4eba877aef052e01ebbfc0bdaa1fbed33c884fed Mon Sep 17 00:00:00 2001 From: "Brzak, Branislav" Date: Wed, 11 Jun 2025 04:32:51 +0200 Subject: [PATCH] SWDEV-531996 - Add legacy fallback Mesa loading via dlsym (#512) [ROCm/clr commit: 494c0e3201caa5ed6aab18d929a746de43073f79] --- .../clr/rocclr/device/rocm/rocglinterop.cpp | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/projects/clr/rocclr/device/rocm/rocglinterop.cpp b/projects/clr/rocclr/device/rocm/rocglinterop.cpp index 9b0f309c4b..b03b1cf3d1 100644 --- a/projects/clr/rocclr/device/rocm/rocglinterop.cpp +++ b/projects/clr/rocclr/device/rocm/rocglinterop.cpp @@ -65,6 +65,33 @@ bool Supported() { #endif } +#if !defined(_WIN32) +// Fallback for older OS' and Mesa versions +static void LegacyInitGLX() { + if (!GlxInfo) { + GlxInfo = (PFNMESAGLINTEROPGLXQUERYDEVICEINFOPROC*)dlsym(RTLD_DEFAULT, + "MesaGLInteropGLXQueryDeviceInfo"); + } + + if (!GlxExport) { + GlxExport = + (PFNMESAGLINTEROPGLXEXPORTOBJECTPROC*)dlsym(RTLD_DEFAULT, "MesaGLInteropGLXExportObject"); + } +} + +static void LegacyInitEGL() { + if (!EglInfo) { + EglInfo = (PFNMESAGLINTEROPEGLQUERYDEVICEINFOPROC*)dlsym(RTLD_DEFAULT, + "MesaGLInteropEGLQueryDeviceInfo"); + } + + if (!EglExport) { + EglExport = + (PFNMESAGLINTEROPEGLEXPORTOBJECTPROC*)dlsym(RTLD_DEFAULT, "MesaGLInteropEGLExportObject"); + } +} +#endif + // Returns true if the required subsystem is supported on the GL device. // Must be called at least once, may be called multiple times. bool Init(MESA_INTEROP_KIND Kind) { @@ -89,6 +116,14 @@ bool Init(MESA_INTEROP_KIND Kind) { (PFNMESAGLINTEROPEGLEXPORTOBJECTPROC*)egl_procaddr_fn("eglGLInteropExportObjectMESA"); } + if (!GlxInfo || !GlxExport) { + LegacyInitGLX(); + } + + if (!EglInfo || !EglExport) { + LegacyInitEGL(); + } + uint32_t ret = MESA_INTEROP_NONE; if (GlxInfo && GlxExport) { ret |= MESA_INTEROP_GLX;