From 1b8b85d99d2ae77ef95ecebe30e38fab66fa6207 Mon Sep 17 00:00:00 2001 From: Simon Zeni Date: Wed, 28 Aug 2024 11:44:23 -0400 Subject: [PATCH] aux/vk: add support for optional VK_ANDROID_external_format_resolve Part-of: --- scripts/generate_vk_helpers.py | 1 + src/xrt/auxiliary/vk/vk_bundle_init.c | 41 +++++++++++++++++++++++ src/xrt/auxiliary/vk/vk_helpers.h | 2 ++ src/xrt/compositor/main/comp_compositor.c | 6 +++- 4 files changed, 49 insertions(+), 1 deletion(-) diff --git a/scripts/generate_vk_helpers.py b/scripts/generate_vk_helpers.py index fe9e84d40..628aabcd3 100755 --- a/scripts/generate_vk_helpers.py +++ b/scripts/generate_vk_helpers.py @@ -305,6 +305,7 @@ DEVICE_EXTENSIONS_TO_CHECK = [ "VK_EXT_global_priority", "VK_EXT_image_drm_format_modifier", "VK_EXT_robustness2", + "VK_ANDROID_external_format_resolve", "VK_GOOGLE_display_timing", ] diff --git a/src/xrt/auxiliary/vk/vk_bundle_init.c b/src/xrt/auxiliary/vk/vk_bundle_init.c index 2e3242ee7..65773cff7 100644 --- a/src/xrt/auxiliary/vk/vk_bundle_init.c +++ b/src/xrt/auxiliary/vk/vk_bundle_init.c @@ -756,6 +756,7 @@ fill_in_has_device_extensions(struct vk_bundle *vk, struct u_string_list *ext_li vk->has_EXT_global_priority = false; vk->has_EXT_image_drm_format_modifier = false; vk->has_EXT_robustness2 = false; + vk->has_ANDROID_external_format_resolve = false; vk->has_GOOGLE_display_timing = false; const char *const *exts = u_string_list_get_data(ext_list); @@ -883,6 +884,13 @@ fill_in_has_device_extensions(struct vk_bundle *vk, struct u_string_list *ext_li } #endif // defined(VK_EXT_robustness2) +#if defined(VK_ANDROID_external_format_resolve) + if (strcmp(ext, VK_ANDROID_EXTERNAL_FORMAT_RESOLVE_EXTENSION_NAME) == 0) { + vk->has_ANDROID_external_format_resolve = true; + continue; + } +#endif // defined(VK_ANDROID_external_format_resolve) + #if defined(VK_GOOGLE_display_timing) if (strcmp(ext, VK_GOOGLE_DISPLAY_TIMING_EXTENSION_NAME) == 0) { vk->has_GOOGLE_display_timing = true; @@ -1030,6 +1038,13 @@ filter_device_features(struct vk_bundle *vk, }; #endif +#ifdef VK_ANDROID_external_format_resolve + VkPhysicalDeviceExternalFormatResolveFeaturesANDROID ext_fmt_resolve_info = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_FORMAT_RESOLVE_FEATURES_ANDROID, + .pNext = NULL, + }; +#endif + VkPhysicalDeviceFeatures2 physical_device_features = { .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, .pNext = NULL, @@ -1056,6 +1071,13 @@ filter_device_features(struct vk_bundle *vk, } #endif +#ifdef VK_ANDROID_external_format_resolve + if (vk->has_ANDROID_external_format_resolve) { + append_to_pnext_chain((VkBaseInStructure *)&physical_device_features, + (VkBaseInStructure *)&ext_fmt_resolve_info); + } +#endif + vk->vkGetPhysicalDeviceFeatures2( // physical_device, // physicalDevice &physical_device_features); // pFeatures @@ -1079,6 +1101,10 @@ filter_device_features(struct vk_bundle *vk, CHECK(synchronization_2, synchronization_2_info.synchronization2); #endif +#ifdef VK_ANDROID_external_format_resolve + CHECK(ext_fmt_resolve, ext_fmt_resolve_info.externalFormatResolve); +#endif + CHECK(shader_image_gather_extended, physical_device_features.features.shaderImageGatherExtended); CHECK(shader_storage_image_write_without_format, @@ -1243,6 +1269,14 @@ vk_create_device(struct vk_bundle *vk, }; #endif +#ifdef VK_ANDROID_external_format_resolve + VkPhysicalDeviceExternalFormatResolveFeaturesANDROID ext_fmt_resolve_info = { + .sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_EXTERNAL_FORMAT_RESOLVE_FEATURES_ANDROID, + .pNext = NULL, + .externalFormatResolve = device_features.ext_fmt_resolve, + }; +#endif + VkPhysicalDeviceFeatures enabled_features = { .shaderImageGatherExtended = device_features.shader_image_gather_extended, .shaderStorageImageWriteWithoutFormat = device_features.shader_storage_image_write_without_format, @@ -1277,6 +1311,13 @@ vk_create_device(struct vk_bundle *vk, } #endif +#ifdef VK_ANDROID_external_format_resolve + if (vk->has_ANDROID_external_format_resolve) { + append_to_pnext_chain((VkBaseInStructure *)&device_create_info, + (VkBaseInStructure *)&ext_fmt_resolve_info); + } +#endif + ret = vk->vkCreateDevice(vk->physical_device, &device_create_info, NULL, &vk->device); u_string_list_destroy(&device_ext_list); diff --git a/src/xrt/auxiliary/vk/vk_helpers.h b/src/xrt/auxiliary/vk/vk_helpers.h index 1e63d3053..cddf67a4b 100644 --- a/src/xrt/auxiliary/vk/vk_helpers.h +++ b/src/xrt/auxiliary/vk/vk_helpers.h @@ -142,6 +142,7 @@ struct vk_bundle bool has_EXT_global_priority; bool has_EXT_image_drm_format_modifier; bool has_EXT_robustness2; + bool has_ANDROID_external_format_resolve; bool has_GOOGLE_display_timing; // end of GENERATED device extension code - do not modify - used by scripts @@ -996,6 +997,7 @@ struct vk_device_features bool null_descriptor; bool timeline_semaphore; bool synchronization_2; + bool ext_fmt_resolve; }; /*! diff --git a/src/xrt/compositor/main/comp_compositor.c b/src/xrt/compositor/main/comp_compositor.c index 0004692d6..2626f8671 100644 --- a/src/xrt/compositor/main/comp_compositor.c +++ b/src/xrt/compositor/main/comp_compositor.c @@ -556,7 +556,11 @@ static const char *optional_device_extensions[] = { VK_KHR_EXTERNAL_FENCE_FD_EXTENSION_NAME, // #elif defined(XRT_GRAPHICS_SYNC_HANDLE_IS_WIN32_HANDLE) // Not optional - +#elif defined(XRT_GRAPHICS_BUFFER_HANDLE_IS_AHARDWAREBUFFER) +#if defined(VK_ANDROID_external_format_resolve) + // Requires Vulkan 1.3.268.1 + VK_ANDROID_EXTERNAL_FORMAT_RESOLVE_EXTENSION_NAME // +#endif #else #error "Need port!" #endif