svgadump: Dump the new depth format names.
[mesa.git] / src / glsl / linker.cpp
index 35d893f499e2c50d50f50013591e58a9a38f6b67..195f58f29c6bb191aaa4d1e73a9080343a6071c7 100644 (file)
@@ -177,6 +177,19 @@ linker_error(gl_shader_program *prog, const char *fmt, ...)
 }
 
 
+void
+linker_warning(gl_shader_program *prog, const char *fmt, ...)
+{
+   va_list ap;
+
+   ralloc_strcat(&prog->InfoLog, "error: ");
+   va_start(ap, fmt);
+   ralloc_vasprintf_append(&prog->InfoLog, fmt, ap);
+   va_end(ap);
+
+}
+
+
 void
 invalidate_variable_locations(gl_shader *sh, enum ir_variable_mode mode,
                              int generic_base)
@@ -249,6 +262,25 @@ validate_vertex_shader_executable(struct gl_shader_program *prog,
       return false;
    }
 
+   if (prog->Version >= 130) {
+      /* From section 7.1 (Vertex Shader Special Variables) of the
+       * GLSL 1.30 spec:
+       *
+       *   "It is an error for a shader to statically write both
+       *   gl_ClipVertex and gl_ClipDistance."
+       */
+      find_assignment_visitor clip_vertex("gl_ClipVertex");
+      find_assignment_visitor clip_distance("gl_ClipDistance");
+
+      clip_vertex.run(shader->ir);
+      clip_distance.run(shader->ir);
+      if (clip_vertex.variable_found() && clip_distance.variable_found()) {
+         linker_error(prog, "vertex shader writes to both `gl_ClipVertex' "
+                      "and `gl_ClipDistance'\n");
+         return false;
+      }
+   }
+
    return true;
 }
 
@@ -382,7 +414,7 @@ cross_validate_globals(struct gl_shader_program *prog,
 
         /* Validate layout qualifiers for gl_FragDepth.
          *
-         * From the AMD_conservative_depth spec:
+         * From the AMD/ARB_conservative_depth specs:
          *    "If gl_FragDepth is redeclared in any fragment shader in
          *    a program, it must be redeclared in all fragment shaders in that
          *    program that have static assignments to gl_FragDepth. All
@@ -909,6 +941,14 @@ link_intrastage_shaders(void *mem_ctx,
 
    free(linking_shaders);
 
+#ifdef DEBUG
+   /* At this point linked should contain all of the linked IR, so
+    * validate it to make sure nothing went wrong.
+    */
+   if (linked)
+      validate_ir_tree(linked->ir);
+#endif
+
    /* Make a pass over all variable declarations to ensure that arrays with
     * unspecified sizes have a size specified.  The size is inferred from the
     * max_array_access field.