Dateien
rocm-systems/rocclr/runtime/device/pal/paldevicegl.cpp
T
foreman c99d679c9e P4 to Git Change 1230521 by gandryey@gera-w8 on 2016/01/22 17:58:08
SWDEV-86035 - Add OCL backend for PAL
	- PAL backend build is disabled by default. "BUILD_PAL_DEVICE = yes" enables the build. You also have to update the client workspace with PAL mapping: //depot/stg/pal/... //<your_opencl_location>/runtime/device/pal/palbe/...

Affected files ...

... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/build/Makefile.api#130 edit
... //depot/stg/opencl/drivers/opencl/compiler/sclibdefs.opencl#8 edit
... //depot/stg/opencl/drivers/opencl/opencldefs#166 edit
... //depot/stg/opencl/drivers/opencl/openclrules#91 edit
... //depot/stg/opencl/drivers/opencl/runtime/Makefile#21 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/device.cpp#192 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/Makefile#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/build/Makefile#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/build/Makefile.pal#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palappprofile.cpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palappprofile.hpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palbinary.cpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palbinary.hpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palblit.cpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palblit.hpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palcompiler.cpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palconstbuf.cpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palconstbuf.hpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palcounters.cpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palcounters.hpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paldebugger.hpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paldebugmanager.cpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paldebugmanager.hpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paldefs.hpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paldevice.cpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paldevice.hpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paldeviced3d10.cpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paldeviced3d11.cpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paldeviced3d9.cpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paldevicegl.cpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palkernel.cpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palkernel.hpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palmemory.cpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palmemory.hpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palprintf.cpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palprintf.hpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palprogram.cpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palprogram.hpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palresource.cpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palresource.hpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palsched.hpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palschedcl.cpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palsettings.cpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palsettings.hpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palthreadtrace.cpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palthreadtrace.hpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paltimestamp.cpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paltimestamp.hpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paltrap.hpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palvirtual.cpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palvirtual.hpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palwavelimiter.cpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palwavelimiter.hpp#1 add
... //depot/stg/opencl/drivers/opencl/runtime/runtimedefs#36 edit
... //depot/stg/opencl/drivers/opencl/runtime/top.hpp#23 edit
2016-01-22 18:18:55 -05:00

307 Zeilen
9.5 KiB
C++

#include "platform/context.hpp"
#include "device/device.hpp"
#include "platform/runtime.hpp"
#include "platform/agent.hpp"
#ifdef _WIN32
#include <d3d10_1.h>
#include "CL/cl_d3d10.h"
#include "CL/cl_d3d11.h"
#endif // _WIN32
#include <GL/gl.h>
#include <GL/glext.h>
#include "CL/cl_gl.h"
#include "paldevice.hpp"
//#include "cwddeci.h"
#include <GL/gl.h>
#include "GL/glATIInternal.h"
#ifdef ATI_OS_LINUX
#include <stdlib.h>
#include <dlfcn.h>
#include "GL/glx.h"
#include "GL/glxext.h"
#include "GL/glXATIPrivate.h"
#else
#include "GL/wglATIPrivate.h"
#endif
#ifdef ATI_OS_LINUX
typedef void* (*PFNGlxGetProcAddress)(const GLubyte* procName);
static PFNGlxGetProcAddress pfnGlxGetProcAddress=NULL;
static PFNGLXBEGINCLINTEROPAMD glXBeginCLInteropAMD = NULL;
static PFNGLXENDCLINTEROPAMD glXEndCLInteropAMD = NULL;
static PFNGLXRESOURCEATTACHAMD glXResourceAttachAMD = NULL;
static PFNGLXRESOURCEDETACHAMD glxResourceAcquireAMD = NULL;
static PFNGLXRESOURCEDETACHAMD glxResourceReleaseAMD = NULL;
static PFNGLXRESOURCEDETACHAMD glXResourceDetachAMD = NULL;
static PFNGLXGETCONTEXTMVPUINFOAMD glXGetContextMVPUInfoAMD = NULL;
#else
static PFNWGLBEGINCLINTEROPAMD wglBeginCLInteropAMD = NULL;
static PFNWGLENDCLINTEROPAMD wglEndCLInteropAMD = NULL;
static PFNWGLRESOURCEATTACHAMD wglResourceAttachAMD = NULL;
static PFNWGLRESOURCEDETACHAMD wglResourceAcquireAMD = NULL;
static PFNWGLRESOURCEDETACHAMD wglResourceReleaseAMD = NULL;
static PFNWGLRESOURCEDETACHAMD wglResourceDetachAMD = NULL;
static PFNWGLGETCONTEXTGPUINFOAMD wglGetContextGPUInfoAMD = NULL;
#endif
namespace pal {
bool
Device::initGLInteropPrivateExt(void* GLplatformContext, void* GLdeviceContext) const
{
#ifdef ATI_OS_LINUX
GLXContext ctx = (GLXContext)GLplatformContext;
void * pModule = dlopen("libGL.so.1",RTLD_NOW);
if(NULL == pModule) {
return false;
}
pfnGlxGetProcAddress = (PFNGlxGetProcAddress) dlsym(pModule,"glXGetProcAddress");
if (NULL == pfnGlxGetProcAddress) {
return false;
}
if (!glXBeginCLInteropAMD || !glXEndCLInteropAMD || !glXResourceAttachAMD ||
!glXResourceDetachAMD || !glXGetContextMVPUInfoAMD) {
glXBeginCLInteropAMD = (PFNGLXBEGINCLINTEROPAMD) pfnGlxGetProcAddress ((const GLubyte *)"glXBeginCLInteroperabilityAMD");
glXEndCLInteropAMD = (PFNGLXENDCLINTEROPAMD) pfnGlxGetProcAddress ((const GLubyte *)"glXEndCLInteroperabilityAMD");
glXResourceAttachAMD = (PFNGLXRESOURCEATTACHAMD) pfnGlxGetProcAddress ((const GLubyte *)"glXResourceAttachAMD");
glxResourceAcquireAMD = (PFNGLXRESOURCEDETACHAMD) pfnGlxGetProcAddress ((const GLubyte *)"glXResourceAcquireAMD");
glxResourceReleaseAMD = (PFNGLXRESOURCEDETACHAMD) pfnGlxGetProcAddress ((const GLubyte *)"glXResourceReleaseAMD");
glXResourceDetachAMD = (PFNGLXRESOURCEDETACHAMD) pfnGlxGetProcAddress ((const GLubyte *)"glXResourceDetachAMD");
glXGetContextMVPUInfoAMD = (PFNGLXGETCONTEXTMVPUINFOAMD) pfnGlxGetProcAddress ((const GLubyte *)"glXGetContextMVPUInfoAMD");
}
if (!glXBeginCLInteropAMD || !glXEndCLInteropAMD || !glXResourceAttachAMD ||
!glXResourceDetachAMD
#ifndef BRAHMA
|| !glXGetContextMVPUInfoAMD
#endif
) {
return false;
}
#else
if (!wglBeginCLInteropAMD || !wglEndCLInteropAMD || !wglResourceAttachAMD ||
!wglResourceDetachAMD || !wglGetContextGPUInfoAMD) {
HGLRC fakeRC = NULL;
if (!wglGetCurrentContext()) {
fakeRC = wglCreateContext((HDC)GLdeviceContext);
wglMakeCurrent((HDC)GLdeviceContext, fakeRC);
}
wglBeginCLInteropAMD = (PFNWGLBEGINCLINTEROPAMD) wglGetProcAddress ("wglBeginCLInteroperabilityAMD");
wglEndCLInteropAMD = (PFNWGLENDCLINTEROPAMD) wglGetProcAddress ("wglEndCLInteroperabilityAMD");
wglResourceAttachAMD = (PFNWGLRESOURCEATTACHAMD) wglGetProcAddress ("wglResourceAttachAMD");
wglResourceAcquireAMD = (PFNWGLRESOURCEDETACHAMD) wglGetProcAddress ("wglResourceAcquireAMD");
wglResourceReleaseAMD = (PFNWGLRESOURCEDETACHAMD) wglGetProcAddress ("wglResourceReleaseAMD");
wglResourceDetachAMD = (PFNWGLRESOURCEDETACHAMD) wglGetProcAddress ("wglResourceDetachAMD");
wglGetContextGPUInfoAMD = (PFNWGLGETCONTEXTGPUINFOAMD) wglGetProcAddress ("wglGetContextGPUInfoAMD");
if (fakeRC) {
wglMakeCurrent(NULL, NULL);
wglDeleteContext(fakeRC);
}
}
if (!wglBeginCLInteropAMD || !wglEndCLInteropAMD || !wglResourceAttachAMD ||
!wglResourceDetachAMD || !wglGetContextGPUInfoAMD) {
return false;
}
#endif
return true;
}
bool
Device::glCanInterop(void* GLplatformContext, void* GLdeviceContext) const
{
bool canInteroperate = false;
#ifdef ATI_OS_WIN
LUID glAdapterLuid = {0, 0};
UINT glChainBitMask = 0;
HGLRC hRC = (HGLRC)GLplatformContext;
//get GL context's LUID and chainBitMask from UGL
if (wglGetContextGPUInfoAMD(hRC, &glAdapterLuid, &glChainBitMask)) {
// match the adapter
canInteroperate =
(properties().osProperties.luidHighPart == glAdapterLuid.HighPart) &&
(properties().osProperties.luidLowPart == glAdapterLuid.LowPart) &&
((1 << properties().gpuIndex) == glChainBitMask);
}
#else
#ifdef BRAHMA
canInteroperate = true;
#else
GLuint glDeviceId = 0 ;
GLuint glChainMask = 0 ;
GLXContext ctx = (GLXContext)GLplatformContext;
if (glXGetContextMVPUInfoAMD(ctx, &glDeviceId, &glChainMask)) {
// we allow intoperability only with GL context reside on a single GPU
canInteroperate =
(properties().deviceId == glDeviceId) &&
((1 << properties().gpuIndex) == glChainBitMask);
}
}
#endif
#endif
return canInteroperate;
}
bool
Device::glAssociate(void* GLplatformContext, void* GLdeviceContext) const
{
//initialize pointers to the gl extension that supports interoperability
if (!initGLInteropPrivateExt(GLplatformContext, GLdeviceContext) ||
!glCanInterop(GLplatformContext, GLdeviceContext)) {
return false;
}
int flags = 0;
/*
if (m_adp->pAsicInfo->svmFineGrainSystem)
{
flags = GL_INTEROP_SVM;
}
*/
#ifdef ATI_OS_LINUX
GLXContext ctx = (GLXContext)GLplatformContext;
return (glXBeginCLInteropAMD(ctx, 0)) ? true : false;
#else
HGLRC hRC = (HGLRC)GLplatformContext;
return (wglBeginCLInteropAMD(hRC, flags)) ? true : false;
#endif
}
bool
Device::glDissociate(void* GLplatformContext, void* GLdeviceContext) const
{
int flags = 0;
/*
if (m_adp->pAsicInfo->svmFineGrainSystem)
{
flags = GL_INTEROP_SVM;
}
*/
#ifdef ATI_OS_LINUX
GLXContext ctx = (GLXContext)GLplatformContext;
return (glXEndCLInteropAMD(ctx, 0)) ? true : false;
#else
HGLRC hRC = (HGLRC)GLplatformContext;
return (wglEndCLInteropAMD(hRC, flags)) ? true : false;
#endif
}
bool
Device::resGLAssociate(
void* GLContext,
uint name,
uint type,
void** handle,
void** mbResHandle,
size_t* offset) const
{
amd::ScopedLock lk(lockPAL());
GLResource hRes = {};
GLResourceData hData = {};
bool status = false;
hRes.type = type;
hRes.name = name;
hData.version = GL_RESOURCE_DATA_VERSION;
#ifdef ATI_OS_LINUX
GLXContext ctx = (GLXContext)GLContext;
if (glXResourceAttachAMD(ctx, &hRes, &hData)) {
attribs.dynamicSharedBufferID = hData->sharedBufferID;
status = true;
}
#else
HGLRC hRC = (HGLRC)GLContext;
if (wglResourceAttachAMD(hRC, &hRes, &hData)) {
status = true;
}
#endif
if (!status) {
return false;
}
*handle = reinterpret_cast<void*>(hData.handle);
*mbResHandle = reinterpret_cast<void*>(hData.mbResHandle);
*offset = static_cast<size_t>(hData.offset);
return status;
}
bool
Device::resGLAcquire(void* GLplatformContext, void* mbResHandle, uint type) const
{
amd::ScopedLock lk(lockPAL());
GLResource hRes = {};
hRes.mbResHandle = (GLuintp)mbResHandle;
hRes.type = type;
#ifdef ATI_OS_LINUX
GLXContext ctx = (GLXContext) GLplatformContext;
return (glxResourceAcquireAMD(ctx, &hRes)) ? true : false;
#else
HGLRC hRC = wglGetCurrentContext();
//! @todo A temporary workaround for MT issue in conformance fence_sync
if (0 == hRC) {
return true;
}
return (wglResourceAcquireAMD(hRC, &hRes)) ? true : false;
#endif
}
bool
Device::resGLRelease(void* GLplatformContext, void* mbResHandle, uint type) const
{
amd::ScopedLock lk(lockPAL());
GLResource hRes = {};
hRes.mbResHandle = (GLuintp)mbResHandle;
hRes.type = type;
#ifdef ATI_OS_LINUX
//TODO : make sure the application GL context is current. if not no
// point calling into the GL RT.
GLXContext ctx = (GLXContext) GLplatformContext;
return (glxResourceReleaseAMD(ctx, &hRes)) ? true : false;
#else
// Make the call into the GL driver only if the application GL context is current
HGLRC hRC = wglGetCurrentContext();
//! @todo A temporary workaround for MT issue in conformance fence_sync
if (0 == hRC) {
return true;
}
return (wglResourceReleaseAMD(hRC, &hRes)) ? true : false;
#endif
}
bool
Device::resGLFree(void* GLplatformContext, void* mbResHandle, uint type) const
{
amd::ScopedLock lk(lockPAL());
GLResource hRes = {};
hRes.mbResHandle = (GLuintp)mbResHandle;
hRes.type = type;
#ifdef ATI_OS_LINUX
GLXContext ctx = (GLXContext)GLplatformContext;
return (glXResourceDetachAMD(ctx, &hRes)) ? true : false;
#else
HGLRC hRC = (HGLRC)GLplatformContext;
return (wglResourceDetachAMD(hRC, &hRes)) ? true : false;
#endif
}
} // pal