diff --git a/opencl/source/sharings/gl/linux/gl_sharing_linux.cpp b/opencl/source/sharings/gl/linux/gl_sharing_linux.cpp index f3cd5a1452e28..4345c8d1cf7e2 100644 --- a/opencl/source/sharings/gl/linux/gl_sharing_linux.cpp +++ b/opencl/source/sharings/gl/linux/gl_sharing_linux.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023-2024 Intel Corporation + * Copyright (C) 2023-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -37,6 +37,9 @@ bool GLSharingFunctionsLinux::isOpenGlExtensionSupported(const unsigned char *pE } bool GLSharingFunctionsLinux::isOpenGlSharingSupported() { + if (glGetString == nullptr) { + return false; + } std::basic_string vendor = glGetString(GL_VENDOR); const unsigned char intelVendor[] = "Intel"; @@ -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; } @@ -102,6 +119,9 @@ GLboolean GLSharingFunctionsLinux::initGLFunctions() { glXGLInteropQueryDeviceInfo = glXGetProc["glXGLInteropQueryDeviceInfoMESA"]; glXGLInteropExportObject = glXGetProc["glXGLInteropExportObjectMESA"]; glXGLInteropFlushObjects = glXGetProc["glXGLInteropFlushObjectsMESA"]; + glXLoaded = ((glXGLInteropQueryDeviceInfo != nullptr) && + (glXGLInteropExportObject != nullptr) && + (glXGLInteropFlushObjects != nullptr)); } GlFunctionHelper eglGetProc(dynLibrary.get(), "eglGetProcAddress"); @@ -109,6 +129,9 @@ GLboolean GLSharingFunctionsLinux::initGLFunctions() { eglGLInteropQueryDeviceInfo = eglGetProc["eglGLInteropQueryDeviceInfoMESA"]; eglGLInteropExportObject = eglGetProc["eglGLInteropExportObjectMESA"]; eglGLInteropFlushObjects = eglGetProc["eglGLInteropFlushObjectsMESA"]; + eglLoaded = ((eglGLInteropQueryDeviceInfo != nullptr) && + (eglGLInteropExportObject != nullptr) && + (eglGLInteropFlushObjects != nullptr)); } glGetString = (*dynLibrary)["glGetString"]; diff --git a/opencl/source/sharings/gl/linux/gl_sharing_linux.h b/opencl/source/sharings/gl/linux/gl_sharing_linux.h index 778f147831e48..e88218558c49c 100644 --- a/opencl/source/sharings/gl/linux/gl_sharing_linux.h +++ b/opencl/source/sharings/gl/linux/gl_sharing_linux.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023-2024 Intel Corporation + * Copyright (C) 2023-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -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; diff --git a/opencl/source/sharings/gl/linux/lin_enable_gl.cpp b/opencl/source/sharings/gl/linux/lin_enable_gl.cpp index 7f9d13be5ff76..5c72316f50f4f 100644 --- a/opencl/source/sharings/gl/linux/lin_enable_gl.cpp +++ b/opencl/source/sharings/gl/linux/lin_enable_gl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2023-2024 Intel Corporation + * Copyright (C) 2023-2025 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -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);