From 3046d28e9fb4e24286c456845140b17defb7f53b Mon Sep 17 00:00:00 2001 From: Iurii Lunev Date: Mon, 12 Oct 2026 16:24:07 +0300 Subject: [PATCH] Custom shaders: Fix stale framebuffers for re-declared named textures When a pipeline does not declare the a, b or persist textures they are freed, along with the per window framebuffers for them, but the per window generation counters are left alone. Loading a pipeline that declares them again recreates the textures without recreating the framebuffers, since the generations still match. Passes into those textures then bind framebuffer 0, which is the backbuffer, so they draw over the terminal contents and only what the shader draws by itself remains visible. Reset the generations when the textures are freed, so that the framebuffers are attached afresh when the textures come back. --- docs/changelog.rst | 4 ++++ kitty/shaders.c | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index a4c67e39c..626ba7b31 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -424,6 +424,10 @@ Detailed list of changes when the shader declares the variable over multiple lines or with a different type +- Custom shaders: Fix the screen going blank, except for parts drawn only by + the shader, when switching from a pipeline that does not use the named + textures to one that does + 0.49.2 [2026-10-01] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/kitty/shaders.c b/kitty/shaders.c index db5340405..16c174af6 100644 --- a/kitty/shaders.c +++ b/kitty/shaders.c @@ -643,6 +643,10 @@ init_custom_programs(void) { // persist is per-window and freed lazily in start_os_window_rendering for (size_t w = 0; w < global_state.num_os_windows; w++) { OSWindow *osw = global_state.os_windows + w; + // Per window framebuffers must be attached afresh to the textures that + // replace the ones freed above, should a later pipeline declare them again + if (!(custom_shaders.end.textures & (1u << CUSTOM_SHADER_TEXTURE_A))) osw->indirect_output.fbo_a_generation = 0; + if (!(custom_shaders.end.textures & (1u << CUSTOM_SHADER_TEXTURE_B))) osw->indirect_output.fbo_b_generation = 0; init_shader_animation_state(osw); // Synthesize focus events for windows that already have focus so that // animations triggered by os-window-focus-in start on the first render @@ -2631,6 +2635,7 @@ start_os_window_rendering(OSWindow *os_window, Tab *tab) { } else { if (os_window->persist_texture_id) free_texture(&os_window->persist_texture_id); if (os_window->persist_fbo_id) free_framebuffer(&os_window->persist_fbo_id); + os_window->persist_texture_generation = 0; } set_framebuffer_to_use_for_output(os_window->indirect_output.framebuffer_id); bind_framebuffer_for_output(0);