Skip to content

Commit

Permalink
Revert "Refactor of glcl sharing"
Browse files Browse the repository at this point in the history
This reverts commit 51ecef7.

Change-Id: Ia654fe0d50a2144371c3def7e768ef9707419c61
Signed-off-by: Artur Harasimiuk <artur.harasimiuk@intel.com>
  • Loading branch information
ArturHarasimiuk authored and Compute-Runtime-Automation committed Oct 8, 2018
1 parent 130a7ac commit a6d9e74
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 84 deletions.
16 changes: 0 additions & 16 deletions runtime/os_interface/os_library.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

#pragma once
#include <string>
#include <type_traits>

namespace OCLRT {

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

public:
struct ConvertibleProcAddr {
template <typename T>
operator T *() const {
static_assert(std::is_function<T>::value, "Cannot convert to non-function and non-void* type");
return reinterpret_cast<T *>(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;
};
Expand Down
52 changes: 30 additions & 22 deletions runtime/os_interface/windows/gl/gl_sharing_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<PFNOGLGetCurrentContext>(loadGlFunction("wglGetCurrentContext", GLHDCType));
GLGetCurrentDisplay = reinterpret_cast<PFNOGLGetCurrentDisplay>(loadGlFunction("wglGetCurrentDC", GLHDCType));
glGetString = reinterpret_cast<PFNglGetString>(loadGlFunction("glGetString", GLHDCType));
glGetIntegerv = reinterpret_cast<PFNglGetIntegerv>(loadGlFunction("glGetIntegerv", GLHDCType));

pfnWglCreateContext = reinterpret_cast<PFNwglCreateContext>(loadGlFunction("wglCreateContext", GLHDCType));
pfnWglDeleteContext = reinterpret_cast<PFNwglDeleteContext>(loadGlFunction("wglDeleteContext", GLHDCType));

pfnWglShareLists = reinterpret_cast<PFNwglShareLists>(loadGlFunction("wglShareLists", GLHDCType));

auto wglGetProcAddressFuncPtr = reinterpret_cast<PROC(WINAPI *)(LPCSTR)>(loadGlFunction("wglGetProcAddress", GLHDCType));
GLSetSharedOCLContextState = reinterpret_cast<PFNOGLSetSharedOCLContextStateINTEL>(wglGetProcAddressFuncPtr("wglSetSharedOCLContextStateINTEL"));
GLAcquireSharedBuffer = reinterpret_cast<PFNOGLAcquireSharedBufferINTEL>(wglGetProcAddressFuncPtr("wglAcquireSharedBufferINTEL"));
GLReleaseSharedBuffer = reinterpret_cast<PFNOGLReleaseSharedBufferINTEL>(wglGetProcAddressFuncPtr("wglReleaseSharedBufferINTEL"));
GLAcquireSharedRenderBuffer = reinterpret_cast<PFNOGLAcquireSharedRenderBufferINTEL>(wglGetProcAddressFuncPtr("wglAcquireSharedRenderBufferINTEL"));
GLReleaseSharedRenderBuffer = reinterpret_cast<PFNOGLReleaseSharedRenderBufferINTEL>(wglGetProcAddressFuncPtr("wglReleaseSharedRenderBufferINTEL"));
GLAcquireSharedTexture = reinterpret_cast<PFNOGLAcquireSharedTextureINTEL>(wglGetProcAddressFuncPtr("wglAcquireSharedTextureINTEL"));
GLReleaseSharedTexture = reinterpret_cast<PFNOGLReleaseSharedTextureINTEL>(wglGetProcAddressFuncPtr("wglReleaseSharedTextureINTEL"));
GLRetainSync = reinterpret_cast<PFNOGLRetainSyncINTEL>(wglGetProcAddressFuncPtr("wglRetainSyncINTEL"));
GLReleaseSync = reinterpret_cast<PFNOGLReleaseSyncINTEL>(wglGetProcAddressFuncPtr("wglReleaseSyncINTEL"));
GLGetSynciv = reinterpret_cast<PFNOGLGetSyncivINTEL>(wglGetProcAddressFuncPtr("wglGetSyncivINTEL"));
glGetStringi = reinterpret_cast<PFNglGetStringi>(wglGetProcAddressFuncPtr("glGetStringi"));
this->wglMakeCurrent = reinterpret_cast<PFNwglMakeCurrent>(loadGlFunction("wglMakeCurrent", GLHDCType));

this->pfnGlArbSyncObjectCleanup = cleanupArbSyncObject;
this->pfnGlArbSyncObjectSetup = setupArbSyncObject;
this->pfnGlArbSyncObjectSignal = signalArbSyncObject;
Expand Down Expand Up @@ -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<PFNglGetString>(GetProcAddress(module, functionName));
}

void GLSharingFunctions::createBackupContext() {
if (pfnWglCreateContext) {
GLHGLRCHandleBkpCtx = pfnWglCreateContext(GLHDCHandle);
Expand Down
6 changes: 4 additions & 2 deletions runtime/sharings/gl/gl_sharing.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <functional>
#include <mutex>
Expand Down Expand Up @@ -207,7 +207,6 @@ class GLSharingFunctions : public SharingFunctions {
}

protected:
std::unique_ptr<OsLibrary> glLibrary = nullptr;
GLType GLHDCType = 0;
GLContext GLHGLRCHandle = 0;
GLContext GLHGLRCHandleBkpCtx = 0;
Expand Down Expand Up @@ -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<Event *, GlArbSyncEvent *> glArbEventMapping;
Expand Down
7 changes: 5 additions & 2 deletions unit_tests/mocks/gl/mock_gl_sharing.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
36 changes: 0 additions & 36 deletions unit_tests/os_interface/os_library_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<void *>(addrA), reinterpret_cast<void *>(functionA));

lib.ptrToReturn = addrB;
FunctionTypeB functionB = lib["funcB"];
EXPECT_STREQ("funcB", lib.lastRequestedProcName.c_str());
EXPECT_EQ(reinterpret_cast<void *>(addrB), reinterpret_cast<void *>(functionB));

lib.ptrToReturn = addrC;
void *rawPtr = lib["funcC"];
EXPECT_STREQ("funcC", lib.lastRequestedProcName.c_str());
EXPECT_EQ(reinterpret_cast<void *>(addrC), rawPtr);
}
14 changes: 8 additions & 6 deletions unit_tests/sharings/gl/gl_sharing_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"};
Expand Down Expand Up @@ -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");
Expand All @@ -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);
}
Expand All @@ -685,7 +687,7 @@ TEST(glSharingBasicTest, givenVendorisNullWhenCheckGLSharingSupportedThenReturnF
};

MockGLSharingFunctions glSharingFunctions;
glSharingFunctions.glGetString = invalidGetStringFcn;
glSharingFunctions.setGetStringFcn(invalidGetStringFcn);

bool RetVal = glSharingFunctions.isOpenGlSharingSupported();
EXPECT_FALSE(RetVal);
Expand Down

0 comments on commit a6d9e74

Please sign in to comment.