From a6d9e74851369d60be4e9b5705b3cf393f44294f Mon Sep 17 00:00:00 2001 From: Artur Harasimiuk Date: Mon, 8 Oct 2018 12:34:19 +0200 Subject: [PATCH] Revert "Refactor of glcl sharing" This reverts commit 51ecef7ec2969cdfeb9f1cbfdfbbda436c2f84f4. Change-Id: Ia654fe0d50a2144371c3def7e768ef9707419c61 Signed-off-by: Artur Harasimiuk --- runtime/os_interface/os_library.h | 16 ------ .../windows/gl/gl_sharing_win.cpp | 52 +++++++++++-------- runtime/sharings/gl/gl_sharing.h | 6 ++- unit_tests/mocks/gl/mock_gl_sharing.h | 7 ++- unit_tests/os_interface/os_library_tests.cpp | 36 ------------- unit_tests/sharings/gl/gl_sharing_tests.cpp | 14 ++--- 6 files changed, 47 insertions(+), 84 deletions(-) diff --git a/runtime/os_interface/os_library.h b/runtime/os_interface/os_library.h index 88be47036ffa2..d2785e0ca8c76 100644 --- a/runtime/os_interface/os_library.h +++ b/runtime/os_interface/os_library.h @@ -7,7 +7,6 @@ #pragma once #include -#include namespace OCLRT { @@ -16,25 +15,10 @@ class OsLibrary { OsLibrary() = default; public: - struct ConvertibleProcAddr { - template - operator T *() const { - static_assert(std::is_function::value, "Cannot convert to non-function and non-void* type"); - return reinterpret_cast(ptr); - } - - operator void *() const { - return ptr; - } - void *ptr = nullptr; - }; virtual ~OsLibrary() = default; static OsLibrary *load(const std::string &name); - ConvertibleProcAddr operator[](const std::string &name) { - return ConvertibleProcAddr{getProcAddress(name)}; - } virtual void *getProcAddress(const std::string &procName) = 0; virtual bool isLoaded() = 0; }; diff --git a/runtime/os_interface/windows/gl/gl_sharing_win.cpp b/runtime/os_interface/windows/gl/gl_sharing_win.cpp index 0980589eb6fcd..8a84807fb5fa9 100644 --- a/runtime/os_interface/windows/gl/gl_sharing_win.cpp +++ b/runtime/os_interface/windows/gl/gl_sharing_win.cpp @@ -31,28 +31,30 @@ GLSharingFunctions::~GLSharingFunctions() { } GLboolean GLSharingFunctions::initGLFunctions() { - glLibrary.reset(OsLibrary::load(Os::openglDllName)); - if (glLibrary->isLoaded()) { - GLGetCurrentContext = (*glLibrary)["wglGetCurrentContext"]; - GLGetCurrentDisplay = (*glLibrary)["wglGetCurrentDC"]; - glGetString = (*glLibrary)["glGetString"]; - glGetIntegerv = (*glLibrary)["glGetIntegerv"]; - pfnWglCreateContext = (*glLibrary)["wglCreateContext"]; - pfnWglDeleteContext = (*glLibrary)["wglDeleteContext"]; - pfnWglShareLists = (*glLibrary)["wglShareLists"]; - GLSetSharedOCLContextState = (*glLibrary)["wglSetSharedOCLContextStateINTEL"]; - GLAcquireSharedBuffer = (*glLibrary)["wglAcquireSharedBufferINTEL"]; - GLReleaseSharedBuffer = (*glLibrary)["wglReleaseSharedBufferINTEL"]; - GLAcquireSharedRenderBuffer = (*glLibrary)["wglAcquireSharedRenderBufferINTEL"]; - GLReleaseSharedRenderBuffer = (*glLibrary)["wglReleaseSharedRenderBufferINTEL"]; - GLAcquireSharedTexture = (*glLibrary)["wglAcquireSharedTextureINTEL"]; - GLReleaseSharedTexture = (*glLibrary)["wglReleaseSharedTextureINTEL"]; - GLRetainSync = (*glLibrary)["wglRetainSyncINTEL"]; - GLReleaseSync = (*glLibrary)["wglReleaseSyncINTEL"]; - GLGetSynciv = (*glLibrary)["wglGetSyncivINTEL"]; - glGetStringi = (*glLibrary)["glGetStringi"]; - this->wglMakeCurrent = (*glLibrary)["wglMakeCurrent"]; - } + GLGetCurrentContext = reinterpret_cast(loadGlFunction("wglGetCurrentContext", GLHDCType)); + GLGetCurrentDisplay = reinterpret_cast(loadGlFunction("wglGetCurrentDC", GLHDCType)); + glGetString = reinterpret_cast(loadGlFunction("glGetString", GLHDCType)); + glGetIntegerv = reinterpret_cast(loadGlFunction("glGetIntegerv", GLHDCType)); + + pfnWglCreateContext = reinterpret_cast(loadGlFunction("wglCreateContext", GLHDCType)); + pfnWglDeleteContext = reinterpret_cast(loadGlFunction("wglDeleteContext", GLHDCType)); + + pfnWglShareLists = reinterpret_cast(loadGlFunction("wglShareLists", GLHDCType)); + + auto wglGetProcAddressFuncPtr = reinterpret_cast(loadGlFunction("wglGetProcAddress", GLHDCType)); + GLSetSharedOCLContextState = reinterpret_cast(wglGetProcAddressFuncPtr("wglSetSharedOCLContextStateINTEL")); + GLAcquireSharedBuffer = reinterpret_cast(wglGetProcAddressFuncPtr("wglAcquireSharedBufferINTEL")); + GLReleaseSharedBuffer = reinterpret_cast(wglGetProcAddressFuncPtr("wglReleaseSharedBufferINTEL")); + GLAcquireSharedRenderBuffer = reinterpret_cast(wglGetProcAddressFuncPtr("wglAcquireSharedRenderBufferINTEL")); + GLReleaseSharedRenderBuffer = reinterpret_cast(wglGetProcAddressFuncPtr("wglReleaseSharedRenderBufferINTEL")); + GLAcquireSharedTexture = reinterpret_cast(wglGetProcAddressFuncPtr("wglAcquireSharedTextureINTEL")); + GLReleaseSharedTexture = reinterpret_cast(wglGetProcAddressFuncPtr("wglReleaseSharedTextureINTEL")); + GLRetainSync = reinterpret_cast(wglGetProcAddressFuncPtr("wglRetainSyncINTEL")); + GLReleaseSync = reinterpret_cast(wglGetProcAddressFuncPtr("wglReleaseSyncINTEL")); + GLGetSynciv = reinterpret_cast(wglGetProcAddressFuncPtr("wglGetSyncivINTEL")); + glGetStringi = reinterpret_cast(wglGetProcAddressFuncPtr("glGetStringi")); + this->wglMakeCurrent = reinterpret_cast(loadGlFunction("wglMakeCurrent", GLHDCType)); + this->pfnGlArbSyncObjectCleanup = cleanupArbSyncObject; this->pfnGlArbSyncObjectSetup = setupArbSyncObject; this->pfnGlArbSyncObjectSignal = signalArbSyncObject; @@ -117,6 +119,12 @@ bool GLSharingFunctions::isOpenGlSharingSupported() { return true; } +void *GLSharingFunctions::loadGlFunction(const char *functionName, uint32_t hdc) { + + HMODULE module = LoadLibraryA(Os::openglDllName); + return reinterpret_cast(GetProcAddress(module, functionName)); +} + void GLSharingFunctions::createBackupContext() { if (pfnWglCreateContext) { GLHGLRCHandleBkpCtx = pfnWglCreateContext(GLHDCHandle); diff --git a/runtime/sharings/gl/gl_sharing.h b/runtime/sharings/gl/gl_sharing.h index 0e90511f3640d..7ce9ebb2d0db3 100644 --- a/runtime/sharings/gl/gl_sharing.h +++ b/runtime/sharings/gl/gl_sharing.h @@ -12,7 +12,7 @@ #include "GL/gl.h" #include "GL/glext.h" #include "runtime/sharings/sharing.h" -#include "runtime/os_interface/windows/gl/gl_sharing_os.h" +#include "gl/gl_sharing_os.h" #include #include @@ -207,7 +207,6 @@ class GLSharingFunctions : public SharingFunctions { } protected: - std::unique_ptr glLibrary = nullptr; GLType GLHDCType = 0; GLContext GLHGLRCHandle = 0; GLContext GLHGLRCHandleBkpCtx = 0; @@ -240,6 +239,9 @@ class GLSharingFunctions : public SharingFunctions { PFNglArbSyncObjectSignal pfnGlArbSyncObjectSignal = nullptr; PFNglArbSyncObjectWaitServer pfnGlArbSyncObjectWaitServer = nullptr; + // loading OGL libraries for OGL_OCL sharing + void *loadGlFunction(const char *functionName, uint32_t hdc); + // support for GL_ARB_cl_event std::mutex glArbEventMutex; std::unordered_map glArbEventMapping; diff --git a/unit_tests/mocks/gl/mock_gl_sharing.h b/unit_tests/mocks/gl/mock_gl_sharing.h index 8aa6d020adb8e..7b4b6b4e0e9fc 100644 --- a/unit_tests/mocks/gl/mock_gl_sharing.h +++ b/unit_tests/mocks/gl/mock_gl_sharing.h @@ -292,9 +292,12 @@ class MockGLSharingFunctions : public GLSharingFunctions { ((ContextInfo *)pContextInfo)->DeviceHandle = 2; return GLSetSharedOCLContextStateReturnedValue; } - using GLSharingFunctions::glGetIntegerv; - using GLSharingFunctions::glGetString; + void *loadGlFunction(const char *FunctionName, DWORD HDC) { return GLSharingFunctions::loadGlFunction(FunctionName, HDC); }; + + void setGetStringFcn(PFNglGetString fcn) { glGetString = fcn; } + + void setglGetIntegervToNull() { glGetIntegerv = nullptr; } MockGLSharingFunctions() { glGetString = (PFNglGetString)glGetStringTest; glGetStringi = (PFNglGetStringi)glGetStringiTest; diff --git a/unit_tests/os_interface/os_library_tests.cpp b/unit_tests/os_interface/os_library_tests.cpp index 6afcf6c022a86..9662439618ca5 100644 --- a/unit_tests/os_interface/os_library_tests.cpp +++ b/unit_tests/os_interface/os_library_tests.cpp @@ -91,39 +91,3 @@ TEST_F(OSLibraryTest, testFailNew) { }; injectFailures(method); } - -TEST(OsLibrary, whenCallingIndexOperatorThenObjectConvertibleToFunctionOrVoidPointerIsReturned) { - struct MockOsLibrary : OsLibrary { - void *getProcAddress(const std::string &procName) override { - lastRequestedProcName = procName; - return ptrToReturn; - } - bool isLoaded() override { return true; } - - void *ptrToReturn = nullptr; - std::string lastRequestedProcName; - }; - - MockOsLibrary lib; - - int varA, varB, varC; - int *addrA = &varA, *addrB = &varB, *addrC = &varC; - - using FunctionTypeA = void (*)(int *, float); - using FunctionTypeB = int (*)(); - - lib.ptrToReturn = addrA; - FunctionTypeA functionA = lib["funcA"]; - EXPECT_STREQ("funcA", lib.lastRequestedProcName.c_str()); - EXPECT_EQ(reinterpret_cast(addrA), reinterpret_cast(functionA)); - - lib.ptrToReturn = addrB; - FunctionTypeB functionB = lib["funcB"]; - EXPECT_STREQ("funcB", lib.lastRequestedProcName.c_str()); - EXPECT_EQ(reinterpret_cast(addrB), reinterpret_cast(functionB)); - - lib.ptrToReturn = addrC; - void *rawPtr = lib["funcC"]; - EXPECT_STREQ("funcC", lib.lastRequestedProcName.c_str()); - EXPECT_EQ(reinterpret_cast(addrC), rawPtr); -} diff --git a/unit_tests/sharings/gl/gl_sharing_tests.cpp b/unit_tests/sharings/gl/gl_sharing_tests.cpp index adb6ee455a529..6a104cf8fca7e 100644 --- a/unit_tests/sharings/gl/gl_sharing_tests.cpp +++ b/unit_tests/sharings/gl/gl_sharing_tests.cpp @@ -32,10 +32,6 @@ #include "test.h" #include "gl/gl_sharing_os.h" -namespace Os { -extern const char *openglDllName; -} - using namespace OCLRT; bool MockGLSharingFunctions::SharingEnabled = false; const char *MockGLSharingFunctions::arrayStringi[2] = {"GL_OES_framebuffer_object", "GL_EXT_framebuffer_object"}; @@ -654,6 +650,12 @@ TEST(glSharingBasicTest, GivenSharingFunctionsWhenItIsConstructedThenOglContextF EXPECT_EQ(1, GLSetSharedOCLContextStateCalled); } +TEST(glSharingBasicTest, givenInvalidFunctionNameWhenLoadGLFunctionThenReturnNullptr) { + MockGLSharingFunctions glSharingFunctions; + auto fPointer = glSharingFunctions.loadGlFunction("BadFunctionName", 0); + EXPECT_EQ(nullptr, fPointer); +} + TEST(glSharingBasicTest, givenInvalidExtensionNameWhenCheckGLExtensionSupportedThenReturnFalse) { GLSharingFunctions glSharingFunctions; bool RetVal = glSharingFunctions.isOpenGlExtensionSupported("InvalidExtensionName"); @@ -662,7 +664,7 @@ TEST(glSharingBasicTest, givenInvalidExtensionNameWhenCheckGLExtensionSupportedT TEST(glSharingBasicTest, givenglGetIntegervIsNullWhenCheckGLExtensionSupportedThenReturnFalse) { MockGLSharingFunctions glSharingFunctions; - glSharingFunctions.glGetIntegerv = nullptr; + glSharingFunctions.setglGetIntegervToNull(); bool RetVal = glSharingFunctions.isOpenGlExtensionSupported("InvalidExtensionName"); EXPECT_FALSE(RetVal); } @@ -685,7 +687,7 @@ TEST(glSharingBasicTest, givenVendorisNullWhenCheckGLSharingSupportedThenReturnF }; MockGLSharingFunctions glSharingFunctions; - glSharingFunctions.glGetString = invalidGetStringFcn; + glSharingFunctions.setGetStringFcn(invalidGetStringFcn); bool RetVal = glSharingFunctions.isOpenGlSharingSupported(); EXPECT_FALSE(RetVal);