Skip to content

Commit a6d9e74

Browse files
Revert "Refactor of glcl sharing"
This reverts commit 51ecef7. Change-Id: Ia654fe0d50a2144371c3def7e768ef9707419c61 Signed-off-by: Artur Harasimiuk <artur.harasimiuk@intel.com>
1 parent 130a7ac commit a6d9e74

File tree

6 files changed

+47
-84
lines changed

6 files changed

+47
-84
lines changed

runtime/os_interface/os_library.h

-16
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
#pragma once
99
#include <string>
10-
#include <type_traits>
1110

1211
namespace OCLRT {
1312

@@ -16,25 +15,10 @@ class OsLibrary {
1615
OsLibrary() = default;
1716

1817
public:
19-
struct ConvertibleProcAddr {
20-
template <typename T>
21-
operator T *() const {
22-
static_assert(std::is_function<T>::value, "Cannot convert to non-function and non-void* type");
23-
return reinterpret_cast<T *>(ptr);
24-
}
25-
26-
operator void *() const {
27-
return ptr;
28-
}
29-
void *ptr = nullptr;
30-
};
3118
virtual ~OsLibrary() = default;
3219

3320
static OsLibrary *load(const std::string &name);
3421

35-
ConvertibleProcAddr operator[](const std::string &name) {
36-
return ConvertibleProcAddr{getProcAddress(name)};
37-
}
3822
virtual void *getProcAddress(const std::string &procName) = 0;
3923
virtual bool isLoaded() = 0;
4024
};

runtime/os_interface/windows/gl/gl_sharing_win.cpp

+30-22
Original file line numberDiff line numberDiff line change
@@ -31,28 +31,30 @@ GLSharingFunctions::~GLSharingFunctions() {
3131
}
3232

3333
GLboolean GLSharingFunctions::initGLFunctions() {
34-
glLibrary.reset(OsLibrary::load(Os::openglDllName));
35-
if (glLibrary->isLoaded()) {
36-
GLGetCurrentContext = (*glLibrary)["wglGetCurrentContext"];
37-
GLGetCurrentDisplay = (*glLibrary)["wglGetCurrentDC"];
38-
glGetString = (*glLibrary)["glGetString"];
39-
glGetIntegerv = (*glLibrary)["glGetIntegerv"];
40-
pfnWglCreateContext = (*glLibrary)["wglCreateContext"];
41-
pfnWglDeleteContext = (*glLibrary)["wglDeleteContext"];
42-
pfnWglShareLists = (*glLibrary)["wglShareLists"];
43-
GLSetSharedOCLContextState = (*glLibrary)["wglSetSharedOCLContextStateINTEL"];
44-
GLAcquireSharedBuffer = (*glLibrary)["wglAcquireSharedBufferINTEL"];
45-
GLReleaseSharedBuffer = (*glLibrary)["wglReleaseSharedBufferINTEL"];
46-
GLAcquireSharedRenderBuffer = (*glLibrary)["wglAcquireSharedRenderBufferINTEL"];
47-
GLReleaseSharedRenderBuffer = (*glLibrary)["wglReleaseSharedRenderBufferINTEL"];
48-
GLAcquireSharedTexture = (*glLibrary)["wglAcquireSharedTextureINTEL"];
49-
GLReleaseSharedTexture = (*glLibrary)["wglReleaseSharedTextureINTEL"];
50-
GLRetainSync = (*glLibrary)["wglRetainSyncINTEL"];
51-
GLReleaseSync = (*glLibrary)["wglReleaseSyncINTEL"];
52-
GLGetSynciv = (*glLibrary)["wglGetSyncivINTEL"];
53-
glGetStringi = (*glLibrary)["glGetStringi"];
54-
this->wglMakeCurrent = (*glLibrary)["wglMakeCurrent"];
55-
}
34+
GLGetCurrentContext = reinterpret_cast<PFNOGLGetCurrentContext>(loadGlFunction("wglGetCurrentContext", GLHDCType));
35+
GLGetCurrentDisplay = reinterpret_cast<PFNOGLGetCurrentDisplay>(loadGlFunction("wglGetCurrentDC", GLHDCType));
36+
glGetString = reinterpret_cast<PFNglGetString>(loadGlFunction("glGetString", GLHDCType));
37+
glGetIntegerv = reinterpret_cast<PFNglGetIntegerv>(loadGlFunction("glGetIntegerv", GLHDCType));
38+
39+
pfnWglCreateContext = reinterpret_cast<PFNwglCreateContext>(loadGlFunction("wglCreateContext", GLHDCType));
40+
pfnWglDeleteContext = reinterpret_cast<PFNwglDeleteContext>(loadGlFunction("wglDeleteContext", GLHDCType));
41+
42+
pfnWglShareLists = reinterpret_cast<PFNwglShareLists>(loadGlFunction("wglShareLists", GLHDCType));
43+
44+
auto wglGetProcAddressFuncPtr = reinterpret_cast<PROC(WINAPI *)(LPCSTR)>(loadGlFunction("wglGetProcAddress", GLHDCType));
45+
GLSetSharedOCLContextState = reinterpret_cast<PFNOGLSetSharedOCLContextStateINTEL>(wglGetProcAddressFuncPtr("wglSetSharedOCLContextStateINTEL"));
46+
GLAcquireSharedBuffer = reinterpret_cast<PFNOGLAcquireSharedBufferINTEL>(wglGetProcAddressFuncPtr("wglAcquireSharedBufferINTEL"));
47+
GLReleaseSharedBuffer = reinterpret_cast<PFNOGLReleaseSharedBufferINTEL>(wglGetProcAddressFuncPtr("wglReleaseSharedBufferINTEL"));
48+
GLAcquireSharedRenderBuffer = reinterpret_cast<PFNOGLAcquireSharedRenderBufferINTEL>(wglGetProcAddressFuncPtr("wglAcquireSharedRenderBufferINTEL"));
49+
GLReleaseSharedRenderBuffer = reinterpret_cast<PFNOGLReleaseSharedRenderBufferINTEL>(wglGetProcAddressFuncPtr("wglReleaseSharedRenderBufferINTEL"));
50+
GLAcquireSharedTexture = reinterpret_cast<PFNOGLAcquireSharedTextureINTEL>(wglGetProcAddressFuncPtr("wglAcquireSharedTextureINTEL"));
51+
GLReleaseSharedTexture = reinterpret_cast<PFNOGLReleaseSharedTextureINTEL>(wglGetProcAddressFuncPtr("wglReleaseSharedTextureINTEL"));
52+
GLRetainSync = reinterpret_cast<PFNOGLRetainSyncINTEL>(wglGetProcAddressFuncPtr("wglRetainSyncINTEL"));
53+
GLReleaseSync = reinterpret_cast<PFNOGLReleaseSyncINTEL>(wglGetProcAddressFuncPtr("wglReleaseSyncINTEL"));
54+
GLGetSynciv = reinterpret_cast<PFNOGLGetSyncivINTEL>(wglGetProcAddressFuncPtr("wglGetSyncivINTEL"));
55+
glGetStringi = reinterpret_cast<PFNglGetStringi>(wglGetProcAddressFuncPtr("glGetStringi"));
56+
this->wglMakeCurrent = reinterpret_cast<PFNwglMakeCurrent>(loadGlFunction("wglMakeCurrent", GLHDCType));
57+
5658
this->pfnGlArbSyncObjectCleanup = cleanupArbSyncObject;
5759
this->pfnGlArbSyncObjectSetup = setupArbSyncObject;
5860
this->pfnGlArbSyncObjectSignal = signalArbSyncObject;
@@ -117,6 +119,12 @@ bool GLSharingFunctions::isOpenGlSharingSupported() {
117119
return true;
118120
}
119121

122+
void *GLSharingFunctions::loadGlFunction(const char *functionName, uint32_t hdc) {
123+
124+
HMODULE module = LoadLibraryA(Os::openglDllName);
125+
return reinterpret_cast<PFNglGetString>(GetProcAddress(module, functionName));
126+
}
127+
120128
void GLSharingFunctions::createBackupContext() {
121129
if (pfnWglCreateContext) {
122130
GLHGLRCHandleBkpCtx = pfnWglCreateContext(GLHDCHandle);

runtime/sharings/gl/gl_sharing.h

+4-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "GL/gl.h"
1313
#include "GL/glext.h"
1414
#include "runtime/sharings/sharing.h"
15-
#include "runtime/os_interface/windows/gl/gl_sharing_os.h"
15+
#include "gl/gl_sharing_os.h"
1616

1717
#include <functional>
1818
#include <mutex>
@@ -207,7 +207,6 @@ class GLSharingFunctions : public SharingFunctions {
207207
}
208208

209209
protected:
210-
std::unique_ptr<OsLibrary> glLibrary = nullptr;
211210
GLType GLHDCType = 0;
212211
GLContext GLHGLRCHandle = 0;
213212
GLContext GLHGLRCHandleBkpCtx = 0;
@@ -240,6 +239,9 @@ class GLSharingFunctions : public SharingFunctions {
240239
PFNglArbSyncObjectSignal pfnGlArbSyncObjectSignal = nullptr;
241240
PFNglArbSyncObjectWaitServer pfnGlArbSyncObjectWaitServer = nullptr;
242241

242+
// loading OGL libraries for OGL_OCL sharing
243+
void *loadGlFunction(const char *functionName, uint32_t hdc);
244+
243245
// support for GL_ARB_cl_event
244246
std::mutex glArbEventMutex;
245247
std::unordered_map<Event *, GlArbSyncEvent *> glArbEventMapping;

unit_tests/mocks/gl/mock_gl_sharing.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,12 @@ class MockGLSharingFunctions : public GLSharingFunctions {
292292
((ContextInfo *)pContextInfo)->DeviceHandle = 2;
293293
return GLSetSharedOCLContextStateReturnedValue;
294294
}
295-
using GLSharingFunctions::glGetIntegerv;
296-
using GLSharingFunctions::glGetString;
297295

296+
void *loadGlFunction(const char *FunctionName, DWORD HDC) { return GLSharingFunctions::loadGlFunction(FunctionName, HDC); };
297+
298+
void setGetStringFcn(PFNglGetString fcn) { glGetString = fcn; }
299+
300+
void setglGetIntegervToNull() { glGetIntegerv = nullptr; }
298301
MockGLSharingFunctions() {
299302
glGetString = (PFNglGetString)glGetStringTest;
300303
glGetStringi = (PFNglGetStringi)glGetStringiTest;

unit_tests/os_interface/os_library_tests.cpp

-36
Original file line numberDiff line numberDiff line change
@@ -91,39 +91,3 @@ TEST_F(OSLibraryTest, testFailNew) {
9191
};
9292
injectFailures(method);
9393
}
94-
95-
TEST(OsLibrary, whenCallingIndexOperatorThenObjectConvertibleToFunctionOrVoidPointerIsReturned) {
96-
struct MockOsLibrary : OsLibrary {
97-
void *getProcAddress(const std::string &procName) override {
98-
lastRequestedProcName = procName;
99-
return ptrToReturn;
100-
}
101-
bool isLoaded() override { return true; }
102-
103-
void *ptrToReturn = nullptr;
104-
std::string lastRequestedProcName;
105-
};
106-
107-
MockOsLibrary lib;
108-
109-
int varA, varB, varC;
110-
int *addrA = &varA, *addrB = &varB, *addrC = &varC;
111-
112-
using FunctionTypeA = void (*)(int *, float);
113-
using FunctionTypeB = int (*)();
114-
115-
lib.ptrToReturn = addrA;
116-
FunctionTypeA functionA = lib["funcA"];
117-
EXPECT_STREQ("funcA", lib.lastRequestedProcName.c_str());
118-
EXPECT_EQ(reinterpret_cast<void *>(addrA), reinterpret_cast<void *>(functionA));
119-
120-
lib.ptrToReturn = addrB;
121-
FunctionTypeB functionB = lib["funcB"];
122-
EXPECT_STREQ("funcB", lib.lastRequestedProcName.c_str());
123-
EXPECT_EQ(reinterpret_cast<void *>(addrB), reinterpret_cast<void *>(functionB));
124-
125-
lib.ptrToReturn = addrC;
126-
void *rawPtr = lib["funcC"];
127-
EXPECT_STREQ("funcC", lib.lastRequestedProcName.c_str());
128-
EXPECT_EQ(reinterpret_cast<void *>(addrC), rawPtr);
129-
}

unit_tests/sharings/gl/gl_sharing_tests.cpp

+8-6
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@
3232
#include "test.h"
3333
#include "gl/gl_sharing_os.h"
3434

35-
namespace Os {
36-
extern const char *openglDllName;
37-
}
38-
3935
using namespace OCLRT;
4036
bool MockGLSharingFunctions::SharingEnabled = false;
4137
const char *MockGLSharingFunctions::arrayStringi[2] = {"GL_OES_framebuffer_object", "GL_EXT_framebuffer_object"};
@@ -654,6 +650,12 @@ TEST(glSharingBasicTest, GivenSharingFunctionsWhenItIsConstructedThenOglContextF
654650
EXPECT_EQ(1, GLSetSharedOCLContextStateCalled);
655651
}
656652

653+
TEST(glSharingBasicTest, givenInvalidFunctionNameWhenLoadGLFunctionThenReturnNullptr) {
654+
MockGLSharingFunctions glSharingFunctions;
655+
auto fPointer = glSharingFunctions.loadGlFunction("BadFunctionName", 0);
656+
EXPECT_EQ(nullptr, fPointer);
657+
}
658+
657659
TEST(glSharingBasicTest, givenInvalidExtensionNameWhenCheckGLExtensionSupportedThenReturnFalse) {
658660
GLSharingFunctions glSharingFunctions;
659661
bool RetVal = glSharingFunctions.isOpenGlExtensionSupported("InvalidExtensionName");
@@ -662,7 +664,7 @@ TEST(glSharingBasicTest, givenInvalidExtensionNameWhenCheckGLExtensionSupportedT
662664

663665
TEST(glSharingBasicTest, givenglGetIntegervIsNullWhenCheckGLExtensionSupportedThenReturnFalse) {
664666
MockGLSharingFunctions glSharingFunctions;
665-
glSharingFunctions.glGetIntegerv = nullptr;
667+
glSharingFunctions.setglGetIntegervToNull();
666668
bool RetVal = glSharingFunctions.isOpenGlExtensionSupported("InvalidExtensionName");
667669
EXPECT_FALSE(RetVal);
668670
}
@@ -685,7 +687,7 @@ TEST(glSharingBasicTest, givenVendorisNullWhenCheckGLSharingSupportedThenReturnF
685687
};
686688

687689
MockGLSharingFunctions glSharingFunctions;
688-
glSharingFunctions.glGetString = invalidGetStringFcn;
690+
glSharingFunctions.setGetStringFcn(invalidGetStringFcn);
689691

690692
bool RetVal = glSharingFunctions.isOpenGlSharingSupported();
691693
EXPECT_FALSE(RetVal);

0 commit comments

Comments
 (0)