mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-01 04:23:00 +08:00
Refactor of glcl sharing
new pattern to load gl functions from dll Change-Id: I6f39945d3c53b5a169b0829f36b2102c3ef5e18a
This commit is contained in:
committed by
sys_ocldev
parent
526a3a664b
commit
51ecef7ec2
@@ -7,6 +7,7 @@
|
||||
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
|
||||
namespace OCLRT {
|
||||
|
||||
@@ -15,10 +16,25 @@ 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;
|
||||
};
|
||||
|
||||
@@ -31,30 +31,28 @@ GLSharingFunctions::~GLSharingFunctions() {
|
||||
}
|
||||
|
||||
GLboolean GLSharingFunctions::initGLFunctions() {
|
||||
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));
|
||||
|
||||
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"];
|
||||
}
|
||||
this->pfnGlArbSyncObjectCleanup = cleanupArbSyncObject;
|
||||
this->pfnGlArbSyncObjectSetup = setupArbSyncObject;
|
||||
this->pfnGlArbSyncObjectSignal = signalArbSyncObject;
|
||||
@@ -119,12 +117,6 @@ 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);
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
#include "GL/gl.h"
|
||||
#include "GL/glext.h"
|
||||
#include "runtime/sharings/sharing.h"
|
||||
#include "gl/gl_sharing_os.h"
|
||||
#include "runtime/os_interface/windows/gl/gl_sharing_os.h"
|
||||
|
||||
#include <functional>
|
||||
#include <mutex>
|
||||
@@ -207,6 +207,7 @@ class GLSharingFunctions : public SharingFunctions {
|
||||
}
|
||||
|
||||
protected:
|
||||
std::unique_ptr<OsLibrary> glLibrary = nullptr;
|
||||
GLType GLHDCType = 0;
|
||||
GLContext GLHGLRCHandle = 0;
|
||||
GLContext GLHGLRCHandleBkpCtx = 0;
|
||||
@@ -239,9 +240,6 @@ 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;
|
||||
|
||||
Reference in New Issue
Block a user