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.
This commit is contained in:
Kovid Goyal 2026-11-06 06:23:19 +05:30
parent ed21ef4f95
commit f6d3b1e537
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
3 changed files with 14 additions and 3 deletions

View file

@ -53,7 +53,7 @@
#include <stddef.h>
#include <stdint.h>
#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;
// }}}

View file

@ -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 = {

View file

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