From b1f9e5811a4eec83f9ab24e358476b152851231e Mon Sep 17 00:00:00 2001 From: Dennis Tsiang Date: Tue, 20 Aug 2024 11:46:07 +0000 Subject: [PATCH] Add initial support for VK_KHR_present_id Layer updated to advertise support for the VK_KHR_present_id extension. vkGetPhysicalDeviceFeatures2KHR and vkCreateDevice updated to handle the new struct. Also add the extensions enabled by the layer to the instance_data and device_data objects so that the layer can correctly check which extensions have been enabled. Signed-off-by: Dennis Tsiang Change-Id: I71ae2b28c94d3f16b485a06094712d6c3f6c7e77 --- layer/VkLayer_window_system_integration.json | 1 + layer/layer.cpp | 16 +++++++++++++++- layer/private_data.cpp | 6 ++++++ layer/private_data.hpp | 13 +++++++++++++ 4 files changed, 35 insertions(+), 1 deletion(-) diff --git a/layer/VkLayer_window_system_integration.json b/layer/VkLayer_window_system_integration.json index d502030..276b937 100644 --- a/layer/VkLayer_window_system_integration.json +++ b/layer/VkLayer_window_system_integration.json @@ -36,6 +36,7 @@ "vkGetPhysicalDevicePresentRectanglesKHR" ] }, + {"name": "VK_KHR_present_id", "spec_version": "1"}, { "name": "VK_EXT_swapchain_maintenance1", "spec_version": "1", diff --git a/layer/layer.cpp b/layer/layer.cpp index d367e40..6f6a408 100644 --- a/layer/layer.cpp +++ b/layer/layer.cpp @@ -193,7 +193,7 @@ VKAPI_ATTR VkResult create_instance(const VkInstanceCreateInfo *pCreateInfo, con */ VkResult result = instance_private_data::get(*pInstance) - .set_instance_enabled_extensions(pCreateInfo->ppEnabledExtensionNames, pCreateInfo->enabledExtensionCount); + .set_instance_enabled_extensions(modified_enabled_extensions.data(), modified_enabled_extensions.size()); if (result != VK_SUCCESS) { instance_private_data::disassociate(*pInstance); @@ -312,6 +312,13 @@ VKAPI_ATTR VkResult create_device(VkPhysicalDevice physicalDevice, const VkDevic } #endif + const auto present_id_features = util::find_extension( + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENT_ID_FEATURES_KHR, pCreateInfo->pNext); + if (present_id_features != nullptr) + { + layer::device_private_data::get(*pDevice).set_present_id_feature_enabled(present_id_features->presentId); + } + auto *physical_device_swapchain_maintenance1_features = util::find_extension( VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SWAPCHAIN_MAINTENANCE_1_FEATURES_EXT, pCreateInfo->pNext); @@ -426,6 +433,13 @@ wsi_layer_vkGetPhysicalDeviceFeatures2KHR(VkPhysicalDevice physicalDevice, } #endif + auto *present_id_features = util::find_extension( + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENT_ID_FEATURES_KHR, pFeatures->pNext); + if (present_id_features != nullptr) + { + present_id_features->presentId = true; + } + auto *physical_device_swapchain_maintenance1_features = util::find_extension( VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_SWAPCHAIN_MAINTENANCE_1_FEATURES_EXT, pFeatures->pNext); diff --git a/layer/private_data.cpp b/layer/private_data.cpp index f723b98..0223e04 100644 --- a/layer/private_data.cpp +++ b/layer/private_data.cpp @@ -395,6 +395,7 @@ device_private_data::device_private_data(instance_private_data &inst_data, VkPhy #if WSI_IMAGE_COMPRESSION_CONTROL_SWAPCHAIN , compression_control_enabled{ false } #endif /* WSI_IMAGE_COMPRESSION_CONTROL_SWAPCHAIN */ + , present_id_enabled { false } , swapchain_maintenance1_enabled{ false } /* clang-format on */ { @@ -548,6 +549,11 @@ bool device_private_data::is_swapchain_compression_control_enabled() const } #endif /* WSI_IMAGE_COMPRESSION_CONTROL_SWAPCHAIN */ +void device_private_data::set_present_id_feature_enabled(bool enable) +{ + present_id_enabled = enable; +} + void device_private_data::set_swapchain_maintenance1_enabled(bool enable) { swapchain_maintenance1_enabled = enable; diff --git a/layer/private_data.hpp b/layer/private_data.hpp index 60884b4..a54ca11 100644 --- a/layer/private_data.hpp +++ b/layer/private_data.hpp @@ -805,6 +805,13 @@ public: bool is_swapchain_compression_control_enabled() const; #endif /* WSI_IMAGE_COMPRESSION_CONTROL_SWAPCHAIN */ + /** + * @brief Set whether the device supports the present ID feature. + * + * @param enable Value to set m_present_id_enabled member variable. + */ + void set_present_id_feature_enabled(bool enable); + /** * @brief Selectively enable/disable the swapchain maintenance1 features for this device. * @@ -862,6 +869,12 @@ private: bool compression_control_enabled; #endif /* WSI_IMAGE_COMPRESSION_CONTROL_SWAPCHAIN */ + /** + * @brief Stores whether the device supports the present ID feature. + * + */ + bool present_id_enabled; + /** * @brief Stores whether the device has enabled support for the swapchain maintenance1 features. */