diff --git a/rocclr/device/pal/palmemory.cpp b/rocclr/device/pal/palmemory.cpp index 4259ad0242..338f5ea7aa 100644 --- a/rocclr/device/pal/palmemory.cpp +++ b/rocclr/device/pal/palmemory.cpp @@ -34,6 +34,7 @@ #include "amdocl/cl_d3d11_amd.hpp" #endif //_WIN32 #include "amdocl/cl_gl_amd.hpp" +#include "amdocl/cl_vk_amd.hpp" #include #include @@ -221,6 +222,7 @@ bool Memory::processGLResource(GLResourceOP operation) { bool Memory::createInterop() { Resource::MemoryType memType = Resource::Empty; Resource::OGLInteropParams oglRes; + Resource::VkInteropParams vkRes; #ifdef _WIN32 Resource::D3DInteropParams d3dRes; #endif //_WIN32 @@ -233,6 +235,7 @@ bool Memory::createInterop() { amd::InteropObject* interop = owner()->getInteropObj(); assert((interop != nullptr) && "An invalid interop object is impossible!"); + amd::VkObject* vkObject = interop->asVkObject(); amd::GLObject* glObject = interop->asGLObject(); #ifdef _WIN32 amd::D3D10Object* d3d10Object = interop->asD3D10Object(); @@ -342,7 +345,16 @@ bool Memory::createInterop() { } } else #endif //_WIN32 - if (glObject != nullptr) { + if (vkObject != nullptr) { + createParams = &vkRes; + vkRes.owner_ = owner(); + memType = Resource::VkInterop; + vkRes.handle_ = vkObject->getVkSharedHandle(); + assert(vkRes.handle_ != nullptr); + vkRes.type_ = Resource::InteropTypeless; + } + + else if (glObject != nullptr) { createParams = &oglRes; oglRes.owner_ = owner(); diff --git a/rocclr/device/pal/palresource.cpp b/rocclr/device/pal/palresource.cpp index 87d2eba066..151c0472b4 100644 --- a/rocclr/device/pal/palresource.cpp +++ b/rocclr/device/pal/palresource.cpp @@ -753,6 +753,10 @@ bool Resource::CreateInterop(CreateParams* params) { desc_.isDoppTexture_ = (openInfo.doppDesktopInfo.gpuVirtAddr != 0); format = dev().getPalFormat(desc().format_, &channels); } + else if (memoryType() == VkInterop) { + VkInteropParams* vparams = reinterpret_cast(params); + openInfo.hExternalResource = vparams->handle_; + } #ifdef ATI_OS_WIN else { D3DInteropParams* d3dRes = reinterpret_cast(params); @@ -1174,6 +1178,7 @@ bool Resource::create(MemoryType memType, CreateParams* params, bool forceLinear case D3D9Interop: case D3D10Interop: case D3D11Interop: + case VkInterop: return CreateInterop(params); case P2PAccess: return CreateP2PAccess(params); diff --git a/rocclr/device/pal/palresource.hpp b/rocclr/device/pal/palresource.hpp index eeee07a785..123b2bbd60 100644 --- a/rocclr/device/pal/palresource.hpp +++ b/rocclr/device/pal/palresource.hpp @@ -136,6 +136,11 @@ class Resource : public amd::HeapObject { void* glPlatformContext_; }; + struct VkInteropParams : public CreateParams { + InteropType type_; //!< Vulkan resource type + void* handle_; + }; + #ifdef _WIN32 struct D3DInteropParams : public CreateParams { InteropType type_; //!< D3D resource type @@ -166,7 +171,8 @@ class Resource : public amd::HeapObject { D3D9Interop, //!< resource is a D3D9 memory object Scratch, //!< resource is scratch memory Shader, //!< resource is a shader - P2PAccess //!< resource is a shared resource for P2P access + P2PAccess, //!< resource is a shared resource for P2P access + VkInterop //!< resource is a Vulkan memory object }; //! Resource map flags diff --git a/rocclr/platform/interop.hpp b/rocclr/platform/interop.hpp index 6aeb916cb6..aac1e3cbc1 100644 --- a/rocclr/platform/interop.hpp +++ b/rocclr/platform/interop.hpp @@ -26,6 +26,9 @@ namespace amd { //! Forward declarations of interop classes class GLObject; class BufferGL; +class VkObject; +class BufferVk; + #ifdef _WIN32 class D3D10Object; @@ -40,13 +43,16 @@ class InteropObject { virtual ~InteropObject() {} // Static cast functions for interop objects - virtual GLObject* asGLObject() { return NULL; } - virtual BufferGL* asBufferGL() { return NULL; } + virtual GLObject* asGLObject() { return nullptr; } + virtual BufferGL* asBufferGL() { return nullptr; } + + virtual VkObject* asVkObject() { return nullptr; } + virtual BufferVk* asBufferVk() { return nullptr; } #ifdef _WIN32 - virtual D3D10Object* asD3D10Object() { return NULL; } - virtual D3D11Object* asD3D11Object() { return NULL; } - virtual D3D9Object* asD3D9Object() { return NULL; } + virtual D3D10Object* asD3D10Object() { return nullptr; } + virtual D3D11Object* asD3D11Object() { return nullptr; } + virtual D3D9Object* asD3D9Object() { return nullptr; } #endif //_WIN32 // On acquire copy data from original resource to shared resource