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.
This commit is contained in:
Benjamin Otte 2024-01-04 14:52:03 +01:00
parent 55dbf0accb
commit 1723ab34e1
19 changed files with 42 additions and 9 deletions

View File

@ -460,7 +460,7 @@ gsk_gl_device_load_shader (GskGLDevice *self,
static GLuint static GLuint
gsk_gl_device_load_program (GskGLDevice *self, gsk_gl_device_load_program (GskGLDevice *self,
const char *program_name, const GskGpuShaderOpClass *op_class,
guint32 variation, guint32 variation,
GskGpuShaderClip clip, GskGpuShaderClip clip,
guint n_external_textures, guint n_external_textures,
@ -469,11 +469,11 @@ gsk_gl_device_load_program (GskGLDevice *self,
GLuint vertex_shader_id, fragment_shader_id, program_id; GLuint vertex_shader_id, fragment_shader_id, program_id;
GLint link_status; 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) if (vertex_shader_id == 0)
return 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) if (fragment_shader_id == 0)
return 0; return 0;
@ -482,6 +482,8 @@ gsk_gl_device_load_program (GskGLDevice *self,
glAttachShader (program_id, vertex_shader_id); glAttachShader (program_id, vertex_shader_id);
glAttachShader (program_id, fragment_shader_id); glAttachShader (program_id, fragment_shader_id);
op_class->setup_attrib_locations (program_id);
glLinkProgram (program_id); glLinkProgram (program_id);
glGetProgramiv (program_id, GL_LINK_STATUS, &link_status); glGetProgramiv (program_id, GL_LINK_STATUS, &link_status);
@ -545,7 +547,7 @@ gsk_gl_device_use_program (GskGLDevice *self,
return; 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) if (program_id == 0)
{ {
g_critical ("Failed to load shader program: %s", error->message); g_critical ("Failed to load shader program: %s", error->message);

View File

@ -51,6 +51,7 @@ static const GskGpuShaderOpClass GSK_GPU_BLEND_MODE_OP_CLASS = {
#ifdef GDK_RENDERING_VULKAN #ifdef GDK_RENDERING_VULKAN
&gsk_gpu_blendmode_info, &gsk_gpu_blendmode_info,
#endif #endif
gsk_gpu_blendmode_setup_attrib_locations,
gsk_gpu_blendmode_setup_vao gsk_gpu_blendmode_setup_vao
}; };

View File

@ -52,6 +52,7 @@ static const GskGpuShaderOpClass GSK_GPU_BLUR_OP_CLASS = {
#ifdef GDK_RENDERING_VULKAN #ifdef GDK_RENDERING_VULKAN
&gsk_gpu_blur_info, &gsk_gpu_blur_info,
#endif #endif
gsk_gpu_blur_setup_attrib_locations,
gsk_gpu_blur_setup_vao gsk_gpu_blur_setup_vao
}; };

View File

@ -95,6 +95,7 @@ static const GskGpuShaderOpClass GSK_GPU_BORDER_OP_CLASS = {
#ifdef GDK_RENDERING_VULKAN #ifdef GDK_RENDERING_VULKAN
&gsk_gpu_border_info, &gsk_gpu_border_info,
#endif #endif
gsk_gpu_border_setup_attrib_locations,
gsk_gpu_border_setup_vao gsk_gpu_border_setup_vao
}; };

View File

@ -73,6 +73,7 @@ static const GskGpuShaderOpClass GSK_GPU_BOX_SHADOW_OP_CLASS = {
#ifdef GDK_RENDERING_VULKAN #ifdef GDK_RENDERING_VULKAN
&gsk_gpu_boxshadow_info, &gsk_gpu_boxshadow_info,
#endif #endif
gsk_gpu_boxshadow_setup_attrib_locations,
gsk_gpu_boxshadow_setup_vao gsk_gpu_boxshadow_setup_vao
}; };

View File

@ -49,6 +49,7 @@ static const GskGpuShaderOpClass GSK_GPU_COLORIZE_OP_CLASS = {
#ifdef GDK_RENDERING_VULKAN #ifdef GDK_RENDERING_VULKAN
&gsk_gpu_colorize_info, &gsk_gpu_colorize_info,
#endif #endif
gsk_gpu_colorize_setup_attrib_locations,
gsk_gpu_colorize_setup_vao gsk_gpu_colorize_setup_vao
}; };

View File

@ -48,6 +48,7 @@ static const GskGpuShaderOpClass GSK_GPU_COLOR_MATRIX_OP_CLASS = {
#ifdef GDK_RENDERING_VULKAN #ifdef GDK_RENDERING_VULKAN
&gsk_gpu_colormatrix_info, &gsk_gpu_colormatrix_info,
#endif #endif
gsk_gpu_colormatrix_setup_attrib_locations,
gsk_gpu_colormatrix_setup_vao gsk_gpu_colormatrix_setup_vao
}; };

View File

@ -49,6 +49,7 @@ static const GskGpuShaderOpClass GSK_GPU_COLOR_OP_CLASS = {
#ifdef GDK_RENDERING_VULKAN #ifdef GDK_RENDERING_VULKAN
&gsk_gpu_color_info, &gsk_gpu_color_info,
#endif #endif
gsk_gpu_color_setup_attrib_locations,
gsk_gpu_color_setup_vao gsk_gpu_color_setup_vao
}; };

View File

@ -49,6 +49,7 @@ static const GskGpuShaderOpClass GSK_GPU_CONIC_GRADIENT_OP_CLASS = {
#ifdef GDK_RENDERING_VULKAN #ifdef GDK_RENDERING_VULKAN
&gsk_gpu_conicgradient_info, &gsk_gpu_conicgradient_info,
#endif #endif
gsk_gpu_conicgradient_setup_attrib_locations,
gsk_gpu_conicgradient_setup_vao gsk_gpu_conicgradient_setup_vao
}; };

View File

@ -50,6 +50,7 @@ static const GskGpuShaderOpClass GSK_GPU_CROSS_FADE_OP_CLASS = {
#ifdef GDK_RENDERING_VULKAN #ifdef GDK_RENDERING_VULKAN
&gsk_gpu_crossfade_info, &gsk_gpu_crossfade_info,
#endif #endif
gsk_gpu_crossfade_setup_attrib_locations,
gsk_gpu_crossfade_setup_vao gsk_gpu_crossfade_setup_vao
}; };

View File

@ -53,6 +53,7 @@ static const GskGpuShaderOpClass GSK_GPU_LINEAR_GRADIENT_OP_CLASS = {
#ifdef GDK_RENDERING_VULKAN #ifdef GDK_RENDERING_VULKAN
&gsk_gpu_lineargradient_info, &gsk_gpu_lineargradient_info,
#endif #endif
gsk_gpu_lineargradient_setup_attrib_locations,
gsk_gpu_lineargradient_setup_vao gsk_gpu_lineargradient_setup_vao
}; };

View File

@ -49,6 +49,7 @@ static const GskGpuShaderOpClass GSK_GPU_MASK_OP_CLASS = {
#ifdef GDK_RENDERING_VULKAN #ifdef GDK_RENDERING_VULKAN
&gsk_gpu_mask_info, &gsk_gpu_mask_info,
#endif #endif
gsk_gpu_mask_setup_attrib_locations,
gsk_gpu_mask_setup_vao gsk_gpu_mask_setup_vao
}; };

View File

@ -53,6 +53,7 @@ static const GskGpuShaderOpClass GSK_GPU_RADIAL_GRADIENT_OP_CLASS = {
#ifdef GDK_RENDERING_VULKAN #ifdef GDK_RENDERING_VULKAN
&gsk_gpu_radialgradient_info, &gsk_gpu_radialgradient_info,
#endif #endif
gsk_gpu_radialgradient_setup_attrib_locations,
gsk_gpu_radialgradient_setup_vao gsk_gpu_radialgradient_setup_vao
}; };

View File

@ -49,6 +49,7 @@ static const GskGpuShaderOpClass GSK_GPU_ROUNDED_COLOR_OP_CLASS = {
#ifdef GDK_RENDERING_VULKAN #ifdef GDK_RENDERING_VULKAN
&gsk_gpu_roundedcolor_info, &gsk_gpu_roundedcolor_info,
#endif #endif
gsk_gpu_roundedcolor_setup_attrib_locations,
gsk_gpu_roundedcolor_setup_vao gsk_gpu_roundedcolor_setup_vao
}; };

View File

@ -25,6 +25,7 @@ struct _GskGpuShaderOpClass
#ifdef GDK_RENDERING_VULKAN #ifdef GDK_RENDERING_VULKAN
const VkPipelineVertexInputStateCreateInfo *vertex_input_state; const VkPipelineVertexInputStateCreateInfo *vertex_input_state;
#endif #endif
void (* setup_attrib_locations) (GLuint program);
void (* setup_vao) (gsize offset); void (* setup_vao) (gsize offset);
}; };

View File

@ -51,6 +51,7 @@ static const GskGpuShaderOpClass GSK_GPU_STRAIGHT_ALPHA_OP_CLASS = {
#ifdef GDK_RENDERING_VULKAN #ifdef GDK_RENDERING_VULKAN
&gsk_gpu_straightalpha_info, &gsk_gpu_straightalpha_info,
#endif #endif
gsk_gpu_straightalpha_setup_attrib_locations,
gsk_gpu_straightalpha_setup_vao gsk_gpu_straightalpha_setup_vao
}; };

View File

@ -48,6 +48,7 @@ static const GskGpuShaderOpClass GSK_GPU_TEXTURE_OP_CLASS = {
#ifdef GDK_RENDERING_VULKAN #ifdef GDK_RENDERING_VULKAN
&gsk_gpu_texture_info, &gsk_gpu_texture_info,
#endif #endif
gsk_gpu_texture_setup_attrib_locations,
gsk_gpu_texture_setup_vao gsk_gpu_texture_setup_vao
}; };

View File

@ -48,6 +48,7 @@ static const GskGpuShaderOpClass GSK_GPU_UBER_OP_CLASS = {
#ifdef GDK_RENDERING_VULKAN #ifdef GDK_RENDERING_VULKAN
&gsk_gpu_uber_info, &gsk_gpu_uber_info,
#endif #endif
gsk_gpu_uber_setup_attrib_locations,
gsk_gpu_uber_setup_vao gsk_gpu_uber_setup_vao
}; };

View File

@ -21,6 +21,7 @@ with open(sys.argv[1]) as f:
if not match.group(3).startswith('in'): if not match.group(3).startswith('in'):
raise Exception("Variable doesn't start with '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:], 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)), 'location': int(match.group(1)),
'type': match.group(2)}) '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 print(f'''#ifdef GDK_RENDERING_VULKAN
static const VkPipelineVertexInputStateCreateInfo {var_name}_info = {{ static const VkPipelineVertexInputStateCreateInfo {var_name}_info = {{