diff --git a/runtime/os_interface/windows/gl/gl_arb_sync_event_os.cpp b/runtime/os_interface/windows/gl/gl_arb_sync_event_os.cpp index e1b81fa974..3a2fdf4a2f 100644 --- a/runtime/os_interface/windows/gl/gl_arb_sync_event_os.cpp +++ b/runtime/os_interface/windows/gl/gl_arb_sync_event_os.cpp @@ -15,7 +15,7 @@ #include "runtime/os_interface/windows/os_interface.h" #include "runtime/os_interface/windows/wddm/wddm.h" #include "runtime/sharings/gl/gl_arb_sync_event.h" -#include "runtime/sharings/gl/gl_sharing.h" +#include "runtime/sharings/gl/windows/gl_sharing.h" #include @@ -59,8 +59,10 @@ void cleanupArbSyncObject(OSInterface &osInterface, CL_GL_SYNC_INFO *glSyncInfo) } bool setupArbSyncObject(GLSharingFunctions &sharing, OSInterface &osInterface, CL_GL_SYNC_INFO &glSyncInfo) { - glSyncInfo.hContextToBlock = static_cast(sharing.getGLContextHandle()); - auto glDevice = static_cast(sharing.getGLDeviceHandle()); + auto &sharingFunctions = static_cast(sharing); + + glSyncInfo.hContextToBlock = static_cast(sharingFunctions.getGLContextHandle()); + auto glDevice = static_cast(sharingFunctions.getGLDeviceHandle()); auto wddm = osInterface.get()->getWddm(); D3DKMT_CREATESYNCHRONIZATIONOBJECT serverSyncInitInfo = {0}; diff --git a/runtime/os_interface/windows/gl/gl_sharing_os.h b/runtime/os_interface/windows/gl/gl_sharing_os.h index 32b5215771..ee448089f6 100644 --- a/runtime/os_interface/windows/gl/gl_sharing_os.h +++ b/runtime/os_interface/windows/gl/gl_sharing_os.h @@ -1,14 +1,16 @@ /* - * Copyright (C) 2018 Intel Corporation + * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT * */ +#include "core/os_interface/windows/windows_wrapper.h" + +#include + #define OSAPI WINAPI typedef uint32_t GLType; typedef HDC GLDisplay; typedef HGLRC GLContext; - -// Windows OpenGL functions diff --git a/runtime/os_interface/windows/gl/gl_sharing_win.cpp b/runtime/os_interface/windows/gl/gl_sharing_win.cpp index 17e98f152f..740ead5c0a 100644 --- a/runtime/os_interface/windows/gl/gl_sharing_win.cpp +++ b/runtime/os_interface/windows/gl/gl_sharing_win.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2019 Intel Corporation + * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,8 +7,9 @@ #include "core/os_interface/windows/windows_wrapper.h" #include "runtime/helpers/timestamp_packet.h" +#include "runtime/helpers/windows/gl_helper.h" #include "runtime/sharings/gl/gl_arb_sync_event.h" -#include "runtime/sharings/gl/gl_sharing.h" +#include "runtime/sharings/gl/windows/gl_sharing.h" #include #include @@ -20,121 +21,6 @@ extern const char *openglDllName; namespace NEO { -GLboolean GLSharingFunctions::makeCurrent(GLContext contextHandle, GLDisplay displayHandle) { - if (displayHandle == 0) { - displayHandle = GLHDCHandle; - } - return this->wglMakeCurrent(displayHandle, contextHandle); -} - -GLSharingFunctions::~GLSharingFunctions() { - if (pfnWglDeleteContext) { - pfnWglDeleteContext(GLHGLRCHandleBkpCtx); - } -} - -GLboolean GLSharingFunctions::initGLFunctions() { - glLibrary.reset(OsLibrary::load(Os::openglDllName)); - - if (glLibrary->isLoaded()) { - glFunctionHelper wglLibrary(glLibrary.get(), "wglGetProcAddress"); - GLGetCurrentContext = (*glLibrary)["wglGetCurrentContext"]; - GLGetCurrentDisplay = (*glLibrary)["wglGetCurrentDC"]; - glGetString = (*glLibrary)["glGetString"]; - glGetIntegerv = (*glLibrary)["glGetIntegerv"]; - pfnWglCreateContext = (*glLibrary)["wglCreateContext"]; - pfnWglDeleteContext = (*glLibrary)["wglDeleteContext"]; - pfnWglShareLists = (*glLibrary)["wglShareLists"]; - wglMakeCurrent = (*glLibrary)["wglMakeCurrent"]; - - GLSetSharedOCLContextState = wglLibrary["wglSetSharedOCLContextStateINTEL"]; - GLAcquireSharedBuffer = wglLibrary["wglAcquireSharedBufferINTEL"]; - GLReleaseSharedBuffer = wglLibrary["wglReleaseSharedBufferINTEL"]; - GLAcquireSharedRenderBuffer = wglLibrary["wglAcquireSharedRenderBufferINTEL"]; - GLReleaseSharedRenderBuffer = wglLibrary["wglReleaseSharedRenderBufferINTEL"]; - GLAcquireSharedTexture = wglLibrary["wglAcquireSharedTextureINTEL"]; - GLReleaseSharedTexture = wglLibrary["wglReleaseSharedTextureINTEL"]; - GLRetainSync = wglLibrary["wglRetainSyncINTEL"]; - GLReleaseSync = wglLibrary["wglReleaseSyncINTEL"]; - GLGetSynciv = wglLibrary["wglGetSyncivINTEL"]; - glGetStringi = wglLibrary["glGetStringi"]; - } - this->pfnGlArbSyncObjectCleanup = cleanupArbSyncObject; - this->pfnGlArbSyncObjectSetup = setupArbSyncObject; - this->pfnGlArbSyncObjectSignal = signalArbSyncObject; - this->pfnGlArbSyncObjectWaitServer = serverWaitForArbSyncObject; - - return 1; -} - -bool GLSharingFunctions::isGlSharingEnabled() { - static bool oglLibAvailable = std::unique_ptr(OsLibrary::load(Os::openglDllName)).get() != nullptr; - return oglLibAvailable; -} - -bool GLSharingFunctions::isOpenGlExtensionSupported(const unsigned char *pExtensionString) { - bool LoadedNull = (glGetStringi == nullptr) || (glGetIntegerv == nullptr); - if (LoadedNull) { - return false; - } - - cl_int NumberOfExtensions = 0; - glGetIntegerv(GL_NUM_EXTENSIONS, &NumberOfExtensions); - for (cl_int i = 0; i < NumberOfExtensions; i++) { - std::basic_string pString = glGetStringi(GL_EXTENSIONS, i); - if (pString == pExtensionString) { - return true; - } - } - return false; -} - -bool GLSharingFunctions::isOpenGlSharingSupported() { - - std::basic_string Vendor = glGetString(GL_VENDOR); - const unsigned char intelVendor[] = "Intel"; - - if ((Vendor.empty()) || (Vendor != intelVendor)) { - return false; - } - std::basic_string Version = glGetString(GL_VERSION); - if (Version.empty()) { - return false; - } - - bool IsOpenGLES = false; - const unsigned char versionES[] = "OpenGL ES"; - if (Version.find(versionES) != std::string::npos) { - IsOpenGLES = true; - } - - if (IsOpenGLES == true) { - const unsigned char versionES1[] = "OpenGL ES 1."; - if (Version.find(versionES1) != std::string::npos) { - const unsigned char supportGLOES[] = "GL_OES_framebuffer_object"; - if (isOpenGlExtensionSupported(supportGLOES) == false) { - return false; - } - } - } else { - if (Version[0] < '3') { - const unsigned char supportGLEXT[] = "GL_EXT_framebuffer_object"; - if (isOpenGlExtensionSupported(supportGLEXT) == false) { - return false; - } - } - } - - return true; -} - -void GLSharingFunctions::createBackupContext() { - if (pfnWglCreateContext) { - GLHGLRCHandleBkpCtx = pfnWglCreateContext(GLHDCHandle); - pfnWglShareLists(GLHGLRCHandle, GLHGLRCHandleBkpCtx); - } -} - cl_int GLSharingFunctions::getSupportedFormats(cl_mem_flags flags, cl_mem_object_type imageType, size_t numEntries, diff --git a/runtime/sharings/gl/CMakeLists.txt b/runtime/sharings/gl/CMakeLists.txt index a90cf5c334..2d49a8dd2e 100644 --- a/runtime/sharings/gl/CMakeLists.txt +++ b/runtime/sharings/gl/CMakeLists.txt @@ -1,27 +1,27 @@ # -# Copyright (C) 2017-2019 Intel Corporation +# Copyright (C) 2017-2020 Intel Corporation # # SPDX-License-Identifier: MIT # if(WIN32) set(RUNTIME_SRCS_SHARINGS_GL - ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt - ${CMAKE_CURRENT_SOURCE_DIR}/cl_gl_api.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/cl_gl_api_intel.h - ${CMAKE_CURRENT_SOURCE_DIR}/gl_arb_sync_event.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/gl_arb_sync_event.h - ${CMAKE_CURRENT_SOURCE_DIR}/gl_buffer.h - ${CMAKE_CURRENT_SOURCE_DIR}/gl_buffer.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/gl_cl_image_format.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/gl_context_guard.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/gl_sharing.h - ${CMAKE_CURRENT_SOURCE_DIR}/gl_sharing.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/gl_sync_event.h - ${CMAKE_CURRENT_SOURCE_DIR}/gl_sync_event.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/gl_texture.h - ${CMAKE_CURRENT_SOURCE_DIR}/gl_texture.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/cl_gl_api.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/cl_gl_api_intel.h + ${CMAKE_CURRENT_SOURCE_DIR}/gl_arb_sync_event.h + ${CMAKE_CURRENT_SOURCE_DIR}/gl_buffer.h + ${CMAKE_CURRENT_SOURCE_DIR}/gl_cl_image_format.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/gl_context_guard.h + ${CMAKE_CURRENT_SOURCE_DIR}/gl_sharing.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/gl_sharing.h + ${CMAKE_CURRENT_SOURCE_DIR}/gl_sync_event.h + ${CMAKE_CURRENT_SOURCE_DIR}/gl_texture.h ) + target_sources(${NEO_STATIC_LIB_NAME} PRIVATE ${RUNTIME_SRCS_SHARINGS_GL}) + + add_subdirectories() + set(ADDITIONAL_EXPORTS "clEnqueueMarkerWithSyncObjectINTEL" "clGetCLObjectInfoINTEL" "clGetCLEventInfoINTEL" @@ -29,9 +29,4 @@ if(WIN32) foreach(EXPORT_NAME ${ADDITIONAL_EXPORTS}) set(MSVC_DEF_ADDITIONAL_EXPORTS "${MSVC_DEF_ADDITIONAL_EXPORTS}\n${EXPORT_NAME}") endforeach(EXPORT_NAME) - - target_sources(${NEO_STATIC_LIB_NAME} PRIVATE ${RUNTIME_SRCS_SHARINGS_GL}) - set(MSVC_DEF_ADDITIONAL_EXPORTS "${MSVC_DEF_ADDITIONAL_EXPORTS}" PARENT_SCOPE) - - target_sources(${SHARINGS_ENABLE_LIB_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/win_enable_gl.cpp) endif() diff --git a/runtime/sharings/gl/cl_gl_api.cpp b/runtime/sharings/gl/cl_gl_api.cpp index 364a161980..1eb731ecb1 100644 --- a/runtime/sharings/gl/cl_gl_api.cpp +++ b/runtime/sharings/gl/cl_gl_api.cpp @@ -19,9 +19,9 @@ #include "runtime/mem_obj/mem_obj.h" #include "runtime/platform/platform.h" #include "runtime/sharings/gl/gl_buffer.h" -#include "runtime/sharings/gl/gl_sharing.h" #include "runtime/sharings/gl/gl_sync_event.h" #include "runtime/sharings/gl/gl_texture.h" +#include "runtime/sharings/gl/windows/gl_sharing.h" #include "runtime/tracing/tracing_notify.h" #include "CL/cl.h" @@ -337,7 +337,7 @@ cl_int CL_API_CALL clGetGLContextInfoKHR(const cl_context_properties *properties return retVal; } - auto glSharing = std::make_unique(); + auto glSharing = std::make_unique(); glSharing->initGLFunctions(); if (glSharing->isOpenGlSharingSupported() == false) { retVal = CL_INVALID_CONTEXT; diff --git a/runtime/sharings/gl/gl_context_guard.cpp b/runtime/sharings/gl/gl_context_guard.cpp deleted file mode 100644 index 0ba618419c..0000000000 --- a/runtime/sharings/gl/gl_context_guard.cpp +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2018-2019 Intel Corporation - * - * SPDX-License-Identifier: MIT - * - */ - -#include "runtime/sharings/gl/gl_sharing.h" - -namespace NEO { -GLContextGuard::GLContextGuard(GLSharingFunctions &sharingFcns) : sharingFunctions(&sharingFcns) { - currentContextHandle = sharingFcns.getCurrentContext(); - currentDisplayHandle = sharingFcns.getCurrentDisplay(); - auto ctxToMakeCurrent = sharingFcns.getContextHandle(); - - if (currentContextHandle == 0) { - ctxToMakeCurrent = sharingFcns.getBackupContextHandle(); - } - - if (currentContextHandle != sharingFcns.getContextHandle() && currentContextHandle != sharingFcns.getBackupContextHandle()) { - if (sharingFcns.makeCurrent(ctxToMakeCurrent) == GL_FALSE) { - while (sharingFcns.makeCurrent(sharingFcns.getBackupContextHandle()) == GL_FALSE) { - ; - } - } - } -} - -GLContextGuard::~GLContextGuard() { - if (currentContextHandle != sharingFunctions->getContextHandle()) { - sharingFunctions->makeCurrent(currentContextHandle, currentDisplayHandle); - } -} -} // namespace NEO diff --git a/runtime/sharings/gl/gl_context_guard.h b/runtime/sharings/gl/gl_context_guard.h new file mode 100644 index 0000000000..33f919c79f --- /dev/null +++ b/runtime/sharings/gl/gl_context_guard.h @@ -0,0 +1,26 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once + +#include "runtime/os_interface/windows/gl/gl_sharing_os.h" +#include "runtime/sharings/gl/gl_sharing.h" + +namespace NEO { +class GLContextGuard { + public: + GLContextGuard() = delete; + GLContextGuard(GLSharingFunctions &sharingFcns); + ~GLContextGuard(); + + protected: + GLSharingFunctions *sharingFunctions; + + GLContext currentContextHandle; + GLDisplay currentDisplayHandle; +}; +} // namespace NEO diff --git a/runtime/sharings/gl/gl_sharing.cpp b/runtime/sharings/gl/gl_sharing.cpp index 2caacc4a02..97f90e80cd 100644 --- a/runtime/sharings/gl/gl_sharing.cpp +++ b/runtime/sharings/gl/gl_sharing.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2019 Intel Corporation + * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -8,9 +8,9 @@ #include "runtime/sharings/gl/gl_sharing.h" #include "core/helpers/string.h" -#include "runtime/context/context.h" +#include "runtime/context/context.inl" #include "runtime/helpers/timestamp_packet.h" -#include "runtime/sharings/gl/gl_arb_sync_event.h" +#include "runtime/sharings/gl/gl_context_guard.h" #include "runtime/sharings/sharing_factory.h" #include @@ -70,35 +70,6 @@ int GlSharing::synchronizeHandler(UpdateData &updateData) { return CL_SUCCESS; } -template <> -GLSharingFunctions *Context::getSharing() { - if (GLSharingFunctions::sharingId >= sharingFunctions.size()) { - DEBUG_BREAK_IF(GLSharingFunctions::sharingId >= sharingFunctions.size()); - return nullptr; - } - - return reinterpret_cast(sharingFunctions[GLSharingFunctions::sharingId].get()); -} - -GlArbSyncEvent *GLSharingFunctions::getGlArbSyncEvent(Event &baseEvent) { - std::lock_guard lock{glArbEventMutex}; - auto it = glArbEventMapping.find(&baseEvent); - if (it != glArbEventMapping.end()) { - return it->second; - } - return nullptr; -} - -void GLSharingFunctions::removeGlArbSyncEventMapping(Event &baseEvent) { - std::lock_guard lock{glArbEventMutex}; - auto it = glArbEventMapping.find(&baseEvent); - if (it == glArbEventMapping.end()) { - DEBUG_BREAK_IF(it == glArbEventMapping.end()); - return; - } - glArbEventMapping.erase(it); -} - char *createArbSyncEventName() { static std::atomic synchCounter{0}; uint32_t id = synchCounter++; @@ -113,4 +84,7 @@ char *createArbSyncEventName() { } void destroyArbSyncEventName(char *name) { delete[] name; } + +template GLSharingFunctions *Context::getSharing(); + } // namespace NEO diff --git a/runtime/sharings/gl/gl_sharing.h b/runtime/sharings/gl/gl_sharing.h index f745794a4b..e13571bcc5 100644 --- a/runtime/sharings/gl/gl_sharing.h +++ b/runtime/sharings/gl/gl_sharing.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2019 Intel Corporation + * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -8,8 +8,6 @@ #pragma once #include "core/os_interface/os_library.h" -#include "runtime/helpers/windows/gl_helper.h" -#include "runtime/os_interface/windows/gl/gl_sharing_os.h" #include "runtime/sharings/sharing.h" #include "CL/cl.h" @@ -32,37 +30,6 @@ class OsContext; typedef unsigned int OS_HANDLE; -//OpenGL API names -typedef GLboolean(OSAPI *PFNOGLSetSharedOCLContextStateINTEL)(GLDisplay hdcHandle, GLContext contextHandle, GLboolean state, GLvoid *pContextInfo); -typedef GLboolean(OSAPI *PFNOGLAcquireSharedBufferINTEL)(GLDisplay hdcHandle, GLContext contextHandle, GLContext backupContextHandle, GLvoid *pBufferInfo); -typedef GLboolean(OSAPI *PFNOGLAcquireSharedRenderBufferINTEL)(GLDisplay hdcHandle, GLContext contextHandle, GLContext backupContextHandle, GLvoid *pResourceInfo); -typedef GLboolean(OSAPI *PFNOGLAcquireSharedTextureINTEL)(GLDisplay hdcHandle, GLContext contextHandle, GLContext backupContextHandle, GLvoid *pResourceInfo); -typedef GLboolean(OSAPI *PFNOGLReleaseSharedBufferINTEL)(GLDisplay hdcHandle, GLContext contextHandle, GLContext backupContextHandle, GLvoid *pBufferInfo); -typedef GLboolean(OSAPI *PFNOGLReleaseSharedRenderBufferINTEL)(GLDisplay hdcHandle, GLContext contextHandle, GLContext backupContextHandle, GLvoid *pResourceInfo); -typedef GLboolean(OSAPI *PFNOGLReleaseSharedTextureINTEL)(GLDisplay hdcHandle, GLContext contextHandle, GLContext backupContextHandle, GLvoid *pResourceInfo); -typedef GLContext(OSAPI *PFNOGLGetCurrentContext)(); -typedef GLDisplay(OSAPI *PFNOGLGetCurrentDisplay)(); -typedef GLboolean(OSAPI *PFNOGLMakeCurrent)(GLDisplay hdcHandle, void *draw, void *read, GLContext contextHandle); -typedef GLboolean(OSAPI *PFNOGLRetainSyncINTEL)(GLDisplay hdcHandle, GLContext contextHandle, GLContext backupContextHandle, GLvoid *pSyncInfo); -typedef GLboolean(OSAPI *PFNOGLReleaseSyncINTEL)(GLDisplay hdcHandle, GLContext contextHandle, GLContext backupContextHandle, GLvoid *pSync); -typedef void(OSAPI *PFNOGLGetSyncivINTEL)(GLvoid *pSync, GLenum pname, GLint *value); - -typedef const GLubyte *(OSAPI *PFNglGetString)(GLenum name); -typedef const GLubyte *(OSAPI *PFNglGetStringi)(GLenum name, GLuint index); -typedef void(OSAPI *PFNglGetIntegerv)(GLenum pname, GLint *params); -typedef void(OSAPI *PFNglBindTexture)(GLenum target, GLuint texture); - -//wgl -typedef BOOL(OSAPI *PFNwglMakeCurrent)(HDC, HGLRC); -typedef GLContext(OSAPI *PFNwglCreateContext)(GLDisplay hdcHandle); -typedef int(OSAPI *PFNwglShareLists)(GLContext contextHandle, GLContext backupContextHandle); -typedef BOOL(OSAPI *PFNwglDeleteContext)(HGLRC hglrcHandle); - -typedef bool (*PFNglArbSyncObjectSetup)(GLSharingFunctions &sharing, OSInterface &osInterface, CL_GL_SYNC_INFO &glSyncInfo); -typedef void (*PFNglArbSyncObjectCleanup)(OSInterface &osInterface, CL_GL_SYNC_INFO *glSyncInfo); -typedef void (*PFNglArbSyncObjectSignal)(OsContext &osContext, CL_GL_SYNC_INFO &glSyncInfo); -typedef void (*PFNglArbSyncObjectWaitServer)(OSInterface &osInterface, CL_GL_SYNC_INFO &glSyncInfo); - typedef struct CLGLContextInfo { OS_HANDLE DeviceHandle; OS_HANDLE ContextHandle; @@ -70,190 +37,21 @@ typedef struct CLGLContextInfo { class GLSharingFunctions : public SharingFunctions { public: - ~GLSharingFunctions() override; - GLSharingFunctions() = default; - GLSharingFunctions(GLType glhdcType, GLContext glhglrcHandle, GLContext glhglrcHandleBkpCtx, GLDisplay glhdcHandle) : GLHDCType(glhdcType), GLHGLRCHandle(glhglrcHandle), GLHGLRCHandleBkpCtx(glhglrcHandleBkpCtx), GLHDCHandle(glhdcHandle) { - - initGLFunctions(); - updateOpenGLContext(); - createBackupContext(); - } - uint32_t getId() const override { return GLSharingFunctions::sharingId; } static const uint32_t sharingId; - void updateOpenGLContext() { - if (GLSetSharedOCLContextState) { - setSharedOCLContextState(); - } - } - - // Interface - GLboolean initGLFunctions(); - - static bool isGlSharingEnabled(); - static cl_int getSupportedFormats(cl_mem_flags flags, cl_mem_object_type imageType, size_t numEntries, cl_GLenum *formats, uint32_t *numImageFormats); - GLboolean setSharedOCLContextState() { - ContextInfo CtxInfo = {0}; - GLboolean retVal = GLSetSharedOCLContextState(GLHDCHandle, GLHGLRCHandle, CL_TRUE, &CtxInfo); - if (retVal == GL_FALSE) { - return GL_FALSE; - } - GLContextHandle = CtxInfo.ContextHandle; - GLDeviceHandle = CtxInfo.DeviceHandle; - - return retVal; - } - - GLboolean acquireSharedBufferINTEL(GLvoid *pBufferInfo) { - return GLAcquireSharedBuffer(GLHDCHandle, GLHGLRCHandle, GLHGLRCHandleBkpCtx, pBufferInfo); - } - - GLboolean releaseSharedBufferINTEL(GLvoid *pBufferInfo) { - return GLReleaseSharedBuffer(GLHDCHandle, GLHGLRCHandle, GLHGLRCHandleBkpCtx, pBufferInfo); - } - - GLboolean acquireSharedRenderBuffer(GLvoid *pResourceInfo) { - return GLAcquireSharedRenderBuffer(GLHDCHandle, GLHGLRCHandle, GLHGLRCHandleBkpCtx, pResourceInfo); - } - - GLboolean releaseSharedRenderBuffer(GLvoid *pResourceInfo) { - return GLReleaseSharedRenderBuffer(GLHDCHandle, GLHGLRCHandle, GLHGLRCHandleBkpCtx, pResourceInfo); - } - - GLboolean acquireSharedTexture(GLvoid *pResourceInfo) { - return GLAcquireSharedTexture(GLHDCHandle, GLHGLRCHandle, GLHGLRCHandleBkpCtx, pResourceInfo); - } - - GLboolean releaseSharedTexture(GLvoid *pResourceInfo) { - return GLReleaseSharedTexture(GLHDCHandle, GLHGLRCHandle, GLHGLRCHandleBkpCtx, pResourceInfo); - } - - GLboolean retainSync(GLvoid *pSyncInfo) { - return GLRetainSync(GLHDCHandle, GLHGLRCHandle, GLHGLRCHandleBkpCtx, pSyncInfo); - } - - GLboolean releaseSync(GLvoid *pSync) { - return GLReleaseSync(GLHDCHandle, GLHGLRCHandle, GLHGLRCHandleBkpCtx, pSync); - } - - void getSynciv(GLvoid *pSync, GLenum pname, GLint *value) { - return GLGetSynciv(pSync, pname, value); - } - - GLContext getCurrentContext() { - return GLGetCurrentContext(); - } - - GLDisplay getCurrentDisplay() { - return GLGetCurrentDisplay(); - } - - GLboolean makeCurrent(GLContext contextHandle, GLDisplay displayHandle = 0); - - GLContext getBackupContextHandle() { - return GLHGLRCHandleBkpCtx; - } - - GLContext getContextHandle() { - return GLHGLRCHandle; - } - - void createBackupContext(); - - bool isOpenGlExtensionSupported(const unsigned char *pExtentionString); - bool isOpenGlSharingSupported(); - - std::mutex mutex; - std::vector> graphicsAllocationsForGlBufferReuse; - - GlArbSyncEvent *getGlArbSyncEvent(Event &baseEvent); - - template - auto getOrCreateGlArbSyncEvent(Event &baseEvent) -> decltype(EventType::create(baseEvent)) { - std::lock_guard lock{glArbEventMutex}; - auto it = glArbEventMapping.find(&baseEvent); - if (it != glArbEventMapping.end()) { - return it->second; - } - - auto arbEvent = EventType::create(baseEvent); - if (nullptr == arbEvent) { - return arbEvent; - } - glArbEventMapping[&baseEvent] = arbEvent; - return arbEvent; - } - - void removeGlArbSyncEventMapping(Event &baseEvent); - - bool glArbSyncObjectSetup(OSInterface &osInterface, CL_GL_SYNC_INFO &glSyncInfo) { - return pfnGlArbSyncObjectSetup(*this, osInterface, glSyncInfo); - } - void glArbSyncObjectCleanup(OSInterface &osInterface, CL_GL_SYNC_INFO *glSyncInfo) { - pfnGlArbSyncObjectCleanup(osInterface, glSyncInfo); - } - void glArbSyncObjectSignal(OsContext &osContext, CL_GL_SYNC_INFO &glSyncInfo) { pfnGlArbSyncObjectSignal(osContext, glSyncInfo); } - void glArbSyncObjectWaitServer(OSInterface &osInterface, CL_GL_SYNC_INFO &glSyncInfo) { - pfnGlArbSyncObjectWaitServer(osInterface, glSyncInfo); - } - - OS_HANDLE getGLDeviceHandle() const { - return GLDeviceHandle; - } - - OS_HANDLE getGLContextHandle() const { - return GLContextHandle; - } - - protected: - std::unique_ptr glLibrary; - - GLType GLHDCType = 0; - GLContext GLHGLRCHandle = 0; - GLContext GLHGLRCHandleBkpCtx = 0; - GLDisplay GLHDCHandle = 0; - OS_HANDLE GLDeviceHandle = 0; - OS_HANDLE GLContextHandle = 0; - - PFNOGLSetSharedOCLContextStateINTEL GLSetSharedOCLContextState = nullptr; - PFNOGLAcquireSharedBufferINTEL GLAcquireSharedBuffer = nullptr; - PFNOGLReleaseSharedBufferINTEL GLReleaseSharedBuffer = nullptr; - PFNOGLAcquireSharedRenderBufferINTEL GLAcquireSharedRenderBuffer = nullptr; - PFNOGLReleaseSharedRenderBufferINTEL GLReleaseSharedRenderBuffer = nullptr; - PFNOGLAcquireSharedTextureINTEL GLAcquireSharedTexture = nullptr; - PFNOGLReleaseSharedTextureINTEL GLReleaseSharedTexture = nullptr; - PFNOGLGetCurrentContext GLGetCurrentContext = nullptr; - PFNOGLGetCurrentDisplay GLGetCurrentDisplay = nullptr; - PFNglGetString glGetString = nullptr; - PFNglGetStringi glGetStringi = nullptr; - PFNglGetIntegerv glGetIntegerv = nullptr; - PFNwglCreateContext pfnWglCreateContext = nullptr; - PFNwglMakeCurrent wglMakeCurrent = nullptr; - PFNwglShareLists pfnWglShareLists = nullptr; - PFNwglDeleteContext pfnWglDeleteContext = nullptr; - PFNOGLRetainSyncINTEL GLRetainSync = nullptr; - PFNOGLReleaseSyncINTEL GLReleaseSync = nullptr; - PFNOGLGetSyncivINTEL GLGetSynciv = nullptr; - - PFNglArbSyncObjectSetup pfnGlArbSyncObjectSetup = nullptr; - PFNglArbSyncObjectCleanup pfnGlArbSyncObjectCleanup = nullptr; - PFNglArbSyncObjectSignal pfnGlArbSyncObjectSignal = nullptr; - PFNglArbSyncObjectWaitServer pfnGlArbSyncObjectWaitServer = nullptr; - - // support for GL_ARB_cl_event - std::mutex glArbEventMutex; - std::unordered_map glArbEventMapping; + virtual GLboolean initGLFunctions() = 0; + virtual bool isOpenGlSharingSupported() = 0; }; class GlSharing : public SharingHandler { @@ -278,17 +76,4 @@ class GlSharing : public SharingHandler { unsigned int clGlObjectId = 0u; }; -class GLContextGuard { - public: - GLContextGuard() = delete; - GLContextGuard(GLSharingFunctions &sharingFcns); - ~GLContextGuard(); - - protected: - GLSharingFunctions *sharingFunctions; - - GLContext currentContextHandle; - GLDisplay currentDisplayHandle; -}; - } // namespace NEO diff --git a/runtime/sharings/gl/windows/CMakeLists.txt b/runtime/sharings/gl/windows/CMakeLists.txt new file mode 100644 index 0000000000..9ef1ebe3fc --- /dev/null +++ b/runtime/sharings/gl/windows/CMakeLists.txt @@ -0,0 +1,27 @@ +# +# Copyright (C) 2020 Intel Corporation +# +# SPDX-License-Identifier: MIT +# + +if(WIN32) + set(RUNTIME_SRCS_SHARINGS_GL_WINDOWS + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/gl_arb_sync_event.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/gl_buffer.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/gl_context_guard.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/gl_sharing.h + ${CMAKE_CURRENT_SOURCE_DIR}/gl_sharing.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/gl_sync_event.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/gl_texture.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/win_enable_gl.h + ) + target_sources(${NEO_STATIC_LIB_NAME} PRIVATE ${RUNTIME_SRCS_SHARINGS_GL_WINDOWS}) + + set(RUNTIME_SRCS_SHARINGS_GL_ENABLE_WINDOWS + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/win_enable_gl.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/win_enable_gl.h + ) + target_sources(${SHARINGS_ENABLE_LIB_NAME} PRIVATE ${RUNTIME_SRCS_SHARINGS_GL_ENABLE_WINDOWS}) +endif() diff --git a/runtime/sharings/gl/gl_arb_sync_event.cpp b/runtime/sharings/gl/windows/gl_arb_sync_event.cpp similarity index 83% rename from runtime/sharings/gl/gl_arb_sync_event.cpp rename to runtime/sharings/gl/windows/gl_arb_sync_event.cpp index b73722950b..8dab3e61f0 100644 --- a/runtime/sharings/gl/gl_arb_sync_event.cpp +++ b/runtime/sharings/gl/windows/gl_arb_sync_event.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2019 Intel Corporation + * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -13,7 +13,7 @@ #include "runtime/context/context.h" #include "runtime/device/device.h" #include "runtime/helpers/base_object.h" -#include "runtime/sharings/gl/gl_sharing.h" +#include "runtime/sharings/gl/windows/gl_sharing.h" #include @@ -30,7 +30,7 @@ bool GlArbSyncEvent::setBaseEvent(Event &ev) { auto cmdQueue = ev.getCommandQueue(); auto osInterface = cmdQueue->getGpgpuCommandStreamReceiver().getOSInterface(); UNRECOVERABLE_IF(osInterface == nullptr); - if (false == ctx->getSharing()->glArbSyncObjectSetup(*osInterface, *glSyncInfo)) { + if (false == ctx->getSharing()->glArbSyncObjectSetup(*osInterface, *glSyncInfo)) { return false; } @@ -45,7 +45,7 @@ bool GlArbSyncEvent::setBaseEvent(Event &ev) { GlArbSyncEvent::~GlArbSyncEvent() { if (baseEvent != nullptr) { - ctx->getSharing()->glArbSyncObjectCleanup(*osInterface, glSyncInfo.get()); + ctx->getSharing()->glArbSyncObjectCleanup(*osInterface, glSyncInfo.get()); baseEvent->decRefInternal(); } } @@ -69,8 +69,8 @@ void GlArbSyncEvent::unblockEventBy(Event &event, uint32_t taskLevel, int32_t tr return; } - ctx->getSharing()->glArbSyncObjectSignal(event.getCommandQueue()->getGpgpuCommandStreamReceiver().getOsContext(), *glSyncInfo); - ctx->getSharing()->glArbSyncObjectWaitServer(*osInterface, *glSyncInfo); + ctx->getSharing()->glArbSyncObjectSignal(event.getCommandQueue()->getGpgpuCommandStreamReceiver().getOsContext(), *glSyncInfo); + ctx->getSharing()->glArbSyncObjectWaitServer(*osInterface, *glSyncInfo); } } // namespace NEO @@ -104,7 +104,7 @@ clGetCLEventInfoINTEL(cl_event event, PCL_GL_SYNC_INFO *pSyncInfoHandleRet, cl_c return CL_SUCCESS; } - auto sharing = neoEvent->getContext()->getSharing(); + auto sharing = neoEvent->getContext()->getSharing(); if (sharing == nullptr) { return CL_INVALID_OPERATION; } @@ -128,8 +128,8 @@ clReleaseGlSharedEventINTEL(cl_event event) { if (nullptr == neoEvent) { return CL_INVALID_EVENT; } - auto arbSyncEvent = neoEvent->getContext()->getSharing()->getGlArbSyncEvent(*neoEvent); - neoEvent->getContext()->getSharing()->removeGlArbSyncEventMapping(*neoEvent); + auto arbSyncEvent = neoEvent->getContext()->getSharing()->getGlArbSyncEvent(*neoEvent); + neoEvent->getContext()->getSharing()->removeGlArbSyncEventMapping(*neoEvent); if (nullptr != arbSyncEvent) { arbSyncEvent->release(); } diff --git a/runtime/sharings/gl/gl_buffer.cpp b/runtime/sharings/gl/windows/gl_buffer.cpp similarity index 90% rename from runtime/sharings/gl/gl_buffer.cpp rename to runtime/sharings/gl/windows/gl_buffer.cpp index 4b501fd939..be727cb5bc 100644 --- a/runtime/sharings/gl/gl_buffer.cpp +++ b/runtime/sharings/gl/windows/gl_buffer.cpp @@ -5,7 +5,7 @@ * */ -#include "gl_buffer.h" +#include "runtime/sharings/gl/gl_buffer.h" // clang-format off #include "public/cl_gl_private_intel.h" @@ -16,6 +16,7 @@ #include "runtime/helpers/get_info.h" #include "runtime/mem_obj/buffer.h" #include "runtime/memory_manager/memory_manager.h" +#include "runtime/sharings/gl/windows/gl_sharing.h" #include "config.h" @@ -26,7 +27,7 @@ Buffer *GlBuffer::createSharedGlBuffer(Context *context, cl_mem_flags flags, uns CL_GL_BUFFER_INFO bufferInfo = {0}; bufferInfo.bufferName = bufferId; - GLSharingFunctions *sharingFunctions = context->getSharing(); + GLSharingFunctionsWindows *sharingFunctions = context->getSharing(); if (sharingFunctions->acquireSharedBufferINTEL(&bufferInfo) == GL_FALSE) { errorCode.set(CL_INVALID_GL_OBJECT); return nullptr; @@ -43,7 +44,8 @@ Buffer *GlBuffer::createSharedGlBuffer(Context *context, cl_mem_flags flags, uns } void GlBuffer::synchronizeObject(UpdateData &updateData) { - const auto currentSharedHandle = updateData.memObject->getGraphicsAllocation()->peekSharedHandle(); + auto sharingFunctions = static_cast(this->sharingFunctions); + CL_GL_BUFFER_INFO bufferInfo = {}; bufferInfo.bufferName = this->clGlObjectId; sharingFunctions->acquireSharedBufferINTEL(&bufferInfo); @@ -52,6 +54,7 @@ void GlBuffer::synchronizeObject(UpdateData &updateData) { updateData.synchronizationStatus = SynchronizeStatus::ACQUIRE_SUCCESFUL; updateData.memObject->getGraphicsAllocation()->setAllocationOffset(bufferInfo.bufferOffset); + const auto currentSharedHandle = updateData.memObject->getGraphicsAllocation()->peekSharedHandle(); if (currentSharedHandle != updateData.sharedHandle) { updateData.updateData = new CL_GL_BUFFER_INFO(bufferInfo); } @@ -81,6 +84,8 @@ void GlBuffer::resolveGraphicsAllocationChange(osHandle currentSharedHandle, Upd } void GlBuffer::popGraphicsAllocationFromReuse(GraphicsAllocation *graphicsAllocation) { + auto sharingFunctions = static_cast(this->sharingFunctions); + std::unique_lock lock(sharingFunctions->mutex); auto &graphicsAllocations = sharingFunctions->graphicsAllocationsForGlBufferReuse; @@ -96,6 +101,8 @@ void GlBuffer::popGraphicsAllocationFromReuse(GraphicsAllocation *graphicsAlloca } void GlBuffer::releaseReusedGraphicsAllocation() { + auto sharingFunctions = static_cast(this->sharingFunctions); + std::unique_lock lock(sharingFunctions->mutex); auto &allocationsVector = sharingFunctions->graphicsAllocationsForGlBufferReuse; @@ -113,7 +120,7 @@ void GlBuffer::releaseReusedGraphicsAllocation() { } GraphicsAllocation *GlBuffer::createGraphicsAllocation(Context *context, unsigned int bufferId, _tagCLGLBufferInfo &bufferInfo) { - GLSharingFunctions *sharingFunctions = context->getSharing(); + GLSharingFunctionsWindows *sharingFunctions = context->getSharing(); auto &allocationsVector = sharingFunctions->graphicsAllocationsForGlBufferReuse; GraphicsAllocation *graphicsAllocation = nullptr; bool reusedAllocation = false; @@ -155,6 +162,7 @@ GraphicsAllocation *GlBuffer::createGraphicsAllocation(Context *context, unsigne } void GlBuffer::releaseResource(MemObj *memObject) { + auto sharingFunctions = static_cast(this->sharingFunctions); CL_GL_BUFFER_INFO bufferInfo = {}; bufferInfo.bufferName = this->clGlObjectId; sharingFunctions->releaseSharedBufferINTEL(&bufferInfo); diff --git a/runtime/sharings/gl/windows/gl_context_guard.cpp b/runtime/sharings/gl/windows/gl_context_guard.cpp new file mode 100644 index 0000000000..bff17a5c11 --- /dev/null +++ b/runtime/sharings/gl/windows/gl_context_guard.cpp @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2018-2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "runtime/sharings/gl/gl_context_guard.h" + +#include "runtime/sharings/gl/windows/gl_sharing.h" + +namespace NEO { +GLContextGuard::GLContextGuard(GLSharingFunctions &sharingFcns) : sharingFunctions(&sharingFcns) { + auto &sharing = *static_cast(sharingFunctions); + + currentContextHandle = sharing.getCurrentContext(); + currentDisplayHandle = sharing.getCurrentDisplay(); + auto ctxToMakeCurrent = sharing.getContextHandle(); + + if (currentContextHandle == 0) { + ctxToMakeCurrent = sharing.getBackupContextHandle(); + } + + if (currentContextHandle != sharing.getContextHandle() && currentContextHandle != sharing.getBackupContextHandle()) { + if (sharing.makeCurrent(ctxToMakeCurrent) == GL_FALSE) { + while (sharing.makeCurrent(sharing.getBackupContextHandle()) == GL_FALSE) { + ; + } + } + } +} + +GLContextGuard::~GLContextGuard() { + auto &sharing = *static_cast(sharingFunctions); + if (currentContextHandle != sharing.getContextHandle()) { + sharing.makeCurrent(currentContextHandle, currentDisplayHandle); + } +} +} // namespace NEO diff --git a/runtime/sharings/gl/windows/gl_sharing.cpp b/runtime/sharings/gl/windows/gl_sharing.cpp new file mode 100644 index 0000000000..556e908cf5 --- /dev/null +++ b/runtime/sharings/gl/windows/gl_sharing.cpp @@ -0,0 +1,162 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#include "runtime/sharings/gl/windows/gl_sharing.h" + +#include "runtime/context/context.inl" +#include "runtime/helpers/windows/gl_helper.h" +#include "runtime/sharings/gl/gl_arb_sync_event.h" + +namespace NEO { +GLSharingFunctionsWindows::GLSharingFunctionsWindows(GLType glhdcType, GLContext glhglrcHandle, GLContext glhglrcHandleBkpCtx, GLDisplay glhdcHandle) + : GLHDCType(glhdcType), GLHGLRCHandle(glhglrcHandle), GLHGLRCHandleBkpCtx(glhglrcHandleBkpCtx), GLHDCHandle(glhdcHandle) { + initGLFunctions(); + updateOpenGLContext(); + createBackupContext(); +} +GLSharingFunctionsWindows::~GLSharingFunctionsWindows() { + if (pfnWglDeleteContext) { + pfnWglDeleteContext(GLHGLRCHandleBkpCtx); + } +} + +bool GLSharingFunctionsWindows::isGlSharingEnabled() { + static bool oglLibAvailable = std::unique_ptr(OsLibrary::load(Os::openglDllName)).get() != nullptr; + return oglLibAvailable; +} + +void GLSharingFunctionsWindows::createBackupContext() { + if (pfnWglCreateContext) { + GLHGLRCHandleBkpCtx = pfnWglCreateContext(GLHDCHandle); + pfnWglShareLists(GLHGLRCHandle, GLHGLRCHandleBkpCtx); + } +} + +GLboolean GLSharingFunctionsWindows::setSharedOCLContextState() { + ContextInfo CtxInfo = {0}; + GLboolean retVal = GLSetSharedOCLContextState(GLHDCHandle, GLHGLRCHandle, CL_TRUE, &CtxInfo); + if (retVal == GL_FALSE) { + return GL_FALSE; + } + GLContextHandle = CtxInfo.ContextHandle; + GLDeviceHandle = CtxInfo.DeviceHandle; + + return retVal; +} + +bool GLSharingFunctionsWindows::isOpenGlExtensionSupported(const unsigned char *pExtensionString) { + bool LoadedNull = (glGetStringi == nullptr) || (glGetIntegerv == nullptr); + if (LoadedNull) { + return false; + } + + cl_int NumberOfExtensions = 0; + glGetIntegerv(GL_NUM_EXTENSIONS, &NumberOfExtensions); + for (cl_int i = 0; i < NumberOfExtensions; i++) { + std::basic_string pString = glGetStringi(GL_EXTENSIONS, i); + if (pString == pExtensionString) { + return true; + } + } + return false; +} + +bool GLSharingFunctionsWindows::isOpenGlSharingSupported() { + + std::basic_string Vendor = glGetString(GL_VENDOR); + const unsigned char intelVendor[] = "Intel"; + + if ((Vendor.empty()) || (Vendor != intelVendor)) { + return false; + } + std::basic_string Version = glGetString(GL_VERSION); + if (Version.empty()) { + return false; + } + + bool IsOpenGLES = false; + const unsigned char versionES[] = "OpenGL ES"; + if (Version.find(versionES) != std::string::npos) { + IsOpenGLES = true; + } + + if (IsOpenGLES == true) { + const unsigned char versionES1[] = "OpenGL ES 1."; + if (Version.find(versionES1) != std::string::npos) { + const unsigned char supportGLOES[] = "GL_OES_framebuffer_object"; + if (isOpenGlExtensionSupported(supportGLOES) == false) { + return false; + } + } + } else { + if (Version[0] < '3') { + const unsigned char supportGLEXT[] = "GL_EXT_framebuffer_object"; + if (isOpenGlExtensionSupported(supportGLEXT) == false) { + return false; + } + } + } + + return true; +} + +GlArbSyncEvent *GLSharingFunctionsWindows::getGlArbSyncEvent(Event &baseEvent) { + std::lock_guard lock{glArbEventMutex}; + auto it = glArbEventMapping.find(&baseEvent); + if (it != glArbEventMapping.end()) { + return it->second; + } + return nullptr; +} + +void GLSharingFunctionsWindows::removeGlArbSyncEventMapping(Event &baseEvent) { + std::lock_guard lock{glArbEventMutex}; + auto it = glArbEventMapping.find(&baseEvent); + if (it == glArbEventMapping.end()) { + DEBUG_BREAK_IF(it == glArbEventMapping.end()); + return; + } + glArbEventMapping.erase(it); +} + +GLboolean GLSharingFunctionsWindows::initGLFunctions() { + glLibrary.reset(OsLibrary::load(Os::openglDllName)); + + if (glLibrary->isLoaded()) { + glFunctionHelper wglLibrary(glLibrary.get(), "wglGetProcAddress"); + GLGetCurrentContext = (*glLibrary)["wglGetCurrentContext"]; + GLGetCurrentDisplay = (*glLibrary)["wglGetCurrentDC"]; + glGetString = (*glLibrary)["glGetString"]; + glGetIntegerv = (*glLibrary)["glGetIntegerv"]; + pfnWglCreateContext = (*glLibrary)["wglCreateContext"]; + pfnWglDeleteContext = (*glLibrary)["wglDeleteContext"]; + pfnWglShareLists = (*glLibrary)["wglShareLists"]; + wglMakeCurrent = (*glLibrary)["wglMakeCurrent"]; + + GLSetSharedOCLContextState = wglLibrary["wglSetSharedOCLContextStateINTEL"]; + GLAcquireSharedBuffer = wglLibrary["wglAcquireSharedBufferINTEL"]; + GLReleaseSharedBuffer = wglLibrary["wglReleaseSharedBufferINTEL"]; + GLAcquireSharedRenderBuffer = wglLibrary["wglAcquireSharedRenderBufferINTEL"]; + GLReleaseSharedRenderBuffer = wglLibrary["wglReleaseSharedRenderBufferINTEL"]; + GLAcquireSharedTexture = wglLibrary["wglAcquireSharedTextureINTEL"]; + GLReleaseSharedTexture = wglLibrary["wglReleaseSharedTextureINTEL"]; + GLRetainSync = wglLibrary["wglRetainSyncINTEL"]; + GLReleaseSync = wglLibrary["wglReleaseSyncINTEL"]; + GLGetSynciv = wglLibrary["wglGetSyncivINTEL"]; + glGetStringi = wglLibrary["glGetStringi"]; + } + this->pfnGlArbSyncObjectCleanup = cleanupArbSyncObject; + this->pfnGlArbSyncObjectSetup = setupArbSyncObject; + this->pfnGlArbSyncObjectSignal = signalArbSyncObject; + this->pfnGlArbSyncObjectWaitServer = serverWaitForArbSyncObject; + + return 1; +} + +template GLSharingFunctionsWindows *Context::getSharing(); + +} // namespace NEO diff --git a/runtime/sharings/gl/windows/gl_sharing.h b/runtime/sharings/gl/windows/gl_sharing.h new file mode 100644 index 0000000000..ff5d2ad146 --- /dev/null +++ b/runtime/sharings/gl/windows/gl_sharing.h @@ -0,0 +1,194 @@ +/* + * Copyright (C) 2020 Intel Corporation + * + * SPDX-License-Identifier: MIT + * + */ + +#pragma once + +#include "runtime/os_interface/windows/gl/gl_sharing_os.h" +#include "runtime/sharings/gl/gl_sharing.h" + +#include + +namespace NEO { +//OpenGL API names +typedef GLboolean(OSAPI *PFNOGLSetSharedOCLContextStateINTEL)(GLDisplay hdcHandle, GLContext contextHandle, GLboolean state, GLvoid *pContextInfo); +typedef GLboolean(OSAPI *PFNOGLAcquireSharedBufferINTEL)(GLDisplay hdcHandle, GLContext contextHandle, GLContext backupContextHandle, GLvoid *pBufferInfo); +typedef GLboolean(OSAPI *PFNOGLAcquireSharedRenderBufferINTEL)(GLDisplay hdcHandle, GLContext contextHandle, GLContext backupContextHandle, GLvoid *pResourceInfo); +typedef GLboolean(OSAPI *PFNOGLAcquireSharedTextureINTEL)(GLDisplay hdcHandle, GLContext contextHandle, GLContext backupContextHandle, GLvoid *pResourceInfo); +typedef GLboolean(OSAPI *PFNOGLReleaseSharedBufferINTEL)(GLDisplay hdcHandle, GLContext contextHandle, GLContext backupContextHandle, GLvoid *pBufferInfo); +typedef GLboolean(OSAPI *PFNOGLReleaseSharedRenderBufferINTEL)(GLDisplay hdcHandle, GLContext contextHandle, GLContext backupContextHandle, GLvoid *pResourceInfo); +typedef GLboolean(OSAPI *PFNOGLReleaseSharedTextureINTEL)(GLDisplay hdcHandle, GLContext contextHandle, GLContext backupContextHandle, GLvoid *pResourceInfo); +typedef GLContext(OSAPI *PFNOGLGetCurrentContext)(); +typedef GLDisplay(OSAPI *PFNOGLGetCurrentDisplay)(); +typedef GLboolean(OSAPI *PFNOGLMakeCurrent)(GLDisplay hdcHandle, void *draw, void *read, GLContext contextHandle); +typedef GLboolean(OSAPI *PFNOGLRetainSyncINTEL)(GLDisplay hdcHandle, GLContext contextHandle, GLContext backupContextHandle, GLvoid *pSyncInfo); +typedef GLboolean(OSAPI *PFNOGLReleaseSyncINTEL)(GLDisplay hdcHandle, GLContext contextHandle, GLContext backupContextHandle, GLvoid *pSync); +typedef void(OSAPI *PFNOGLGetSyncivINTEL)(GLvoid *pSync, GLenum pname, GLint *value); + +typedef const GLubyte *(OSAPI *PFNglGetString)(GLenum name); +typedef const GLubyte *(OSAPI *PFNglGetStringi)(GLenum name, GLuint index); +typedef void(OSAPI *PFNglGetIntegerv)(GLenum pname, GLint *params); +typedef void(OSAPI *PFNglBindTexture)(GLenum target, GLuint texture); + +//wgl +typedef BOOL(OSAPI *PFNwglMakeCurrent)(HDC, HGLRC); +typedef GLContext(OSAPI *PFNwglCreateContext)(GLDisplay hdcHandle); +typedef int(OSAPI *PFNwglShareLists)(GLContext contextHandle, GLContext backupContextHandle); +typedef BOOL(OSAPI *PFNwglDeleteContext)(HGLRC hglrcHandle); + +typedef bool (*PFNglArbSyncObjectSetup)(GLSharingFunctions &sharing, OSInterface &osInterface, CL_GL_SYNC_INFO &glSyncInfo); +typedef void (*PFNglArbSyncObjectCleanup)(OSInterface &osInterface, CL_GL_SYNC_INFO *glSyncInfo); +typedef void (*PFNglArbSyncObjectSignal)(OsContext &osContext, CL_GL_SYNC_INFO &glSyncInfo); +typedef void (*PFNglArbSyncObjectWaitServer)(OSInterface &osInterface, CL_GL_SYNC_INFO &glSyncInfo); + +class GLSharingFunctionsWindows : public GLSharingFunctions { + public: + GLSharingFunctionsWindows() = default; + GLSharingFunctionsWindows(GLType glhdcType, GLContext glhglrcHandle, GLContext glhglrcHandleBkpCtx, GLDisplay glhdcHandle); + ~GLSharingFunctionsWindows() override; + + OS_HANDLE getGLDeviceHandle() const { return GLDeviceHandle; } + OS_HANDLE getGLContextHandle() const { return GLContextHandle; } + + GLboolean initGLFunctions() override; + bool isOpenGlSharingSupported() override; + static bool isGlSharingEnabled(); + + // Arb sync event + template + auto getOrCreateGlArbSyncEvent(Event &baseEvent) -> decltype(EventType::create(baseEvent)); + GlArbSyncEvent *getGlArbSyncEvent(Event &baseEvent); + void removeGlArbSyncEventMapping(Event &baseEvent); + + // Gl functions + GLboolean acquireSharedBufferINTEL(GLvoid *pBufferInfo) { + return GLAcquireSharedBuffer(GLHDCHandle, GLHGLRCHandle, GLHGLRCHandleBkpCtx, pBufferInfo); + } + GLboolean releaseSharedBufferINTEL(GLvoid *pBufferInfo) { + return GLReleaseSharedBuffer(GLHDCHandle, GLHGLRCHandle, GLHGLRCHandleBkpCtx, pBufferInfo); + } + GLboolean acquireSharedRenderBuffer(GLvoid *pResourceInfo) { + return GLAcquireSharedRenderBuffer(GLHDCHandle, GLHGLRCHandle, GLHGLRCHandleBkpCtx, pResourceInfo); + } + GLboolean releaseSharedRenderBuffer(GLvoid *pResourceInfo) { + return GLReleaseSharedRenderBuffer(GLHDCHandle, GLHGLRCHandle, GLHGLRCHandleBkpCtx, pResourceInfo); + } + GLboolean acquireSharedTexture(GLvoid *pResourceInfo) { + return GLAcquireSharedTexture(GLHDCHandle, GLHGLRCHandle, GLHGLRCHandleBkpCtx, pResourceInfo); + } + GLboolean releaseSharedTexture(GLvoid *pResourceInfo) { + return GLReleaseSharedTexture(GLHDCHandle, GLHGLRCHandle, GLHGLRCHandleBkpCtx, pResourceInfo); + } + GLboolean retainSync(GLvoid *pSyncInfo) { + return GLRetainSync(GLHDCHandle, GLHGLRCHandle, GLHGLRCHandleBkpCtx, pSyncInfo); + } + GLboolean releaseSync(GLvoid *pSync) { + return GLReleaseSync(GLHDCHandle, GLHGLRCHandle, GLHGLRCHandleBkpCtx, pSync); + } + void getSynciv(GLvoid *pSync, GLenum pname, GLint *value) { + return GLGetSynciv(pSync, pname, value); + } + GLContext getCurrentContext() { + return GLGetCurrentContext(); + } + GLDisplay getCurrentDisplay() { + return GLGetCurrentDisplay(); + } + GLboolean makeCurrent(GLContext contextHandle, GLDisplay displayHandle = 0) { + if (displayHandle == 0) { + displayHandle = GLHDCHandle; + } + return this->wglMakeCurrent(displayHandle, contextHandle); + } + GLContext getBackupContextHandle() { + return GLHGLRCHandleBkpCtx; + } + GLContext getContextHandle() { + return GLHGLRCHandle; + } + bool glArbSyncObjectSetup(OSInterface &osInterface, CL_GL_SYNC_INFO &glSyncInfo) { + return pfnGlArbSyncObjectSetup(*this, osInterface, glSyncInfo); + } + void glArbSyncObjectCleanup(OSInterface &osInterface, CL_GL_SYNC_INFO *glSyncInfo) { + pfnGlArbSyncObjectCleanup(osInterface, glSyncInfo); + } + void glArbSyncObjectSignal(OsContext &osContext, CL_GL_SYNC_INFO &glSyncInfo) { + pfnGlArbSyncObjectSignal(osContext, glSyncInfo); + } + void glArbSyncObjectWaitServer(OSInterface &osInterface, CL_GL_SYNC_INFO &glSyncInfo) { + pfnGlArbSyncObjectWaitServer(osInterface, glSyncInfo); + } + + // Buffer reuse + std::mutex mutex; + std::vector> graphicsAllocationsForGlBufferReuse; + + protected: + void updateOpenGLContext() { + if (GLSetSharedOCLContextState) { + setSharedOCLContextState(); + } + } + GLboolean setSharedOCLContextState(); + void createBackupContext(); + bool isOpenGlExtensionSupported(const unsigned char *pExtentionString); + + // Handles + GLType GLHDCType = 0; + GLContext GLHGLRCHandle = 0; + GLContext GLHGLRCHandleBkpCtx = 0; + GLDisplay GLHDCHandle = 0; + OS_HANDLE GLDeviceHandle = 0; + OS_HANDLE GLContextHandle = 0; + + // GL functions + std::unique_ptr glLibrary; + PFNOGLSetSharedOCLContextStateINTEL GLSetSharedOCLContextState = nullptr; + PFNOGLAcquireSharedBufferINTEL GLAcquireSharedBuffer = nullptr; + PFNOGLReleaseSharedBufferINTEL GLReleaseSharedBuffer = nullptr; + PFNOGLAcquireSharedRenderBufferINTEL GLAcquireSharedRenderBuffer = nullptr; + PFNOGLReleaseSharedRenderBufferINTEL GLReleaseSharedRenderBuffer = nullptr; + PFNOGLAcquireSharedTextureINTEL GLAcquireSharedTexture = nullptr; + PFNOGLReleaseSharedTextureINTEL GLReleaseSharedTexture = nullptr; + PFNOGLGetCurrentContext GLGetCurrentContext = nullptr; + PFNOGLGetCurrentDisplay GLGetCurrentDisplay = nullptr; + PFNglGetString glGetString = nullptr; + PFNglGetStringi glGetStringi = nullptr; + PFNglGetIntegerv glGetIntegerv = nullptr; + PFNwglCreateContext pfnWglCreateContext = nullptr; + PFNwglMakeCurrent wglMakeCurrent = nullptr; + PFNwglShareLists pfnWglShareLists = nullptr; + PFNwglDeleteContext pfnWglDeleteContext = nullptr; + PFNOGLRetainSyncINTEL GLRetainSync = nullptr; + PFNOGLReleaseSyncINTEL GLReleaseSync = nullptr; + PFNOGLGetSyncivINTEL GLGetSynciv = nullptr; + PFNglArbSyncObjectSetup pfnGlArbSyncObjectSetup = nullptr; + PFNglArbSyncObjectCleanup pfnGlArbSyncObjectCleanup = nullptr; + PFNglArbSyncObjectSignal pfnGlArbSyncObjectSignal = nullptr; + PFNglArbSyncObjectWaitServer pfnGlArbSyncObjectWaitServer = nullptr; + + // support for GL_ARB_cl_event + std::mutex glArbEventMutex; + std::unordered_map glArbEventMapping; +}; + +template +inline auto GLSharingFunctionsWindows::getOrCreateGlArbSyncEvent(Event &baseEvent) -> decltype(EventType::create(baseEvent)) { + std::lock_guard lock{glArbEventMutex}; + auto it = glArbEventMapping.find(&baseEvent); + if (it != glArbEventMapping.end()) { + return it->second; + } + + auto arbEvent = EventType::create(baseEvent); + if (nullptr == arbEvent) { + return arbEvent; + } + glArbEventMapping[&baseEvent] = arbEvent; + return arbEvent; +} + +} // namespace NEO diff --git a/runtime/sharings/gl/gl_sync_event.cpp b/runtime/sharings/gl/windows/gl_sync_event.cpp similarity index 71% rename from runtime/sharings/gl/gl_sync_event.cpp rename to runtime/sharings/gl/windows/gl_sync_event.cpp index 35b84556b8..59ecb08ecb 100644 --- a/runtime/sharings/gl/gl_sync_event.cpp +++ b/runtime/sharings/gl/windows/gl_sync_event.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2019 Intel Corporation + * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -16,7 +16,8 @@ #include "runtime/helpers/get_info.h" #include "runtime/helpers/timestamp_packet.h" #include "runtime/platform/platform.h" -#include "runtime/sharings/gl/gl_sharing.h" +#include "runtime/sharings/gl/gl_context_guard.h" +#include "runtime/sharings/gl/windows/gl_sharing.h" namespace NEO { GlSyncEvent::GlSyncEvent(Context &context, const GL_CL_SYNC_INFO &sync) @@ -25,15 +26,17 @@ GlSyncEvent::GlSyncEvent(Context &context, const GL_CL_SYNC_INFO &sync) transitionExecutionStatus(CL_SUBMITTED); } -GlSyncEvent::~GlSyncEvent() { ctx->getSharing()->releaseSync(glSync->pSync); } +GlSyncEvent::~GlSyncEvent() { + ctx->getSharing()->releaseSync(glSync->pSync); +} GlSyncEvent *GlSyncEvent::create(Context &context, cl_GLsync sync, cl_int *errCode) { - GLContextGuard guard(*context.getSharing()); + GLContextGuard guard(*context.getSharing()); ErrorCodeHelper err(errCode, CL_SUCCESS); GL_CL_SYNC_INFO syncInfo = {sync, nullptr}; - context.getSharing()->retainSync(&syncInfo); + context.getSharing()->retainSync(&syncInfo); DEBUG_BREAK_IF(!syncInfo.pSync); EventBuilder eventBuilder; @@ -42,10 +45,10 @@ GlSyncEvent *GlSyncEvent::create(Context &context, cl_GLsync sync, cl_int *errCo } void GlSyncEvent::updateExecutionStatus() { - GLContextGuard guard(*ctx->getSharing()); + GLContextGuard guard(*ctx->getSharing()); int retVal = 0; - ctx->getSharing()->getSynciv(glSync->pSync, GL_SYNC_STATUS, &retVal); + ctx->getSharing()->getSynciv(glSync->pSync, GL_SYNC_STATUS, &retVal); if (retVal == GL_SIGNALED) { setStatus(CL_COMPLETE); } diff --git a/runtime/sharings/gl/gl_texture.cpp b/runtime/sharings/gl/windows/gl_texture.cpp similarity index 96% rename from runtime/sharings/gl/gl_texture.cpp rename to runtime/sharings/gl/windows/gl_texture.cpp index f164f2f850..432477374e 100644 --- a/runtime/sharings/gl/gl_texture.cpp +++ b/runtime/sharings/gl/windows/gl_texture.cpp @@ -19,6 +19,7 @@ #include "runtime/helpers/get_info.h" #include "runtime/mem_obj/image.h" #include "runtime/memory_manager/memory_manager.h" +#include "runtime/sharings/gl/windows/gl_sharing.h" #include "CL/cl_gl.h" #include "config.h" @@ -38,7 +39,7 @@ Image *GlTexture::createSharedGlTexture(Context *context, cl_mem_flags flags, cl texInfo.name = texture; texInfo.target = getBaseTargetType(target); - GLSharingFunctions *sharingFunctions = context->getSharing(); + GLSharingFunctionsWindows *sharingFunctions = context->getSharing(); if (target == GL_RENDERBUFFER_EXT) { sharingFunctions->acquireSharedRenderBuffer(&texInfo); @@ -151,6 +152,7 @@ Image *GlTexture::createSharedGlTexture(Context *context, cl_mem_flags flags, cl } // namespace NEO void GlTexture::synchronizeObject(UpdateData &updateData) { + auto sharingFunctions = static_cast(this->sharingFunctions); CL_GL_RESOURCE_INFO resourceInfo = {0}; resourceInfo.name = this->clGlObjectId; if (target == GL_RENDERBUFFER_EXT) { @@ -246,6 +248,7 @@ cl_GLenum GlTexture::getBaseTargetType(cl_GLenum target) { } void GlTexture::releaseResource(MemObj *memObject) { + auto sharingFunctions = static_cast(this->sharingFunctions); if (target == GL_RENDERBUFFER_EXT) { sharingFunctions->releaseSharedRenderBuffer(&textureInfo); } else { diff --git a/runtime/sharings/gl/win_enable_gl.cpp b/runtime/sharings/gl/windows/win_enable_gl.cpp similarity index 88% rename from runtime/sharings/gl/win_enable_gl.cpp rename to runtime/sharings/gl/windows/win_enable_gl.cpp index 408fc18061..e85a701ce1 100644 --- a/runtime/sharings/gl/win_enable_gl.cpp +++ b/runtime/sharings/gl/windows/win_enable_gl.cpp @@ -1,16 +1,17 @@ /* - * Copyright (C) 2018-2019 Intel Corporation + * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT * */ +#include "runtime/sharings/gl/windows/win_enable_gl.h" + #include "core/debug_settings/debug_settings_manager.h" #include "runtime/context/context.h" #include "runtime/context/context.inl" #include "runtime/sharings/gl/cl_gl_api_intel.h" -#include "runtime/sharings/gl/enable_gl.h" -#include "runtime/sharings/gl/gl_sharing.h" +#include "runtime/sharings/gl/windows/gl_sharing.h" #include "runtime/sharings/sharing_factory.h" #include "runtime/sharings/sharing_factory.inl" @@ -58,8 +59,8 @@ bool GlSharingContextBuilder::finalizeProperties(Context &context, int32_t &errc return true; if (contextData->GLHGLRCHandle) { - context.registerSharing( - new GLSharingFunctions(contextData->GLHDCType, contextData->GLHGLRCHandle, nullptr, contextData->GLHDCHandle)); + context.registerSharing(new GLSharingFunctionsWindows(contextData->GLHDCType, contextData->GLHGLRCHandle, + nullptr, contextData->GLHDCHandle)); } contextData.reset(nullptr); @@ -90,7 +91,7 @@ std::string GlSharingBuilderFactory::getExtensions() { "cl_khr_gl_depth_images " "cl_khr_gl_event " "cl_khr_gl_msaa_sharing "; - } else if (GLSharingFunctions::isGlSharingEnabled()) { + } else if (GLSharingFunctionsWindows::isGlSharingEnabled()) { return "cl_khr_gl_sharing " "cl_khr_gl_depth_images " "cl_khr_gl_event " @@ -108,5 +109,5 @@ void *GlSharingBuilderFactory::getExtensionFunctionAddress(const std::string &fu return nullptr; } -static SharingFactory::RegisterSharing glSharing; +static SharingFactory::RegisterSharing glSharing; } // namespace NEO diff --git a/runtime/sharings/gl/enable_gl.h b/runtime/sharings/gl/windows/win_enable_gl.h similarity index 91% rename from runtime/sharings/gl/enable_gl.h rename to runtime/sharings/gl/windows/win_enable_gl.h index ebb7b39d73..aaa0f6b78c 100644 --- a/runtime/sharings/gl/enable_gl.h +++ b/runtime/sharings/gl/windows/win_enable_gl.h @@ -1,12 +1,12 @@ /* - * Copyright (C) 2018-2019 Intel Corporation + * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT * */ #pragma once -#include "runtime/sharings/gl/gl_sharing.h" +#include "runtime/sharings/gl/windows/gl_sharing.h" #include "runtime/sharings/sharing_factory.h" #include diff --git a/unit_tests/command_queue/gl/enqueue_kernel_gl_tests.cpp b/unit_tests/command_queue/gl/enqueue_kernel_gl_tests.cpp index f8a872e894..4b1fe082e8 100644 --- a/unit_tests/command_queue/gl/enqueue_kernel_gl_tests.cpp +++ b/unit_tests/command_queue/gl/enqueue_kernel_gl_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2019 Intel Corporation + * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -8,7 +8,6 @@ #include "core/helpers/preamble.h" #include "core/memory_manager/graphics_allocation.h" #include "core/memory_manager/memory_constants.h" -#include "core/os_interface/windows/windows_wrapper.h" #include "runtime/built_ins/built_ins.h" #include "runtime/sharings/gl/gl_buffer.h" #include "unit_tests/command_queue/enqueue_fixture.h" diff --git a/unit_tests/context/gl/context_gl_tests.cpp b/unit_tests/context/gl/context_gl_tests.cpp index 58653c9455..c40e13d5f1 100644 --- a/unit_tests/context/gl/context_gl_tests.cpp +++ b/unit_tests/context/gl/context_gl_tests.cpp @@ -11,7 +11,7 @@ #include "runtime/device/device.h" #include "runtime/device_queue/device_queue.h" #include "runtime/os_interface/windows/gl/gl_sharing_os.h" -#include "runtime/sharings/gl/gl_sharing.h" +#include "runtime/sharings/gl/windows/gl_sharing.h" #include "unit_tests/fixtures/platform_fixture.h" #include "unit_tests/mocks/mock_context.h" #include "unit_tests/mocks/mock_deferred_deleter.h" diff --git a/unit_tests/mocks/gl/mock_gl_sharing.cpp b/unit_tests/mocks/gl/mock_gl_sharing.cpp index 5e7efa1d8d..60c2360c65 100644 --- a/unit_tests/mocks/gl/mock_gl_sharing.cpp +++ b/unit_tests/mocks/gl/mock_gl_sharing.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2019 Intel Corporation + * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -22,7 +22,7 @@ EGLBkpContextParams eglBkpContextParams = {0}; GLXBkpContextParams glxBkpContextParams = {0}; void GlSharingFunctionsMock::initMembers() { - GLSharingFunctions::initGLFunctions(); + GLSharingFunctionsWindows::initGLFunctions(); glDllHelper dllParam; dllParam.setGLSetSharedOCLContextStateReturnedValue(1u); dllParam.resetParam(""); diff --git a/unit_tests/mocks/gl/mock_gl_sharing.h b/unit_tests/mocks/gl/mock_gl_sharing.h index e306608dd8..5e47dadebe 100644 --- a/unit_tests/mocks/gl/mock_gl_sharing.h +++ b/unit_tests/mocks/gl/mock_gl_sharing.h @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2019 Intel Corporation + * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -7,7 +7,7 @@ #pragma once #include "public/cl_gl_private_intel.h" -#include "runtime/sharings/gl/gl_sharing.h" +#include "runtime/sharings/gl/windows/gl_sharing.h" #include "unit_tests/os_interface/windows/gl/gl_dll_helper.h" #include "config.h" @@ -70,7 +70,7 @@ static const unsigned int supportedTargets[] = { }; } -class GlSharingFunctionsMock : public GLSharingFunctions { +class GlSharingFunctionsMock : public GLSharingFunctionsWindows { void initMembers(); @@ -81,38 +81,40 @@ class GlSharingFunctionsMock : public GLSharingFunctions { }; ~GlSharingFunctionsMock() override = default; - using GLSharingFunctions::GLAcquireSharedBuffer; - using GLSharingFunctions::GLAcquireSharedRenderBuffer; - using GLSharingFunctions::GLAcquireSharedTexture; - using GLSharingFunctions::GLGetCurrentContext; - using GLSharingFunctions::GLGetCurrentDisplay; - using GLSharingFunctions::glGetIntegerv; - using GLSharingFunctions::glGetString; - using GLSharingFunctions::glGetStringi; - using GLSharingFunctions::GLGetSynciv; - using GLSharingFunctions::GLReleaseSharedBuffer; - using GLSharingFunctions::GLReleaseSharedRenderBuffer; - using GLSharingFunctions::GLReleaseSharedTexture; - using GLSharingFunctions::GLReleaseSync; - using GLSharingFunctions::GLRetainSync; - using GLSharingFunctions::GLSetSharedOCLContextState; - using GLSharingFunctions::pfnWglCreateContext; - using GLSharingFunctions::pfnWglDeleteContext; - using GLSharingFunctions::pfnWglShareLists; - using GLSharingFunctions::wglMakeCurrent; + using GLSharingFunctionsWindows::GLAcquireSharedBuffer; + using GLSharingFunctionsWindows::GLAcquireSharedRenderBuffer; + using GLSharingFunctionsWindows::GLAcquireSharedTexture; + using GLSharingFunctionsWindows::GLGetCurrentContext; + using GLSharingFunctionsWindows::GLGetCurrentDisplay; + using GLSharingFunctionsWindows::glGetIntegerv; + using GLSharingFunctionsWindows::glGetString; + using GLSharingFunctionsWindows::glGetStringi; + using GLSharingFunctionsWindows::GLGetSynciv; + using GLSharingFunctionsWindows::GLReleaseSharedBuffer; + using GLSharingFunctionsWindows::GLReleaseSharedRenderBuffer; + using GLSharingFunctionsWindows::GLReleaseSharedTexture; + using GLSharingFunctionsWindows::GLReleaseSync; + using GLSharingFunctionsWindows::GLRetainSync; + using GLSharingFunctionsWindows::GLSetSharedOCLContextState; + using GLSharingFunctionsWindows::isOpenGlExtensionSupported; + using GLSharingFunctionsWindows::pfnWglCreateContext; + using GLSharingFunctionsWindows::pfnWglDeleteContext; + using GLSharingFunctionsWindows::pfnWglShareLists; + using GLSharingFunctionsWindows::setSharedOCLContextState; + using GLSharingFunctionsWindows::wglMakeCurrent; - using GLSharingFunctions::glArbEventMapping; - using GLSharingFunctions::GLContextHandle; - using GLSharingFunctions::GLDeviceHandle; + using GLSharingFunctionsWindows::glArbEventMapping; + using GLSharingFunctionsWindows::GLContextHandle; + using GLSharingFunctionsWindows::GLDeviceHandle; - using GLSharingFunctions::getSupportedFormats; - using GLSharingFunctions::pfnGlArbSyncObjectCleanup; - using GLSharingFunctions::pfnGlArbSyncObjectSetup; - using GLSharingFunctions::pfnGlArbSyncObjectSignal; - using GLSharingFunctions::pfnGlArbSyncObjectWaitServer; + using GLSharingFunctionsWindows::getSupportedFormats; + using GLSharingFunctionsWindows::pfnGlArbSyncObjectCleanup; + using GLSharingFunctionsWindows::pfnGlArbSyncObjectSetup; + using GLSharingFunctionsWindows::pfnGlArbSyncObjectSignal; + using GLSharingFunctionsWindows::pfnGlArbSyncObjectWaitServer; GlSharingFunctionsMock(GLType GLHDCType, GLContext GLHGLRCHandle, GLContext GLHGLRCHandleBkpCtx, GLDisplay GLHDCHandle) - : GLSharingFunctions(GLHDCType, GLHGLRCHandle, GLHGLRCHandleBkpCtx, GLHDCHandle) { + : GLSharingFunctionsWindows(GLHDCType, GLHGLRCHandle, GLHGLRCHandleBkpCtx, GLHDCHandle) { initMembers(); updateOpenGLContext(); createBackupContext(); @@ -176,19 +178,22 @@ class MockGlSharing { GLMockReturnedValues glMockReturnedValues = {0}; }; -class MockGLSharingFunctions : public GLSharingFunctions { +class MockGLSharingFunctions : public GLSharingFunctionsWindows { public: + using GLSharingFunctionsWindows::isOpenGlExtensionSupported; + using GLSharingFunctionsWindows::setSharedOCLContextState; + static bool SharingEnabled; static void OSAPI glGetIntegervTest(GLenum pname, GLint *data) { if (pname == GL_NUM_EXTENSIONS) *data = 2; }; - using GLSharingFunctions::glGetIntegerv; - using GLSharingFunctions::glGetString; + using GLSharingFunctionsWindows::glGetIntegerv; + using GLSharingFunctionsWindows::glGetString; std::unique_ptr dllParam = std::make_unique(); MockGLSharingFunctions() { - GLSharingFunctions::initGLFunctions(); + GLSharingFunctionsWindows::initGLFunctions(); MockGLSharingFunctions::SharingEnabled = 1; } }; diff --git a/unit_tests/os_interface/windows/gl/gl_os_sharing_tests.cpp b/unit_tests/os_interface/windows/gl/gl_os_sharing_tests.cpp index 2ad30664ac..55ecec4721 100644 --- a/unit_tests/os_interface/windows/gl/gl_os_sharing_tests.cpp +++ b/unit_tests/os_interface/windows/gl/gl_os_sharing_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2019 Intel Corporation + * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT * @@ -14,7 +14,7 @@ #include "runtime/os_interface/windows/wddm/wddm.h" #include "runtime/os_interface/windows/wddm_memory_operations_handler.h" #include "runtime/sharings/gl/gl_arb_sync_event.h" -#include "runtime/sharings/gl/gl_sharing.h" +#include "runtime/sharings/gl/windows/gl_sharing.h" #include "unit_tests/mocks/gl/mock_gl_sharing.h" #include "unit_tests/mocks/mock_execution_environment.h" #include "unit_tests/os_interface/windows/wddm_fixture.h" diff --git a/unit_tests/sharings/gl/CMakeLists.txt b/unit_tests/sharings/gl/CMakeLists.txt index d5c76026b2..24658f6d0c 100644 --- a/unit_tests/sharings/gl/CMakeLists.txt +++ b/unit_tests/sharings/gl/CMakeLists.txt @@ -1,19 +1,11 @@ # -# Copyright (C) 2017-2018 Intel Corporation +# Copyright (C) 2017-2020 Intel Corporation # # SPDX-License-Identifier: MIT # -if(WIN32) - set(IGDRCL_SRCS_tests_sharings_gl - ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt - ${CMAKE_CURRENT_SOURCE_DIR}/gl_arb_sync_event_tests.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/gl_create_from_texture_tests.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/gl_reused_buffers_tests.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/gl_sharing_enable_tests.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/gl_sharing_tests.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/gl_texture_tests.cpp - ${CMAKE_CURRENT_SOURCE_DIR}/gl_types_tests.cpp - ) - target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_tests_sharings_gl}) -endif() +set(IGDRCL_SRCS_tests_sharings_gl + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt +) +target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_tests_sharings_gl}) +add_subdirectories() diff --git a/unit_tests/sharings/gl/windows/CMakeLists.txt b/unit_tests/sharings/gl/windows/CMakeLists.txt new file mode 100644 index 0000000000..42e360c1d0 --- /dev/null +++ b/unit_tests/sharings/gl/windows/CMakeLists.txt @@ -0,0 +1,19 @@ +# +# Copyright (C) 2017-2020 Intel Corporation +# +# SPDX-License-Identifier: MIT +# + +if(WIN32) + set(IGDRCL_SRCS_tests_sharings_gl_windows + ${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt + ${CMAKE_CURRENT_SOURCE_DIR}/gl_arb_sync_event_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/gl_create_from_texture_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/gl_reused_buffers_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/gl_sharing_enable_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/gl_sharing_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/gl_texture_tests.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/gl_types_tests.cpp + ) + target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_tests_sharings_gl_windows}) +endif() diff --git a/unit_tests/sharings/gl/gl_arb_sync_event_tests.cpp b/unit_tests/sharings/gl/windows/gl_arb_sync_event_tests.cpp similarity index 100% rename from unit_tests/sharings/gl/gl_arb_sync_event_tests.cpp rename to unit_tests/sharings/gl/windows/gl_arb_sync_event_tests.cpp diff --git a/unit_tests/sharings/gl/gl_create_from_texture_tests.cpp b/unit_tests/sharings/gl/windows/gl_create_from_texture_tests.cpp similarity index 100% rename from unit_tests/sharings/gl/gl_create_from_texture_tests.cpp rename to unit_tests/sharings/gl/windows/gl_create_from_texture_tests.cpp diff --git a/unit_tests/sharings/gl/gl_reused_buffers_tests.cpp b/unit_tests/sharings/gl/windows/gl_reused_buffers_tests.cpp similarity index 100% rename from unit_tests/sharings/gl/gl_reused_buffers_tests.cpp rename to unit_tests/sharings/gl/windows/gl_reused_buffers_tests.cpp diff --git a/unit_tests/sharings/gl/gl_sharing_enable_tests.cpp b/unit_tests/sharings/gl/windows/gl_sharing_enable_tests.cpp similarity index 98% rename from unit_tests/sharings/gl/gl_sharing_enable_tests.cpp rename to unit_tests/sharings/gl/windows/gl_sharing_enable_tests.cpp index 7707289756..5a264afa4f 100644 --- a/unit_tests/sharings/gl/gl_sharing_enable_tests.cpp +++ b/unit_tests/sharings/gl/windows/gl_sharing_enable_tests.cpp @@ -1,11 +1,11 @@ /* - * Copyright (C) 2018-2019 Intel Corporation + * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT * */ -#include "runtime/sharings/gl/enable_gl.h" +#include "runtime/sharings/gl/windows/win_enable_gl.h" #include "unit_tests/fixtures/memory_management_fixture.h" #include "unit_tests/mocks/mock_context.h" diff --git a/unit_tests/sharings/gl/gl_sharing_tests.cpp b/unit_tests/sharings/gl/windows/gl_sharing_tests.cpp similarity index 99% rename from unit_tests/sharings/gl/gl_sharing_tests.cpp rename to unit_tests/sharings/gl/windows/gl_sharing_tests.cpp index a2648432e9..b8958b1a26 100644 --- a/unit_tests/sharings/gl/gl_sharing_tests.cpp +++ b/unit_tests/sharings/gl/windows/gl_sharing_tests.cpp @@ -18,8 +18,10 @@ #include "runtime/sharings/gl/cl_gl_api_intel.h" #include "runtime/sharings/gl/gl_arb_sync_event.h" #include "runtime/sharings/gl/gl_buffer.h" +#include "runtime/sharings/gl/gl_context_guard.h" #include "runtime/sharings/gl/gl_sync_event.h" #include "runtime/sharings/gl/gl_texture.h" +#include "runtime/sharings/gl/windows/gl_sharing.h" #include "runtime/sharings/sharing.h" #include "test.h" #include "unit_tests/libult/create_command_stream.h" @@ -651,7 +653,7 @@ TEST(glSharingBasicTest, GivenSharingFunctionsWhenItIsConstructedThenOglContextF } TEST(glSharingBasicTest, givenInvalidExtensionNameWhenCheckGLExtensionSupportedThenReturnFalse) { - GLSharingFunctions glSharingFunctions; + MockGLSharingFunctions glSharingFunctions; const unsigned char invalidExtension[] = "InvalidExtensionName"; bool RetVal = glSharingFunctions.isOpenGlExtensionSupported(invalidExtension); EXPECT_FALSE(RetVal); @@ -1086,7 +1088,7 @@ TEST(glSharingContextSwitch, givenZeroCurrentContextWhenSwitchAttemptedThenMakeS } TEST(glSharingContextSwitch, givenSharingFunctionsWhenGlDeleteContextIsNotPresentThenItIsNotCalled) { - auto glSharingFunctions = new GLSharingFunctions(); + auto glSharingFunctions = new GLSharingFunctionsWindows(); glDllHelper dllParam; auto currentGlDeleteContextCalledCount = dllParam.getParam("GLDeleteContextCalled"); delete glSharingFunctions; @@ -1172,7 +1174,7 @@ TEST_F(glSharingTests, givenContextWhenEmptySharingTableEmptyThenReturnsNullptr) } TEST_F(glSharingTests, givenUnknownBaseEventWhenGetGlArbSyncEventIsCalledThenNullptrIsReturned) { - auto *sharing = context.getSharing(); + auto *sharing = context.getSharing(); ASSERT_NE(nullptr, sharing); auto event = new MockEvent(); MockContext context; diff --git a/unit_tests/sharings/gl/gl_texture_tests.cpp b/unit_tests/sharings/gl/windows/gl_texture_tests.cpp similarity index 100% rename from unit_tests/sharings/gl/gl_texture_tests.cpp rename to unit_tests/sharings/gl/windows/gl_texture_tests.cpp diff --git a/unit_tests/sharings/gl/gl_types_tests.cpp b/unit_tests/sharings/gl/windows/gl_types_tests.cpp similarity index 99% rename from unit_tests/sharings/gl/gl_types_tests.cpp rename to unit_tests/sharings/gl/windows/gl_types_tests.cpp index cc8c51d037..5bc35de29d 100644 --- a/unit_tests/sharings/gl/gl_types_tests.cpp +++ b/unit_tests/sharings/gl/windows/gl_types_tests.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2018-2019 Intel Corporation + * Copyright (C) 2018-2020 Intel Corporation * * SPDX-License-Identifier: MIT *