From dc9e0f300ef4defa6fb2dccefe69bb8a63abb71e Mon Sep 17 00:00:00 2001 From: Jeroen Bakker Date: Thu, 23 Feb 2023 14:40:40 +0100 Subject: [PATCH] GPU: Fix Potential Error in Builtin Resolution. When using ShaderCreateInfo with builtin uniform(blocks) there are cases where the current implementation could not find an existing block. The reason is that it uses name matching and name matching requires that the shader inputs are sorted based on the name hash. This change fixes this by first for the sorting of the shader inputs before resolving the builtins. Pull Request #105127 --- source/blender/gpu/opengl/gl_shader_interface.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/blender/gpu/opengl/gl_shader_interface.cc b/source/blender/gpu/opengl/gl_shader_interface.cc index 4b10780e551..0b0bd2c1ea8 100644 --- a/source/blender/gpu/opengl/gl_shader_interface.cc +++ b/source/blender/gpu/opengl/gl_shader_interface.cc @@ -529,6 +529,9 @@ GLShaderInterface::GLShaderInterface(GLuint program, const shader::ShaderCreateI } } + this->sort_inputs(); + + /* Resolving builtins must happen after the inputs have been sorted. */ /* Builtin Uniforms */ for (int32_t u_int = 0; u_int < GPU_NUM_UNIFORMS; u_int++) { GPUUniformBuiltin u = static_cast(u_int); @@ -543,8 +546,6 @@ GLShaderInterface::GLShaderInterface(GLuint program, const shader::ShaderCreateI builtin_blocks_[u] = (block != nullptr) ? block->binding : -1; } - this->sort_inputs(); - // this->debug_print(); glUseProgram(last_program);