From 4f5d1466e01498ebf60edea5aaea36028fd5d791 Mon Sep 17 00:00:00 2001 From: pgm1207 <104554896+pgm1207@users.noreply.github.com> Date: Sun, 15 Nov 2026 13:05:38 +0100 Subject: [PATCH] VKBRIDGE_SWAPCHAIN_IMAGES: more swapchain images on Wayland (default off) On the Wayland path the swapchain has at least 3 images. When the compositor holds all of them (a buffer comes back about three refreshes after its commit) the game waits for a release before it can draw the next frame, which on a 120 Hz screen shows as frames missing their slot. VKBRIDGE_SWAPCHAIN_IMAGES= (1-8) raises the minimum to n; unset or 0 keeps the application's count (at least 3). The chosen count is logged. --- client/wsi.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/client/wsi.c b/client/wsi.c index 9b897d7..09c3122 100644 --- a/client/wsi.c +++ b/client/wsi.c @@ -958,6 +958,17 @@ VKAPI_ATTR VkResult VKAPI_CALL vkb_ep_vkCreateSwapchainKHR(VkDevice device, cons } sc->count = pCreateInfo->minImageCount < 2 ? 2 : pCreateInfo->minImageCount; if (s->kind == VKB_SURF_WAYLAND && sc->count < 3) sc->count = 3; + /* VKBRIDGE_SWAPCHAIN_IMAGES= (Wayland, default off): at least n images (max 8), so a frame can be drawn while the + * compositor still holds three (on Android the release of a buffer comes about three refreshes after its commit). */ + if (s->kind == VKB_SURF_WAYLAND) { + const char *ev = getenv("VKBRIDGE_SWAPCHAIN_IMAGES"); + int n = ev ? atoi(ev) : 0; + if (n > 8) n = 8; + if (n > 0 && sc->count < (uint32_t)n) { + VKB_INFO("swapchain: %u images instead of %u (VKBRIDGE_SWAPCHAIN_IMAGES=%d)", (unsigned)n, sc->count, n); + sc->count = (uint32_t)n; + } + } sc->images = calloc(sc->count, sizeof(vkb_swap_image)); sc->copy_cbs = calloc(sc->count, sizeof(VkCommandBuffer)); for (uint32_t i = 0; i < sc->count; i++) sc->images[i].dmabuf_fd = sc->images[i].ahb_sock = -1;