summaryrefslogtreecommitdiffstats
path: root/tools/gfx/vulkan/vk-buffer.cpp
diff options
context:
space:
mode:
authorskallweitNV <64953474+skallweitNV@users.noreply.github.com>2024-02-27 17:42:39 +0100
committerGitHub <noreply@github.com>2024-02-27 08:42:39 -0800
commite3fdfe5176e28c6b4548aeb860c1abaa1987ee57 (patch)
treefa9b88565426eff0d8c91e1743b41ff96383d79c /tools/gfx/vulkan/vk-buffer.cpp
parent188482e83dc4f7dc4c940214033dd95518b9d18c (diff)
add support for shared resources on vulkan/linux (#3636)
Diffstat (limited to 'tools/gfx/vulkan/vk-buffer.cpp')
-rw-r--r--tools/gfx/vulkan/vk-buffer.cpp20
1 files changed, 19 insertions, 1 deletions
diff --git a/tools/gfx/vulkan/vk-buffer.cpp b/tools/gfx/vulkan/vk-buffer.cpp
index 9e1986b38..32c14bcb9 100644
--- a/tools/gfx/vulkan/vk-buffer.cpp
+++ b/tools/gfx/vulkan/vk-buffer.cpp
@@ -57,10 +57,12 @@ Result VKBufferHandleRAII::init(
#if SLANG_WINDOWS_FAMILY
VkExportMemoryWin32HandleInfoKHR exportMemoryWin32HandleInfo = {
VK_STRUCTURE_TYPE_EXPORT_MEMORY_WIN32_HANDLE_INFO_KHR };
+#endif
VkExportMemoryAllocateInfoKHR exportMemoryAllocateInfo = {
VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO_KHR };
if (isShared)
{
+#if SLANG_WINDOWS_FAMILY
exportMemoryWin32HandleInfo.pNext = nullptr;
exportMemoryWin32HandleInfo.pAttributes = nullptr;
exportMemoryWin32HandleInfo.dwAccess =
@@ -71,10 +73,10 @@ Result VKBufferHandleRAII::init(
extMemHandleType & VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT_KHR
? &exportMemoryWin32HandleInfo
: nullptr;
+#endif
exportMemoryAllocateInfo.handleTypes = extMemHandleType;
allocateInfo.pNext = &exportMemoryAllocateInfo;
}
-#endif
VkMemoryAllocateFlagsInfo flagInfo = { VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_FLAGS_INFO };
if (usage & VK_BUFFER_USAGE_SHADER_DEVICE_ADDRESS_BIT)
{
@@ -151,6 +153,22 @@ Result BufferResourceImpl::getSharedHandle(InteropHandle* outHandle)
}
SLANG_VK_RETURN_ON_FAIL(
vkCreateSharedHandle(api->m_device, &info, (HANDLE*)&outHandle->handleValue));
+#else
+ VkMemoryGetFdInfoKHR info = {};
+ info.sType = VK_STRUCTURE_TYPE_MEMORY_GET_FD_INFO_KHR;
+ info.pNext = nullptr;
+ info.memory = m_buffer.m_memory;
+ info.handleType = VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT;
+
+ auto api = m_buffer.m_api;
+ PFN_vkGetMemoryFdKHR vkCreateSharedHandle;
+ vkCreateSharedHandle = api->vkGetMemoryFdKHR;
+ if (!vkCreateSharedHandle)
+ {
+ return SLANG_FAIL;
+ }
+ SLANG_VK_RETURN_ON_FAIL(
+ vkCreateSharedHandle(api->m_device, &info, (int*)&outHandle->handleValue));
#endif
outHandle->api = InteropHandleAPI::Vulkan;
return SLANG_OK;