From ff4d492b747214fc5494a2a3413790f221d11d1a Mon Sep 17 00:00:00 2001 From: Christoph Haag Date: Mon, 6 Dec 2021 23:42:30 +0100 Subject: [PATCH] c/util: add optional vk instance extensions --- src/xrt/compositor/main/comp_compositor.c | 2 +- src/xrt/compositor/util/comp_vulkan.c | 30 +++++++++++++++++++++-- src/xrt/compositor/util/comp_vulkan.h | 5 +++- 3 files changed, 33 insertions(+), 4 deletions(-) diff --git a/src/xrt/compositor/main/comp_compositor.c b/src/xrt/compositor/main/comp_compositor.c index 08ebbf43a..6aa1eb608 100644 --- a/src/xrt/compositor/main/comp_compositor.c +++ b/src/xrt/compositor/main/comp_compositor.c @@ -714,7 +714,7 @@ compositor_init_vulkan(struct comp_compositor *c) struct comp_vulkan_arguments vk_args = { .get_instance_proc_address = vkGetInstanceProcAddr, - .instance_extensions = instance_extension_list, + .required_instance_extensions = instance_extension_list, .required_device_extensions = required_device_extension_list, .optional_device_extensions = optional_device_extension_list, .log_level = c->settings.log_level, diff --git a/src/xrt/compositor/util/comp_vulkan.c b/src/xrt/compositor/util/comp_vulkan.c index 9683e53ee..b9cd67642 100644 --- a/src/xrt/compositor/util/comp_vulkan.c +++ b/src/xrt/compositor/util/comp_vulkan.c @@ -110,6 +110,30 @@ create_instance(struct vk_bundle *vk, const struct comp_vulkan_arguments *vk_arg { VkResult ret; + uint32_t prop_count = 0; + vk->vkEnumerateInstanceExtensionProperties(NULL, &prop_count, NULL); + + VkExtensionProperties *props = U_TYPED_ARRAY_CALLOC(VkExtensionProperties, prop_count); + vk->vkEnumerateInstanceExtensionProperties(NULL, &prop_count, props); + + struct u_string_list *instance_ext_list = u_string_list_create_from_list(vk_args->required_instance_extensions); + + + uint32_t optional_instance_ext_count = u_string_list_get_size(vk_args->optional_instance_extensions); + const char *const *optional_instance_exts = u_string_list_get_data(vk_args->optional_instance_extensions); + for (uint32_t i = 0; i < optional_instance_ext_count; i++) { + const char *optional_ext = optional_instance_exts[i]; + for (uint32_t j = 0; j < prop_count; j++) { + if (strcmp(optional_ext, props[j].extensionName) == 0) { + int added = u_string_list_append_unique(instance_ext_list, optional_ext); + if (added == 0) { + VK_ERROR(vk, "Duplicate device extension %s not added twice", optional_ext); + } + break; + } + } + } + VkApplicationInfo app_info = { .sType = VK_STRUCTURE_TYPE_APPLICATION_INFO, .pApplicationName = "Monado Compositor", @@ -120,8 +144,8 @@ create_instance(struct vk_bundle *vk, const struct comp_vulkan_arguments *vk_arg VkInstanceCreateInfo instance_info = { .sType = VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO, .pApplicationInfo = &app_info, - .enabledExtensionCount = u_string_list_get_size(vk_args->instance_extensions), - .ppEnabledExtensionNames = u_string_list_get_data(vk_args->instance_extensions), + .enabledExtensionCount = u_string_list_get_size(instance_ext_list), + .ppEnabledExtensionNames = u_string_list_get_data(instance_ext_list), }; ret = vk->vkCreateInstance(&instance_info, NULL, &vk->instance); @@ -130,6 +154,8 @@ create_instance(struct vk_bundle *vk, const struct comp_vulkan_arguments *vk_arg return ret; } + u_string_list_destroy(&instance_ext_list); + ret = vk_get_instance_functions(vk); if (ret != VK_SUCCESS) { VK_ERROR_RET(vk, "vk_get_instance_functions", "Failed to get Vulkan instance functions.", ret); diff --git a/src/xrt/compositor/util/comp_vulkan.h b/src/xrt/compositor/util/comp_vulkan.h index d8599cd00..c92a10f76 100644 --- a/src/xrt/compositor/util/comp_vulkan.h +++ b/src/xrt/compositor/util/comp_vulkan.h @@ -29,7 +29,10 @@ struct comp_vulkan_arguments PFN_vkGetInstanceProcAddr get_instance_proc_address; //! Extensions that the instance is created with. - struct u_string_list *instance_extensions; + struct u_string_list *required_instance_extensions; + + //! Extensions that the instance is created with. + struct u_string_list *optional_instance_extensions; //! Extensions that the device is created with. struct u_string_list *required_device_extensions;