<div dir="ltr">On 30 August 2013 16:07, Ian Romanick <span dir="ltr"><<a href="mailto:idr@freedesktop.org" target="_blank">idr@freedesktop.org</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
From: Ian Romanick <<a href="mailto:ian.d.romanick@intel.com">ian.d.romanick@intel.com</a>><br>
<br>
The new function, cross_validate_types_and_qualifiers, will have<br>
multiple callers from this file in future commits.<br>
<br>
Signed-off-by: Ian Romanick <<a href="mailto:ian.d.romanick@intel.com">ian.d.romanick@intel.com</a>><br>
---<br>
 src/glsl/link_varyings.cpp | 171 +++++++++++++++++++++++++--------------------<br>
 1 file changed, 94 insertions(+), 77 deletions(-)<br>
<br>
diff --git a/src/glsl/link_varyings.cpp b/src/glsl/link_varyings.cpp<br>
index 4ceb1d3..a1899f7 100644<br>
--- a/src/glsl/link_varyings.cpp<br>
+++ b/src/glsl/link_varyings.cpp<br>
@@ -41,6 +41,97 @@<br>
<br>
<br>
 /**<br>
+ * Validate the types and qualifiers of an output from one stage against the<br>
+ * matching input to another stage.<br>
+ */<br>
+static void<br>
+cross_validate_types_and_qualifiers(struct gl_shader_program *prog,<br>
+                                    const ir_variable *input,<br>
+                                    const ir_variable *output,<br>
+                                    GLenum consumer_type,<br>
+                                    const char *consumer_stage,<br>
+                                    const char *producer_stage)<br></blockquote><div><br></div><div>It seems redundant to pass both consumer_type and consumer_stage as arguments, since the latter is just _mesa_glsl_shader_target_name(consumer_type).  You might want to just pass consumer_type and producer_type, and use _mesa_glsl_shader_target_name() to convert them to strings in the event of an error.<br>
<br></div><div>However, it's extra bookkeeping work to do that, so I'm ambivalent about it.  Either way,<br></div><div><br></div><div>Reviewed-by: Paul Berry <<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>><br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
+{<br>
+   /* Check that the types match between stages.<br>
+    */<br>
+   const glsl_type *type_to_match = input->type;<br>
+   if (consumer_type == GL_GEOMETRY_SHADER) {<br>
+      assert(type_to_match->is_array()); /* Enforced by ast_to_hir */<br>
+      type_to_match = type_to_match->element_type();<br>
+   }<br>
+   if (type_to_match != output->type) {<br>
+      /* There is a bit of a special case for gl_TexCoord.  This<br>
+       * built-in is unsized by default.  Applications that variable<br>
+       * access it must redeclare it with a size.  There is some<br>
+       * language in the GLSL spec that implies the fragment shader<br>
+       * and vertex shader do not have to agree on this size.  Other<br>
+       * driver behave this way, and one or two applications seem to<br>
+       * rely on it.<br>
+       *<br>
+       * Neither declaration needs to be modified here because the array<br>
+       * sizes are fixed later when update_array_sizes is called.<br>
+       *<br>
+       * From page 48 (page 54 of the PDF) of the GLSL 1.10 spec:<br>
+       *<br>
+       *     "Unlike user-defined varying variables, the built-in<br>
+       *     varying variables don't have a strict one-to-one<br>
+       *     correspondence between the vertex language and the<br>
+       *     fragment language."<br>
+       */<br>
+      if (!output->type->is_array()<br>
+          || (strncmp("gl_", output->name, 3) != 0)) {<br>
+         linker_error(prog,<br>
+                      "%s shader output `%s' declared as type `%s', "<br>
+                      "but %s shader input declared as type `%s'\n",<br>
+                      producer_stage, output->name,<br>
+                      output->type->name,<br>
+                      consumer_stage, input->type->name);<br>
+         return;<br>
+      }<br>
+   }<br>
+<br>
+   /* Check that all of the qualifiers match between stages.<br>
+    */<br>
+   if (input->centroid != output->centroid) {<br>
+      linker_error(prog,<br>
+                   "%s shader output `%s' %s centroid qualifier, "<br>
+                   "but %s shader input %s centroid qualifier\n",<br>
+                   producer_stage,<br>
+                   output->name,<br>
+                   (output->centroid) ? "has" : "lacks",<br>
+                   consumer_stage,<br>
+                   (input->centroid) ? "has" : "lacks");<br>
+      return;<br>
+   }<br>
+<br>
+   if (input->invariant != output->invariant) {<br>
+      linker_error(prog,<br>
+                   "%s shader output `%s' %s invariant qualifier, "<br>
+                   "but %s shader input %s invariant qualifier\n",<br>
+                   producer_stage,<br>
+                   output->name,<br>
+                   (output->invariant) ? "has" : "lacks",<br>
+                   consumer_stage,<br>
+                   (input->invariant) ? "has" : "lacks");<br>
+      return;<br>
+   }<br>
+<br>
+   if (input->interpolation != output->interpolation) {<br>
+      linker_error(prog,<br>
+                   "%s shader output `%s' specifies %s "<br>
+                   "interpolation qualifier, "<br>
+                   "but %s shader input specifies %s "<br>
+                   "interpolation qualifier\n",<br>
+                   producer_stage,<br>
+                   output->name,<br>
+                   output->interpolation_string(),<br>
+                   consumer_stage,<br>
+                   input->interpolation_string());<br>
+      return;<br>
+   }<br>
+}<br>
+<br>
+/**<br>
  * Validate that outputs from one stage match inputs of another<br>
  */<br>
 void<br>
@@ -81,83 +172,9 @@ cross_validate_outputs_to_inputs(struct gl_shader_program *prog,<br>
<br>
       ir_variable *const output = parameters.get_variable(input->name);<br>
       if (output != NULL) {<br>
-        /* Check that the types match between stages.<br>
-         */<br>
-         const glsl_type *type_to_match = input->type;<br>
-         if (consumer->Type == GL_GEOMETRY_SHADER) {<br>
-            assert(type_to_match->is_array()); /* Enforced by ast_to_hir */<br>
-            type_to_match = type_to_match->element_type();<br>
-         }<br>
-        if (type_to_match != output->type) {<br>
-           /* There is a bit of a special case for gl_TexCoord.  This<br>
-            * built-in is unsized by default.  Applications that variable<br>
-            * access it must redeclare it with a size.  There is some<br>
-            * language in the GLSL spec that implies the fragment shader<br>
-            * and vertex shader do not have to agree on this size.  Other<br>
-            * driver behave this way, and one or two applications seem to<br>
-            * rely on it.<br>
-            *<br>
-            * Neither declaration needs to be modified here because the array<br>
-            * sizes are fixed later when update_array_sizes is called.<br>
-            *<br>
-            * From page 48 (page 54 of the PDF) of the GLSL 1.10 spec:<br>
-            *<br>
-            *     "Unlike user-defined varying variables, the built-in<br>
-            *     varying variables don't have a strict one-to-one<br>
-            *     correspondence between the vertex language and the<br>
-            *     fragment language."<br>
-            */<br>
-           if (!output->type->is_array()<br>
-               || (strncmp("gl_", output->name, 3) != 0)) {<br>
-              linker_error(prog,<br>
-                           "%s shader output `%s' declared as type `%s', "<br>
-                           "but %s shader input declared as type `%s'\n",<br>
-                           producer_stage, output->name,<br>
-                           output->type->name,<br>
-                           consumer_stage, input->type->name);<br>
-              return;<br>
-           }<br>
-        }<br>
-<br>
-        /* Check that all of the qualifiers match between stages.<br>
-         */<br>
-        if (input->centroid != output->centroid) {<br>
-           linker_error(prog,<br>
-                        "%s shader output `%s' %s centroid qualifier, "<br>
-                        "but %s shader input %s centroid qualifier\n",<br>
-                        producer_stage,<br>
-                        output->name,<br>
-                        (output->centroid) ? "has" : "lacks",<br>
-                        consumer_stage,<br>
-                        (input->centroid) ? "has" : "lacks");<br>
-           return;<br>
-        }<br>
-<br>
-        if (input->invariant != output->invariant) {<br>
-           linker_error(prog,<br>
-                        "%s shader output `%s' %s invariant qualifier, "<br>
-                        "but %s shader input %s invariant qualifier\n",<br>
-                        producer_stage,<br>
-                        output->name,<br>
-                        (output->invariant) ? "has" : "lacks",<br>
-                        consumer_stage,<br>
-                        (input->invariant) ? "has" : "lacks");<br>
-           return;<br>
-        }<br>
-<br>
-        if (input->interpolation != output->interpolation) {<br>
-           linker_error(prog,<br>
-                        "%s shader output `%s' specifies %s "<br>
-                        "interpolation qualifier, "<br>
-                        "but %s shader input specifies %s "<br>
-                        "interpolation qualifier\n",<br>
-                        producer_stage,<br>
-                        output->name,<br>
-                        output->interpolation_string(),<br>
-                        consumer_stage,<br>
-                        input->interpolation_string());<br>
-           return;<br>
-        }<br>
+         cross_validate_types_and_qualifiers(prog, input, output,<br>
+                                             consumer->Type, consumer_stage,<br>
+                                             producer_stage);<br>
       }<br>
    }<br>
 }<br>
<span class=""><font color="#888888">--<br>
1.8.1.4<br>
<br>
_______________________________________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org">mesa-dev@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/mesa-dev" target="_blank">http://lists.freedesktop.org/mailman/listinfo/mesa-dev</a><br>
</font></span></blockquote></div><br></div></div>