glsl: Cross-validate explicit binding points.
authorKenneth Graunke <kenneth@whitecape.org>
Tue, 16 Jul 2013 19:18:57 +0000 (12:18 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Thu, 18 Jul 2013 23:57:24 +0000 (16:57 -0700)
All compilation units need to agree on the binding point, if they
specify one at all.

v2: Use binding, not constant_value.

Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
Reviewed-by: Paul Berry <stereotype441@gmail.com>
src/glsl/linker.cpp

index da5677067cdc86bb059184776b6af6631f05dee7..ac010cfbb6a84fa4230479402ce548807afc2038 100644 (file)
@@ -541,6 +541,25 @@ cross_validate_globals(struct gl_shader_program *prog,
               existing->explicit_location = true;
            }
 
+            /* From the GLSL 4.20 specification:
+             * "A link error will result if two compilation units in a program
+             *  specify different integer-constant bindings for the same
+             *  opaque-uniform name.  However, it is not an error to specify a
+             *  binding on some but not all declarations for the same name"
+             */
+            if (var->explicit_binding) {
+               if (existing->explicit_binding &&
+                   var->binding != existing->binding) {
+                  linker_error(prog, "explicit bindings for %s "
+                               "`%s' have differing values\n",
+                               mode_string(var), var->name);
+                  return false;
+               }
+
+               existing->binding = var->binding;
+               existing->explicit_binding = true;
+            }
+
            /* Validate layout qualifiers for gl_FragDepth.
             *
             * From the AMD/ARB_conservative_depth specs: