vulkan: Enable VK_EXT_swapchain_maintenance1 if available

This just adds the plumbing, usage will happen later.

For testing, GDK_VULKAN_DISABLE=swapchain-maintenance will turn it off.
This commit is contained in:
Benjamin Otte 2024-09-04 20:37:20 +02:00
parent 5a027594c3
commit 6c72a223f5
2 changed files with 26 additions and 0 deletions

View File

@ -48,6 +48,7 @@ typedef enum {
GDK_VULKAN_FEATURE_SEMAPHORE_EXPORT = 1 << 2,
GDK_VULKAN_FEATURE_SEMAPHORE_IMPORT = 1 << 3,
GDK_VULKAN_FEATURE_INCREMENTAL_PRESENT = 1 << 4,
GDK_VULKAN_FEATURE_SWAPCHAIN_MAINTENANCE = 1 << 5,
} GdkVulkanFeatures;
/* Tracks information about the device grab on this display */

View File

@ -41,6 +41,7 @@ static const GdkDebugKey gsk_vulkan_feature_keys[] = {
{ "semaphore-export", GDK_VULKAN_FEATURE_SEMAPHORE_EXPORT, "Disable sync of exported dmabufs" },
{ "semaphore-import", GDK_VULKAN_FEATURE_SEMAPHORE_IMPORT, "Disable sync of imported dmabufs" },
{ "incremental-present", GDK_VULKAN_FEATURE_INCREMENTAL_PRESENT, "Do not send damage regions" },
{ "swapchain-maintenance", GDK_VULKAN_FEATURE_SWAPCHAIN_MAINTENANCE, "Do not used advanced swapchain features" },
};
#endif
@ -565,8 +566,12 @@ physical_device_supports_extension (VkPhysicalDevice device,
static GdkVulkanFeatures
physical_device_check_features (VkPhysicalDevice device)
{
VkPhysicalDeviceSwapchainMaintenance1FeaturesEXT swapchain_maintenance1_features = {
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SWAPCHAIN_MAINTENANCE_1_FEATURES_EXT,
};
VkPhysicalDeviceVulkan12Features v12_features = {
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES,
.pNext = &swapchain_maintenance1_features
};
VkPhysicalDeviceSamplerYcbcrConversionFeatures ycbcr_features = {
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SAMPLER_YCBCR_CONVERSION_FEATURES,
@ -612,6 +617,10 @@ physical_device_check_features (VkPhysicalDevice device)
if (physical_device_supports_extension (device, VK_KHR_INCREMENTAL_PRESENT_EXTENSION_NAME))
features |= GDK_VULKAN_FEATURE_INCREMENTAL_PRESENT;
if (swapchain_maintenance1_features.swapchainMaintenance1 ||
physical_device_supports_extension (device, VK_EXT_SWAPCHAIN_MAINTENANCE_1_EXTENSION_NAME))
features |= GDK_VULKAN_FEATURE_SWAPCHAIN_MAINTENANCE;
return features;
}
@ -1515,6 +1524,11 @@ gdk_display_create_vulkan_device (GdkDisplay *display,
{
if (queue_props[j].queueFlags & VK_QUEUE_GRAPHICS_BIT)
{
VkPhysicalDeviceSwapchainMaintenance1FeaturesEXT swapchain_maintenance1_features = {
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SWAPCHAIN_MAINTENANCE_1_FEATURES_EXT,
.swapchainMaintenance1 = VK_TRUE,
};
gpointer create_device_pNext = NULL;
GPtrArray *device_extensions;
device_extensions = g_ptr_array_new ();
@ -1543,6 +1557,12 @@ gdk_display_create_vulkan_device (GdkDisplay *display,
}
if (features & GDK_VULKAN_FEATURE_INCREMENTAL_PRESENT)
g_ptr_array_add (device_extensions, (gpointer) VK_KHR_INCREMENTAL_PRESENT_EXTENSION_NAME);
if (features & GDK_VULKAN_FEATURE_SWAPCHAIN_MAINTENANCE)
{
g_ptr_array_add (device_extensions, (gpointer) VK_EXT_SWAPCHAIN_MAINTENANCE_1_EXTENSION_NAME);
swapchain_maintenance1_features.pNext = create_device_pNext;
create_device_pNext = &swapchain_maintenance1_features;
}
#define ENABLE_IF(flag) ((features & (flag)) ? VK_TRUE : VK_FALSE)
GDK_DISPLAY_DEBUG (display, VULKAN, "Using Vulkan device %u, queue %u", i, j);
@ -1561,6 +1581,7 @@ gdk_display_create_vulkan_device (GdkDisplay *display,
.pNext = &(VkPhysicalDeviceVulkan11Features) {
.sType = VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_1_FEATURES,
.samplerYcbcrConversion = ENABLE_IF (GDK_VULKAN_FEATURE_YCBCR),
.pNext = create_device_pNext,
}
},
NULL,
@ -1679,6 +1700,10 @@ gdk_display_create_vulkan_instance (GdkDisplay *display,
g_ptr_array_add (used_extensions, (gpointer) VK_KHR_EXTERNAL_MEMORY_CAPABILITIES_EXTENSION_NAME);
if (g_str_equal (extensions[i].extensionName, VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME))
g_ptr_array_add (used_extensions, (gpointer) VK_KHR_EXTERNAL_SEMAPHORE_CAPABILITIES_EXTENSION_NAME);
if (g_str_equal (extensions[i].extensionName, VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME))
g_ptr_array_add (used_extensions, (gpointer) VK_KHR_GET_SURFACE_CAPABILITIES_2_EXTENSION_NAME);
if (g_str_equal (extensions[i].extensionName, VK_EXT_SURFACE_MAINTENANCE_1_EXTENSION_NAME))
g_ptr_array_add (used_extensions, (gpointer) VK_EXT_SURFACE_MAINTENANCE_1_EXTENSION_NAME);
}
res = vkCreateInstance (&(VkInstanceCreateInfo) {