<div dir="ltr">On 27 October 2013 14:59, 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:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">From: Ian Romanick <<a href="mailto:ian.d.romanick@intel.com">ian.d.romanick@intel.com</a>><br>
<br>
Future patches will add some extra code to this path, and some of that<br>
code will want to exit from the explicit location code early.<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/ast_to_hir.cpp | 159 +++++++++++++++++++++++++-----------------------<br>
1 file changed, 84 insertions(+), 75 deletions(-)<br>
<br>
diff --git a/src/glsl/ast_to_hir.cpp b/src/glsl/ast_to_hir.cpp<br>
index 561d942..05539b8 100644<br>
--- a/src/glsl/ast_to_hir.cpp<br>
+++ b/src/glsl/ast_to_hir.cpp<br>
@@ -2043,6 +2043,89 @@ interpret_interpolation_qualifier(const struct ast_type_qualifier *qual,<br>
<br>
<br>
static void<br>
+validate_explicit_location(const struct ast_type_qualifier *qual,<br>
+ ir_variable *var,<br>
+ struct _mesa_glsl_parse_state *state,<br>
+ YYLTYPE *loc)<br>
+{<br>
+ const bool global_scope = (state->current_function == NULL);<br>
+ bool fail = false;<br>
+ const char *string = "";<br>
+<br>
+ /* In the vertex shader only shader inputs can be given explicit<br>
+ * locations.<br>
+ *<br>
+ * In the fragment shader only shader outputs can be given explicit<br>
+ * locations.<br>
+ */<br>
+ switch (state->target) {<br>
+ case vertex_shader:<br>
+ if (!global_scope || (var->mode != ir_var_shader_in)) {<br>
+ fail = true;<br>
+ string = "input";<br>
+ }<br>
+ break;<br>
+<br>
+ case geometry_shader:<br>
+ _mesa_glsl_error(loc, state,<br>
+ "geometry shader variables cannot be given "<br>
+ "explicit locations");<br>
+ break;<br></blockquote><div><br></div><div>While you're at it (either in this patch or a separate patch) you might want to change this "break;" to a "return;". That way we won't end up trying to apply a bogus geometry shader location qualifier (which could might cause cascading errors).<br>
<br></div><div>Either way, though, this patch is:<br><br>Reviewed-by: Paul Berry <<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
+<br>
+ case fragment_shader:<br>
+ if (!global_scope || (var->mode != ir_var_shader_out)) {<br>
+ fail = true;<br>
+ string = "output";<br>
+ }<br>
+ break;<br>
+ };<br>
+<br>
+ if (fail) {<br>
+ _mesa_glsl_error(loc, state,<br>
+ "only %s shader %s variables can be given an "<br>
+ "explicit location",<br>
+ _mesa_glsl_shader_target_name(state->target),<br>
+ string);<br>
+ } else {<br>
+ var->explicit_location = true;<br>
+<br>
+ /* This bit of silliness is needed because invalid explicit locations<br>
+ * are supposed to be flagged during linking. Small negative values<br>
+ * biased by VERT_ATTRIB_GENERIC0 or FRAG_RESULT_DATA0 could alias<br>
+ * built-in values (e.g., -16+VERT_ATTRIB_GENERIC0 = VERT_ATTRIB_POS).<br>
+ * The linker needs to be able to differentiate these cases. This<br>
+ * ensures that negative values stay negative.<br>
+ */<br>
+ if (qual->location >= 0) {<br>
+ var->location = (state->target == vertex_shader)<br>
+ ? (qual->location + VERT_ATTRIB_GENERIC0)<br>
+ : (qual->location + FRAG_RESULT_DATA0);<br>
+ } else {<br>
+ var->location = qual->location;<br>
+ }<br>
+<br>
+ if (qual->flags.q.explicit_index) {<br>
+ /* From the GLSL 4.30 specification, section 4.4.2 (Output<br>
+ * Layout Qualifiers):<br>
+ *<br>
+ * "It is also a compile-time error if a fragment shader<br>
+ * sets a layout index to less than 0 or greater than 1."<br>
+ *<br>
+ * Older specifications don't mandate a behavior; we take<br>
+ * this as a clarification and always generate the error.<br>
+ */<br>
+ if (qual->index < 0 || qual->index > 1) {<br>
+ _mesa_glsl_error(loc, state,<br>
+ "explicit index may only be 0 or 1");<br>
+ } else {<br>
+ var->explicit_index = true;<br>
+ var->index = qual->index;<br>
+ }<br>
+ }<br>
+ }<br>
+}<br>
+<br>
+static void<br>
apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual,<br>
ir_variable *var,<br>
struct _mesa_glsl_parse_state *state,<br>
@@ -2194,81 +2277,7 @@ apply_type_qualifier_to_variable(const struct ast_type_qualifier *qual,<br>
}<br>
<br>
if (qual->flags.q.explicit_location) {<br>
- const bool global_scope = (state->current_function == NULL);<br>
- bool fail = false;<br>
- const char *string = "";<br>
-<br>
- /* In the vertex shader only shader inputs can be given explicit<br>
- * locations.<br>
- *<br>
- * In the fragment shader only shader outputs can be given explicit<br>
- * locations.<br>
- */<br>
- switch (state->target) {<br>
- case vertex_shader:<br>
- if (!global_scope || (var->mode != ir_var_shader_in)) {<br>
- fail = true;<br>
- string = "input";<br>
- }<br>
- break;<br>
-<br>
- case geometry_shader:<br>
- _mesa_glsl_error(loc, state,<br>
- "geometry shader variables cannot be given "<br>
- "explicit locations");<br>
- break;<br>
-<br>
- case fragment_shader:<br>
- if (!global_scope || (var->mode != ir_var_shader_out)) {<br>
- fail = true;<br>
- string = "output";<br>
- }<br>
- break;<br>
- };<br>
-<br>
- if (fail) {<br>
- _mesa_glsl_error(loc, state,<br>
- "only %s shader %s variables can be given an "<br>
- "explicit location",<br>
- _mesa_glsl_shader_target_name(state->target),<br>
- string);<br>
- } else {<br>
- var->explicit_location = true;<br>
-<br>
- /* This bit of silliness is needed because invalid explicit locations<br>
- * are supposed to be flagged during linking. Small negative values<br>
- * biased by VERT_ATTRIB_GENERIC0 or FRAG_RESULT_DATA0 could alias<br>
- * built-in values (e.g., -16+VERT_ATTRIB_GENERIC0 = VERT_ATTRIB_POS).<br>
- * The linker needs to be able to differentiate these cases. This<br>
- * ensures that negative values stay negative.<br>
- */<br>
- if (qual->location >= 0) {<br>
- var->location = (state->target == vertex_shader)<br>
- ? (qual->location + VERT_ATTRIB_GENERIC0)<br>
- : (qual->location + FRAG_RESULT_DATA0);<br>
- } else {<br>
- var->location = qual->location;<br>
- }<br>
-<br>
- if (qual->flags.q.explicit_index) {<br>
- /* From the GLSL 4.30 specification, section 4.4.2 (Output<br>
- * Layout Qualifiers):<br>
- *<br>
- * "It is also a compile-time error if a fragment shader<br>
- * sets a layout index to less than 0 or greater than 1."<br>
- *<br>
- * Older specifications don't mandate a behavior; we take<br>
- * this as a clarification and always generate the error.<br>
- */<br>
- if (qual->index < 0 || qual->index > 1) {<br>
- _mesa_glsl_error(loc, state,<br>
- "explicit index may only be 0 or 1");<br>
- } else {<br>
- var->explicit_index = true;<br>
- var->index = qual->index;<br>
- }<br>
- }<br>
- }<br>
+ validate_explicit_location(qual, var, state, loc);<br>
} else if (qual->flags.q.explicit_index) {<br>
_mesa_glsl_error(loc, state,<br>
"explicit index requires explicit location");<br>
<span class="HOEnZb"><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>