From 72617030adc9c24b77aea2c53daec53c7a766042 Mon Sep 17 00:00:00 2001 From: PENGUINLIONG Date: Sat, 21 May 2022 14:51:21 +0800 Subject: [PATCH 1/2] Support importing external vulkan buffers --- taichi/backends/vulkan/vulkan_device.cpp | 16 ++++++++++++++++ taichi/backends/vulkan/vulkan_device.h | 4 ++++ 2 files changed, 20 insertions(+) diff --git a/taichi/backends/vulkan/vulkan_device.cpp b/taichi/backends/vulkan/vulkan_device.cpp index a739758e69f88..7c06f9b79d400 100644 --- a/taichi/backends/vulkan/vulkan_device.cpp +++ b/taichi/backends/vulkan/vulkan_device.cpp @@ -1682,6 +1682,22 @@ vkapi::IVkFramebuffer VulkanDevice::get_framebuffer( return framebuffer; } +DeviceAllocation VulkanDevice::import_vkbuffer(vkapi::IVkBuffer buffer) { + AllocationInternal alloc_int{}; + alloc_int.external = true; + alloc_int.buffer = buffer; + alloc_int.mapped = false; + alloc_int.addr = 0; + + DeviceAllocation alloc; + alloc.device = this; + alloc.alloc_id = alloc_cnt_++; + + allocations_[alloc.alloc_id] = alloc_int; + + return alloc; +} + DeviceAllocation VulkanDevice::import_vk_image(vkapi::IVkImage image, vkapi::IVkImageView view, VkFormat format) { diff --git a/taichi/backends/vulkan/vulkan_device.h b/taichi/backends/vulkan/vulkan_device.h index 5a4b9eeeefff8..15d5cde4d88a8 100644 --- a/taichi/backends/vulkan/vulkan_device.h +++ b/taichi/backends/vulkan/vulkan_device.h @@ -604,6 +604,9 @@ class TI_DLL_EXPORT VulkanDevice : public GraphicsDevice { std::tuple get_vk_image( const DeviceAllocation &alloc) const; + + DeviceAllocation import_vkbuffer(vkapi::IVkBuffer buffer); + DeviceAllocation import_vk_image(vkapi::IVkImage image, vkapi::IVkImageView view, VkFormat format); @@ -642,6 +645,7 @@ class TI_DLL_EXPORT VulkanDevice : public GraphicsDevice { // Memory allocation struct AllocationInternal { + bool external{false}; VmaAllocationInfo alloc_info; vkapi::IVkBuffer buffer; void *mapped{nullptr}; From c6fbc0c7bd69bfaf8d1ead81660b65fece6c9465 Mon Sep 17 00:00:00 2001 From: PENGUINLIONG Date: Sat, 21 May 2022 15:16:02 +0800 Subject: [PATCH 2/2] Fix compilation error --- taichi/backends/vulkan/vulkan_device.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/taichi/backends/vulkan/vulkan_device.cpp b/taichi/backends/vulkan/vulkan_device.cpp index 7c06f9b79d400..ff00fb18e6648 100644 --- a/taichi/backends/vulkan/vulkan_device.cpp +++ b/taichi/backends/vulkan/vulkan_device.cpp @@ -1686,7 +1686,7 @@ DeviceAllocation VulkanDevice::import_vkbuffer(vkapi::IVkBuffer buffer) { AllocationInternal alloc_int{}; alloc_int.external = true; alloc_int.buffer = buffer; - alloc_int.mapped = false; + alloc_int.mapped = nullptr; alloc_int.addr = 0; DeviceAllocation alloc;