From eeaaaf398be47be4a9fdc30c3c1ceefe2ceb832c Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Wed, 7 Sep 2022 20:32:40 +0100 Subject: [PATCH] a/vk: Add helper to get buffer handle types The image version of it was used for buffers as well. --- src/xrt/auxiliary/vk/vk_compositor_flags.c | 14 ++++++++++++++ src/xrt/auxiliary/vk/vk_helpers.h | 11 ++++++++++- src/xrt/compositor/render/render_buffer.c | 4 ++-- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/xrt/auxiliary/vk/vk_compositor_flags.c b/src/xrt/auxiliary/vk/vk_compositor_flags.c index eb617c79e..ccae0399c 100644 --- a/src/xrt/auxiliary/vk/vk_compositor_flags.c +++ b/src/xrt/auxiliary/vk/vk_compositor_flags.c @@ -58,6 +58,20 @@ check_feature(VkFormat format, * */ +VkExternalMemoryHandleTypeFlags +vk_cb_get_buffer_external_handle_type(struct vk_bundle *vk) +{ +#if defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_FD) + return VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_FD_BIT_KHR; +#elif defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_AHARDWAREBUFFER) + return VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID; +#elif defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_WIN32_HANDLE) + return VK_EXTERNAL_MEMORY_HANDLE_TYPE_OPAQUE_WIN32_BIT; +#else +#error "need port" +#endif +} + VkAccessFlags vk_csci_get_barrier_access_mask(enum xrt_swapchain_usage_bits bits) { diff --git a/src/xrt/auxiliary/vk/vk_helpers.h b/src/xrt/auxiliary/vk/vk_helpers.h index 2e3bb5341..e06582a03 100644 --- a/src/xrt/auxiliary/vk/vk_helpers.h +++ b/src/xrt/auxiliary/vk/vk_helpers.h @@ -1087,10 +1087,18 @@ vk_create_compute_pipeline(struct vk_bundle *vk, /* * - * Compositor swapchain image flags helpers, in the vk_compositor_flags.c file. + * Compositor buffer and swapchain image flags helpers, in the vk_compositor_flags.c file. * */ +/*! + * Return the extern handle type that a buffer should be created with. + * + * cb = Compositor Buffer. + */ +VkExternalMemoryHandleTypeFlags +vk_cb_get_buffer_external_handle_type(struct vk_bundle *vk); + /*! * Helper for all of the supported formats to check support for. * @@ -1217,6 +1225,7 @@ vk_csci_get_image_external_support(struct vk_bundle *vk, bool *out_importable, bool *out_exportable); + /* * * Sync objects, in the vk_sync_objects.c file. diff --git a/src/xrt/compositor/render/render_buffer.c b/src/xrt/compositor/render/render_buffer.c index dea8c8cd0..e175d7266 100644 --- a/src/xrt/compositor/render/render_buffer.c +++ b/src/xrt/compositor/render/render_buffer.c @@ -159,13 +159,13 @@ render_buffer_init_exportable(struct vk_bundle *vk, VkExternalMemoryBufferCreateInfo export_create_info = { .sType = VK_STRUCTURE_TYPE_EXTERNAL_MEMORY_BUFFER_CREATE_INFO, - .handleTypes = vk_csci_get_image_external_handle_type(vk), + .handleTypes = vk_cb_get_buffer_external_handle_type(vk), }; VkExportMemoryAllocateInfo export_alloc_info = { .sType = VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO_KHR, .pNext = NULL, - .handleTypes = vk_csci_get_image_external_handle_type(vk), + .handleTypes = vk_cb_get_buffer_external_handle_type(vk), }; ret = create_buffer(vk, //