From c5230c075cab81cf756c1642540df9eed73f27ca Mon Sep 17 00:00:00 2001 From: Patrick Nicolas Date: Sat, 20 Jan 2024 12:53:46 +0100 Subject: [PATCH] c/main: Compositor targets can set more parameters Allow compositor targets to require a minimum Vulkan version, and additional optional device extensions. --- src/xrt/compositor/main/comp_compositor.c | 12 +++++++++++- src/xrt/compositor/main/comp_target.h | 12 ++++++++++++ src/xrt/compositor/main/comp_window_android.c | 3 +++ src/xrt/compositor/main/comp_window_direct_nvidia.c | 3 +++ src/xrt/compositor/main/comp_window_direct_randr.c | 3 +++ src/xrt/compositor/main/comp_window_direct_wayland.c | 3 +++ src/xrt/compositor/main/comp_window_mswin.c | 3 +++ src/xrt/compositor/main/comp_window_vk_display.c | 3 +++ src/xrt/compositor/main/comp_window_wayland.c | 3 +++ src/xrt/compositor/main/comp_window_xcb.c | 3 +++ 10 files changed, 47 insertions(+), 1 deletion(-) diff --git a/src/xrt/compositor/main/comp_compositor.c b/src/xrt/compositor/main/comp_compositor.c index cbbd5790a..a16827a4c 100644 --- a/src/xrt/compositor/main/comp_compositor.c +++ b/src/xrt/compositor/main/comp_compositor.c @@ -46,6 +46,8 @@ #include "xrt/xrt_config_have.h" #include "xrt/xrt_results.h" +#include "math/m_api.h" + #include "os/os_time.h" #include "util/u_var.h" @@ -614,6 +616,14 @@ compositor_init_vulkan(struct comp_compositor *c) optional_device_extensions, // ARRAY_SIZE(optional_device_extensions)); // + // Add per target optional device extensions. + u_string_list_append_array( // + optional_device_extension_list, // + c->target_factory->optional_device_extensions, // + c->target_factory->optional_device_extension_count); // + + // Select required Vulkan version, suitable for both compositor and target + uint32_t required_instance_version = MAX(c->target_factory->required_instance_version, VK_API_VERSION_1_0); /* * Create the device. @@ -621,7 +631,7 @@ compositor_init_vulkan(struct comp_compositor *c) struct comp_vulkan_arguments vk_args = { .get_instance_proc_address = vkGetInstanceProcAddr, - .required_instance_version = VK_MAKE_VERSION(1, 0, 0), + .required_instance_version = required_instance_version, .required_instance_extensions = required_instance_ext_list, .optional_instance_extensions = optional_instance_ext_list, .required_device_extensions = required_device_extension_list, diff --git a/src/xrt/compositor/main/comp_target.h b/src/xrt/compositor/main/comp_target.h index 389ab1894..bababbe1d 100644 --- a/src/xrt/compositor/main/comp_target.h +++ b/src/xrt/compositor/main/comp_target.h @@ -593,12 +593,24 @@ struct comp_target_factory */ bool is_deferred; + /*! + * Vulkan version that is required or 0 if no specific + * requirement, equivalent to VK_MAKE_VERSION(1, 0, 0) + */ + uint32_t required_instance_version; + //! Required instance extensions. const char **required_instance_extensions; //! Required instance extension count. size_t required_instance_extension_count; + //! Optional device extensions. + const char **optional_device_extensions; + + //! Optional device extension count. + size_t optional_device_extension_count; + /*! * Checks if this target can be detected, is the preferred target or * some other special consideration that this target should be used over diff --git a/src/xrt/compositor/main/comp_window_android.c b/src/xrt/compositor/main/comp_window_android.c index 4730753c3..67352150a 100644 --- a/src/xrt/compositor/main/comp_window_android.c +++ b/src/xrt/compositor/main/comp_window_android.c @@ -240,8 +240,11 @@ const struct comp_target_factory comp_target_factory_android = { .identifier = "android", .requires_vulkan_for_create = false, .is_deferred = true, + .required_instance_version = 0, .required_instance_extensions = instance_extensions, .required_instance_extension_count = ARRAY_SIZE(instance_extensions), + .optional_device_extensions = NULL, + .optional_device_extension_count = 0, .detect = detect, .create_target = create_target, }; diff --git a/src/xrt/compositor/main/comp_window_direct_nvidia.c b/src/xrt/compositor/main/comp_window_direct_nvidia.c index a65c27a2a..71287c506 100644 --- a/src/xrt/compositor/main/comp_window_direct_nvidia.c +++ b/src/xrt/compositor/main/comp_window_direct_nvidia.c @@ -476,8 +476,11 @@ const struct comp_target_factory comp_target_factory_direct_nvidia = { .identifier = "x11_direct_nvidia", .requires_vulkan_for_create = true, .is_deferred = false, + .required_instance_version = 0, .required_instance_extensions = instance_extensions, .required_instance_extension_count = ARRAY_SIZE(instance_extensions), + .optional_device_extensions = NULL, + .optional_device_extension_count = 0, .detect = detect, .create_target = create_target, }; diff --git a/src/xrt/compositor/main/comp_window_direct_randr.c b/src/xrt/compositor/main/comp_window_direct_randr.c index fc570467c..2d773b3f8 100644 --- a/src/xrt/compositor/main/comp_window_direct_randr.c +++ b/src/xrt/compositor/main/comp_window_direct_randr.c @@ -502,8 +502,11 @@ const struct comp_target_factory comp_target_factory_direct_randr = { .identifier = "x11_direct", .requires_vulkan_for_create = false, .is_deferred = false, + .required_instance_version = 0, .required_instance_extensions = instance_extensions, .required_instance_extension_count = ARRAY_SIZE(instance_extensions), + .optional_device_extensions = NULL, + .optional_device_extension_count = 0, .detect = detect, .create_target = create_target, }; diff --git a/src/xrt/compositor/main/comp_window_direct_wayland.c b/src/xrt/compositor/main/comp_window_direct_wayland.c index 0f0f57d70..e21ae0fd5 100644 --- a/src/xrt/compositor/main/comp_window_direct_wayland.c +++ b/src/xrt/compositor/main/comp_window_direct_wayland.c @@ -506,8 +506,11 @@ const struct comp_target_factory comp_target_factory_direct_wayland = { .identifier = "direct_wayland", .requires_vulkan_for_create = false, .is_deferred = false, + .required_instance_version = 0, .required_instance_extensions = instance_extensions, .required_instance_extension_count = ARRAY_SIZE(instance_extensions), + .optional_device_extensions = NULL, + .optional_device_extension_count = 0, .detect = detect, .create_target = create_target, }; diff --git a/src/xrt/compositor/main/comp_window_mswin.c b/src/xrt/compositor/main/comp_window_mswin.c index 180b5b8c2..2cf7f06f2 100644 --- a/src/xrt/compositor/main/comp_window_mswin.c +++ b/src/xrt/compositor/main/comp_window_mswin.c @@ -438,8 +438,11 @@ const struct comp_target_factory comp_target_factory_mswin = { .identifier = "mswin", .requires_vulkan_for_create = false, .is_deferred = true, + .required_instance_version = 0, .required_instance_extensions = instance_extensions, .required_instance_extension_count = ARRAY_SIZE(instance_extensions), + .optional_device_extensions = NULL, + .optional_device_extension_count = 0, .detect = detect, .create_target = create_target, }; diff --git a/src/xrt/compositor/main/comp_window_vk_display.c b/src/xrt/compositor/main/comp_window_vk_display.c index abc867394..e8bbe95f7 100644 --- a/src/xrt/compositor/main/comp_window_vk_display.c +++ b/src/xrt/compositor/main/comp_window_vk_display.c @@ -301,8 +301,11 @@ const struct comp_target_factory comp_target_factory_vk_display = { .identifier = "vk_display", .requires_vulkan_for_create = true, .is_deferred = false, + .required_instance_version = 0, .required_instance_extensions = instance_extensions, .required_instance_extension_count = ARRAY_SIZE(instance_extensions), + .optional_device_extensions = NULL, + .optional_device_extension_count = 0, .detect = detect, .create_target = create_target, }; diff --git a/src/xrt/compositor/main/comp_window_wayland.c b/src/xrt/compositor/main/comp_window_wayland.c index 96b1216f2..f6db5707b 100644 --- a/src/xrt/compositor/main/comp_window_wayland.c +++ b/src/xrt/compositor/main/comp_window_wayland.c @@ -387,8 +387,11 @@ const struct comp_target_factory comp_target_factory_wayland = { .identifier = "wayland", .requires_vulkan_for_create = false, .is_deferred = false, + .required_instance_version = 0, .required_instance_extensions = instance_extensions, .required_instance_extension_count = ARRAY_SIZE(instance_extensions), + .optional_device_extensions = NULL, + .optional_device_extension_count = 0, .detect = detect, .create_target = create_target, }; diff --git a/src/xrt/compositor/main/comp_window_xcb.c b/src/xrt/compositor/main/comp_window_xcb.c index 3e643669d..727d71fe3 100644 --- a/src/xrt/compositor/main/comp_window_xcb.c +++ b/src/xrt/compositor/main/comp_window_xcb.c @@ -496,8 +496,11 @@ const struct comp_target_factory comp_target_factory_xcb = { .identifier = "x11", .requires_vulkan_for_create = false, .is_deferred = true, + .required_instance_version = 0, .required_instance_extensions = instance_extensions, .required_instance_extension_count = ARRAY_SIZE(instance_extensions), + .optional_device_extensions = NULL, + .optional_device_extension_count = 0, .detect = detect, .create_target = create_target, };