From f6d3b1e53751fca67689030eff81fdc40e0eface Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 6 Nov 2026 06:23:19 +0530 Subject: [PATCH] Vulkan: Create the swapchain with the right present mode the first time The swapchain was created with the FIFO present mode and then recreated on the first frame, because the swap interval of the window was set only after the surface was created. Pass the initial swap interval to the driver in GPUSurfaceConfig so the swapchain is created correctly when the surface is created. --- gpu/api.h | 7 ++++++- gpu/vulkan/surfaces.c | 2 +- kitty/glfw.c | 8 +++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/gpu/api.h b/gpu/api.h index d9fa6dd2a..04367c2b4 100644 --- a/gpu/api.h +++ b/gpu/api.h @@ -53,7 +53,7 @@ #include #include -#define KITTY_GPU_API_VERSION 6u +#define KITTY_GPU_API_VERSION 7u #define KITTY_GPU_DRIVER_ENTRY_POINT "kitty_gpu_driver_load" #define GPU_NULL_HANDLE ((uint64_t)0) @@ -149,6 +149,11 @@ typedef struct GPUSurfaceConfig { bool allow_offline_renderers; // macOS: render at the full resolution of high DPI (retina) displays bool high_resolution; + // The swap interval the surface starts with, as for + // surface_set_swap_interval(). Drivers for which changing the swap + // interval is expensive, such as Vulkan, where it requires recreating the + // swapchain, use it to configure the surface correctly at creation. + int swap_interval; } GPUSurfaceConfig; // }}} diff --git a/gpu/vulkan/surfaces.c b/gpu/vulkan/surfaces.c index 25d74e44f..012aa7704 100644 --- a/gpu/vulkan/surfaces.c +++ b/gpu/vulkan/surfaces.c @@ -328,7 +328,7 @@ surface_create(void *driver, const GPUNativeWindow *native, const GPUSurfaceConf s->config = *config; s->width = width; s->height = height; - s->swap_interval = 1; + s->swap_interval = config->swap_interval; VkResult r; if (native->platform == GPU_PLATFORM_WAYLAND) { const VkWaylandSurfaceCreateInfoKHR info = { diff --git a/kitty/glfw.c b/kitty/glfw.c index 375d299a8..966f17425 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -29,13 +29,18 @@ typedef struct mouse_cursor { static mouse_cursor cursors[GLFW_INVALID_CURSOR + 1] = {0}; +static int +default_swap_interval(void) { + return OPT(sync_to_monitor) && !global_state.is_wayland ? 1 : 0; +} + // Must be called with the surface current static void apply_swap_interval(gpu_surface_t surface, int val) { (void)val; (void)surface; #ifndef __APPLE__ - if (val < 0) val = OPT(sync_to_monitor) && !global_state.is_wayland ? 1 : 0; + if (val < 0) val = default_swap_interval(); gpu_surface_set_swap_interval(surface, val); #endif } @@ -68,6 +73,7 @@ gpu_surface_config(bool transparent) { .srgb = !global_state.is_wayland, .allow_offline_renderers = true, .high_resolution = true, + .swap_interval = default_swap_interval(), }; }