From 2e630297afc19ef4e69b8afe79dfd337171dbd60 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Foucault?= Date: Fri, 21 Aug 2020 14:25:58 +0200 Subject: [PATCH] GPUShader: Fix linking working even if one shader compilation failed Linking without valid shaders works on some drivers. Avoid this case by forcing linking step to return false. --- source/blender/gpu/opengl/gl_shader.cc | 5 +++++ source/blender/gpu/opengl/gl_shader.hh | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/source/blender/gpu/opengl/gl_shader.cc b/source/blender/gpu/opengl/gl_shader.cc index b2cca2ef45e..3ec818b53a6 100644 --- a/source/blender/gpu/opengl/gl_shader.cc +++ b/source/blender/gpu/opengl/gl_shader.cc @@ -151,6 +151,7 @@ GLuint GLShader::create_shader_stage(GLenum gl_stage, MutableSpan } if (!status) { glDeleteShader(shader); + compilation_failed_ = true; return 0; } @@ -193,6 +194,10 @@ void GLShader::fragment_shader_from_glsl(MutableSpan sources) bool GLShader::finalize(void) { + if (compilation_failed_) { + return false; + } + glLinkProgram(shader_program_); GLint status; diff --git a/source/blender/gpu/opengl/gl_shader.hh b/source/blender/gpu/opengl/gl_shader.hh index 37119b8b093..a686014f4c5 100644 --- a/source/blender/gpu/opengl/gl_shader.hh +++ b/source/blender/gpu/opengl/gl_shader.hh @@ -39,10 +39,12 @@ class GLShader : public Shader { private: /** Handle for full program (links shader stages below). */ GLuint shader_program_ = 0; - + /** Individual shader stages. */ GLuint vert_shader_ = 0; GLuint geom_shader_ = 0; GLuint frag_shader_ = 0; + /** True if any shader failed to compile. */ + bool compilation_failed_ = false; eGPUShaderTFBType transform_feedback_type_ = GPU_SHADER_TFB_NONE;