Skip to content

fix: In Linux CL/GL sharing, handle failed symbols lookup #808

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion opencl/source/sharings/gl/linux/gl_sharing_linux.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Intel Corporation
* Copyright (C) 2023-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -37,6 +37,9 @@ bool GLSharingFunctionsLinux::isOpenGlExtensionSupported(const unsigned char *pE
}

bool GLSharingFunctionsLinux::isOpenGlSharingSupported() {
if (glGetString == nullptr) {
return false;
}

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

switch (glHDCType) {
case CL_GLX_DISPLAY_KHR:
if (!glXLoaded)
return false;
break;
case CL_EGL_DISPLAY_KHR:
if (!eglLoaded)
return false;
break;
default:
if (!glXLoaded && !eglLoaded)
return false;
}

return true;
}

Expand Down Expand Up @@ -102,13 +119,19 @@ GLboolean GLSharingFunctionsLinux::initGLFunctions() {
glXGLInteropQueryDeviceInfo = glXGetProc["glXGLInteropQueryDeviceInfoMESA"];
glXGLInteropExportObject = glXGetProc["glXGLInteropExportObjectMESA"];
glXGLInteropFlushObjects = glXGetProc["glXGLInteropFlushObjectsMESA"];
glXLoaded = ((glXGLInteropQueryDeviceInfo != nullptr) &&
(glXGLInteropExportObject != nullptr) &&
(glXGLInteropFlushObjects != nullptr));
}

GlFunctionHelper eglGetProc(dynLibrary.get(), "eglGetProcAddress");
if (eglGetProc.ready()) {
eglGLInteropQueryDeviceInfo = eglGetProc["eglGLInteropQueryDeviceInfoMESA"];
eglGLInteropExportObject = eglGetProc["eglGLInteropExportObjectMESA"];
eglGLInteropFlushObjects = eglGetProc["eglGLInteropFlushObjectsMESA"];
eglLoaded = ((eglGLInteropQueryDeviceInfo != nullptr) &&
(eglGLInteropExportObject != nullptr) &&
(eglGLInteropFlushObjects != nullptr));
}

glGetString = (*dynLibrary)["glGetString"];
Expand Down
6 changes: 5 additions & 1 deletion opencl/source/sharings/gl/linux/gl_sharing_linux.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Intel Corporation
* Copyright (C) 2023-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -127,6 +127,10 @@ class GLSharingFunctionsLinux : public GLSharingFunctions {
GLContext glHGLRCHandleBkpCtx = 0;
GLDisplay glHDCHandle = 0;

// Readiness
bool glXLoaded = false;
bool eglLoaded = false;

// GL functions
PFNglGetString glGetString = nullptr;
PFNglGetStringi glGetStringi = nullptr;
Expand Down
13 changes: 10 additions & 3 deletions opencl/source/sharings/gl/linux/lin_enable_gl.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023-2024 Intel Corporation
* Copyright (C) 2023-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -54,8 +54,15 @@ bool GlSharingContextBuilder::finalizeProperties(Context &context, int32_t &errc
return true;

if (contextData->glHGLRCHandle) {
context.registerSharing(new GLSharingFunctionsLinux(contextData->glHDCType, contextData->glHGLRCHandle,
nullptr, contextData->glHDCHandle));
GLSharingFunctionsLinux *sharing_fn = new GLSharingFunctionsLinux(contextData->glHDCType,
contextData->glHGLRCHandle,
nullptr, contextData->glHDCHandle);
if (!sharing_fn->isOpenGlSharingSupported()) {
delete sharing_fn;
errcodeRet = CL_INVALID_PROPERTY;
return false;
}
context.registerSharing(sharing_fn);
}

contextData.reset(nullptr);
Expand Down