From 9b0402343eac38cee17230cee33fa5409faf656f Mon Sep 17 00:00:00 2001 From: foreman Date: Thu, 16 Oct 2014 14:25:54 -0400 Subject: [PATCH] P4 to Git Change 1088224 by gandryey@gera-dev-w7 on 2014/10/16 14:05:07 EPR #403341 - [Regression][OCL] P2P SDI to GPU (RGBA) and P2P SDI to GPU (RGB) show corruption on sdi output - Remove CALResGLBufferTypeEnum. - Code clean-up - Add a workaround for conformance fence_sync failures Affected files ... ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuresource.cpp#195 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuresource.hpp#77 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gslbe/src/include/cal/calcl.h#30 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gslbe/src/rt/GSLDevice.h#42 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gslbe/src/rt/GSLDeviceGL.cpp#19 edit --- rocclr/runtime/device/gpu/gpuresource.cpp | 8 +- rocclr/runtime/device/gpu/gpuresource.hpp | 2 +- .../device/gpu/gslbe/src/include/cal/calcl.h | 7 - .../device/gpu/gslbe/src/rt/GSLDevice.h | 4 +- .../device/gpu/gslbe/src/rt/GSLDeviceGL.cpp | 234 ++++++------------ 5 files changed, 82 insertions(+), 173 deletions(-) diff --git a/rocclr/runtime/device/gpu/gpuresource.cpp b/rocclr/runtime/device/gpu/gpuresource.cpp index 4b5cc14665..cd44e86ee0 100644 --- a/rocclr/runtime/device/gpu/gpuresource.cpp +++ b/rocclr/runtime/device/gpu/gpuresource.cpp @@ -12,6 +12,8 @@ #include "device/gpu/gpublit.hpp" #include "device/gpu/gputimestamp.hpp" #include "thread/atomic.hpp" +#include +#include "GL/glATIInternal.h" #include #include @@ -668,15 +670,15 @@ Resource::create(MemoryType memType, CreateParams* params, bool heap) "We don't have OGL context!"); switch (oglRes->type_) { case InteropVertexBuffer: - glType_ = CAL_RES_GL_BUFFER_TYPE_VERTEXBUFFER; + glType_ = GL_RESOURCE_ATTACH_VERTEXBUFFER_AMD; break; case InteropRenderBuffer: - glType_ = CAL_RES_GL_BUFFER_TYPE_RENDERBUFFER; + glType_ = GL_RESOURCE_ATTACH_RENDERBUFFER_AMD; break; case InteropTexture: case InteropTextureViewLevel: case InteropTextureViewCube: - glType_ = CAL_RES_GL_BUFFER_TYPE_TEXTURE; + glType_ = GL_RESOURCE_ATTACH_TEXTURE_AMD; break; default: LogError("Unknown OGL interop type!"); diff --git a/rocclr/runtime/device/gpu/gpuresource.hpp b/rocclr/runtime/device/gpu/gpuresource.hpp index 0c891c2dde..a47ba4fbe4 100644 --- a/rocclr/runtime/device/gpu/gpuresource.hpp +++ b/rocclr/runtime/device/gpu/gpuresource.hpp @@ -440,7 +440,7 @@ private: Resource* shortView_; //!< Short view memory object gslMemObject glInterop_; //!< Original GL interop object void* glInteropMbRes_;//!< Mb Res handle - CALResGLBufferType glType_; //!< GL interop type + uint32_t glType_; //!< GL interop type void* glPlatformContext_; void* glDeviceContext_; diff --git a/rocclr/runtime/device/gpu/gslbe/src/include/cal/calcl.h b/rocclr/runtime/device/gpu/gslbe/src/include/cal/calcl.h index 59dd8e1b92..849aa0bf45 100644 --- a/rocclr/runtime/device/gpu/gslbe/src/include/cal/calcl.h +++ b/rocclr/runtime/device/gpu/gslbe/src/include/cal/calcl.h @@ -640,13 +640,6 @@ typedef enum CALmemcopyflagsEnum CAL_MEMCOPY_ASYNC = 2, /**< used to indicate completely asynchronous behavior */ } CALmemcopyflags; -typedef enum CALResGLBufferTypeEnum{ - CAL_RES_GL_BUFFER_TYPE_TEXTURE = 0, - CAL_RES_GL_BUFFER_TYPE_FRAMEBUFFER = 1, - CAL_RES_GL_BUFFER_TYPE_RENDERBUFFER = 2, - CAL_RES_GL_BUFFER_TYPE_VERTEXBUFFER = 3 -}CALResGLBufferType; - typedef struct CALDeviceGLParamsRec { CALvoid *GLplatformContext; CALvoid *GLdeviceContext; diff --git a/rocclr/runtime/device/gpu/gslbe/src/rt/GSLDevice.h b/rocclr/runtime/device/gpu/gslbe/src/rt/GSLDevice.h index f9f911c94c..819094576a 100644 --- a/rocclr/runtime/device/gpu/gslbe/src/rt/GSLDevice.h +++ b/rocclr/runtime/device/gpu/gslbe/src/rt/GSLDevice.h @@ -42,7 +42,7 @@ public: void* GLContext; //(IN) handle to HGLRC or GLXContext void* GLdeviceContext; //(IN) a handle to device context uint name; //(IN) gl identifier of the object - CALResGLBufferType type; // (IN) type of the interop object . + uint type; // (IN) type of the interop object . uint flags; // (IN) flags assigned to 'GLResource' struct void* mbResHandle; // (OUT) Internal GL driver handle for the resource gslMemObject mem_base; // (OUT) Base memory object for the resource @@ -188,7 +188,7 @@ private: gslDynamicRuntimeConfig m_dcfg; //GL Extension specific - void initGLInteropPrivateExt(CALvoid* GLplatformContext, CALvoid* GLdeviceContext) const; + bool initGLInteropPrivateExt(CALvoid* GLplatformContext, CALvoid* GLdeviceContext) const; bool glCanInterop(CALvoid* GLplatformContext, CALvoid* GLdeviceContext); bool PerformDMACopy(gslMemObject srcMem, gslMemObject destMem, cmSurfFmt format, CALuint flags); diff --git a/rocclr/runtime/device/gpu/gslbe/src/rt/GSLDeviceGL.cpp b/rocclr/runtime/device/gpu/gslbe/src/rt/GSLDeviceGL.cpp index 7f9d87eea7..201db415e3 100644 --- a/rocclr/runtime/device/gpu/gslbe/src/rt/GSLDeviceGL.cpp +++ b/rocclr/runtime/device/gpu/gslbe/src/rt/GSLDeviceGL.cpp @@ -203,7 +203,7 @@ static const cmFormatXlateParams cmFormatXlateTable [] = { {CM_SURF_FMT_R5_G6_B5UI, (cmSurfFmt)500, GSL_CHANNEL_ORDER_RGBA}, {CM_SURF_FMT_DEPTH32F_X24_STEN8_UNCLAMPED, CM_SURF_FMT_RG32I, GSL_CHANNEL_ORDER_REPLICATE_R}, {CM_SURF_FMT_DEPTH32F_UNCLAMPED, CM_SURF_FMT_R32F, GSL_CHANNEL_ORDER_REPLICATE_R}, - {CM_SURF_FMT_L8_X16_A8_SRGB, (cmSurfFmt)500, GSL_CHANNEL_ORDER_RGBA}, + {CM_SURF_FMT_L8_X16_A8_SRGB, (cmSurfFmt)500, GSL_CHANNEL_ORDER_RGBA}, {CM_SURF_FMT_L8_X24_SRGB, (cmSurfFmt)500, GSL_CHANNEL_ORDER_RGBA}, {CM_SURF_FMT_STENCIL8, CM_SURF_FMT_R8I, GSL_CHANNEL_ORDER_R}, }; @@ -406,7 +406,7 @@ dummyAssertIfCmSurfFmtChanges(void) COMPILE_TIME_ASSERT(188 == CM_SURF_FMT_R5_G6_B5UI); COMPILE_TIME_ASSERT(189 == CM_SURF_FMT_DEPTH32F_X24_STEN8_UNCLAMPED); COMPILE_TIME_ASSERT(190 == CM_SURF_FMT_DEPTH32F_UNCLAMPED); - COMPILE_TIME_ASSERT(191 == CM_SURF_FMT_L8_X16_A8_SRGB); + COMPILE_TIME_ASSERT(191 == CM_SURF_FMT_L8_X16_A8_SRGB); COMPILE_TIME_ASSERT(192 == CM_SURF_FMT_L8_X24_SRGB); COMPILE_TIME_ASSERT(193 == CM_SURF_FMT_STENCIL8); @@ -434,7 +434,7 @@ static PFNWGLRESOURCEDETACHAMD wglResourceDetachAMD = NULL; static PFNWGLGETCONTEXTGPUINFOAMD wglGetContextGPUInfoAMD = NULL; #endif -void +bool CALGSLDevice::initGLInteropPrivateExt(CALvoid* GLplatformContext, CALvoid* GLdeviceContext) const { #ifdef ATI_OS_LINUX @@ -442,15 +442,16 @@ CALGSLDevice::initGLInteropPrivateExt(CALvoid* GLplatformContext, CALvoid* GLdev void * pModule = dlopen("libGL.so.1",RTLD_NOW); if(NULL == pModule){ - return; + return false; } pfnGlxGetProcAddress = (PFNGlxGetProcAddress) dlsym(pModule,"glXGetProcAddress"); if (NULL == pfnGlxGetProcAddress){ - return; + return false; } - if (!glXBeginCLInteropAMD || !glXEndCLInteropAMD || !glXResourceAttachAMD || !glXResourceDetachAMD || !glXGetContextMVPUInfoAMD) + if (!glXBeginCLInteropAMD || !glXEndCLInteropAMD || !glXResourceAttachAMD || + !glXResourceDetachAMD || !glXGetContextMVPUInfoAMD) { glXBeginCLInteropAMD = (PFNGLXBEGINCLINTEROPAMD) pfnGlxGetProcAddress ((const GLubyte *)"glXBeginCLInteroperabilityAMD"); glXEndCLInteropAMD = (PFNGLXENDCLINTEROPAMD) pfnGlxGetProcAddress ((const GLubyte *)"glXEndCLInteroperabilityAMD"); @@ -460,8 +461,15 @@ CALGSLDevice::initGLInteropPrivateExt(CALvoid* GLplatformContext, CALvoid* GLdev glXResourceDetachAMD = (PFNGLXRESOURCEDETACHAMD) pfnGlxGetProcAddress ((const GLubyte *)"glXResourceDetachAMD"); glXGetContextMVPUInfoAMD = (PFNGLXGETCONTEXTMVPUINFOAMD) pfnGlxGetProcAddress ((const GLubyte *)"glXGetContextMVPUInfoAMD"); } + + if (!glXBeginCLInteropAMD || !glXEndCLInteropAMD || !glXResourceAttachAMD || + !glXResourceDetachAMD || !glXGetContextMVPUInfoAMD) + { + return false; + } #else - if (!wglBeginCLInteropAMD || !wglEndCLInteropAMD || !wglResourceAttachAMD || !wglResourceDetachAMD || !wglGetContextGPUInfoAMD) + if (!wglBeginCLInteropAMD || !wglEndCLInteropAMD || !wglResourceAttachAMD || + !wglResourceDetachAMD || !wglGetContextGPUInfoAMD) { HGLRC fakeRC = NULL; @@ -485,7 +493,13 @@ CALGSLDevice::initGLInteropPrivateExt(CALvoid* GLplatformContext, CALvoid* GLdev wglDeleteContext(fakeRC); } } + if (!wglBeginCLInteropAMD || !wglEndCLInteropAMD || !wglResourceAttachAMD || + !wglResourceDetachAMD || !wglGetContextGPUInfoAMD) + { + return false; + } #endif + return true; } bool @@ -503,7 +517,7 @@ CALGSLDevice::glCanInterop(CALvoid* GLplatformContext, CALvoid* GLdeviceContext) HGLRC hRC = (HGLRC)GLplatformContext; //get GL context's LUID and chainBitMask from UGL - if (wglGetContextGPUInfoAMD && wglGetContextGPUInfoAMD(hRC, &glAdapterLuid, &glChainBitMask)) + if (wglGetContextGPUInfoAMD(hRC, &glAdapterLuid, &glChainBitMask)) { //now check against the CAL device' LUID and chainBitMask. if (m_adp->getMVPUinfo(&calAdapterLuid, &calChainBitMask)) @@ -514,23 +528,19 @@ CALGSLDevice::glCanInterop(CALvoid* GLplatformContext, CALvoid* GLdeviceContext) } } #elif defined (ATI_OS_LINUX) - //if the extension is supported by the base driver - if (NULL != glXGetContextMVPUInfoAMD) - { - GLuint glDeviceId = 0 ; - GLuint glChainMask = 0 ; - GLXContext ctx = (GLXContext)GLplatformContext; - if ( glXGetContextMVPUInfoAMD(ctx,&glDeviceId,&glChainMask)){ - GLuint deviceId = 0 ; - GLuint chainMask = 0 ; + GLuint glDeviceId = 0 ; + GLuint glChainMask = 0 ; + GLXContext ctx = (GLXContext)GLplatformContext; + if (glXGetContextMVPUInfoAMD(ctx,&glDeviceId,&glChainMask)){ + GLuint deviceId = 0 ; + GLuint chainMask = 0 ; - if (m_adp->getMVPUinfo(&deviceId, &chainMask)) - { - // we allow intoperability only with GL context - // reside on a single GPU - if (deviceId == glDeviceId && chainMask == glChainMask){ - canInteroperate = true; - } + if (m_adp->getMVPUinfo(&deviceId, &chainMask)) + { + // we allow intoperability only with GL context + // reside on a single GPU + if (deviceId == glDeviceId && chainMask == glChainMask){ + canInteroperate = true; } } } @@ -542,49 +552,31 @@ bool CALGSLDevice::glAssociate(CALvoid* GLplatformContext, CALvoid* GLdeviceContext) { //initialize pointers to the gl extension that supports interoperability - initGLInteropPrivateExt(GLplatformContext, GLdeviceContext); - - bool canInterop = glCanInterop(GLplatformContext, GLdeviceContext); + if (!initGLInteropPrivateExt(GLplatformContext, GLdeviceContext) || + !glCanInterop(GLplatformContext, GLdeviceContext)) + { + return false; + } #ifdef ATI_OS_LINUX GLXContext ctx = (GLXContext)GLplatformContext; - - if (canInterop && glXBeginCLInteropAMD && glXBeginCLInteropAMD(ctx, 0)) - { - return true; - } + return (glXBeginCLInteropAMD(ctx, 0)) ? true : false; #else HGLRC hRC = (HGLRC)GLplatformContext; - - if (canInterop && wglBeginCLInteropAMD && wglBeginCLInteropAMD(hRC, 0)) - { - return true; - } + return (wglBeginCLInteropAMD(hRC, 0)) ? true : false; #endif - - return false; } bool CALGSLDevice::glDissociate(CALvoid* GLplatformContext, CALvoid* GLdeviceContext) { - initGLInteropPrivateExt(GLplatformContext, GLdeviceContext); - #ifdef ATI_OS_LINUX GLXContext ctx = (GLXContext)GLplatformContext; - if(glXEndCLInteropAMD && glXEndCLInteropAMD(ctx, 0)) - { - return true; - } + return (glXEndCLInteropAMD(ctx, 0)) ? true : false; #else HGLRC hRC = (HGLRC)GLplatformContext; - if (wglEndCLInteropAMD && wglEndCLInteropAMD(hRC, 0)) - { - return true; - } + return (wglEndCLInteropAMD(hRC, 0)) ? true : false; #endif - - return false; } bool @@ -612,23 +604,7 @@ CALGSLDevice::resGLAssociate(GLResAssociate & resData) const GSL_ALLOCATION_INSTANCED // alloc_type ); - switch(resData.type) - { - case CAL_RES_GL_BUFFER_TYPE_TEXTURE: - hRes.type = GL_RESOURCE_ATTACH_TEXTURE_AMD; - break; - case CAL_RES_GL_BUFFER_TYPE_FRAMEBUFFER: - hRes.type = GL_RESOURCE_ATTACH_FRAMEBUFFER_AMD; - break; - case CAL_RES_GL_BUFFER_TYPE_RENDERBUFFER: - hRes.type = GL_RESOURCE_ATTACH_RENDERBUFFER_AMD; - break; - case CAL_RES_GL_BUFFER_TYPE_VERTEXBUFFER: - hRes.type = GL_RESOURCE_ATTACH_VERTEXBUFFER_AMD; - break; - default: - return false; - } + hRes.type = resData.type; GLResourceData* hData = new GLResourceData; if (NULL == hData) @@ -641,18 +617,16 @@ CALGSLDevice::resGLAssociate(GLResAssociate & resData) const hRes.flags = resData.flags; hData->version = GL_RESOURCE_DATA_VERSION; - initGLInteropPrivateExt(resData.GLContext, resData.GLdeviceContext); - #ifdef ATI_OS_LINUX GLXContext ctx = (GLXContext)resData.GLContext; - if (glXResourceAttachAMD && glXResourceAttachAMD(ctx, &hRes, hData)) + if (glXResourceAttachAMD(ctx, &hRes, hData)) { - attribs.dynamicSharedBufferID = hData->sharedBufferID ; + attribs.dynamicSharedBufferID = hData->sharedBufferID; status = true; } #else HGLRC hRC = (HGLRC)resData.GLContext; - if (wglResourceAttachAMD && wglResourceAttachAMD(hRC, &hRes, hData)) + if (wglResourceAttachAMD(hRC, &hRes, hData)) { status = true; } @@ -748,7 +722,7 @@ CALGSLDevice::resGLAssociate(GLResAssociate & resData) const } free (attribs.alias_swizzles); resData.mbResHandle = (CALvoid*)hData->mbResHandle; - resData.memObject = mem; + resData.memObject = mem; delete hData; return mem != 0; } @@ -764,37 +738,19 @@ CALGSLDevice::resGLAcquire(CALvoid* GLplatformContext, GLResource hRes = {0}; osAssert(mbResHandle); hRes.mbResHandle = (GLuintp)mbResHandle; - switch(type) - { - case CAL_RES_GL_BUFFER_TYPE_TEXTURE: - hRes.type = GL_RESOURCE_ATTACH_TEXTURE_AMD; - break; - case CAL_RES_GL_BUFFER_TYPE_RENDERBUFFER: - hRes.type = GL_RESOURCE_ATTACH_RENDERBUFFER_AMD; - break; - case CAL_RES_GL_BUFFER_TYPE_VERTEXBUFFER: - hRes.type = GL_RESOURCE_ATTACH_VERTEXBUFFER_AMD; - break; - default: - // @note: No acquire for GL_RESOURCE_ATTACH_FRAMEBUFFER_AMD - return true; - } - bool status = false; + hRes.type = type; + #ifdef ATI_OS_LINUX - GLXContext ctx = (GLXContext) GLplatformContext; - if (glxResourceAcquireAMD && glxResourceAcquireAMD(ctx, &hRes)) - { - status = true; - } + GLXContext ctx = (GLXContext) GLplatformContext; + return (glxResourceAcquireAMD(ctx, &hRes)) ? true : false; #else HGLRC hRC = wglGetCurrentContext(); - if ( wglResourceAcquireAMD && wglResourceAcquireAMD(hRC, &hRes)) - { - status = true; + //! @todo A temporary workaround for MT issue in conformance fence_sync + if (0 == hRC) { + return true; } + return (wglResourceAcquireAMD(hRC, &hRes)) ? true : false; #endif - - return status; } bool @@ -807,42 +763,25 @@ CALGSLDevice::resGLRelease(CALvoid* GLplatformContext, GLResource hRes = {0}; osAssert(mbResHandle); - bool status = false; hRes.mbResHandle = (GLuintp)mbResHandle; - switch(type) - { - case CAL_RES_GL_BUFFER_TYPE_TEXTURE: - hRes.type = GL_RESOURCE_ATTACH_TEXTURE_AMD; - break; - case CAL_RES_GL_BUFFER_TYPE_RENDERBUFFER: - hRes.type = GL_RESOURCE_ATTACH_RENDERBUFFER_AMD; - break; - case CAL_RES_GL_BUFFER_TYPE_VERTEXBUFFER: - hRes.type = GL_RESOURCE_ATTACH_VERTEXBUFFER_AMD; - break; - default: - // @note: No release for GL_RESOURCE_ATTACH_FRAMEBUFFER_AMD - return true; - } + 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; - if ((0 != ctx) && glxResourceReleaseAMD && glxResourceReleaseAMD(ctx, &hRes)) - { - status = true; - } + 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 + // Make the call into the GL driver only if the application GL context is current HGLRC hRC = wglGetCurrentContext(); - if ( (0 != hRC) && wglResourceReleaseAMD && wglResourceReleaseAMD(hRC, &hRes)) - { - status = true; + //! @todo A temporary workaround for MT issue in conformance fence_sync + if (0 == hRC) { + return true; } + return (wglResourceReleaseAMD(hRC, &hRes)) ? true : false; #endif - return status; } + bool CALGSLDevice::resGLFree ( CALvoid* GLplatformContext, @@ -859,44 +798,19 @@ CALGSLDevice::resGLFree ( osAssert(mbResHandle); hRes.mbResHandle = (GLuintp)mbResHandle; - switch(type) - { - case CAL_RES_GL_BUFFER_TYPE_TEXTURE: - hRes.type = GL_RESOURCE_ATTACH_TEXTURE_AMD; - break; - case CAL_RES_GL_BUFFER_TYPE_FRAMEBUFFER: - hRes.type = GL_RESOURCE_ATTACH_FRAMEBUFFER_AMD; - break; - case CAL_RES_GL_BUFFER_TYPE_RENDERBUFFER: - hRes.type = GL_RESOURCE_ATTACH_RENDERBUFFER_AMD; - break; - case CAL_RES_GL_BUFFER_TYPE_VERTEXBUFFER: - hRes.type = GL_RESOURCE_ATTACH_VERTEXBUFFER_AMD; - break; - default: - return false; - } + hRes.type = type; - initGLInteropPrivateExt(GLplatformContext, GLdeviceContext); - -#ifdef ATI_OS_LINUX - GLXContext ctx = (GLXContext)GLplatformContext; - if (!glXResourceDetachAMD || !glXResourceDetachAMD(ctx, &hRes)) - { - return true; - } -#else - HGLRC hRC = (HGLRC)GLplatformContext; - if (!wglResourceDetachAMD || !wglResourceDetachAMD(hRC, &hRes)) - { - return false; - } -#endif - m_cs->Flush(); if (mem_base) { m_cs->destroyMemObject(mem_base); } m_cs->destroyMemObject(mem); - return true; + +#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 };