From 902b9e9693c9b2d8f3e9738aa4978dfa7fd9b87d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 18 Jul 2023 19:28:15 +0530 Subject: [PATCH] Go back to using uniforms for the gamma LUT Apparently older macOS M1 GPU drivers' performance falls off a cliff when using const float arrays instead. Fixes #6479 --- docs/changelog.rst | 5 +++++ gen-srgb-lut.py | 3 --- kitty/border_vertex.glsl | 2 +- kitty/cell_vertex.glsl | 2 +- kitty/shaders.c | 4 ++++ kitty/srgb_gamma.glsl | 20 -------------------- 6 files changed, 11 insertions(+), 25 deletions(-) delete mode 100644 kitty/srgb_gamma.glsl diff --git a/docs/changelog.rst b/docs/changelog.rst index b8a9ce143..636dd938d 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -35,6 +35,11 @@ mouse anywhere in the current command to move the cursor there. See Detailed list of changes ------------------------------------- +0.29.2 [future] +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +- macOS: Fix a performance regression on M1 machines using outdated macOS versions (:iss:`6479`) + 0.29.1 [2023-07-17] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/gen-srgb-lut.py b/gen-srgb-lut.py index 5bbed87dc..4ba33cef8 100755 --- a/gen-srgb-lut.py +++ b/gen-srgb-lut.py @@ -45,9 +45,6 @@ def main() -> None: c = generate_srgb_gamma() with open(os.path.join('kitty', 'srgb_gamma.h'), 'w') as f: f.write(f'{c}\n') - g = generate_srgb_gamma('const float gamma_lut[256] = float[256](', ');') - with open(os.path.join('kitty', 'srgb_gamma.glsl'), 'w') as f: - f.write(f'{g}\n') if __name__ == '__main__': diff --git a/kitty/border_vertex.glsl b/kitty/border_vertex.glsl index 2b23bbf0f..4a74b50b2 100644 --- a/kitty/border_vertex.glsl +++ b/kitty/border_vertex.glsl @@ -1,8 +1,8 @@ -#pragma kitty_include_shader uniform uvec2 viewport; uniform uint colors[9]; uniform float background_opacity; uniform float tint_opacity, tint_premult; +uniform float gamma_lut[256]; in vec4 rect; // left, top, right, bottom in uint rect_color; out vec4 color; diff --git a/kitty/cell_vertex.glsl b/kitty/cell_vertex.glsl index 473d23adb..71086e255 100644 --- a/kitty/cell_vertex.glsl +++ b/kitty/cell_vertex.glsl @@ -1,5 +1,4 @@ #extension GL_ARB_explicit_attrib_location : require -#pragma kitty_include_shader #pragma kitty_include_shader @@ -22,6 +21,7 @@ uniform uint draw_bg_bitfield; layout(location=0) in uvec3 colors; layout(location=1) in uvec4 sprite_coords; layout(location=2) in uint is_selected; +uniform float gamma_lut[256]; const int fg_index_map[] = int[3](0, 1, 0); diff --git a/kitty/shaders.c b/kitty/shaders.c index a6e62472e..dec83ebed 100644 --- a/kitty/shaders.c +++ b/kitty/shaders.c @@ -222,6 +222,8 @@ init_cell_program(void) { cell_program_layouts[i].color_table.offset = get_uniform_information(i, "color_table[0]", GL_UNIFORM_OFFSET); cell_program_layouts[i].color_table.stride = get_uniform_information(i, "color_table[0]", GL_UNIFORM_ARRAY_STRIDE); get_uniform_locations_cell(i, &cell_program_layouts[i].uniforms); + bind_program(i); + glUniform1fv(cell_program_layouts[i].uniforms.gamma_lut, arraysz(srgb_lut), srgb_lut); } // Sanity check to ensure the attribute location binding worked @@ -976,6 +978,8 @@ static BorderProgramLayout border_program_layout; static void init_borders_program(void) { get_uniform_locations_border(BORDERS_PROGRAM, &border_program_layout.uniforms); + bind_program(BORDERS_PROGRAM); + glUniform1fv(border_program_layout.uniforms.gamma_lut, 256, srgb_lut); } ssize_t diff --git a/kitty/srgb_gamma.glsl b/kitty/srgb_gamma.glsl deleted file mode 100644 index 9ff4a1a04..000000000 --- a/kitty/srgb_gamma.glsl +++ /dev/null @@ -1,20 +0,0 @@ -// Generated by gen-srgb-lut.py DO NOT edit - -const float gamma_lut[256] = float[256]( - 0.00000f, 0.00030f, 0.00061f, 0.00091f, 0.00121f, 0.00152f, 0.00182f, 0.00212f, 0.00243f, 0.00273f, 0.00304f, 0.00335f, 0.00368f, 0.00402f, 0.00439f, 0.00478f, - 0.00518f, 0.00561f, 0.00605f, 0.00651f, 0.00700f, 0.00750f, 0.00802f, 0.00857f, 0.00913f, 0.00972f, 0.01033f, 0.01096f, 0.01161f, 0.01229f, 0.01298f, 0.01370f, - 0.01444f, 0.01521f, 0.01600f, 0.01681f, 0.01764f, 0.01850f, 0.01938f, 0.02029f, 0.02122f, 0.02217f, 0.02315f, 0.02416f, 0.02519f, 0.02624f, 0.02732f, 0.02843f, - 0.02956f, 0.03071f, 0.03190f, 0.03310f, 0.03434f, 0.03560f, 0.03689f, 0.03820f, 0.03955f, 0.04092f, 0.04231f, 0.04374f, 0.04519f, 0.04667f, 0.04817f, 0.04971f, - 0.05127f, 0.05286f, 0.05448f, 0.05613f, 0.05781f, 0.05951f, 0.06125f, 0.06301f, 0.06480f, 0.06663f, 0.06848f, 0.07036f, 0.07227f, 0.07421f, 0.07619f, 0.07819f, - 0.08022f, 0.08228f, 0.08438f, 0.08650f, 0.08866f, 0.09084f, 0.09306f, 0.09531f, 0.09759f, 0.09990f, 0.10224f, 0.10462f, 0.10702f, 0.10946f, 0.11193f, 0.11444f, - 0.11697f, 0.11954f, 0.12214f, 0.12477f, 0.12744f, 0.13014f, 0.13287f, 0.13563f, 0.13843f, 0.14126f, 0.14413f, 0.14703f, 0.14996f, 0.15293f, 0.15593f, 0.15896f, - 0.16203f, 0.16513f, 0.16827f, 0.17144f, 0.17465f, 0.17789f, 0.18116f, 0.18447f, 0.18782f, 0.19120f, 0.19462f, 0.19807f, 0.20156f, 0.20508f, 0.20864f, 0.21223f, - 0.21586f, 0.21953f, 0.22323f, 0.22697f, 0.23074f, 0.23455f, 0.23840f, 0.24228f, 0.24620f, 0.25016f, 0.25415f, 0.25818f, 0.26225f, 0.26636f, 0.27050f, 0.27468f, - 0.27889f, 0.28315f, 0.28744f, 0.29177f, 0.29614f, 0.30054f, 0.30499f, 0.30947f, 0.31399f, 0.31855f, 0.32314f, 0.32778f, 0.33245f, 0.33716f, 0.34191f, 0.34670f, - 0.35153f, 0.35640f, 0.36131f, 0.36625f, 0.37124f, 0.37626f, 0.38133f, 0.38643f, 0.39157f, 0.39676f, 0.40198f, 0.40724f, 0.41254f, 0.41789f, 0.42327f, 0.42869f, - 0.43415f, 0.43966f, 0.44520f, 0.45079f, 0.45641f, 0.46208f, 0.46778f, 0.47353f, 0.47932f, 0.48515f, 0.49102f, 0.49693f, 0.50289f, 0.50888f, 0.51492f, 0.52100f, - 0.52712f, 0.53328f, 0.53948f, 0.54572f, 0.55201f, 0.55834f, 0.56471f, 0.57112f, 0.57758f, 0.58408f, 0.59062f, 0.59720f, 0.60383f, 0.61050f, 0.61721f, 0.62396f, - 0.63076f, 0.63760f, 0.64448f, 0.65141f, 0.65837f, 0.66539f, 0.67244f, 0.67954f, 0.68669f, 0.69387f, 0.70110f, 0.70838f, 0.71569f, 0.72306f, 0.73046f, 0.73791f, - 0.74540f, 0.75294f, 0.76052f, 0.76815f, 0.77582f, 0.78354f, 0.79130f, 0.79910f, 0.80695f, 0.81485f, 0.82279f, 0.83077f, 0.83880f, 0.84687f, 0.85499f, 0.86316f, - 0.87137f, 0.87962f, 0.88792f, 0.89627f, 0.90466f, 0.91310f, 0.92158f, 0.93011f, 0.93869f, 0.94731f, 0.95597f, 0.96469f, 0.97345f, 0.98225f, 0.99110f, 1.00000f -);