diff --git a/CMakeLists.txt b/CMakeLists.txt index 6c2d6ed..e37697a 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_id2/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 48eade2..c909387 100644 --- a/layer/VkLayer_window_system_integration.json +++ b/layer/VkLayer_window_system_integration.json @@ -37,6 +37,7 @@ ] }, {"name": "VK_KHR_present_id", "spec_version": "1"}, + {"name": "VK_KHR_present_id2", "spec_version": "1"}, { "name": "VK_EXT_swapchain_maintenance1", "spec_version": "1", diff --git a/layer/layer.cpp b/layer/layer.cpp index 76823af..a4b1028 100644 --- a/layer/layer.cpp +++ b/layer/layer.cpp @@ -365,6 +365,15 @@ VKAPI_ATTR VkResult create_device(VkPhysicalDevice physicalDevice, const VkDevic device_data.set_present_id_feature_enabled(present_id_features->presentId); } +#if VULKAN_WSI_LAYER_EXPERIMENTAL + const auto present_id2_features = util::find_extension( + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENT_ID_2_FEATURES_KHR, pCreateInfo->pNext); + if (present_id2_features != nullptr) + { + device_data.set_present_id2_feature_enabled(present_id2_features->presentId2); + } +#endif + const auto present_mode_fifo_latest_ready_features = util::find_extension( VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENT_MODE_FIFO_LATEST_READY_FEATURES_EXT, pCreateInfo->pNext); @@ -514,6 +523,15 @@ wsi_layer_vkGetPhysicalDeviceFeatures2(VkPhysicalDevice physical_device, present_id_features->presentId = VK_TRUE; } +#if VULKAN_WSI_LAYER_EXPERIMENTAL + auto *present_id2_features = util::find_extension( + VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENT_ID_2_FEATURES_KHR, pFeatures->pNext); + if (present_id2_features != nullptr) + { + present_id2_features->presentId2 = VK_TRUE; + } +#endif + wsi::set_swapchain_maintenance1_state(physical_device, swapchain_maintenance1_features); if (present_wait_features != nullptr) diff --git a/layer/private_data.cpp b/layer/private_data.cpp index f9b57bf..f4f150b 100644 --- a/layer/private_data.cpp +++ b/layer/private_data.cpp @@ -432,7 +432,8 @@ device_private_data::device_private_data(instance_private_data &inst_data, VkPhy , present_id_enabled { false } , swapchain_maintenance1_enabled{ false } #if VULKAN_WSI_LAYER_EXPERIMENTAL - , present_timing_enabled { true } + , present_timing_enabled { true } + , present_id2_enabled { false } #endif , present_mode_fifo_latest_ready_enabled { false } /* clang-format on */ @@ -606,6 +607,18 @@ bool device_private_data::is_present_id_enabled() return present_id_enabled; } +#if VULKAN_WSI_LAYER_EXPERIMENTAL +void device_private_data::set_present_id2_feature_enabled(bool enable) +{ + present_id2_enabled = enable; +} + +bool device_private_data::is_present_id2_enabled() +{ + return present_id2_enabled; +} +#endif + 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 cb61dab..af8fa2f 100644 --- a/layer/private_data.hpp +++ b/layer/private_data.hpp @@ -931,6 +931,22 @@ public: */ bool is_present_id_enabled(); +#if VULKAN_WSI_LAYER_EXPERIMENTAL + /** + * @brief Set whether the device supports the present ID2 feature. + * + * @param enable Value to set m_present_id2_enabled member variable. + */ + void set_present_id2_feature_enabled(bool enable); + + /** + * @brief Check whether the device can support the present ID2 feature. + * + * @return true if supported, false otherwise. + */ + bool is_present_id2_enabled(); +#endif + /** * @brief Selectively enable/disable the fifo_latest_ready for this device * @@ -1034,6 +1050,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 ID2 feature. + * + */ + bool present_id2_enabled{ false }; #endif /** diff --git a/wsi/display/surface_properties.cpp b/wsi/display/surface_properties.cpp index 339bfdf..f87b4b5 100644 --- a/wsi/display/surface_properties.cpp +++ b/wsi/display/surface_properties.cpp @@ -99,6 +99,15 @@ VkResult surface_properties::get_surface_capabilities(VkPhysicalDevice physical_ surface_scaling_capabilities->maxScaledImageExtent = pSurfaceCapabilities->surfaceCapabilities.maxImageExtent; } +#if VULKAN_WSI_LAYER_EXPERIMENTAL + auto present_id2_surface_cap = util::find_extension( + VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_PRESENT_ID_2_KHR, pSurfaceCapabilities->pNext); + if (present_id2_surface_cap != nullptr) + { + present_id2_surface_cap->presentId2Supported = VK_TRUE; + } +#endif + return VK_SUCCESS; } diff --git a/wsi/display/swapchain.cpp b/wsi/display/swapchain.cpp index 6560334..9ad48ed 100644 --- a/wsi/display/swapchain.cpp +++ b/wsi/display/swapchain.cpp @@ -85,7 +85,11 @@ VkResult swapchain::add_required_extensions(VkDevice device, const VkSwapchainCr } } - if (m_device_data.is_present_id_enabled()) + if (m_device_data.is_present_id_enabled() +#if VULKAN_WSI_LAYER_EXPERIMENTAL + || (swapchain_create_info->flags & VK_SWAPCHAIN_CREATE_PRESENT_ID_2_BIT_KHR) +#endif + ) { if (!add_swapchain_extension(m_allocator.make_unique())) { @@ -568,9 +572,9 @@ void swapchain::present_image(const pending_present_request &pending_present) /* The image is on screen, change the image status to PRESENTED. */ m_swapchain_images[pending_present.image_index].status = swapchain_image::PRESENTED; - if (m_device_data.is_present_id_enabled()) + auto *ext = get_swapchain_extension(); + if (ext != nullptr) { - auto *ext = get_swapchain_extension(true); ext->mark_delivered(pending_present.present_id); } diff --git a/wsi/display/swapchain.hpp b/wsi/display/swapchain.hpp index 5957dd8..199d177 100644 --- a/wsi/display/swapchain.hpp +++ b/wsi/display/swapchain.hpp @@ -84,7 +84,9 @@ class swapchain : public wsi::swapchain_base { public: swapchain(layer::device_private_data &dev_data, const VkAllocationCallbacks *pAllocator, surface &wsi_surface); + virtual ~swapchain(); + virtual VkResult init_platform(VkDevice device, const VkSwapchainCreateInfoKHR *swapchain_create_info, bool &use_presentation_thread) override; diff --git a/wsi/headless/surface_properties.cpp b/wsi/headless/surface_properties.cpp index e6e1ec0..c175b28 100644 --- a/wsi/headless/surface_properties.cpp +++ b/wsi/headless/surface_properties.cpp @@ -105,6 +105,15 @@ VkResult surface_properties::get_surface_capabilities(VkPhysicalDevice physical_ surface_scaling_capabilities->maxScaledImageExtent = surface_capabilities->surfaceCapabilities.maxImageExtent; } +#if VULKAN_WSI_LAYER_EXPERIMENTAL + auto present_id2_surface_cap = util::find_extension( + VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_PRESENT_ID_2_KHR, surface_capabilities->pNext); + if (present_id2_surface_cap != nullptr) + { + present_id2_surface_cap->presentId2Supported = VK_TRUE; + } +#endif + return VK_SUCCESS; } diff --git a/wsi/headless/swapchain.cpp b/wsi/headless/swapchain.cpp index ea09b2b..c3bc10a 100644 --- a/wsi/headless/swapchain.cpp +++ b/wsi/headless/swapchain.cpp @@ -71,9 +71,15 @@ swapchain::~swapchain() VkResult swapchain::add_required_extensions(VkDevice device, const VkSwapchainCreateInfoKHR *swapchain_create_info) { UNUSED(device); +#if !VULKAN_WSI_LAYER_EXPERIMENTAL UNUSED(swapchain_create_info); +#endif - if (m_device_data.is_present_id_enabled()) + if (m_device_data.is_present_id_enabled() +#if VULKAN_WSI_LAYER_EXPERIMENTAL + || (swapchain_create_info->flags & VK_SWAPCHAIN_CREATE_PRESENT_ID_2_BIT_KHR) +#endif + ) { if (!add_swapchain_extension(m_allocator.make_unique())) { @@ -246,10 +252,10 @@ void swapchain::present_image(const pending_present_request &pending_present) } #endif - if (m_device_data.is_present_id_enabled()) + auto *ext = get_swapchain_extension(); + if (ext != nullptr) { - auto *ext_present_id = get_swapchain_extension(true); - ext_present_id->mark_delivered(pending_present.present_id); + ext->mark_delivered(pending_present.present_id); } #if VULKAN_WSI_LAYER_EXPERIMENTAL diff --git a/wsi/wayland/surface_properties.cpp b/wsi/wayland/surface_properties.cpp index c72e72d..eb8bfca 100644 --- a/wsi/wayland/surface_properties.cpp +++ b/wsi/wayland/surface_properties.cpp @@ -119,6 +119,15 @@ VkResult surface_properties::get_surface_capabilities(VkPhysicalDevice physical_ surface_scaling_capabilities->maxScaledImageExtent = pSurfaceCapabilities->surfaceCapabilities.maxImageExtent; } +#if VULKAN_WSI_LAYER_EXPERIMENTAL + auto present_id2_surface_cap = util::find_extension( + VK_STRUCTURE_TYPE_SURFACE_CAPABILITIES_PRESENT_ID_2_KHR, pSurfaceCapabilities->pNext); + if (present_id2_surface_cap != nullptr) + { + present_id2_surface_cap->presentId2Supported = VK_TRUE; + } +#endif + return VK_SUCCESS; } diff --git a/wsi/wayland/swapchain.cpp b/wsi/wayland/swapchain.cpp index d649009..11a5a39 100644 --- a/wsi/wayland/swapchain.cpp +++ b/wsi/wayland/swapchain.cpp @@ -92,7 +92,11 @@ VkResult swapchain::add_required_extensions(VkDevice device, const VkSwapchainCr } } - if (m_device_data.is_present_id_enabled()) + if (m_device_data.is_present_id_enabled() +#if VULKAN_WSI_LAYER_EXPERIMENTAL + || (swapchain_create_info->flags & VK_SWAPCHAIN_CREATE_PRESENT_ID_2_BIT_KHR) +#endif + ) { #if VULKAN_WSI_LAYER_EXPERIMENTAL if (!add_swapchain_extension(m_allocator.make_unique())) @@ -623,14 +627,20 @@ void swapchain::present_image(const pending_present_request &pending_present) if (m_device_data.is_present_id_enabled()) { #if VULKAN_WSI_LAYER_EXPERIMENTAL - auto *ext = get_swapchain_extension(true); - if (m_wsi_surface->get_presentation_time_interface() == nullptr) -#else - auto *ext = get_swapchain_extension(true); -#endif + auto *ext = get_swapchain_extension(); + if (ext != nullptr) { - ext->mark_delivered(pending_present.present_id); + if (m_wsi_surface->get_presentation_time_interface() == nullptr) +#else + auto *ext = get_swapchain_extension(); + if (ext != nullptr) +#endif + { + ext->mark_delivered(pending_present.present_id); + } +#if VULKAN_WSI_LAYER_EXPERIMENTAL } +#endif } }