From dbf8ad01c02f49b3255c8dce07aaf5cc3d0a056f Mon Sep 17 00:00:00 2001 From: Dennis Tsiang Date: Tue, 15 Oct 2024 13:41:21 +0100 Subject: [PATCH] Disable the FIFO present thread implementation on Wayland by default The FIFO implementation in the Wayland backend that uses the presentation thread is not technically Vulkan conformant. This commit enables a true FIFO implementation that is conformant to the Vulkan spec by blocking in the vkQueuePresent path. On Wayland this is achieved by having the main thread wait for the frame_done event to be sent by the compositor. This was already used in FIFO before but previously it would be the presentation thread that would block. This implementation is now used by default. The downside of this approach is that it has a significant performance impact due to blocking the main thread. Users wishing to continue using the presentation thread implementation to achieve better performance can still do so through a new build option `ENABLE_WAYLAND_FIFO_PRESENTATION_THREAD`. The README has also been updated to document the FIFO shortcomings. Signed-off-by: Dennis Tsiang Change-Id: I8674f9ea330a45f97d32024f97057ffc25c76c7a --- CMakeLists.txt | 6 ++++++ README.md | 14 ++++++++++++++ wsi/wayland/swapchain.cpp | 3 ++- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7aa2c66..4729c0c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -67,6 +67,7 @@ set(EXTERNAL_WSIALLOC_LIBRARY "" CACHE STRING "External implementation of the ws option(BUILD_WSI_IMAGE_COMPRESSION_CONTROL_SWAPCHAIN "Build with support for VK_EXT_image_compression_control_swapchain" OFF) option(BUILD_WSI_DISPLAY_SUPPORT_FORMAT_MODIFIERS "Build with support for format modifiers in VK_KHR_display" ON) option(VULKAN_WSI_LAYER_EXPERIMENTAL "Enable the Vulkan WSI Experimental features" OFF) +option(ENABLE_WAYLAND_FIFO_PRESENTATION_THREAD "Enable the non-conformant FIFO presentation thread implementation in the Wayland backend" OFF) # Enables the layer to pass frame boundary events if the ICD or layers below have support for it by # making use of the VK_EXT_frame_boundary extension. If the application itself makes use of the @@ -182,6 +183,11 @@ if(BUILD_WSI_WAYLAND) endif() target_link_libraries(wayland_wsi drm_utils ${WAYLAND_CLIENT_LDFLAGS}) list(APPEND LINK_WSI_LIBS wayland_wsi) + if(ENABLE_WAYLAND_FIFO_PRESENTATION_THREAD) + target_compile_definitions(wayland_wsi PRIVATE "-DWAYLAND_FIFO_PRESENTATION_THREAD_ENABLED=1") + else() + target_compile_definitions(wayland_wsi PRIVATE "-DWAYLAND_FIFO_PRESENTATION_THREAD_ENABLED=0") + endif() else() list(APPEND JSON_COMMANDS COMMAND sed -i '/VK_KHR_wayland_surface/d' ${CMAKE_CURRENT_BINARY_DIR}/VkLayer_window_system_integration.json) endif() diff --git a/README.md b/README.md index 85c3daa..fc2603c 100644 --- a/README.md +++ b/README.md @@ -126,6 +126,20 @@ provides a generic ion implementation that may work in systems that support linear formats. This is selected by the `-DSELECT_EXTERNAL_ALLOCATOR=ion` option, as shown above. +### Wayland support with FIFO presentation mode + +The WSI Layer has 2 FIFO implementations for the Wayland backend. One that +blocks in vkQueuePresent and one that uses a presentation thread. This is due +to the fact that the FIFO implementation that utilises the presentation thread +in the Wayland backend is not strictly conformant to the Vulkan specification, +however it has a much better performance due to not needing to block in vkQueuePresent. + +By default, the WSI Layer uses the queue present blocking FIFO implementation +when using Wayland swapchains. This can be switched to instead use the presentation +thread implementation by including the build option `ENABLE_WAYLAND_FIFO_PRESENTATION_THREAD`, +along with the other build options mentioned in "Building with Wayland support" +section. + ### Building with frame instrumentation support The layer can be built to pass frame boundary information down to other diff --git a/wsi/wayland/swapchain.cpp b/wsi/wayland/swapchain.cpp index 747efbe..6392bb4 100644 --- a/wsi/wayland/swapchain.cpp +++ b/wsi/wayland/swapchain.cpp @@ -104,7 +104,8 @@ VkResult swapchain::init_platform(VkDevice device, const VkSwapchainCreateInfoKH * initialize the page flip thread so the present_image function can be called * during vkQueuePresent. */ - use_presentation_thread = (m_present_mode != VK_PRESENT_MODE_MAILBOX_KHR); + use_presentation_thread = + WAYLAND_FIFO_PRESENTATION_THREAD_ENABLED && (m_present_mode != VK_PRESENT_MODE_MAILBOX_KHR); return VK_SUCCESS; }