diff --git a/src/xrt/auxiliary/vk/vk_bundle_init.c b/src/xrt/auxiliary/vk/vk_bundle_init.c index 52786b398..8ec5df0d9 100644 --- a/src/xrt/auxiliary/vk/vk_bundle_init.c +++ b/src/xrt/auxiliary/vk/vk_bundle_init.c @@ -1,4 +1,4 @@ -// Copyright 2019-2023, Collabora, Ltd. +// Copyright 2019-2024, Collabora, Ltd. // SPDX-License-Identifier: BSL-1.0 /*! * @file @@ -14,6 +14,7 @@ * @author Jakob Bornecrantz * @author Lubosz Sarnecki * @author Moses Turner + * @author Korcan Hussein * @ingroup aux_vk */ @@ -1395,6 +1396,7 @@ vk_init_from_given(struct vk_bundle *vk, bool external_fence_fd_enabled, bool external_semaphore_fd_enabled, bool timeline_semaphore_enabled, + bool image_format_list_enabled, bool debug_utils_enabled, enum u_logging_level log_level) { @@ -1435,6 +1437,11 @@ vk_init_from_given(struct vk_bundle *vk, vk->has_KHR_external_semaphore_fd = true; } + // Vulkan does not let us read what extensions was enabled. + if (image_format_list_enabled) { + vk->has_KHR_image_format_list = image_format_list_enabled; + } + #ifdef VK_KHR_timeline_semaphore /* * Has the timeline semaphore extension and feature been enabled? diff --git a/src/xrt/auxiliary/vk/vk_helpers.c b/src/xrt/auxiliary/vk/vk_helpers.c index 0420b80ea..62f505391 100644 --- a/src/xrt/auxiliary/vk/vk_helpers.c +++ b/src/xrt/auxiliary/vk/vk_helpers.c @@ -1136,6 +1136,20 @@ vk_create_image_from_native(struct vk_bundle *vk, .handleTypes = handle_type, }; +#ifdef VK_KHR_image_format_list + VkImageFormatListCreateInfoKHR image_format_list_create_info = { + .sType = VK_STRUCTURE_TYPE_IMAGE_FORMAT_LIST_CREATE_INFO_KHR, + .pNext = NULL, + .viewFormatCount = info->format_count, + .pViewFormats = info->formats, + }; + const bool has_mutable_format_list = + has_mutable_usage && vk->has_KHR_image_format_list && info->format_count > 0; + if (has_mutable_format_list) { + external_memory_image_create_info.pNext = &image_format_list_create_info; + } +#endif + // In VkImageCreateInfo vk_info = { .sType = VK_STRUCTURE_TYPE_IMAGE_CREATE_INFO, diff --git a/src/xrt/auxiliary/vk/vk_helpers.h b/src/xrt/auxiliary/vk/vk_helpers.h index 2d2e3558b..c956c9f86 100644 --- a/src/xrt/auxiliary/vk/vk_helpers.h +++ b/src/xrt/auxiliary/vk/vk_helpers.h @@ -1,4 +1,4 @@ -// Copyright 2019-2023, Collabora, Ltd. +// Copyright 2019-2024, Collabora, Ltd. // SPDX-License-Identifier: BSL-1.0 /*! * @file @@ -14,6 +14,7 @@ * @author Jakob Bornecrantz * @author Lubosz Sarnecki * @author Moses Turner + * @author Korcan Hussein * @ingroup aux_vk */ @@ -1049,6 +1050,7 @@ vk_init_from_given(struct vk_bundle *vk, bool external_fence_fd_enabled, bool external_semaphore_fd_enabled, bool timeline_semaphore_enabled, + bool image_format_list_enabled, bool debug_utils_enabled, enum u_logging_level log_level); diff --git a/src/xrt/compositor/client/comp_vk_client.c b/src/xrt/compositor/client/comp_vk_client.c index 717d82a7e..bb0c6dc8b 100644 --- a/src/xrt/compositor/client/comp_vk_client.c +++ b/src/xrt/compositor/client/comp_vk_client.c @@ -1,10 +1,11 @@ -// Copyright 2019-2023, Collabora, Ltd. +// Copyright 2019-2024, Collabora, Ltd. // SPDX-License-Identifier: BSL-1.0 /*! * @file * @brief Vulkan client side glue to compositor implementation. * @author Jakob Bornecrantz * @author Lubosz Sarnecki + * @author Korcan Hussein * @ingroup comp_client */ @@ -816,6 +817,7 @@ client_vk_compositor_create(struct xrt_compositor_native *xcn, bool external_fence_fd_enabled, bool external_semaphore_fd_enabled, bool timeline_semaphore_enabled, + bool image_format_list_enabled, bool debug_utils_enabled, bool renderdoc_enabled, uint32_t queueFamilyIndex, @@ -872,6 +874,7 @@ client_vk_compositor_create(struct xrt_compositor_native *xcn, external_fence_fd_enabled, // external_fence_fd_enabled external_semaphore_fd_enabled, // external_semaphore_fd_enabled timeline_semaphore_enabled, // timeline_semaphore_enabled + image_format_list_enabled, // image_format_list_enabled debug_utils_enabled, // debug_utils_enabled log_level); // log_level if (ret != VK_SUCCESS) { diff --git a/src/xrt/compositor/client/comp_vk_client.h b/src/xrt/compositor/client/comp_vk_client.h index 4acc0c4c7..05d398266 100644 --- a/src/xrt/compositor/client/comp_vk_client.h +++ b/src/xrt/compositor/client/comp_vk_client.h @@ -1,10 +1,11 @@ -// Copyright 2019-2023, Collabora, Ltd. +// Copyright 2019-2024, Collabora, Ltd. // SPDX-License-Identifier: BSL-1.0 /*! * @file * @brief Vulkan client side glue to compositor header. * @author Jakob Bornecrantz * @author Lubosz Sarnecki + * @author Korcan Hussein * @ingroup comp_client */ @@ -108,6 +109,7 @@ client_vk_compositor_create(struct xrt_compositor_native *xcn, bool external_fence_fd_enabled, bool external_semaphore_fd_enabled, bool timeline_semaphore_enabled, + bool image_format_list_enabled, bool debug_utils_enabled, bool renderdoc_enabled, uint32_t queueFamilyIndex, diff --git a/src/xrt/compositor/client/comp_vk_glue.c b/src/xrt/compositor/client/comp_vk_glue.c index 0ea298900..783e5164d 100644 --- a/src/xrt/compositor/client/comp_vk_glue.c +++ b/src/xrt/compositor/client/comp_vk_glue.c @@ -1,9 +1,10 @@ -// Copyright 2019, Collabora, Ltd. +// Copyright 2019-2024, Collabora, Ltd. // SPDX-License-Identifier: BSL-1.0 /*! * @file * @brief Glue code to vulkan client side code. * @author Jakob Bornecrantz + * @author Korcan Hussein * @ingroup comp_client */ @@ -26,6 +27,7 @@ const char *xrt_gfx_vk_instance_extensions = VK_KHR_EXTERNAL_FENCE_CAPABILITIES_ const char *xrt_gfx_vk_device_extensions = VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME " " VK_KHR_EXTERNAL_FENCE_EXTENSION_NAME " " VK_KHR_EXTERNAL_MEMORY_EXTENSION_NAME " " VK_KHR_EXTERNAL_SEMAPHORE_EXTENSION_NAME " " VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME + " " VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME // Platform version of "external_memory" #if defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_FD) @@ -76,6 +78,7 @@ xrt_gfx_vk_provider_create(struct xrt_compositor_native *xcn, bool external_fence_fd_enabled, bool external_semaphore_fd_enabled, bool timeline_semaphore_enabled, + bool image_format_list_enabled, bool debug_utils_enabled, bool renderdoc_enabled, uint32_t queue_family_index, @@ -90,6 +93,7 @@ xrt_gfx_vk_provider_create(struct xrt_compositor_native *xcn, external_fence_fd_enabled, // external_semaphore_fd_enabled, // timeline_semaphore_enabled, // + image_format_list_enabled, // debug_utils_enabled, // renderdoc_enabled, // queue_family_index, // diff --git a/src/xrt/include/xrt/xrt_gfx_vk.h b/src/xrt/include/xrt/xrt_gfx_vk.h index 5f13263b2..1bcfa4541 100644 --- a/src/xrt/include/xrt/xrt_gfx_vk.h +++ b/src/xrt/include/xrt/xrt_gfx_vk.h @@ -1,9 +1,10 @@ -// Copyright 2019, Collabora, Ltd. +// Copyright 2019-2024, Collabora, Ltd. // SPDX-License-Identifier: BSL-1.0 /*! * @file * @brief Header defining an XRT graphics provider. * @author Jakob Bornecrantz + * @author Korcan Hussein * @ingroup xrt_iface */ @@ -64,6 +65,7 @@ xrt_gfx_vk_provider_create(struct xrt_compositor_native *xcn, bool external_fence_fd_enabled, bool external_semaphore_fd_enabled, bool timeline_semaphore_enabled, + bool image_format_list_enabled, bool debug_utils_enabled, bool renderdoc_enabled, uint32_t queue_family_index, diff --git a/src/xrt/state_trackers/oxr/oxr_objects.h b/src/xrt/state_trackers/oxr/oxr_objects.h index bd229cc57..7c2a9c268 100644 --- a/src/xrt/state_trackers/oxr/oxr_objects.h +++ b/src/xrt/state_trackers/oxr/oxr_objects.h @@ -1503,6 +1503,7 @@ struct oxr_system bool external_semaphore_fd_enabled; bool timeline_semaphore_enabled; bool debug_utils_enabled; + bool image_format_list_enabled; } vk; #endif diff --git a/src/xrt/state_trackers/oxr/oxr_session_gfx_vk.c b/src/xrt/state_trackers/oxr/oxr_session_gfx_vk.c index f955429d0..c95aa41d0 100644 --- a/src/xrt/state_trackers/oxr/oxr_session_gfx_vk.c +++ b/src/xrt/state_trackers/oxr/oxr_session_gfx_vk.c @@ -1,9 +1,10 @@ -// Copyright 2018-2022, Collabora, Ltd. +// Copyright 2018-2024, Collabora, Ltd. // SPDX-License-Identifier: BSL-1.0 /*! * @file * @brief Holds Vulkan specific session functions. * @author Jakob Bornecrantz + * @author Korcan Hussein * @ingroup oxr_main * @ingroup comp_client */ @@ -82,6 +83,8 @@ oxr_session_populate_vk(struct oxr_logger *log, bool timeline_semaphore_enabled = sess->sys->vk.timeline_semaphore_enabled; bool external_fence_fd_enabled = sess->sys->vk.external_fence_fd_enabled; bool external_semaphore_fd_enabled = sess->sys->vk.external_semaphore_fd_enabled; + bool image_format_list_enabled = + sys->inst->extensions.KHR_vulkan_enable || sess->sys->vk.image_format_list_enabled; bool debug_utils_enabled = false; bool renderdoc_enabled = false; @@ -146,6 +149,7 @@ oxr_session_populate_vk(struct oxr_logger *log, external_fence_fd_enabled, // external_semaphore_fd_enabled, // timeline_semaphore_enabled, // + image_format_list_enabled, // debug_utils_enabled, // renderdoc_enabled, // next->queueFamilyIndex, // diff --git a/src/xrt/state_trackers/oxr/oxr_vulkan.c b/src/xrt/state_trackers/oxr/oxr_vulkan.c index 432c82164..b919dd88e 100644 --- a/src/xrt/state_trackers/oxr/oxr_vulkan.c +++ b/src/xrt/state_trackers/oxr/oxr_vulkan.c @@ -1,9 +1,10 @@ -// Copyright 2018-2020, Collabora, Ltd. +// Copyright 2018-2024, Collabora, Ltd. // SPDX-License-Identifier: BSL-1.0 /*! * @file * @brief Holds Vulkan related functions. * @author Jakob Bornecrantz + * @author Korcan Hussein * @ingroup oxr_main */ @@ -428,6 +429,7 @@ oxr_vk_create_vulkan_device(struct oxr_logger *log, bool external_fence_fd_enabled = false; bool external_semaphore_fd_enabled = false; #endif + bool image_format_list_enabled = false; for (uint32_t i = 0; i < ARRAY_SIZE(optional_device_extensions); i++) { // Empty list or a not supported extension. @@ -446,6 +448,10 @@ oxr_vk_create_vulkan_device(struct oxr_logger *log, external_semaphore_fd_enabled = true; } #endif + + if (strcmp(optional_device_extensions[i], VK_KHR_IMAGE_FORMAT_LIST_EXTENSION_NAME) == 0) { + image_format_list_enabled = true; + } } free(props); @@ -549,6 +555,12 @@ oxr_vk_create_vulkan_device(struct oxr_logger *log, } #endif +#ifdef VK_KHR_image_format_list + if (*vulkanResult == VK_SUCCESS) { + sys->vk.image_format_list_enabled = image_format_list_enabled; + } +#endif + u_string_list_destroy(&device_extension_list); return XR_SUCCESS; diff --git a/tests/tests_comp_client_vulkan.cpp b/tests/tests_comp_client_vulkan.cpp index 6c1ec059e..e8f954833 100644 --- a/tests/tests_comp_client_vulkan.cpp +++ b/tests/tests_comp_client_vulkan.cpp @@ -1,9 +1,10 @@ -// Copyright 2022, Collabora, Ltd. +// Copyright 2022-2024, Collabora, Ltd. // SPDX-License-Identifier: BSL-1.0 /*! * @file * @brief Basic Vulkan compositor tests. * @author Rylie Pavlik + * @author Korcan Hussein */ @@ -148,9 +149,10 @@ TEST_CASE("client_compositor", "[.][needgpu]") #else #error "Need port for fence sync handles checkers" #endif - false, // debug_utils_enabled - false, // renderdoc_enabled - vk->queue_family_index, // + vk->has_KHR_image_format_list, // image_format_list_enabled + false, // debug_utils_enabled + false, // renderdoc_enabled + vk->queue_family_index, // vk->queue_index); struct xrt_compositor *xc = &xcvk->base;