P4 to Git Change 1479084 by gandryey@gera-w8 on 2017/11/06 13:39:25

SWDEV-133813 - PAL support for Linux Pro: cl-gl interop on OpenCL 1.2
	- Enable GL interop under Linux
	- Enable proper GL device detection logic

Affected files ...

... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paldevice.hpp#21 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paldevicegl.cpp#7 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palresource.cpp#40 edit


[ROCm/clr commit: 69b10d77ec]
This commit is contained in:
foreman
2017-11-06 13:45:22 -05:00
parent 9f30f9d211
commit dfc7fdba8c
3 ha cambiato i file con 78 aggiunte e 31 eliminazioni
@@ -481,8 +481,8 @@ class Device : public NullDevice {
//! Interop for GL device
bool initGLInteropPrivateExt(void* GLplatformContext, void* GLdeviceContext) const;
bool glCanInterop(void* GLplatformContext, void* GLdeviceContext) const;
bool resGLAssociate(void* GLContext, uint name, uint type, void** handle, void** mbResHandle,
size_t* offset, cl_image_format& newClFormat
bool resGLAssociate(void* GLContext, uint name, uint type, Pal::OsExternalHandle* handle,
void** mbResHandle, size_t* offset, cl_image_format& newClFormat
#ifdef ATI_OS_WIN
,
Pal::DoppDesktopInfo& doppDesktopInfo
@@ -25,24 +25,44 @@
#include "GL/wglATIPrivate.h"
#endif
/**
* Device information returned by Mesa/Orca.
*/
typedef struct _mesa_glinterop_device_info {
uint32_t size; /* size of this structure */
/* PCI location */
uint32_t pci_segment_group;
uint32_t pci_bus;
uint32_t pci_device;
uint32_t pci_function;
/* Device identification */
uint32_t vendor_id;
uint32_t device_id;
} mesa_glinterop_device_info;
#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;
static PFNGlxGetProcAddress pfnGlxGetProcAddress = nullptr;
typedef int(APIENTRYP PFNMesaGLInteropGLXQueryDeviceInfo)(
Display* dpy, GLXContext context, mesa_glinterop_device_info* out);
static PFNMesaGLInteropGLXQueryDeviceInfo pfnMesaGLInteropGLXQueryDeviceInfo = nullptr;
static PFNGLXBEGINCLINTEROPAMD glXBeginCLInteropAMD = nullptr;
static PFNGLXENDCLINTEROPAMD glXEndCLInteropAMD = nullptr;
static PFNGLXRESOURCEATTACHAMD glXResourceAttachAMD = nullptr;
static PFNGLXRESOURCEDETACHAMD glxResourceAcquireAMD = nullptr;
static PFNGLXRESOURCEDETACHAMD glxResourceReleaseAMD = nullptr;
static PFNGLXRESOURCEDETACHAMD glXResourceDetachAMD = nullptr;
static PFNGLXGETCONTEXTMVPUINFOAMD glXGetContextMVPUInfoAMD = nullptr;
#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;
static PFNWGLBEGINCLINTEROPAMD wglBeginCLInteropAMD = nullptr;
static PFNWGLENDCLINTEROPAMD wglEndCLInteropAMD = nullptr;
static PFNWGLRESOURCEATTACHAMD wglResourceAttachAMD = nullptr;
static PFNWGLRESOURCEDETACHAMD wglResourceAcquireAMD = nullptr;
static PFNWGLRESOURCEDETACHAMD wglResourceReleaseAMD = nullptr;
static PFNWGLRESOURCEDETACHAMD wglResourceDetachAMD = nullptr;
static PFNWGLGETCONTEXTGPUINFOAMD wglGetContextGPUInfoAMD = nullptr;
#endif
namespace pal {
@@ -529,12 +549,17 @@ bool Device::initGLInteropPrivateExt(void* GLplatformContext, void* GLdeviceCont
GLXContext ctx = (GLXContext)GLplatformContext;
void* pModule = dlopen("libGL.so.1", RTLD_NOW);
if (NULL == pModule) {
if (nullptr == pModule) {
return false;
}
pfnGlxGetProcAddress = (PFNGlxGetProcAddress)dlsym(pModule, "glXGetProcAddress");
if (nullptr == pfnGlxGetProcAddress) {
return false;
}
if (NULL == pfnGlxGetProcAddress) {
pfnMesaGLInteropGLXQueryDeviceInfo = (PFNMesaGLInteropGLXQueryDeviceInfo)dlsym(
pModule, "MesaGLInteropGLXQueryDeviceInfo");
if (nullptr == pfnMesaGLInteropGLXQueryDeviceInfo) {
return false;
}
@@ -557,13 +582,13 @@ bool Device::initGLInteropPrivateExt(void* GLplatformContext, void* GLdeviceCont
}
if (!glXBeginCLInteropAMD || !glXEndCLInteropAMD || !glXResourceAttachAMD ||
!glXResourceDetachAMD) {
!glXResourceDetachAMD || !glXGetContextMVPUInfoAMD) {
return false;
}
#else
if (!wglBeginCLInteropAMD || !wglEndCLInteropAMD || !wglResourceAttachAMD ||
!wglResourceDetachAMD || !wglGetContextGPUInfoAMD) {
HGLRC fakeRC = NULL;
HGLRC fakeRC = nullptr;
if (!wglGetCurrentContext()) {
fakeRC = wglCreateContext((HDC)GLdeviceContext);
@@ -581,7 +606,7 @@ bool Device::initGLInteropPrivateExt(void* GLplatformContext, void* GLdeviceCont
(PFNWGLGETCONTEXTGPUINFOAMD)wglGetProcAddress("wglGetContextGPUInfoAMD");
if (fakeRC) {
wglMakeCurrent(NULL, NULL);
wglMakeCurrent(nullptr, nullptr);
wglDeleteContext(fakeRC);
}
}
@@ -609,7 +634,22 @@ bool Device::glCanInterop(void* GLplatformContext, void* GLdeviceContext) const
((1 << properties().gpuIndex) == glChainBitMask);
}
#else
canInteroperate = true;
GLuint glDeviceId = 0 ;
GLuint glChainMask = 0 ;
GLXContext ctx = static_cast<GLXContext>(GLplatformContext);
Display* disp = static_cast<Display*>(GLdeviceContext);
if (glXGetContextMVPUInfoAMD(ctx, &glDeviceId, &glChainMask)) {
mesa_glinterop_device_info info = {};
if (pfnMesaGLInteropGLXQueryDeviceInfo(disp, ctx, &info) == 0) {
// match the adapter
canInteroperate = (properties().pciProperties.busNumber == info.pci_bus) &&
(properties().pciProperties.deviceNumber == info.pci_device) &&
(properties().pciProperties.functionNumber == info.pci_function) &&
(static_cast<GLuint>(1 << properties().gpuIndex) == glChainMask);
}
}
#endif
return canInteroperate;
}
@@ -654,7 +694,7 @@ bool Device::glDissociate(void* GLplatformContext, void* GLdeviceContext) const
#endif
}
bool Device::resGLAssociate(void* GLContext, uint name, uint type, void** handle,
bool Device::resGLAssociate(void* GLContext, uint name, uint type, Pal::OsExternalHandle* handle,
void** mbResHandle, size_t* offset, cl_image_format& newClFormat
#ifdef ATI_OS_WIN
,
@@ -675,7 +715,6 @@ bool Device::resGLAssociate(void* GLContext, uint name, uint type, void** handle
#ifdef ATI_OS_LINUX
GLXContext ctx = (GLXContext)GLContext;
if (glXResourceAttachAMD(ctx, &hRes, &hData)) {
// attribs.dynamicSharedBufferID = hData->sharedBufferID;
status = true;
}
#else
@@ -689,10 +728,10 @@ bool Device::resGLAssociate(void* GLContext, uint name, uint type, void** handle
return false;
}
*handle = reinterpret_cast<void*>(hData.handle);
*mbResHandle = reinterpret_cast<void*>(hData.mbResHandle);
*offset = static_cast<size_t>(hData.offset);
#ifdef ATI_OS_WIN
*handle = reinterpret_cast<Pal::OsExternalHandle>(hData.handle);
if (hData.isDoppDesktopTexture) {
doppDesktopInfo.gpuVirtAddr = hData.cardAddr;
doppDesktopInfo.vidPnSourceId = hData.vidpnSourceId;
@@ -700,6 +739,8 @@ bool Device::resGLAssociate(void* GLContext, uint name, uint type, void** handle
doppDesktopInfo.gpuVirtAddr = 0;
doppDesktopInfo.vidPnSourceId = 0;
}
#else
*handle = static_cast<Pal::OsExternalHandle>(hData.sharedBufferID);
#endif
// OCL supports only a limited number of cm_surf formats, so we
@@ -455,7 +455,6 @@ bool Resource::create(MemoryType memType, CreateParams* params) {
Pal::Result result;
#ifdef _WIN32
if ((memoryType() == OGLInterop) || (memoryType() == D3D9Interop) ||
(memoryType() == D3D10Interop) || (memoryType() == D3D11Interop)) {
Pal::ExternalGpuMemoryOpenInfo gpuMemOpenInfo = {};
@@ -491,13 +490,18 @@ bool Resource::create(MemoryType memType, CreateParams* params) {
mipLevel = oglRes->mipLevel_;
if (!dev().resGLAssociate(oglRes->glPlatformContext_, oglRes->handle_, glType_,
&openInfo.hExternalResource, &glInteropMbRes_, &offset_, desc_.format_,
openInfo.doppDesktopInfo)) {
&openInfo.hExternalResource, &glInteropMbRes_, &offset_, desc_.format_
#ifdef ATI_OS_WIN
, openInfo.doppDesktopInfo
#endif
)) {
return false;
}
desc_.isDoppTexture_ = (openInfo.doppDesktopInfo.gpuVirtAddr != 0);
format = dev().getPalFormat(desc().format_, &channels);
} else {
}
#ifdef ATI_OS_WIN
else {
D3DInteropParams* d3dRes = reinterpret_cast<D3DInteropParams*>(params);
openInfo.hExternalResource = d3dRes->handle_;
misc = d3dRes->misc;
@@ -505,6 +509,7 @@ bool Resource::create(MemoryType memType, CreateParams* params) {
type = d3dRes->type_;
mipLevel = d3dRes->mipLevel_;
}
#endif
//! @todo PAL query for image/buffer object doesn't work properly!
#if 0
bool isImage = false;
@@ -685,6 +690,8 @@ bool Resource::create(MemoryType memType, CreateParams* params) {
case Pal::ImageType::Tex1d:
viewInfo.viewType = Pal::ImageViewType::Tex1d;
break;
default:
break;
}
viewInfo.pImage = image_;
viewInfo.swizzledFormat.format = format;
@@ -720,7 +727,6 @@ bool Resource::create(MemoryType memType, CreateParams* params) {
}
return true;
}
#endif // _WIN32
if (!desc_.buffer_) {
if (desc().topology_ == CL_MEM_OBJECT_IMAGE1D_BUFFER) {