diff --git a/projects/clr/rocclr/runtime/device/cpu/cpudevice.hpp b/projects/clr/rocclr/runtime/device/cpu/cpudevice.hpp index 1381dc6ff6..7399721aeb 100644 --- a/projects/clr/rocclr/runtime/device/cpu/cpudevice.hpp +++ b/projects/clr/rocclr/runtime/device/cpu/cpudevice.hpp @@ -122,12 +122,12 @@ public: //! Needed for OpenGL objects on CPU device //! Return true if initialized interoperability, otherwise false - virtual bool bindExternalDevice(uint flags, void* pDevice, void* pContext, bool validateOnly) + virtual bool bindExternalDevice(uint flags, void* const pDevice[], void* pContext, bool validateOnly) { return true; // On CPU always avail if pD3DDevice is not NULL } - virtual bool unbindExternalDevice(uint flags, void* pDevice, void* pContext, bool validateOnly) + virtual bool unbindExternalDevice(uint flags, void* const pDevice[], void* pContext, bool validateOnly) { return true; } diff --git a/projects/clr/rocclr/runtime/device/device.hpp b/projects/clr/rocclr/runtime/device/device.hpp index 23d064490f..7b8b26ac1c 100644 --- a/projects/clr/rocclr/runtime/device/device.hpp +++ b/projects/clr/rocclr/runtime/device/device.hpp @@ -1657,14 +1657,14 @@ public: //! Return true if initialized external API interop, otherwise false virtual bool bindExternalDevice( uint flags, //!< Enum val. for ext.API type: GL, D3D10, etc. - void* pDevice, //!< D3D device do D3D, HDC/Display handle of X Window for GL + void* const pDevice[], //!< D3D device do D3D, HDC/Display handle of X Window for GL void* pContext, //!< HGLRC/GLXContext handle bool validateOnly //! Only validate if the device can inter-operate with pDevice/pContext, do not bind. ) = 0; virtual bool unbindExternalDevice( uint flags, //!< Enum val. for ext.API type: GL, D3D10, etc. - void* pDevice, //!< D3D device do D3D, HDC/Display handle of X Window for GL + void* const pDevice[], //!< D3D device do D3D, HDC/Display handle of X Window for GL void* pContext, //!< HGLRC/GLXContext handle bool validateOnly //! Only validate if the device can inter-operate with pDevice/pContext, do not bind. ) = 0; diff --git a/projects/clr/rocclr/runtime/device/gpu/gpudevice.cpp b/projects/clr/rocclr/runtime/device/gpu/gpudevice.cpp index e2f7d137fd..2a6daa1dcf 100644 --- a/projects/clr/rocclr/runtime/device/gpu/gpudevice.cpp +++ b/projects/clr/rocclr/runtime/device/gpu/gpudevice.cpp @@ -1769,7 +1769,7 @@ Device::createView(amd::Memory& owner, const device::Memory& parent) const //! Attempt to bind with external graphics API's device/context bool Device::bindExternalDevice( - uint flags, void* pDevice, void* pContext, bool validateOnly) + uint flags, void* const pDevice[], void* pContext, bool validateOnly) { assert(pDevice); @@ -1781,15 +1781,16 @@ Device::bindExternalDevice( PerformAdapterInitialization(); // Attempt to associate GSL-OGL - if (!glAssociate((CALvoid*)pContext, pDevice)) { + if (!glAssociate((CALvoid*)pContext, pDevice[amd::Context::DeviceFlagIdx::GLDeviceKhrIdx])) { if (!validateOnly) { LogError("Failed gslGLAssociate()"); } return false; } } + #ifdef _WIN32 - else if (flags & amd::Context::Flags::D3D10DeviceKhr) { + if (flags & amd::Context::Flags::D3D10DeviceKhr) { // There is no need to perform full initialization here // if the GSLDevice is still uninitialized. // Only adapter initialization is required @@ -1798,12 +1799,13 @@ Device::bindExternalDevice( // Associate GSL-D3D if (!associateD3D10Device( - reinterpret_cast(pDevice))) { + reinterpret_cast(pDevice[amd::Context::DeviceFlagIdx::D3D10DeviceKhrIdx]))) { LogError("Failed gslD3D10Associate()"); return false; } } - else if (flags & amd::Context::Flags::D3D11DeviceKhr) { + + if (flags & amd::Context::Flags::D3D11DeviceKhr) { // There is no need to perform full initialization here // if the GSLDevice is still uninitialized. // Only adapter initialization is required to validate @@ -1812,47 +1814,51 @@ Device::bindExternalDevice( // Associate GSL-D3D if (!associateD3D11Device( - reinterpret_cast(pDevice))) { + reinterpret_cast(pDevice[amd::Context::DeviceFlagIdx::D3D11DeviceKhrIdx]))) { LogError("Failed gslD3D11Associate()"); return false; } } - else if (flags & amd::Context::Flags::D3D9DeviceKhr) { + + if (flags & amd::Context::Flags::D3D9DeviceKhr) { PerformAdapterInitialization(); // Associate GSL-D3D if (!associateD3D9Device( - reinterpret_cast(pDevice))) { + reinterpret_cast(pDevice[amd::Context::DeviceFlagIdx::D3D9DeviceKhrIdx]))) { LogWarning("D3D9<->OpenCL adapter mismatch or D3D9Associate() failure"); return false; } } - else if (flags & amd::Context::Flags::D3D9DeviceEXKhr) { + + if (flags & amd::Context::Flags::D3D9DeviceEXKhr) { PerformAdapterInitialization(); // Associate GSL-D3D if (!associateD3D9Device( - reinterpret_cast(pDevice))) { + reinterpret_cast(pDevice[amd::Context::DeviceFlagIdx::D3D9DeviceEXKhrIdx]))) { LogWarning("D3D9<->OpenCL adapter mismatch or D3D9Associate() failure"); return false; } } - else if (flags & amd::Context::Flags::D3D9DeviceVAKhr) { + + if (flags & amd::Context::Flags::D3D9DeviceVAKhr) { } #endif //_WIN32 return true; } bool -Device::unbindExternalDevice(uint flags, void* pDevice, void* pContext, bool validateOnly) +Device::unbindExternalDevice(uint flags, void* const pDevice[], void* pContext, bool validateOnly) { if ((flags & amd::Context::Flags::GLDeviceKhr) == 0) { return true; } - if (pDevice != NULL) { + void * glDevice = pDevice[amd::Context::DeviceFlagIdx::GLDeviceKhrIdx]; + if (glDevice != NULL) { // Dissociate GSL-OGL - if (true != glDissociate(pContext, pDevice)) { + if (true != glDissociate(pContext, glDevice)) { if (validateOnly) { LogWarning("Failed gslGLDiassociate()"); } diff --git a/projects/clr/rocclr/runtime/device/gpu/gpudevice.hpp b/projects/clr/rocclr/runtime/device/gpu/gpudevice.hpp index 9c4d4027ea..985eb079f6 100644 --- a/projects/clr/rocclr/runtime/device/gpu/gpudevice.hpp +++ b/projects/clr/rocclr/runtime/device/gpu/gpudevice.hpp @@ -95,10 +95,10 @@ public: //! Needed for OpenGL objects on CPU device virtual bool bindExternalDevice( - uint flags, void* pDevice, void* pContext, bool validateOnly) { return true; } + uint flags, void* const pDevice[], void* pContext, bool validateOnly) { return true; } virtual bool unbindExternalDevice( - uint flags, void* pDevice, void* pContext, bool validateOnly) { return true; } + uint flags, void* const pDevice[], void* pContext, bool validateOnly) { return true; } //! Releases non-blocking map target memory virtual void freeMapTarget(amd::Memory& mem, void* target) {} @@ -429,14 +429,14 @@ public: //! Attempt to bind with external graphics API's device/context virtual bool bindExternalDevice( uint flags, - void* pDevice, + void* const pDevice[], void* pContext, bool validateOnly); //! Attempt to unbind with external graphics API's device/context virtual bool unbindExternalDevice( uint flags, - void* pDevice, + void* const pDevice[], void* pContext, bool validateOnly); diff --git a/projects/clr/rocclr/runtime/device/gpu/gpumemory.cpp b/projects/clr/rocclr/runtime/device/gpu/gpumemory.cpp index 6fd4bfd7b3..1cf44ba8bd 100644 --- a/projects/clr/rocclr/runtime/device/gpu/gpumemory.cpp +++ b/projects/clr/rocclr/runtime/device/gpu/gpumemory.cpp @@ -268,6 +268,7 @@ Memory::createInterop(InteropType type) assert((interop != NULL) && "An invalid interop object is impossible!"); amd::GLObject* glObject = interop->asGLObject(); + #ifdef _WIN32 amd::D3D10Object* d3d10Object = interop->asD3D10Object(); amd::D3D11Object* d3d11Object = interop->asD3D11Object(); @@ -442,14 +443,15 @@ Memory::createInterop(InteropType type) return false; break; } + + oglRes.glPlatformContext_ = owner()->getContext().info().hCtx_; + oglRes.glDeviceContext_ = owner()->getContext().info().hDev_[amd::Context::DeviceFlagIdx::GLDeviceKhrIdx]; + // We dont pass any flags here for the GL Resource. + oglRes.flags_ = 0; } else { return false; } - oglRes.glPlatformContext_ = owner()->getContext().info().hCtx_; - oglRes.glDeviceContext_ = owner()->getContext().info().hDev_; - // We dont pass any flags here for the GL Resource. - oglRes.flags_ = 0; // Get the interop settings if (type == InteropDirectAccess) { diff --git a/projects/clr/rocclr/runtime/device/pal/paldevice.cpp b/projects/clr/rocclr/runtime/device/pal/paldevice.cpp index 2406795ae8..e7878641da 100644 --- a/projects/clr/rocclr/runtime/device/pal/paldevice.cpp +++ b/projects/clr/rocclr/runtime/device/pal/paldevice.cpp @@ -1529,36 +1529,37 @@ Device::createView(amd::Memory& owner, const device::Memory& parent) const //! Attempt to bind with external graphics API's device/context bool -Device::bindExternalDevice(uint flags, void* pDevice, void* pContext, bool validateOnly) +Device::bindExternalDevice(uint flags, void* const pDevice[], void* pContext, bool validateOnly) { assert(pDevice); #ifdef _WIN32 if (flags & amd::Context::Flags::D3D10DeviceKhr) { - if (!associateD3D10Device(pDevice)) { + if (!associateD3D10Device(pDevice[amd::Context::DeviceFlagIdx::D3D10DeviceKhrIdx])); LogError("Failed gslD3D10Associate()"); return false; } } - else if (flags & amd::Context::Flags::D3D11DeviceKhr) { - if (!associateD3D11Device(pDevice)) { + + if (flags & amd::Context::Flags::D3D11DeviceKhr) { + if (!associateD3D11Device(pDevice[amd::Context::DeviceFlagIdx::D3D11DeviceKhrIdx])) { LogError("Failed gslD3D11Associate()"); return false; } } - else if (flags & (amd::Context::Flags::D3D9DeviceKhr | + + if (flags & (amd::Context::Flags::D3D9DeviceKhr | amd::Context::Flags::D3D9DeviceEXKhr)) { - if (!associateD3D9Device(pDevice)) { + if (!associateD3D9Device(pDevice[amd::Context::DeviceFlagIdx::D3D9DeviceKhrIdx])) { LogWarning("D3D9<->OpenCL adapter mismatch or D3D9Associate() failure"); return false; } } - else if (flags & amd::Context::Flags::D3D9DeviceVAKhr) { - } #endif //_WIN32 + if (flags & amd::Context::Flags::GLDeviceKhr) { // Attempt to associate GSL-OGL - if (!glAssociate(pContext, pDevice)) { + if (!glAssociate(pContext, pDevice[amd::Context::DeviceFlagIdx::GLDeviceKhrIdx])) { if (!validateOnly) { LogError("Failed gslGLAssociate()"); } @@ -1570,15 +1571,16 @@ Device::bindExternalDevice(uint flags, void* pDevice, void* pContext, bool valid } bool -Device::unbindExternalDevice(uint flags, void* pDevice, void* pContext, bool validateOnly) +Device::unbindExternalDevice(uint flags, void* const pDevice[], void* pContext, bool validateOnly) { if ((flags & amd::Context::Flags::GLDeviceKhr) == 0) { return true; } - if (pDevice != nullptr) { + void * glDevice = pDevice[amd::Context::DeviceFlagIdx::GLDeviceKhrIdx]; + if (glDevice != nullptr) { // Dissociate GSL-OGL - if (!glDissociate(pContext, pDevice)) { + if (!glDissociate(pContext, glDevice)) { if (validateOnly) { LogWarning("Failed gslGLDiassociate()"); } diff --git a/projects/clr/rocclr/runtime/device/pal/paldevice.hpp b/projects/clr/rocclr/runtime/device/pal/paldevice.hpp index c629fcb6c4..7ef971ad8c 100644 --- a/projects/clr/rocclr/runtime/device/pal/paldevice.hpp +++ b/projects/clr/rocclr/runtime/device/pal/paldevice.hpp @@ -89,10 +89,10 @@ public: //! Needed for OpenGL objects on CPU device virtual bool bindExternalDevice( - uint flags, void* pDevice, void* pContext, bool validateOnly) { return true; } + uint flags, void* const pDevice[], void* pContext, bool validateOnly) { return true; } virtual bool unbindExternalDevice( - uint flags, void* pDevice, void* pContext, bool validateOnly) { return true; } + uint flags, void* const pDevice[], void* pContext, bool validateOnly) { return true; } //! Releases non-blocking map target memory virtual void freeMapTarget(amd::Memory& mem, void* target) {} @@ -348,11 +348,11 @@ public: //! Attempt to bind with external graphics API's device/context virtual bool bindExternalDevice( - uint flags, void* pDevice, void* pContext, bool validateOnly); + uint flags, void* pDevice[], void* pContext, bool validateOnly); //! Attempt to unbind with external graphics API's device/context virtual bool unbindExternalDevice( - uint flags, void* pDevice, void* pContext, bool validateOnly); + uint flags, void* pDevice[], void* pContext, bool validateOnly); //! Validates kernel before execution virtual bool validateKernel( diff --git a/projects/clr/rocclr/runtime/device/pal/palmemory.cpp b/projects/clr/rocclr/runtime/device/pal/palmemory.cpp index 79c12945d0..1df7cdab96 100644 --- a/projects/clr/rocclr/runtime/device/pal/palmemory.cpp +++ b/projects/clr/rocclr/runtime/device/pal/palmemory.cpp @@ -399,14 +399,15 @@ Memory::createInterop(InteropType type) return false; break; } + + oglRes.glPlatformContext_ = owner()->getContext().info().hCtx_; + oglRes.glDeviceContext_ = owner()->getContext().info().hDev_[amd::Context::DeviceFlagIdx::GLDeviceKhrIdx]; + // We dont pass any flags here for the GL Resource. + oglRes.flags_ = 0; } else { return false; } - oglRes.glPlatformContext_ = owner()->getContext().info().hCtx_; - oglRes.glDeviceContext_ = owner()->getContext().info().hDev_; - // We dont pass any flags here for the GL Resource. - oglRes.flags_ = 0; // Get the interop settings if (type == InteropDirectAccess) { diff --git a/projects/clr/rocclr/runtime/platform/context.cpp b/projects/clr/rocclr/runtime/platform/context.cpp index 126ea765e6..e2efcbff85 100644 --- a/projects/clr/rocclr/runtime/platform/context.cpp +++ b/projects/clr/rocclr/runtime/platform/context.cpp @@ -118,52 +118,50 @@ Context::checkProperties( if (p->ptr == NULL) { return CL_INVALID_VALUE; } - info->hDev_ = p->ptr; + info->hDev_[D3D10DeviceKhrIdx] = p->ptr; info->flags_ |= D3D10DeviceKhr; break; case CL_CONTEXT_D3D11_DEVICE_KHR: if (p->ptr == NULL) { return CL_INVALID_VALUE; } - info->hDev_ = p->ptr; + info->hDev_[D3D11DeviceKhrIdx] = p->ptr; info->flags_ |= D3D11DeviceKhr; break; case CL_CONTEXT_ADAPTER_D3D9_KHR: if (p->ptr == NULL) { //not supported for xp return CL_INVALID_VALUE; } - info->hDev_ = p->ptr; + info->hDev_[D3D9DeviceKhrIdx] = p->ptr; info->flags_ |= D3D9DeviceKhr; break; case CL_CONTEXT_ADAPTER_D3D9EX_KHR: if (p->ptr == NULL) { return CL_INVALID_VALUE; } - info->hDev_ = p->ptr; + info->hDev_[D3D9DeviceEXKhrIdx] = p->ptr; info->flags_ |= D3D9DeviceEXKhr; break; case CL_CONTEXT_ADAPTER_DXVA_KHR: if (p->ptr == NULL) { return CL_INVALID_VALUE; } - info->hDev_ = p->ptr; + info->hDev_[D3D9DeviceVAKhrIdx] = p->ptr; info->flags_ |= D3D9DeviceVAKhr; break; #endif //_WIN32 case CL_EGL_DISPLAY_KHR: - info->hDev_ = p->ptr; info->flags_ |= EGLDeviceKhr; #ifdef _WIN32 case CL_WGL_HDC_KHR: - info->hDev_ = p->ptr; #endif //_WIN32 #if defined(__linux__) case CL_GLX_DISPLAY_KHR: - info->hDev_ = p->ptr; #endif //linux + info->hDev_[GLDeviceKhrIdx] = p->ptr; #if defined(__APPLE__) || defined(__MACOSX) case CL_CGL_SHAREGROUP_KHR: @@ -267,7 +265,7 @@ Context::create(const intptr_t* properties) ); if (h && (glenv_ = new GLFunctions(h, (info_.flags_ & Flags::EGLDeviceKhr) != 0))) { - if (!glenv_->init(reinterpret_cast(info_.hDev_), + if (!glenv_->init(reinterpret_cast(info_.hDev_[GLDeviceKhrIdx]), reinterpret_cast(info_.hCtx_))) { delete glenv_; glenv_ = NULL; diff --git a/projects/clr/rocclr/runtime/platform/context.hpp b/projects/clr/rocclr/runtime/platform/context.hpp index de7946ee5e..cd42ff4058 100644 --- a/projects/clr/rocclr/runtime/platform/context.hpp +++ b/projects/clr/rocclr/runtime/platform/context.hpp @@ -30,25 +30,40 @@ class Context : public RuntimeObject std::vector devices_; public: + enum DeviceFlagIdx + { + GLDeviceKhrIdx = 0, //!< GL + D3D10DeviceKhrIdx, //!< D3D10 + OfflineDevicesIdx, //!< Offline devices + CommandInterceptIdx, //!< Command intercept + D3D11DeviceKhrIdx, //!< D3D11 + InteropUserSyncIdx, //!< Interop user sync enabled + D3D9DeviceKhrIdx, //!< d3d9 device + D3D9DeviceEXKhrIdx, //!< d3d9EX device + D3D9DeviceVAKhrIdx, //!< d3d9VA device + EGLDeviceKhrIdx, //!< EGL device + LastDeviceFlagIdx + }; + enum Flags { - GLDeviceKhr = 1<<0, //!< GL - D3D10DeviceKhr = 1<<1, //!< D3D10 - OfflineDevices = 1<<2, //!< Offline devices - CommandIntercept = 1<<3, //!< Command intercept - D3D11DeviceKhr = 1<<4, //!< D3D11 - InteropUserSync = 1<<5, //!< Interop user sync enabled - D3D9DeviceKhr = 1<<6, //!< d3d9 device - D3D9DeviceEXKhr = 1<<7, //!< d3d9EX device - D3D9DeviceVAKhr = 1<<8, //!< d3d9VA device - EGLDeviceKhr = 1<<9, //!< EGL device + GLDeviceKhr = 1 << GLDeviceKhrIdx, //!< GL + D3D10DeviceKhr = 1 << D3D10DeviceKhrIdx, //!< D3D10 + OfflineDevices = 1 << OfflineDevicesIdx, //!< Offline devices + CommandIntercept = 1 << CommandInterceptIdx, //!< Command intercept + D3D11DeviceKhr = 1 << D3D11DeviceKhrIdx, //!< D3D11 + InteropUserSync = 1 << InteropUserSyncIdx, //!< Interop user sync enabled + D3D9DeviceKhr = 1 << D3D9DeviceKhrIdx, //!< d3d9 device + D3D9DeviceEXKhr = 1 << D3D9DeviceEXKhrIdx, //!< d3d9EX device + D3D9DeviceVAKhr = 1 << D3D9DeviceVAKhrIdx, //!< d3d9VA device + EGLDeviceKhr = 1 << EGLDeviceKhrIdx, //!< EGL device }; //! Context info structure struct Info { uint flags_; //!< Context info flags - void* hDev_; //!< Device object reference + void* hDev_[LastDeviceFlagIdx]; //!< Device object reference void* hCtx_; //!< Context object reference size_t propertiesSize_;//!< Size of the original properties in bytes cl_int (CL_CALLBACK * commandIntercept_)(cl_event, cl_int *);