Merge 'Add initial support for VK_KHR_present_id2 in the layer' into 'main'

See merge request mesa/vulkan-wsi-layer!181
This commit is contained in:
Rosen Zhelev 2025-08-13 09:41:22 +01:00
commit a0700e3e86
12 changed files with 119 additions and 16 deletions

View file

@ -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()

View file

@ -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",

View file

@ -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<VkPhysicalDevicePresentId2FeaturesKHR>(
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<VkPhysicalDevicePresentModeFifoLatestReadyFeaturesEXT>(
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<VkPhysicalDevicePresentId2FeaturesKHR>(
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)

View file

@ -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;

View file

@ -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
/**

View file

@ -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<VkSurfaceCapabilitiesPresentId2KHR>(
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;
}

View file

@ -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<wsi_ext_present_id>()))
{
@ -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<wsi_ext_present_id>();
if (ext != nullptr)
{
auto *ext = get_swapchain_extension<wsi_ext_present_id>(true);
ext->mark_delivered(pending_present.present_id);
}

View file

@ -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;

View file

@ -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<VkSurfaceCapabilitiesPresentId2KHR>(
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;
}

View file

@ -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<wsi_ext_present_id>()))
{
@ -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<wsi_ext_present_id>();
if (ext != nullptr)
{
auto *ext_present_id = get_swapchain_extension<wsi_ext_present_id>(true);
ext_present_id->mark_delivered(pending_present.present_id);
ext->mark_delivered(pending_present.present_id);
}
#if VULKAN_WSI_LAYER_EXPERIMENTAL

View file

@ -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<VkSurfaceCapabilitiesPresentId2KHR>(
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;
}

View file

@ -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<wsi_ext_present_id_wayland>()))
@ -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<wsi_ext_present_id_wayland>(true);
if (m_wsi_surface->get_presentation_time_interface() == nullptr)
#else
auto *ext = get_swapchain_extension<wsi_ext_present_id>(true);
#endif
auto *ext = get_swapchain_extension<wsi_ext_present_id_wayland>();
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<wsi_ext_present_id>();
if (ext != nullptr)
#endif
{
ext->mark_delivered(pending_present.present_id);
}
#if VULKAN_WSI_LAYER_EXPERIMENTAL
}
#endif
}
}