From 67e9aac68976503b75a9a7cbd525d34ea07d41c9 Mon Sep 17 00:00:00 2001 From: pghafari Date: Fri, 19 Mar 2021 18:22:16 -0400 Subject: [PATCH] SWDEV-245532 - HIP - Vulkan interop Change-Id: Ied16503cc154fbda8ce28db25df746cccb19e0ba --- opencl/amdocl/cl_vk_amd.hpp | 119 ++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 opencl/amdocl/cl_vk_amd.hpp diff --git a/opencl/amdocl/cl_vk_amd.hpp b/opencl/amdocl/cl_vk_amd.hpp new file mode 100644 index 0000000000..34ae04b5c4 --- /dev/null +++ b/opencl/amdocl/cl_vk_amd.hpp @@ -0,0 +1,119 @@ +/* Copyright (c) 2010-present Advanced Micro Devices, Inc. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. */ + +#pragma once + +#include "platform/context.hpp" +#include "platform/memory.hpp" + +namespace amd +{ + class VkObject : public InteropObject + { + protected: + amd::Os::FileDesc handleVk_; + + public: + //! GLObject constructor initializes member variables + VkObject( + amd::Os::FileDesc handle + ) // Initialization of member variables + + { + handleVk_ = handle; + } + + virtual ~VkObject() {} + VkObject* asVkObject() { return this; } + amd::Os::FileDesc getVkSharedHandle() const { return handleVk_; } + + + }; + + class BufferVk : public Buffer, public VkObject + { + protected: + //! Initializes the device memory array which is nested + // after'BufferVk' object in memory layout. + void BufferVk::initDeviceMemory() { + deviceMemories_ = + reinterpret_cast(reinterpret_cast(this) + sizeof(BufferVk)); + memset(deviceMemories_, 0, context_().devices().size() * sizeof(DeviceMemory)); + } + public: + //! BufferVk constructor just calls constructors of base classes + //! to pass down the parameters + BufferVk( + Context& amdContext, + size_t uiSizeInBytes, + amd::Os::FileDesc handle) + : // Call base classes constructors + Buffer( + amdContext, + 0, + uiSizeInBytes + ), + VkObject( + handle + ) + { + setInteropObj(this); + } + virtual ~BufferVk() {} + + BufferVk* asBufferVk() { return this; } + }; + + // to be modified once image requirments are known, for now, implement like buffer + + class ImageVk : public Buffer, public VkObject + { + protected: + //! Initializes the device memory array which is nested + // after'ImageVk' object in memory layout. + void ImageVk::initDeviceMemory() { + deviceMemories_ = + reinterpret_cast(reinterpret_cast(this) + sizeof(ImageVk)); + memset(deviceMemories_, 0, context_().devices().size() * sizeof(DeviceMemory)); + } + public: + //! ImageVk constructor just calls constructors of base classes + //! to pass down the parameters + ImageVk( + Context& amdContext, + size_t uiSizeInBytes, + amd::Os::FileDesc handle) + : // Call base classes constructors + Buffer( + amdContext, + 0, + uiSizeInBytes + ), + VkObject( + handle + ) + { + setInteropObj(this); + } + virtual ~ImageVk() {} + + ImageVk* asImageVk() { return this; } + }; +}