From 73f68fd111e94231608d9abfe1cf92e78b9c85b3 Mon Sep 17 00:00:00 2001 From: Jakob Bornecrantz Date: Thu, 27 Apr 2023 01:28:59 +0100 Subject: [PATCH] c/main: Prefer only two swapchain images --- src/xrt/compositor/main/comp_target_swapchain.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/xrt/compositor/main/comp_target_swapchain.c b/src/xrt/compositor/main/comp_target_swapchain.c index 859796d5b..6bc7bb651 100644 --- a/src/xrt/compositor/main/comp_target_swapchain.c +++ b/src/xrt/compositor/main/comp_target_swapchain.c @@ -719,8 +719,23 @@ comp_target_swapchain_create_images(struct comp_target *ct, extent.height = w2; } + /* + * For all direct mode outputs 2 is what we want since we want to run + * lockstep with the display. Most direct mode swapchains only supports + * FIFO mode, and since there is no commonly available Vulkan API to + * wait for a specific VBLANK event, even just the latest, we can set + * the number of images to two and then acquire immediately after + * present. Since the old images are being displayed and the new can't + * be flipped this will block until the flip has gone through. Crude but + * works well enough on both AMD(Mesa) and Nvidia(Blob). + * + * When not in direct mode and display to a composited window we + * probably want 3, but most compositors on Linux sets the minImageCount + * to 3 anyways so we get what we want. + */ + const uint32_t preferred_at_least_image_count = 2; + // Get the image count. - const uint32_t preferred_at_least_image_count = 3; uint32_t image_count = select_image_count(cts, surface_caps, preferred_at_least_image_count);