Skip to content

Commit 960e818

Browse files
committed
fix: In Linux CL/GL sharing, handle failed symbols lookup
In some cases we endup with GL being found but neither GLX or EGL found and this currently leads to crash. So to better handle this case (and others), we keep track if we found symbols or not. If we're asked if CL/GL sharing is supported we check the load worked. If it's during an actual context creation we check what we were given match what we could load and fail context property finalization if not. If it's during an "info" request where we don't have any properties yet, we return yes if either GLX or EGL was found. Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
1 parent c645f84 commit 960e818

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

opencl/source/sharings/gl/linux/gl_sharing_linux.cpp

+23
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ bool GLSharingFunctionsLinux::isOpenGlExtensionSupported(const unsigned char *pE
3737
}
3838

3939
bool GLSharingFunctionsLinux::isOpenGlSharingSupported() {
40+
if (glGetString == nullptr) {
41+
return false;
42+
}
4043

4144
std::basic_string<unsigned char> vendor = glGetString(GL_VENDOR);
4245
const unsigned char intelVendor[] = "Intel";
@@ -72,6 +75,20 @@ bool GLSharingFunctionsLinux::isOpenGlSharingSupported() {
7275
}
7376
}
7477

78+
switch (glHDCType) {
79+
case CL_GLX_DISPLAY_KHR:
80+
if (!glXLoaded)
81+
return false;
82+
break;
83+
case CL_EGL_DISPLAY_KHR:
84+
if (!eglLoaded)
85+
return false;
86+
break;
87+
default:
88+
if (!glXLoaded && !eglLoaded)
89+
return false;
90+
}
91+
7592
return true;
7693
}
7794

@@ -102,13 +119,19 @@ GLboolean GLSharingFunctionsLinux::initGLFunctions() {
102119
glXGLInteropQueryDeviceInfo = glXGetProc["glXGLInteropQueryDeviceInfoMESA"];
103120
glXGLInteropExportObject = glXGetProc["glXGLInteropExportObjectMESA"];
104121
glXGLInteropFlushObjects = glXGetProc["glXGLInteropFlushObjectsMESA"];
122+
glXLoaded = ((glXGLInteropQueryDeviceInfo != nullptr) &&
123+
(glXGLInteropExportObject != nullptr) &&
124+
(glXGLInteropFlushObjects != nullptr));
105125
}
106126

107127
GlFunctionHelper eglGetProc(dynLibrary.get(), "eglGetProcAddress");
108128
if (eglGetProc.ready()) {
109129
eglGLInteropQueryDeviceInfo = eglGetProc["eglGLInteropQueryDeviceInfoMESA"];
110130
eglGLInteropExportObject = eglGetProc["eglGLInteropExportObjectMESA"];
111131
eglGLInteropFlushObjects = eglGetProc["eglGLInteropFlushObjectsMESA"];
132+
eglLoaded = ((eglGLInteropQueryDeviceInfo != nullptr) &&
133+
(eglGLInteropExportObject != nullptr) &&
134+
(eglGLInteropFlushObjects != nullptr));
112135
}
113136

114137
glGetString = (*dynLibrary)["glGetString"];

opencl/source/sharings/gl/linux/gl_sharing_linux.h

+4
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ class GLSharingFunctionsLinux : public GLSharingFunctions {
127127
GLContext glHGLRCHandleBkpCtx = 0;
128128
GLDisplay glHDCHandle = 0;
129129

130+
// Readiness
131+
bool glXLoaded = false;
132+
bool eglLoaded = false;
133+
130134
// GL functions
131135
PFNglGetString glGetString = nullptr;
132136
PFNglGetStringi glGetStringi = nullptr;

opencl/source/sharings/gl/linux/lin_enable_gl.cpp

+9-2
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,15 @@ bool GlSharingContextBuilder::finalizeProperties(Context &context, int32_t &errc
5454
return true;
5555

5656
if (contextData->glHGLRCHandle) {
57-
context.registerSharing(new GLSharingFunctionsLinux(contextData->glHDCType, contextData->glHGLRCHandle,
58-
nullptr, contextData->glHDCHandle));
57+
GLSharingFunctionsLinux *sharing_fn = new GLSharingFunctionsLinux(contextData->glHDCType,
58+
contextData->glHGLRCHandle,
59+
nullptr, contextData->glHDCHandle);
60+
if (!sharing_fn->isOpenGlSharingSupported()) {
61+
delete sharing_fn;
62+
errcodeRet = CL_INVALID_PROPERTY;
63+
return false;
64+
}
65+
context.registerSharing(sharing_fn);
5966
}
6067

6168
contextData.reset(nullptr);

0 commit comments

Comments
 (0)