<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>
I made this a function (instead of a method of ir_variable) because it<br>
made the change set smaller, and I expect that there will be an overload<br>
that takes an ir_var_mode enum.  Having both functions used the same way<br>
seemed better.<br>
<br>
v2: Add missing case for ir_var_system_value.<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/ir.cpp     | 41 +++++++++++++++++++++++++++++++++++++++++<br>
 src/glsl/ir.h       |  3 +++<br>
 src/glsl/linker.cpp | 23 -----------------------<br>
 3 files changed, 44 insertions(+), 23 deletions(-)<br>
<br>
diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp<br>
index c682e3e..90e8f5d 100644<br>
--- a/src/glsl/ir.cpp<br>
+++ b/src/glsl/ir.cpp<br>
@@ -1891,3 +1891,44 @@ vertices_per_prim(GLenum prim)<br>
       return 3;<br>
    }<br>
 }<br>
+<br>
+/**<br>
+ * Generate a string describing the mode of a variable<br>
+ */<br>
+const char *<br>
+mode_string(const ir_variable *var)<br>
+{<br>
+   switch (var->mode) {<br>
+   case ir_var_auto:<br>
+      return (var->read_only) ? "global constant" : "global variable";<br>
+<br>
+   case ir_var_uniform:<br>
+      return "uniform";<br>
+<br>
+   case ir_var_shader_in:<br>
+      return "shader input";<br>
+<br>
+   case ir_var_shader_out:<br>
+      return "shader output";<br>
+<br>
+   case ir_var_function_in:<br>
+   case ir_var_const_in:<br>
+      return "function input";<br>
+<br>
+   case ir_var_function_out:<br>
+      return "function output";<br>
+<br>
+   case ir_var_function_inout:<br>
+      return "function inout";<br>
+<br>
+   case ir_var_system_value:<br>
+      return "shader input";<br>
+<br>
+   case ir_var_temporary:<br>
+      return "compiler temporary";<br>
+<br>
+   case ir_var_mode_count:<br>
+      assert(!"Should not get here.");<br>
+      return "invalid variable";<br></blockquote><div><br></div><div>I'd suggest changing this case to "break;", and moving these two lines after the end of the switch statement.  That way, in the unlikely event that var->mode is an invalid value other than ir_var_mode_count, the assertion will still fire, and in release builds we won't wind up returning a garbage pointer.<br>
<br>With that change, the 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>
+}<br>
diff --git a/src/glsl/ir.h b/src/glsl/ir.h<br>
index 8d5bec9..75c9f18 100644<br>
--- a/src/glsl/ir.h<br>
+++ b/src/glsl/ir.h<br>
@@ -2292,6 +2292,9 @@ extern char *<br>
 prototype_string(const glsl_type *return_type, const char *name,<br>
                 exec_list *parameters);<br>
<br>
+const char *<br>
+mode_string(const ir_variable *var);<br>
+<br>
 extern "C" {<br>
 #endif /* __cplusplus */<br>
<br>
diff --git a/src/glsl/linker.cpp b/src/glsl/linker.cpp<br>
index d8f655c..d081afb 100644<br>
--- a/src/glsl/linker.cpp<br>
+++ b/src/glsl/linker.cpp<br>
@@ -558,29 +558,6 @@ validate_geometry_shader_executable(struct gl_shader_program *prog,<br>
<br>
<br>
 /**<br>
- * Generate a string describing the mode of a variable<br>
- */<br>
-static const char *<br>
-mode_string(const ir_variable *var)<br>
-{<br>
-   switch (var->mode) {<br>
-   case ir_var_auto:<br>
-      return (var->read_only) ? "global constant" : "global variable";<br>
-<br>
-   case ir_var_uniform:    return "uniform";<br>
-   case ir_var_shader_in:  return "shader input";<br>
-   case ir_var_shader_out: return "shader output";<br>
-<br>
-   case ir_var_const_in:<br>
-   case ir_var_temporary:<br>
-   default:<br>
-      assert(!"Should not get here.");<br>
-      return "invalid variable";<br>
-   }<br>
-}<br>
-<br>
-<br>
-/**<br>
  * Perform validation of global variables used across multiple shaders<br>
  */<br>
 void<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>