From 8345975050d1aa91a36262154ff7e875775f847e Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 1 Aug 2025 16:05:43 +0530 Subject: [PATCH] Get rid of transparency specialisation in cell shader It's not a significant optimisation anymore as it only elides call to adjust_alpha_for_incorrect_blending_by_compositor, which will probably not be needed anymore anyway. --- kitty/cell_defines.glsl | 5 ----- kitty/cell_fragment.glsl | 4 ---- kitty/fast_data_types.pyi | 2 +- kitty/glfw.c | 3 +-- kitty/main.py | 4 ++-- kitty/shaders.c | 2 +- kitty/shaders.py | 7 ++----- 7 files changed, 7 insertions(+), 20 deletions(-) diff --git a/kitty/cell_defines.glsl b/kitty/cell_defines.glsl index c49ecf510..58593e4a3 100644 --- a/kitty/cell_defines.glsl +++ b/kitty/cell_defines.glsl @@ -1,4 +1,3 @@ -#define HAS_TRANSPARENCY {TRANSPARENT} #define DO_FG_OVERRIDE {DO_FG_OVERRIDE} #define FG_OVERRIDE_THRESHOLD {FG_OVERRIDE_THRESHOLD} #define FG_OVERRIDE_ALGO {FG_OVERRIDE_ALGO} @@ -13,9 +12,5 @@ #define USE_SELECTION_FG #define NUM_COLORS 256 -#if (HAS_TRANSPARENCY == 1) -#define TRANSPARENT -#endif - // sRGB luminance values const vec3 Y = vec3(0.2126, 0.7152, 0.0722); diff --git a/kitty/cell_fragment.glsl b/kitty/cell_fragment.glsl index 60f7649ca..3ee2db30a 100644 --- a/kitty/cell_fragment.glsl +++ b/kitty/cell_fragment.glsl @@ -112,11 +112,7 @@ void main() { vec4 text_fg = load_text_foreground_color(); text_fg = adjust_foreground_contrast_with_background(text_fg, background); vec4 text_fg_premul = calculate_premul_foreground_from_sprites(text_fg); -#ifdef TRANSPARENT final_color = alpha_blend_premul(text_fg_premul, vec4_premul(background, bg_alpha)); final_color.a = adjust_alpha_for_incorrect_blending_by_compositor(text_fg_premul.a, final_color.a); -#else - final_color = alpha_blend_premul(text_fg_premul, background); -#endif output_color = final_color; } diff --git a/kitty/fast_data_types.pyi b/kitty/fast_data_types.pyi index 80991c8d2..ce03957a3 100644 --- a/kitty/fast_data_types.pyi +++ b/kitty/fast_data_types.pyi @@ -604,7 +604,7 @@ def create_os_window( wm_class_name: str, wm_class_class: str, window_state: Optional[int] = WINDOW_NORMAL, - load_programs: Optional[Callable[[bool], None]] = None, + load_programs: Optional[Callable[[], None]] = None, x: Optional[int] = None, y: Optional[int] = None, disallow_override_title: bool = False, diff --git a/kitty/glfw.c b/kitty/glfw.c index 6348608f9..21f5808d2 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -1487,7 +1487,7 @@ create_os_window(PyObject UNUSED *self, PyObject *args, PyObject *kw) { } } if (is_first_window) { - PyObject *ret = PyObject_CallFunction(load_programs, "O", is_semi_transparent ? Py_True : Py_False); + PyObject *ret = PyObject_CallNoArgs(load_programs); if (ret == NULL) return NULL; Py_DECREF(ret); get_platform_dependent_config_values(glfw_window); @@ -1495,7 +1495,6 @@ create_os_window(PyObject UNUSED *self, PyObject *args, PyObject *kw) { glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_BACK_LEFT, GL_FRAMEBUFFER_ATTACHMENT_COLOR_ENCODING, &encoding); if (encoding != GL_SRGB) log_error("The output buffer does not support sRGB color encoding, colors will be incorrect."); is_first_window = false; - } OSWindow *w = add_os_window(); w->handle = glfw_window; diff --git a/kitty/main.py b/kitty/main.py index 9746fd95c..a273c5187 100644 --- a/kitty/main.py +++ b/kitty/main.py @@ -86,9 +86,9 @@ def set_custom_ibeam_cursor() -> None: log_error(f'Failed to set custom beam cursor with error: {e}') -def load_all_shaders(semi_transparent: bool = False) -> None: +def load_all_shaders() -> None: try: - load_shader_programs(semi_transparent) + load_shader_programs() load_borders_program() except CompileError as err: raise SystemExit(err) diff --git a/kitty/shaders.c b/kitty/shaders.c index f26d8854b..6db7cd938 100644 --- a/kitty/shaders.c +++ b/kitty/shaders.c @@ -16,9 +16,9 @@ /* * TODO: for shader refactoring - * Get rid of TRANSPARENT define and always use premul colors * Change rendering of cursor -- should now be rendered with full blending as a layer between bg and fg layers * Check that rendering of special cells aka selections still works + * Check color fringing issues and background lightness isssues are properly fixed * Port graphics rendering to start use a dummy 1 pixel empty texture then possibly replace with defines so that the most * common use case of no graphics has zero performance overhead. * Convert all images loaded to GPU to linear space for correct blending or alternately do conversion to linear space in diff --git a/kitty/shaders.py b/kitty/shaders.py index 34924792d..681746509 100644 --- a/kitty/shaders.py +++ b/kitty/shaders.py @@ -136,7 +136,6 @@ class TextFgOverrideThreshold(NamedTuple): class LoadShaderPrograms: text_fg_override_threshold: TextFgOverrideThreshold = TextFgOverrideThreshold() text_old_gamma: bool = False - semi_transparent: bool = False cell_program_replacer: MultiReplacer = null_replacer @property @@ -149,10 +148,9 @@ class LoadShaderPrograms: def recompile_if_needed(self) -> None: if self.needs_recompile: - self(self.semi_transparent, allow_recompile=True) + self(allow_recompile=True) - def __call__(self, semi_transparent: bool = False, allow_recompile: bool = False) -> None: - self.semi_transparent = semi_transparent + def __call__(self, allow_recompile: bool = False) -> None: opts = get_options() self.text_old_gamma = opts.text_composition_strategy == 'legacy' @@ -179,7 +177,6 @@ class LoadShaderPrograms: def resolve_cell_defines(src: str) -> str: r = self.cell_program_replacer.replacements - r['TRANSPARENT'] = '1' if semi_transparent else '0' r['DO_FG_OVERRIDE'] = '1' if self.text_fg_override_threshold.scaled_value else '0' r['FG_OVERRIDE_ALGO'] = '1' if self.text_fg_override_threshold.unit == '%' else '2' r['FG_OVERRIDE_THRESHOLD'] = str(self.text_fg_override_threshold.scaled_value)