diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c2d6ed..966dc30 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -332,7 +332,7 @@ if (VULKAN_WSI_LAYER_EXPERIMENTAL) target_sources(${PROJECT_NAME} PUBLIC ${PROJECT_SOURCE_DIR}/wsi/extensions/present_timing.cpp) add_definitions("-DVULKAN_WSI_LAYER_EXPERIMENTAL=1") else() - list(APPEND JSON_COMMANDS COMMAND sed -Ei '/VK_EXT_present_timing/d' ${CMAKE_CURRENT_BINARY_DIR}/VkLayer_window_system_integration.json) + list(APPEND JSON_COMMANDS COMMAND sed -Ei '/VK_EXT_present_timing|VK_KHR_present_wait2/d' ${CMAKE_CURRENT_BINARY_DIR}/VkLayer_window_system_integration.json) add_definitions("-DVULKAN_WSI_LAYER_EXPERIMENTAL=0") endif() diff --git a/layer/VkLayer_window_system_integration.json b/layer/VkLayer_window_system_integration.json index c909387..d802b68 100644 --- a/layer/VkLayer_window_system_integration.json +++ b/layer/VkLayer_window_system_integration.json @@ -62,6 +62,13 @@ "vkWaitForPresentKHR" ] }, + { + "name": "VK_KHR_present_wait2", + "spec_version": "1", + "entrypoints": [ + "vkWaitForPresent2KHR" + ] + }, { "name": "VK_EXT_present_mode_fifo_latest_ready", "spec_version": "1" diff --git a/layer/layer.cpp b/layer/layer.cpp index fa5b3a2..ae32e63 100644 --- a/layer/layer.cpp +++ b/layer/layer.cpp @@ -397,6 +397,15 @@ VKAPI_ATTR VkResult create_device(VkPhysicalDevice physicalDevice, const VkDevic device_data.set_present_wait_enabled(present_wait_features->presentWait); } +#if VULKAN_WSI_LAYER_EXPERIMENTAL + auto *present_wait2_features = util::find_extension( + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENT_WAIT_2_FEATURES_KHR, pCreateInfo->pNext); + if (present_wait2_features != nullptr) + { + device_data.set_present_wait2_enabled(present_wait2_features->presentWait2); + } +#endif + return VK_SUCCESS; } @@ -503,6 +512,15 @@ wsi_layer_vkGetPhysicalDeviceFeatures2(VkPhysicalDevice physical_device, present_wait_features->presentWait = VK_FALSE; } +#if VULKAN_WSI_LAYER_EXPERIMENTAL + auto *present_wait2_features = util::find_extension( + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENT_WAIT_2_FEATURES_KHR, pFeatures->pNext); + if (present_wait2_features != nullptr) + { + present_wait2_features->presentWait2 = VK_TRUE; + } +#endif + instance.disp.GetPhysicalDeviceFeatures2KHR(physical_device, pFeatures); auto *image_compression_control_swapchain_features = diff --git a/layer/private_data.cpp b/layer/private_data.cpp index b0acc02..520ccda 100644 --- a/layer/private_data.cpp +++ b/layer/private_data.cpp @@ -433,6 +433,7 @@ device_private_data::device_private_data(instance_private_data &inst_data, VkPhy , swapchain_maintenance1_enabled{ false } #if VULKAN_WSI_LAYER_EXPERIMENTAL , present_timing_enabled { true } + , present_wait2_enabled { false } #endif , present_id2_enabled { false } , present_mode_fifo_latest_ready_enabled { false } @@ -637,6 +638,18 @@ bool device_private_data::is_present_wait_enabled() return present_wait_enabled; } +#if VULKAN_WSI_LAYER_EXPERIMENTAL +void device_private_data::set_present_wait2_enabled(bool enable) +{ + present_wait2_enabled = enable; +} + +bool device_private_data::is_present_wait2_enabled() +{ + return present_wait2_enabled; +} +#endif + void device_private_data::set_present_mode_fifo_latest_ready_enabled(bool enable) { present_mode_fifo_latest_ready_enabled = enable; diff --git a/layer/private_data.hpp b/layer/private_data.hpp index 329fe6c..13e965c 100644 --- a/layer/private_data.hpp +++ b/layer/private_data.hpp @@ -980,6 +980,22 @@ public: */ bool is_present_wait_enabled(); +#if VULKAN_WSI_LAYER_EXPERIMENTAL + /** + * @brief Set whether present wait2 feature is enabled. + * + * @return true if enabled, false otherwise. + */ + void set_present_wait2_enabled(bool enable); + + /** + * @brief Check whether present wait2 feature has been enabled. + * + * @return true if supported, false otherwise. + */ + bool is_present_wait2_enabled(); +#endif + private: /* Allow util::allocator to access the private constructor */ friend util::allocator; @@ -1048,6 +1064,12 @@ private: * @brief Stores whether the device has enabled support for the present timing features. */ bool present_timing_enabled{ false }; + + /** + * @brief Stores whether the device supports the present wait2 feature. + * + */ + bool present_wait2_enabled{ false }; #endif /** diff --git a/wsi/display/surface_properties.cpp b/wsi/display/surface_properties.cpp index cbf36bb..629dac2 100644 --- a/wsi/display/surface_properties.cpp +++ b/wsi/display/surface_properties.cpp @@ -106,6 +106,15 @@ VkResult surface_properties::get_surface_capabilities(VkPhysicalDevice physical_ present_id2_surface_cap->presentId2Supported = VK_TRUE; } +#if VULKAN_WSI_LAYER_EXPERIMENTAL + auto present_wait2_surface_cap = util::find_extension( + VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_PRESENT_WAIT_2_KHR, pSurfaceCapabilities->pNext); + if (present_wait2_surface_cap != nullptr) + { + present_wait2_surface_cap->presentWait2Supported = VK_TRUE; + } +#endif + return VK_SUCCESS; } diff --git a/wsi/display/swapchain.cpp b/wsi/display/swapchain.cpp index 4d9ab9c..47d08c9 100644 --- a/wsi/display/swapchain.cpp +++ b/wsi/display/swapchain.cpp @@ -102,7 +102,12 @@ VkResult swapchain::add_required_extensions(VkDevice device, const VkSwapchainCr } } - if (m_device_data.is_present_wait_enabled()) + if (m_device_data.is_present_wait_enabled() +#if VULKAN_WSI_LAYER_EXPERIMENTAL + || (swapchain_create_info->flags & + (VK_SWAPCHAIN_CREATE_PRESENT_ID_2_BIT_KHR | VK_SWAPCHAIN_CREATE_PRESENT_WAIT_2_BIT_KHR)) +#endif + ) { if (!add_swapchain_extension( m_allocator.make_unique(*get_swapchain_extension(true)))) diff --git a/wsi/headless/surface_properties.cpp b/wsi/headless/surface_properties.cpp index 5c36df4..bb6cd6c 100644 --- a/wsi/headless/surface_properties.cpp +++ b/wsi/headless/surface_properties.cpp @@ -112,6 +112,15 @@ VkResult surface_properties::get_surface_capabilities(VkPhysicalDevice physical_ present_id2_surface_cap->presentId2Supported = VK_TRUE; } +#if VULKAN_WSI_LAYER_EXPERIMENTAL + auto present_wait2_surface_cap = util::find_extension( + VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_PRESENT_WAIT_2_KHR, surface_capabilities->pNext); + if (present_wait2_surface_cap != nullptr) + { + present_wait2_surface_cap->presentWait2Supported = VK_TRUE; + } +#endif + return VK_SUCCESS; } diff --git a/wsi/headless/swapchain.cpp b/wsi/headless/swapchain.cpp index 12b82b9..95e582f 100644 --- a/wsi/headless/swapchain.cpp +++ b/wsi/headless/swapchain.cpp @@ -109,7 +109,12 @@ VkResult swapchain::add_required_extensions(VkDevice device, const VkSwapchainCr } #endif - if (m_device_data.is_present_wait_enabled()) + if (m_device_data.is_present_wait_enabled() +#if VULKAN_WSI_LAYER_EXPERIMENTAL + || (swapchain_create_info->flags & + (VK_SWAPCHAIN_CREATE_PRESENT_ID_2_BIT_KHR | VK_SWAPCHAIN_CREATE_PRESENT_WAIT_2_BIT_KHR)) +#endif + ) { if (!add_swapchain_extension(m_allocator.make_unique( *get_swapchain_extension(true)))) diff --git a/wsi/wayland/surface_properties.cpp b/wsi/wayland/surface_properties.cpp index 672571c..642607d 100644 --- a/wsi/wayland/surface_properties.cpp +++ b/wsi/wayland/surface_properties.cpp @@ -126,6 +126,15 @@ VkResult surface_properties::get_surface_capabilities(VkPhysicalDevice physical_ present_id2_surface_cap->presentId2Supported = VK_TRUE; } +#if VULKAN_WSI_LAYER_EXPERIMENTAL + auto present_wait2_surface_cap = util::find_extension( + VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_PRESENT_WAIT_2_KHR, pSurfaceCapabilities->pNext); + if (present_wait2_surface_cap != nullptr) + { + present_wait2_surface_cap->presentWait2Supported = VK_TRUE; + } +#endif + return VK_SUCCESS; } diff --git a/wsi/wayland/swapchain.cpp b/wsi/wayland/swapchain.cpp index 78ec4eb..8a8f9a0 100644 --- a/wsi/wayland/swapchain.cpp +++ b/wsi/wayland/swapchain.cpp @@ -113,7 +113,12 @@ VkResult swapchain::add_required_extensions(VkDevice device, const VkSwapchainCr } } - if (m_device_data.is_present_wait_enabled()) + if (m_device_data.is_present_wait_enabled() +#if VULKAN_WSI_LAYER_EXPERIMENTAL + || (swapchain_create_info->flags & + (VK_SWAPCHAIN_CREATE_PRESENT_ID_2_BIT_KHR | VK_SWAPCHAIN_CREATE_PRESENT_WAIT_2_BIT_KHR)) +#endif + ) { if (!add_swapchain_extension( m_allocator.make_unique(*get_swapchain_extension(true))))