From 980ad8600871397de4316fdcf3427b3c61656676 Mon Sep 17 00:00:00 2001 From: Ryan Pavlik Date: Wed, 20 Jul 2022 16:56:13 -0500 Subject: [PATCH] a/vk: Get and show some external buffer data on startup, too. --- src/xrt/auxiliary/vk/vk_bundle_init.c | 50 +++++++++++++++++++++++++++ src/xrt/auxiliary/vk/vk_helpers.h | 8 +++++ src/xrt/auxiliary/vk/vk_print.c | 12 +++++++ 3 files changed, 70 insertions(+) diff --git a/src/xrt/auxiliary/vk/vk_bundle_init.c b/src/xrt/auxiliary/vk/vk_bundle_init.c index 931abd902..52f286f85 100644 --- a/src/xrt/auxiliary/vk/vk_bundle_init.c +++ b/src/xrt/auxiliary/vk/vk_bundle_init.c @@ -181,6 +181,46 @@ fill_in_device_features(struct vk_bundle *vk) free(props); } +static bool +is_buffer_bit_supported(struct vk_bundle *vk, + VkExternalMemoryHandleTypeFlagBits handle_type, + VkExternalMemoryFeatureFlagBits bits) +{ + VkPhysicalDeviceExternalBufferInfo external_buffer_info = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_BUFFER_INFO, + .handleType = handle_type, + }; + VkExternalBufferProperties external_buffer_props = { + .sType = VK_STRUCTURE_TYPE_EXTERNAL_BUFFER_PROPERTIES, + }; + + vk->vkGetPhysicalDeviceExternalBufferPropertiesKHR( // + vk->physical_device, // physicalDevice + &external_buffer_info, // pExternalBufferInfo + &external_buffer_props); // pExternalBufferProperties + + // const VkExternalMemoryFeatureFlagBits bits = // + // VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT | // + // VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT; // + + VkExternalFenceFeatureFlagBits masked = + bits & external_buffer_props.externalMemoryProperties.externalMemoryFeatures; + // All must be supported. + return masked == bits; +} + +static bool +is_buffer_bit_supported_for_import(struct vk_bundle *vk, VkExternalMemoryHandleTypeFlagBits handle_type) +{ + return is_buffer_bit_supported(vk, handle_type, VK_EXTERNAL_MEMORY_FEATURE_IMPORTABLE_BIT); +} + +static bool +is_buffer_bit_supported_for_export(struct vk_bundle *vk, VkExternalMemoryHandleTypeFlagBits handle_type) +{ + return is_buffer_bit_supported(vk, handle_type, VK_EXTERNAL_MEMORY_FEATURE_EXPORTABLE_BIT); +} + static bool is_fence_bit_supported(struct vk_bundle *vk, VkExternalFenceHandleTypeFlagBits handle_type) { @@ -313,7 +353,17 @@ fill_in_external_object_properties(struct vk_bundle *vk) VK_WARN(vk, "vkGetPhysicalDeviceExternalSemaphorePropertiesKHR not supported, should always be."); return; } +#if defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_WIN32_HANDLE) + vk->external.buffer_import_opaque_win32 = + is_buffer_bit_supported_for_import(vk, VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT); + vk->external.buffer_export_opaque_win32 = + is_buffer_bit_supported_for_export(vk, VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT); + vk->external.buffer_import_d3d11 = + is_buffer_bit_supported_for_import(vk, VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_TEXTURE_BIT); + vk->external.buffer_export_d3d11 = + is_buffer_bit_supported_for_export(vk, VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_TEXTURE_BIT); +#endif #if defined(XRT_GRAPHICS_SYNC_HANDLE_IS_FD) vk->external.fence_sync_fd = is_fence_bit_supported( // diff --git a/src/xrt/auxiliary/vk/vk_helpers.h b/src/xrt/auxiliary/vk/vk_helpers.h index 13c89cb26..c6fc4ac67 100644 --- a/src/xrt/auxiliary/vk/vk_helpers.h +++ b/src/xrt/auxiliary/vk/vk_helpers.h @@ -61,6 +61,14 @@ struct vk_bundle struct { +#if defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_WIN32_HANDLE) + bool buffer_import_opaque_win32; + bool buffer_export_opaque_win32; + + bool buffer_import_d3d11; + bool buffer_export_d3d11; +#endif + #if defined(XRT_GRAPHICS_SYNC_HANDLE_IS_FD) bool fence_sync_fd; bool fence_opaque_fd; diff --git a/src/xrt/auxiliary/vk/vk_print.c b/src/xrt/auxiliary/vk/vk_print.c index f04438aba..3112790de 100644 --- a/src/xrt/auxiliary/vk/vk_print.c +++ b/src/xrt/auxiliary/vk/vk_print.c @@ -63,6 +63,18 @@ vk_print_features_info(struct vk_bundle *vk, enum u_logging_level log_level) void vk_print_external_handles_info(struct vk_bundle *vk, enum u_logging_level log_level) { + +#if defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_WIN32_HANDLE) + U_LOG_IFL(log_level, vk->log_level, // + "Supported buffers:\n\t%s: import=%s export=%s\n\t%s: import=%s export=%s", // + "VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT", // + vk->external.buffer_import_opaque_win32 ? "true" : "false", // + vk->external.buffer_export_opaque_win32 ? "true" : "false", // + "VK_EXTERNAL_MEMORY_HANDLE_TYPE_D3D11_TEXTURE_BIT", // + vk->external.buffer_import_d3d11 ? "true" : "false", // + vk->external.buffer_export_d3d11 ? "true" : "false"); // +#endif + #if defined(XRT_GRAPHICS_SYNC_HANDLE_IS_FD) U_LOG_IFL(log_level, vk->log_level, //