From 490e90b4938408f357ff2781dbf93841ee9e4f6a Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Sat, 21 May 2022 00:54:46 +0100 Subject: [PATCH] a/vk: Also check for d3d12 fence semaphores --- src/xrt/auxiliary/vk/vk_bundle_init.c | 68 ++++++++++++++++---------- src/xrt/auxiliary/vk/vk_helpers.h | 2 + src/xrt/auxiliary/vk/vk_print.c | 6 ++- src/xrt/auxiliary/vk/vk_sync_objects.c | 6 +++ 4 files changed, 55 insertions(+), 27 deletions(-) diff --git a/src/xrt/auxiliary/vk/vk_bundle_init.c b/src/xrt/auxiliary/vk/vk_bundle_init.c index a37e1a238..cc0011611 100644 --- a/src/xrt/auxiliary/vk/vk_bundle_init.c +++ b/src/xrt/auxiliary/vk/vk_bundle_init.c @@ -210,8 +210,11 @@ is_fence_bit_supported(struct vk_bundle *vk, VkExternalFenceHandleTypeFlagBits h return true; } -static bool -is_binary_semaphore_bit_supported(struct vk_bundle *vk, VkExternalSemaphoreHandleTypeFlagBits handle_type) +static void +get_binary_semaphore_bit_support(struct vk_bundle *vk, + VkExternalSemaphoreHandleTypeFlagBits handle_type, + bool *out_importable, + bool *out_exportable) { VkPhysicalDeviceExternalSemaphoreInfo external_semaphore_info = { .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_SEMAPHORE_INFO, @@ -227,29 +230,37 @@ is_binary_semaphore_bit_supported(struct vk_bundle *vk, VkExternalSemaphoreHandl &external_semaphore_info, // pExternalSemaphoreInfo &external_semaphore_props); // pExternalSemaphoreProperties - const VkExternalSemaphoreFeatureFlagBits bits = // - VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT | // - VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT; // + const VkExternalSemaphoreFeatureFlagBits bits = external_semaphore_props.externalSemaphoreFeatures; - VkExternalSemaphoreFeatureFlagBits masked = bits & external_semaphore_props.externalSemaphoreFeatures; - if (masked != bits) { - // All must be supported. - return false; - } - - return true; + *out_importable = (bits & VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT) != 0; + *out_exportable = (bits & VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT) != 0; } static bool -is_timeline_semaphore_bit_supported(struct vk_bundle *vk, VkExternalSemaphoreHandleTypeFlagBits handle_type) +is_binary_semaphore_bit_supported(struct vk_bundle *vk, VkExternalSemaphoreHandleTypeFlagBits handle_type) { + bool importable = false, exportable = false; + get_binary_semaphore_bit_support(vk, handle_type, &importable, &exportable); + + return importable && exportable; +} + +static void +get_timeline_semaphore_bit_support(struct vk_bundle *vk, + VkExternalSemaphoreHandleTypeFlagBits handle_type, + bool *out_importable, + bool *out_exportable) +{ + *out_importable = false; + *out_exportable = false; + #ifdef VK_KHR_timeline_semaphore /* * This technically is for the device not the physical device, * but we can use it as a way to gate running the detection code. */ if (!vk->features.timeline_semaphore) { - return false; + return; } VkSemaphoreTypeCreateInfo semaphore_type_create_info = { @@ -271,22 +282,22 @@ is_timeline_semaphore_bit_supported(struct vk_bundle *vk, VkExternalSemaphoreHan &external_semaphore_info, // pExternalSemaphoreInfo &external_semaphore_props); // pExternalSemaphoreProperties - const VkExternalSemaphoreFeatureFlagBits bits = // - VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT | // - VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT; // + const VkExternalSemaphoreFeatureFlagBits bits = external_semaphore_props.externalSemaphoreFeatures; - VkExternalSemaphoreFeatureFlagBits masked = bits & external_semaphore_props.externalSemaphoreFeatures; - if (masked != bits) { - // All must be supported. - return false; - } - - return true; -#else - return false; + *out_importable = (bits & VK_EXTERNAL_SEMAPHORE_FEATURE_IMPORTABLE_BIT) != 0; + *out_exportable = (bits & VK_EXTERNAL_SEMAPHORE_FEATURE_EXPORTABLE_BIT) != 0; #endif } +bool +is_timeline_semaphore_bit_supported(struct vk_bundle *vk, VkExternalSemaphoreHandleTypeFlagBits handle_type) +{ + bool importable = false, exportable = false; + get_timeline_semaphore_bit_support(vk, handle_type, &importable, &exportable); + + return importable && exportable; +} + static void fill_in_external_object_properties(struct vk_bundle *vk) { @@ -322,13 +333,18 @@ fill_in_external_object_properties(struct vk_bundle *vk) vk, VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT); #elif defined(XRT_GRAPHICS_SYNC_HANDLE_IS_WIN32_HANDLE) + vk->external.fence_win32_handle = is_fence_bit_supported( // vk, VK_EXTERNAL_FENCE_HANDLE_TYPE_OPAQUE_WIN32_BIT); + vk->external.binary_semaphore_d3d12_fence = is_binary_semaphore_bit_supported( // + vk, VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D12_FENCE_BIT); vk->external.binary_semaphore_win32_handle = is_binary_semaphore_bit_supported( // vk, VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT); //! @todo Is this safe to assume working, do we need to check an extension? + vk->external.timeline_semaphore_d3d12_fence = is_timeline_semaphore_bit_supported( // + vk, VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D12_FENCE_BIT); vk->external.timeline_semaphore_win32_handle = is_timeline_semaphore_bit_supported( // vk, VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT); diff --git a/src/xrt/auxiliary/vk/vk_helpers.h b/src/xrt/auxiliary/vk/vk_helpers.h index 935b6cfb5..72c9d3cd6 100644 --- a/src/xrt/auxiliary/vk/vk_helpers.h +++ b/src/xrt/auxiliary/vk/vk_helpers.h @@ -72,8 +72,10 @@ struct vk_bundle #elif defined(XRT_GRAPHICS_SYNC_HANDLE_IS_WIN32_HANDLE) bool fence_win32_handle; + bool binary_semaphore_d3d12_fence; bool binary_semaphore_win32_handle; + bool timeline_semaphore_d3d12_fence; bool timeline_semaphore_win32_handle; #else #error "Need port for fence sync handles checkers" diff --git a/src/xrt/auxiliary/vk/vk_print.c b/src/xrt/auxiliary/vk/vk_print.c index 1a522a888..f04438aba 100644 --- a/src/xrt/auxiliary/vk/vk_print.c +++ b/src/xrt/auxiliary/vk/vk_print.c @@ -91,9 +91,13 @@ vk_print_external_handles_info(struct vk_bundle *vk, enum u_logging_level log_le vk->external.fence_win32_handle ? "true" : "false"); // U_LOG_IFL(log_level, vk->log_level, // - "Supported semaphores:\n\t%s: %s\n\t%s: %s", // + "Supported semaphores:\n\t%s: %s\n\t%s: %s\n\t%s: %s\n\t%s: %s", // + "VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D12_FENCE_BIT(binary)", // + vk->external.binary_semaphore_d3d12_fence ? "true" : "false", // "VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT(binary)", // vk->external.binary_semaphore_win32_handle ? "true" : "false", // + "VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D12_FENCE_BIT(timeline)", // + vk->external.timeline_semaphore_d3d12_fence ? "true" : "false", // "VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT(timeline)", // vk->external.timeline_semaphore_win32_handle ? "true" : "false"); // diff --git a/src/xrt/auxiliary/vk/vk_sync_objects.c b/src/xrt/auxiliary/vk/vk_sync_objects.c index b96931b51..6c9c1f02f 100644 --- a/src/xrt/auxiliary/vk/vk_sync_objects.c +++ b/src/xrt/auxiliary/vk/vk_sync_objects.c @@ -32,6 +32,9 @@ vk_get_semaphore_handle_type(struct vk_bundle *vk) } #elif defined(XRT_GRAPHICS_SYNC_HANDLE_IS_WIN32_HANDLE) + if (vk->external.binary_semaphore_d3d12_fence) { + return VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D12_FENCE_BIT; + } if (vk->external.binary_semaphore_win32_handle) { return VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT; } @@ -50,6 +53,9 @@ vk_get_timeline_semaphore_handle_type(struct vk_bundle *vk) return VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_FD_BIT; } #elif defined(XRT_GRAPHICS_SYNC_HANDLE_IS_WIN32_HANDLE) + if (vk->external.timeline_semaphore_d3d12_fence) { + return VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_D3D12_FENCE_BIT; + } if (vk->external.timeline_semaphore_win32_handle) { return VK_EXTERNAL_SEMAPHORE_HANDLE_TYPE_OPAQUE_WIN32_BIT; }