diff options
Diffstat (limited to 'tools/gfx/vulkan/vk-fence.cpp')
| -rw-r--r-- | tools/gfx/vulkan/vk-fence.cpp | 43 |
1 files changed, 41 insertions, 2 deletions
diff --git a/tools/gfx/vulkan/vk-fence.cpp b/tools/gfx/vulkan/vk-fence.cpp index 0cef86a13..7ef2323f7 100644 --- a/tools/gfx/vulkan/vk-fence.cpp +++ b/tools/gfx/vulkan/vk-fence.cpp @@ -4,6 +4,10 @@ #include "vk-device.h" #include "vk-util.h" +#if SLANG_WINDOWS_FAMILY +#include <dxgi1_2.h> +#endif + namespace gfx { @@ -40,6 +44,30 @@ Result FenceImpl::init(const IFence::Desc& desc) createInfo.pNext = &timelineCreateInfo; createInfo.flags = 0; +#if SLANG_WINDOWS_FAMILY + VkExportSemaphoreWin32HandleInfoKHR exportSemaphoreWin32HandleInfoKHR; +#endif + VkExportSemaphoreCreateInfoKHR exportSemaphoreCreateInfo; + if (desc.isShared) + { +#if SLANG_WINDOWS_FAMILY + exportSemaphoreWin32HandleInfoKHR.sType = VK_STRUCTURE_TYPE_EXPORT_SEMAPHORE_WIN32_HANDLE_INFO_KHR; + exportSemaphoreWin32HandleInfoKHR.pNext = timelineCreateInfo.pNext;; + exportSemaphoreWin32HandleInfoKHR.pAttributes = nullptr; + exportSemaphoreWin32HandleInfoKHR.dwAccess = DXGI_SHARED_RESOURCE_READ | DXGI_SHARED_RESOURCE_WRITE; + exportSemaphoreWin32HandleInfoKHR.name = (LPCWSTR)nullptr; +#endif + exportSemaphoreCreateInfo.sType = VK_STRUCTURE_TYPE_EXPORT_SEMAPHORE_CREATE_INFO_KHR; +#if SLANG_WINDOWS_FAMILY + exportSemaphoreCreateInfo.pNext = &exportSemaphoreWin32HandleInfoKHR; + exportSemaphoreCreateInfo.handleTypes = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT; +#else + exportSemaphoreCreateInfo.pNext = timelineCreateInfo.pNext; + exportSemaphoreCreateInfo.handleTypes = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT; +#endif + timelineCreateInfo.pNext = &exportSemaphoreCreateInfo; + } + SLANG_VK_RETURN_ON_FAIL(m_device->m_api.vkCreateSemaphore( m_device->m_api.m_device, &createInfo, nullptr, &m_semaphore)); @@ -62,7 +90,7 @@ Result FenceImpl::setCurrentValue(uint64_t value) { VkSemaphoreSignalInfo signalInfo; signalInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_SIGNAL_INFO; - signalInfo.pNext = NULL; + signalInfo.pNext = nullptr; signalInfo.semaphore = m_semaphore; signalInfo.value = value; @@ -89,9 +117,20 @@ Result FenceImpl::getSharedHandle(InteropHandle* outHandle) handleInfo.handleType = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT; SLANG_VK_RETURN_ON_FAIL(m_device->m_api.vkGetSemaphoreWin32HandleKHR( - m_device->m_api.m_device, &handleInfo, (HANDLE*)&outHandle->handleValue)); + m_device->m_api.m_device, &handleInfo, (HANDLE*)&sharedHandle.handleValue)); +#else + VkSemaphoreGetFdInfoKHR fdInfo = { + VK_STRUCTURE_TYPE_SEMAPHORE_GET_FD_INFO_KHR}; + fdInfo.pNext = nullptr; + fdInfo.semaphore = m_semaphore; + fdInfo.handleType = VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT; + + SLANG_VK_RETURN_ON_FAIL(m_device->m_api.vkGetSemaphoreFdKHR( + m_device->m_api.m_device, &fdInfo, (int*)&sharedHandle.handleValue)); #endif + sharedHandle.api = InteropHandleAPI::Vulkan; + *outHandle = sharedHandle; return SLANG_OK; } |
