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