From 1723ab34e1e7a7e38bcd58fb3ed6cccc12fd049f Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Thu, 4 Jan 2024 14:52:03 +0100 Subject: [PATCH] gpu: Setup attribute locations Make the generator generate calls for the correct glBindAttribLocation() calls. Usually this was done correctly, but we can't rely on it. So do it explicitly. --- gsk/gpu/gskgldevice.c | 20 +++++++++++--------- gsk/gpu/gskgpublendmodeop.c | 1 + gsk/gpu/gskgpublurop.c | 1 + gsk/gpu/gskgpuborderop.c | 1 + gsk/gpu/gskgpuboxshadowop.c | 1 + gsk/gpu/gskgpucolorizeop.c | 1 + gsk/gpu/gskgpucolormatrixop.c | 1 + gsk/gpu/gskgpucolorop.c | 1 + gsk/gpu/gskgpuconicgradientop.c | 1 + gsk/gpu/gskgpucrossfadeop.c | 1 + gsk/gpu/gskgpulineargradientop.c | 1 + gsk/gpu/gskgpumaskop.c | 1 + gsk/gpu/gskgpuradialgradientop.c | 1 + gsk/gpu/gskgpuroundedcolorop.c | 1 + gsk/gpu/gskgpushaderopprivate.h | 1 + gsk/gpu/gskgpustraightalphaop.c | 1 + gsk/gpu/gskgputextureop.c | 1 + gsk/gpu/gskgpuuberop.c | 1 + gsk/gpu/shaders/generate-header.py | 14 ++++++++++++++ 19 files changed, 42 insertions(+), 9 deletions(-) diff --git a/gsk/gpu/gskgldevice.c b/gsk/gpu/gskgldevice.c index bf2b36dc5d..4d7a4cc530 100644 --- a/gsk/gpu/gskgldevice.c +++ b/gsk/gpu/gskgldevice.c @@ -459,21 +459,21 @@ gsk_gl_device_load_shader (GskGLDevice *self, } static GLuint -gsk_gl_device_load_program (GskGLDevice *self, - const char *program_name, - guint32 variation, - GskGpuShaderClip clip, - guint n_external_textures, - GError **error) +gsk_gl_device_load_program (GskGLDevice *self, + const GskGpuShaderOpClass *op_class, + guint32 variation, + GskGpuShaderClip clip, + guint n_external_textures, + GError **error) { GLuint vertex_shader_id, fragment_shader_id, program_id; GLint link_status; - vertex_shader_id = gsk_gl_device_load_shader (self, program_name, GL_VERTEX_SHADER, variation, clip, n_external_textures, error); + vertex_shader_id = gsk_gl_device_load_shader (self, op_class->shader_name, GL_VERTEX_SHADER, variation, clip, n_external_textures, error); if (vertex_shader_id == 0) return 0; - fragment_shader_id = gsk_gl_device_load_shader (self, program_name, GL_FRAGMENT_SHADER, variation, clip, n_external_textures, error); + fragment_shader_id = gsk_gl_device_load_shader (self, op_class->shader_name, GL_FRAGMENT_SHADER, variation, clip, n_external_textures, error); if (fragment_shader_id == 0) return 0; @@ -482,6 +482,8 @@ gsk_gl_device_load_program (GskGLDevice *self, glAttachShader (program_id, vertex_shader_id); glAttachShader (program_id, fragment_shader_id); + op_class->setup_attrib_locations (program_id); + glLinkProgram (program_id); glGetProgramiv (program_id, GL_LINK_STATUS, &link_status); @@ -545,7 +547,7 @@ gsk_gl_device_use_program (GskGLDevice *self, return; } - program_id = gsk_gl_device_load_program (self, op_class->shader_name, variation, clip, n_external_textures, &error); + program_id = gsk_gl_device_load_program (self, op_class, variation, clip, n_external_textures, &error); if (program_id == 0) { g_critical ("Failed to load shader program: %s", error->message); diff --git a/gsk/gpu/gskgpublendmodeop.c b/gsk/gpu/gskgpublendmodeop.c index f22f859c9b..8a10cd2ec9 100644 --- a/gsk/gpu/gskgpublendmodeop.c +++ b/gsk/gpu/gskgpublendmodeop.c @@ -51,6 +51,7 @@ static const GskGpuShaderOpClass GSK_GPU_BLEND_MODE_OP_CLASS = { #ifdef GDK_RENDERING_VULKAN &gsk_gpu_blendmode_info, #endif + gsk_gpu_blendmode_setup_attrib_locations, gsk_gpu_blendmode_setup_vao }; diff --git a/gsk/gpu/gskgpublurop.c b/gsk/gpu/gskgpublurop.c index c24305de39..ed188eee4b 100644 --- a/gsk/gpu/gskgpublurop.c +++ b/gsk/gpu/gskgpublurop.c @@ -52,6 +52,7 @@ static const GskGpuShaderOpClass GSK_GPU_BLUR_OP_CLASS = { #ifdef GDK_RENDERING_VULKAN &gsk_gpu_blur_info, #endif + gsk_gpu_blur_setup_attrib_locations, gsk_gpu_blur_setup_vao }; diff --git a/gsk/gpu/gskgpuborderop.c b/gsk/gpu/gskgpuborderop.c index a888cb57ac..c741b7c918 100644 --- a/gsk/gpu/gskgpuborderop.c +++ b/gsk/gpu/gskgpuborderop.c @@ -95,6 +95,7 @@ static const GskGpuShaderOpClass GSK_GPU_BORDER_OP_CLASS = { #ifdef GDK_RENDERING_VULKAN &gsk_gpu_border_info, #endif + gsk_gpu_border_setup_attrib_locations, gsk_gpu_border_setup_vao }; diff --git a/gsk/gpu/gskgpuboxshadowop.c b/gsk/gpu/gskgpuboxshadowop.c index 5a404e62e9..7bf3b19958 100644 --- a/gsk/gpu/gskgpuboxshadowop.c +++ b/gsk/gpu/gskgpuboxshadowop.c @@ -73,6 +73,7 @@ static const GskGpuShaderOpClass GSK_GPU_BOX_SHADOW_OP_CLASS = { #ifdef GDK_RENDERING_VULKAN &gsk_gpu_boxshadow_info, #endif + gsk_gpu_boxshadow_setup_attrib_locations, gsk_gpu_boxshadow_setup_vao }; diff --git a/gsk/gpu/gskgpucolorizeop.c b/gsk/gpu/gskgpucolorizeop.c index 66b35f58b5..8fab07d247 100644 --- a/gsk/gpu/gskgpucolorizeop.c +++ b/gsk/gpu/gskgpucolorizeop.c @@ -49,6 +49,7 @@ static const GskGpuShaderOpClass GSK_GPU_COLORIZE_OP_CLASS = { #ifdef GDK_RENDERING_VULKAN &gsk_gpu_colorize_info, #endif + gsk_gpu_colorize_setup_attrib_locations, gsk_gpu_colorize_setup_vao }; diff --git a/gsk/gpu/gskgpucolormatrixop.c b/gsk/gpu/gskgpucolormatrixop.c index 6e596c0b74..32509a53f5 100644 --- a/gsk/gpu/gskgpucolormatrixop.c +++ b/gsk/gpu/gskgpucolormatrixop.c @@ -48,6 +48,7 @@ static const GskGpuShaderOpClass GSK_GPU_COLOR_MATRIX_OP_CLASS = { #ifdef GDK_RENDERING_VULKAN &gsk_gpu_colormatrix_info, #endif + gsk_gpu_colormatrix_setup_attrib_locations, gsk_gpu_colormatrix_setup_vao }; diff --git a/gsk/gpu/gskgpucolorop.c b/gsk/gpu/gskgpucolorop.c index 814c29ccf3..5042ba0b80 100644 --- a/gsk/gpu/gskgpucolorop.c +++ b/gsk/gpu/gskgpucolorop.c @@ -49,6 +49,7 @@ static const GskGpuShaderOpClass GSK_GPU_COLOR_OP_CLASS = { #ifdef GDK_RENDERING_VULKAN &gsk_gpu_color_info, #endif + gsk_gpu_color_setup_attrib_locations, gsk_gpu_color_setup_vao }; diff --git a/gsk/gpu/gskgpuconicgradientop.c b/gsk/gpu/gskgpuconicgradientop.c index c143ae1607..1fc24dbe99 100644 --- a/gsk/gpu/gskgpuconicgradientop.c +++ b/gsk/gpu/gskgpuconicgradientop.c @@ -49,6 +49,7 @@ static const GskGpuShaderOpClass GSK_GPU_CONIC_GRADIENT_OP_CLASS = { #ifdef GDK_RENDERING_VULKAN &gsk_gpu_conicgradient_info, #endif + gsk_gpu_conicgradient_setup_attrib_locations, gsk_gpu_conicgradient_setup_vao }; diff --git a/gsk/gpu/gskgpucrossfadeop.c b/gsk/gpu/gskgpucrossfadeop.c index d11eef74ce..d8524232b1 100644 --- a/gsk/gpu/gskgpucrossfadeop.c +++ b/gsk/gpu/gskgpucrossfadeop.c @@ -50,6 +50,7 @@ static const GskGpuShaderOpClass GSK_GPU_CROSS_FADE_OP_CLASS = { #ifdef GDK_RENDERING_VULKAN &gsk_gpu_crossfade_info, #endif + gsk_gpu_crossfade_setup_attrib_locations, gsk_gpu_crossfade_setup_vao }; diff --git a/gsk/gpu/gskgpulineargradientop.c b/gsk/gpu/gskgpulineargradientop.c index 075cd600a9..b32acec04d 100644 --- a/gsk/gpu/gskgpulineargradientop.c +++ b/gsk/gpu/gskgpulineargradientop.c @@ -53,6 +53,7 @@ static const GskGpuShaderOpClass GSK_GPU_LINEAR_GRADIENT_OP_CLASS = { #ifdef GDK_RENDERING_VULKAN &gsk_gpu_lineargradient_info, #endif + gsk_gpu_lineargradient_setup_attrib_locations, gsk_gpu_lineargradient_setup_vao }; diff --git a/gsk/gpu/gskgpumaskop.c b/gsk/gpu/gskgpumaskop.c index 128759db99..2c83b3f082 100644 --- a/gsk/gpu/gskgpumaskop.c +++ b/gsk/gpu/gskgpumaskop.c @@ -49,6 +49,7 @@ static const GskGpuShaderOpClass GSK_GPU_MASK_OP_CLASS = { #ifdef GDK_RENDERING_VULKAN &gsk_gpu_mask_info, #endif + gsk_gpu_mask_setup_attrib_locations, gsk_gpu_mask_setup_vao }; diff --git a/gsk/gpu/gskgpuradialgradientop.c b/gsk/gpu/gskgpuradialgradientop.c index 92945ccb8f..778b82fa06 100644 --- a/gsk/gpu/gskgpuradialgradientop.c +++ b/gsk/gpu/gskgpuradialgradientop.c @@ -53,6 +53,7 @@ static const GskGpuShaderOpClass GSK_GPU_RADIAL_GRADIENT_OP_CLASS = { #ifdef GDK_RENDERING_VULKAN &gsk_gpu_radialgradient_info, #endif + gsk_gpu_radialgradient_setup_attrib_locations, gsk_gpu_radialgradient_setup_vao }; diff --git a/gsk/gpu/gskgpuroundedcolorop.c b/gsk/gpu/gskgpuroundedcolorop.c index 81667bb42c..b4e97e5ed3 100644 --- a/gsk/gpu/gskgpuroundedcolorop.c +++ b/gsk/gpu/gskgpuroundedcolorop.c @@ -49,6 +49,7 @@ static const GskGpuShaderOpClass GSK_GPU_ROUNDED_COLOR_OP_CLASS = { #ifdef GDK_RENDERING_VULKAN &gsk_gpu_roundedcolor_info, #endif + gsk_gpu_roundedcolor_setup_attrib_locations, gsk_gpu_roundedcolor_setup_vao }; diff --git a/gsk/gpu/gskgpushaderopprivate.h b/gsk/gpu/gskgpushaderopprivate.h index df2b5110b2..f7759a6115 100644 --- a/gsk/gpu/gskgpushaderopprivate.h +++ b/gsk/gpu/gskgpushaderopprivate.h @@ -25,6 +25,7 @@ struct _GskGpuShaderOpClass #ifdef GDK_RENDERING_VULKAN const VkPipelineVertexInputStateCreateInfo *vertex_input_state; #endif + void (* setup_attrib_locations) (GLuint program); void (* setup_vao) (gsize offset); }; diff --git a/gsk/gpu/gskgpustraightalphaop.c b/gsk/gpu/gskgpustraightalphaop.c index aa67178b0c..28274f72f4 100644 --- a/gsk/gpu/gskgpustraightalphaop.c +++ b/gsk/gpu/gskgpustraightalphaop.c @@ -51,6 +51,7 @@ static const GskGpuShaderOpClass GSK_GPU_STRAIGHT_ALPHA_OP_CLASS = { #ifdef GDK_RENDERING_VULKAN &gsk_gpu_straightalpha_info, #endif + gsk_gpu_straightalpha_setup_attrib_locations, gsk_gpu_straightalpha_setup_vao }; diff --git a/gsk/gpu/gskgputextureop.c b/gsk/gpu/gskgputextureop.c index c90118d4b2..36454c88fd 100644 --- a/gsk/gpu/gskgputextureop.c +++ b/gsk/gpu/gskgputextureop.c @@ -48,6 +48,7 @@ static const GskGpuShaderOpClass GSK_GPU_TEXTURE_OP_CLASS = { #ifdef GDK_RENDERING_VULKAN &gsk_gpu_texture_info, #endif + gsk_gpu_texture_setup_attrib_locations, gsk_gpu_texture_setup_vao }; diff --git a/gsk/gpu/gskgpuuberop.c b/gsk/gpu/gskgpuuberop.c index 26ae08573e..21a71b04de 100644 --- a/gsk/gpu/gskgpuuberop.c +++ b/gsk/gpu/gskgpuuberop.c @@ -48,6 +48,7 @@ static const GskGpuShaderOpClass GSK_GPU_UBER_OP_CLASS = { #ifdef GDK_RENDERING_VULKAN &gsk_gpu_uber_info, #endif + gsk_gpu_uber_setup_attrib_locations, gsk_gpu_uber_setup_vao }; diff --git a/gsk/gpu/shaders/generate-header.py b/gsk/gpu/shaders/generate-header.py index 63e291bce7..0938392fea 100644 --- a/gsk/gpu/shaders/generate-header.py +++ b/gsk/gpu/shaders/generate-header.py @@ -21,6 +21,7 @@ with open(sys.argv[1]) as f: if not match.group(3).startswith('in'): raise Exception("Variable doesn't start with 'in'") matches.append({'name': ''.join('_' + char.lower() if char.isupper() else char for char in match.group(3))[3:], + 'attrib_name': match.group(3), 'location': int(match.group(1)), 'type': match.group(2)}) @@ -190,6 +191,19 @@ print(f'''}} '''); + +print(f'''static void +{var_name}_setup_attrib_locations (GLuint program) +{{''') + +for match in matches: + print(f''' glBindAttribLocation (program, {match['location']}, "{match['attrib_name']}");''') + +print(f'''}} + +'''); + + print(f'''#ifdef GDK_RENDERING_VULKAN static const VkPipelineVertexInputStateCreateInfo {var_name}_info = {{