diff --git a/rocclr/runtime/device/cpu/cpudevice.hpp b/rocclr/runtime/device/cpu/cpudevice.hpp index 86067c7f01..1381dc6ff6 100644 --- a/rocclr/runtime/device/cpu/cpudevice.hpp +++ b/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(intptr_t type, void* pDevice, void* pContext, bool validateOnly) + virtual bool bindExternalDevice(uint flags, void* pDevice, void* pContext, bool validateOnly) { return true; // On CPU always avail if pD3DDevice is not NULL } - virtual bool unbindExternalDevice(intptr_t type, void* pDevice, void* pContext, bool validateOnly) + virtual bool unbindExternalDevice(uint flags, void* pDevice, void* pContext, bool validateOnly) { return true; } diff --git a/rocclr/runtime/device/device.hpp b/rocclr/runtime/device/device.hpp index 5f58f27d02..a94ada3787 100644 --- a/rocclr/runtime/device/device.hpp +++ b/rocclr/runtime/device/device.hpp @@ -1614,14 +1614,14 @@ public: //! Return true if initialized external API interop, otherwise false virtual bool bindExternalDevice( - intptr_t type, //!< Enum val. for ext.API type: GL, D3D10, etc. + 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* pContext, //!< HGLRC/GLXContext handle bool validateOnly //! Only validate if the device can inter-operate with pDevice/pContext, do not bind. ) = 0; virtual bool unbindExternalDevice( - intptr_t type, //!< Enum val. for ext.API type: GL, D3D10, etc. + 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* pContext, //!< HGLRC/GLXContext handle bool validateOnly //! Only validate if the device can inter-operate with pDevice/pContext, do not bind. diff --git a/rocclr/runtime/device/gpu/gpudevice.cpp b/rocclr/runtime/device/gpu/gpudevice.cpp index 185866a765..792b96a4e4 100644 --- a/rocclr/runtime/device/gpu/gpudevice.cpp +++ b/rocclr/runtime/device/gpu/gpudevice.cpp @@ -1767,13 +1767,12 @@ Device::createView(amd::Memory& owner, const device::Memory& parent) const //! Attempt to bind with external graphics API's device/context bool Device::bindExternalDevice( - intptr_t type, void* pDevice, void* pContext, bool validateOnly) + uint flags, void* pDevice, void* pContext, bool validateOnly) { assert(pDevice); - switch (type) { #ifdef _WIN32 - case CL_CONTEXT_D3D10_DEVICE_KHR: + 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 @@ -1786,8 +1785,8 @@ Device::bindExternalDevice( LogError("Failed gslD3D10Associate()"); return false; } - break; - case CL_CONTEXT_D3D11_DEVICE_KHR: + } + else 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 @@ -1800,8 +1799,8 @@ Device::bindExternalDevice( LogError("Failed gslD3D11Associate()"); return false; } - break; - case CL_CONTEXT_ADAPTER_D3D9_KHR: + } + else if (flags & amd::Context::Flags::D3D9DeviceKhr) { PerformAdapterInitialization(); // Associate GSL-D3D @@ -1810,8 +1809,8 @@ Device::bindExternalDevice( LogWarning("D3D9<->OpenCL adapter mismatch or D3D9Associate() failure"); return false; } - break; - case CL_CONTEXT_ADAPTER_D3D9EX_KHR: + } + else if (flags & amd::Context::Flags::D3D9DeviceEXKhr) { PerformAdapterInitialization(); // Associate GSL-D3D @@ -1820,13 +1819,11 @@ Device::bindExternalDevice( LogWarning("D3D9<->OpenCL adapter mismatch or D3D9Associate() failure"); return false; } - break; - case CL_CONTEXT_ADAPTER_DXVA_KHR: - break; + } + else if (flags & amd::Context::Flags::D3D9DeviceVAKhr) { + } #endif //_WIN32 - case CL_GL_CONTEXT_KHR: - { - + if (flags & amd::Context::Flags::GLDeviceKhr) { // There is no need to perform full initialization here // if the GSLDevice is still uninitialized. // Only adapter initialization is required to validate @@ -1841,20 +1838,14 @@ Device::bindExternalDevice( return false; } } - break; - default: - LogError("Unknown external device!"); - return false; - break; - } return true; } bool -Device::unbindExternalDevice(intptr_t type, void* pDevice, void* pContext, bool validateOnly) +Device::unbindExternalDevice(uint flags, void* pDevice, void* pContext, bool validateOnly) { - if (type != CL_GL_CONTEXT_KHR) { + if ((flags & amd::Context::Flags::GLDeviceKhr) == 0) { return true; } diff --git a/rocclr/runtime/device/gpu/gpudevice.hpp b/rocclr/runtime/device/gpu/gpudevice.hpp index 987b9f0279..02957051a2 100644 --- a/rocclr/runtime/device/gpu/gpudevice.hpp +++ b/rocclr/runtime/device/gpu/gpudevice.hpp @@ -95,10 +95,10 @@ public: //! Needed for OpenGL objects on CPU device virtual bool bindExternalDevice( - intptr_t type, void* pDevice, void* pContext, bool validateOnly) { return true; } + uint flags, void* pDevice, void* pContext, bool validateOnly) { return true; } virtual bool unbindExternalDevice( - intptr_t type, void* pDevice, void* pContext, bool validateOnly) { return true; } + uint flags, void* pDevice, void* pContext, bool validateOnly) { return true; } //! Releases non-blocking map target memory virtual void freeMapTarget(amd::Memory& mem, void* target) {} @@ -438,14 +438,14 @@ public: //! Attempt to bind with external graphics API's device/context virtual bool bindExternalDevice( - intptr_t type, + uint flags, void* pDevice, void* pContext, bool validateOnly); //! Attempt to unbind with external graphics API's device/context virtual bool unbindExternalDevice( - intptr_t type, + uint flags, void* pDevice, void* pContext, bool validateOnly); diff --git a/rocclr/runtime/platform/context.cpp b/rocclr/runtime/platform/context.cpp index 9e2bc7576c..126ea765e6 100644 --- a/rocclr/runtime/platform/context.cpp +++ b/rocclr/runtime/platform/context.cpp @@ -67,7 +67,7 @@ Context::~Context() std::vector::const_iterator it; // Loop through all devices for (it = devices_.begin(); it != devices_.end(); it++) { - (*it)->unbindExternalDevice(info_.type_, info_.hDev_, info_.hCtx_, VALIDATE_ONLY); + (*it)->unbindExternalDevice(info_.flags_, info_.hDev_, info_.hCtx_, VALIDATE_ONLY); } } @@ -119,7 +119,6 @@ Context::checkProperties( return CL_INVALID_VALUE; } info->hDev_ = p->ptr; - info->type_ = CL_CONTEXT_D3D10_DEVICE_KHR; info->flags_ |= D3D10DeviceKhr; break; case CL_CONTEXT_D3D11_DEVICE_KHR: @@ -127,7 +126,6 @@ Context::checkProperties( return CL_INVALID_VALUE; } info->hDev_ = p->ptr; - info->type_ = CL_CONTEXT_D3D11_DEVICE_KHR; info->flags_ |= D3D11DeviceKhr; break; case CL_CONTEXT_ADAPTER_D3D9_KHR: @@ -135,7 +133,6 @@ Context::checkProperties( return CL_INVALID_VALUE; } info->hDev_ = p->ptr; - info->type_ = CL_CONTEXT_ADAPTER_D3D9_KHR; info->flags_ |= D3D9DeviceKhr; break; case CL_CONTEXT_ADAPTER_D3D9EX_KHR: @@ -143,7 +140,6 @@ Context::checkProperties( return CL_INVALID_VALUE; } info->hDev_ = p->ptr; - info->type_ = CL_CONTEXT_ADAPTER_D3D9EX_KHR; info->flags_ |= D3D9DeviceEXKhr; break; case CL_CONTEXT_ADAPTER_DXVA_KHR: @@ -151,9 +147,15 @@ Context::checkProperties( return CL_INVALID_VALUE; } info->hDev_ = p->ptr; - info->type_ = CL_CONTEXT_ADAPTER_DXVA_KHR; 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 @@ -174,7 +176,6 @@ Context::checkProperties( return CL_INVALID_GL_SHAREGROUP_REFERENCE_KHR; } if (p->name == CL_GL_CONTEXT_KHR) { - info->type_ = p->name; info->hCtx_ = p->ptr; } info->flags_ |= GLDeviceKhr; @@ -232,7 +233,7 @@ Context::create(const intptr_t* properties) // Loop through all devices for (it = devices_.begin(); it != devices_.end(); it++) { if (!(*it)->bindExternalDevice( - info_.type_, info_.hDev_, info_.hCtx_, VALIDATE_ONLY)) { + info_.flags_, info_.hDev_, info_.hCtx_, VALIDATE_ONLY)) { result = CL_INVALID_VALUE; } } @@ -265,7 +266,7 @@ Context::create(const intptr_t* properties) #endif //!_WIN32 ); - if (h && (glenv_ = new GLFunctions(h))) { + if (h && (glenv_ = new GLFunctions(h, (info_.flags_ & Flags::EGLDeviceKhr) != 0))) { if (!glenv_->init(reinterpret_cast(info_.hDev_), reinterpret_cast(info_.hCtx_))) { delete glenv_; diff --git a/rocclr/runtime/platform/context.hpp b/rocclr/runtime/platform/context.hpp index 64e5568757..de7946ee5e 100644 --- a/rocclr/runtime/platform/context.hpp +++ b/rocclr/runtime/platform/context.hpp @@ -41,13 +41,13 @@ public: D3D9DeviceKhr = 1<<6, //!< d3d9 device D3D9DeviceEXKhr = 1<<7, //!< d3d9EX device D3D9DeviceVAKhr = 1<<8, //!< d3d9VA device + EGLDeviceKhr = 1<<9, //!< EGL device }; //! Context info structure struct Info { uint flags_; //!< Context info flags - intptr_t type_; //!< Context type void* hDev_; //!< Device object reference void* hCtx_; //!< Context object reference size_t propertiesSize_;//!< Size of the original properties in bytes