From 25f51d3b9b8c36c41cd23d2797b6a06f6e27ff86 Mon Sep 17 00:00:00 2001 From: Ian Romanick Date: Fri, 16 Jul 2010 15:51:50 -0700 Subject: linker: Track and validate GLSL versions used in shaders --- src/glsl/linker.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/glsl/linker.cpp') diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp index 06aa24e66f5..4933686b5e9 100644 --- a/src/glsl/linker.cpp +++ b/src/glsl/linker.cpp @@ -66,12 +66,14 @@ #include #include #include +#include extern "C" { #include } #include "main/mtypes.h" +#include "main/macros.h" #include "glsl_symbol_table.h" #include "ir.h" #include "program.h" @@ -1107,7 +1109,12 @@ link_shaders(struct gl_shader_program *prog) calloc(2 * prog->NumShaders, sizeof(struct gl_shader *)); frag_shader_list = &vert_shader_list[prog->NumShaders]; + unsigned min_version = UINT_MAX; + unsigned max_version = 0; for (unsigned i = 0; i < prog->NumShaders; i++) { + min_version = MIN2(min_version, prog->Shaders[i]->Version); + max_version = MAX2(max_version, prog->Shaders[i]->Version); + switch (prog->Shaders[i]->Type) { case GL_VERTEX_SHADER: vert_shader_list[num_vert_shaders] = prog->Shaders[i]; @@ -1124,6 +1131,20 @@ link_shaders(struct gl_shader_program *prog) } } + /* Previous to GLSL version 1.30, different compilation units could mix and + * match shading language versions. With GLSL 1.30 and later, the versions + * of all shaders must match. + */ + assert(min_version >= 110); + assert(max_version <= 130); + if ((max_version >= 130) && (min_version != max_version)) { + linker_error_printf(prog, "all shaders must use same shading " + "language version\n"); + goto done; + } + + prog->Version = max_version; + /* FINISHME: Implement intra-stage linking. */ prog->_NumLinkedShaders = 0; if (num_vert_shaders > 0) { -- cgit v1.2.3