<div dir="ltr">On 1 August 2013 16:03, 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">
A couple of comments below.  Other than that,<br>
<br>
Reviewed-by: Ian Romanick <<a href="mailto:ian.d.romanick@intel.com" target="_blank">ian.d.romanick@intel.com</a>><div><div class="h5"><br>
<br>
On 07/31/2013 02:18 PM, Paul Berry wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
---<br>
  src/glsl/ir_set_program_<u></u>inouts.cpp | 85 ++++++++++++++++++++++++++++++<u></u>++------<br>
  1 file changed, 73 insertions(+), 12 deletions(-)<br>
<br>
diff --git a/src/glsl/ir_set_program_<u></u>inouts.cpp b/src/glsl/ir_set_program_<u></u>inouts.cpp<br>
index 018342b..8f96324 100644<br>
--- a/src/glsl/ir_set_program_<u></u>inouts.cpp<br>
+++ b/src/glsl/ir_set_program_<u></u>inouts.cpp<br>
@@ -114,7 +114,13 @@ mark(struct gl_program *prog, ir_variable *var, int offset, int len,<br>
  void<br>
  ir_set_program_inouts_visitor:<u></u>:mark_whole_variable(ir_<u></u>variable *var)<br>
  {<br>
-   mark(this->prog, var, 0, var->type->count_attribute_<u></u>slots(),<br>
+   const glsl_type *type = var->type;<br>
+   if (this->shader_type == GL_GEOMETRY_SHADER &&<br>
+       var->mode == ir_var_shader_in && type->is_array()) {<br>
+      type = type->fields.array;<br>
+   }<br>
+<br>
+   mark(this->prog, var, 0, type->count_attribute_slots(),<br>
          this->shader_type == GL_FRAGMENT_SHADER);<br>
  }<br>
<br>
@@ -133,7 +139,9 @@ ir_set_program_inouts_visitor:<u></u>:visit(ir_dereference_variable *ir)<br>
  /**<br>
   * Try to mark a portion of the given variable as used.  Caller must ensure<br>
   * that the variable represents a shader input or output which can be indexed<br>
- * into in array fashion (an array, matrix, or vector).<br>
+ * into in array fashion (an array, matrix, or vector).  For the purpose of<br>
+ * geometry shader inputs (which are always arrays), this means that the array<br>
+ * element must be something that can be indexed into in array fashion.<br>
</blockquote>
<br></div></div>
Except gl_PrimitiveIDIn, as noted below.</blockquote><div><br></div><div>Good point.  I've updated the comment.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div class="h5"><br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
   *<br>
   * If the index can't be interpreted as a constant, or some other problem<br>
   * occurs, then nothing will be marked and false will be returned.<br>
@@ -144,6 +152,16 @@ ir_set_program_inouts_visitor:<u></u>:try_mark_partial_variable(ir_<u></u>variable *var,<br>
  {<br>
     const glsl_type *type = var->type;<br>
<br>
+   if (this->shader_type == GL_GEOMETRY_SHADER &&<br>
+       var->mode == ir_var_shader_in) {<br>
+      /* The only geometry shader input that is not an array is<br>
+       * gl_PrimitiveIDIn, and in that case, this code will never be reached,<br>
+       * because gl_PrimitiveIDIn can't be indexed into in array fashion.<br>
+       */<br>
+      assert(type->is_array());<br>
+      type = type->fields.array;<br>
+   }<br>
+<br>
     /* The code below only handles:<br>
      *<br>
      * - Indexing into matrices<br>
@@ -205,17 +223,60 @@ ir_set_program_inouts_visitor:<u></u>:try_mark_partial_variable(ir_<u></u>variable *var,<br>
  ir_visitor_status<br>
  ir_set_program_inouts_visitor:<u></u>:visit_enter(ir_dereference_<u></u>array *ir)<br>
  {<br>
-   ir_dereference_variable *deref_var;<br>
-   deref_var = ir->array->as_dereference_<u></u>variable();<br>
-   ir_variable *var = deref_var ? deref_var->var : NULL;<br>
-<br>
-   /* Check that we're dereferencing a shader in or out */<br>
-   if (!var || !is_shader_inout(var))<br>
-      return visit_continue;<br>
-<br>
-   if (try_mark_partial_variable(<u></u>var, ir->array_index))<br>
-      return visit_continue_with_parent;<br>
+   /* Note: for geometry shader inputs, lower_named_interface_blocks may<br>
+    * create 2D arrays, so we need to be able to handle those.  2D arrays<br>
+    * shouldn't be able to crop up for any other reason.<br>
+    */<br>
+   if (ir_dereference_array *inner_array =<br>
+       ir->array->as_dereference_<u></u>array()) {<br>
</blockquote>
<br></div></div>
'ir_dereference_array *const'?<br>
<br>
I'm not sure whether I love or hate this style.  I seem some significant advantages to it (the big one being the limited scope of the variable), but it has some stylistic issues (the long if-condition).  Having an assignment in an if-condition also feels icky.<br>

<br>
I guess it's pretty similar to what we already do with for-loops, so I'm leaning towards liking it.</blockquote><div><br></div><div>Those are all fair points.  I'm leaning towards liking it too, so I'm going to go ahead with it.  If there are strong objections later, we can always change it.<br>
<br></div><div>I like the idea of marking these declarations-inside-if-statements as const--it reduces the potential ick a little bit by clarifying that we're not going to do anything dangerous with them :)<br><br>Thanks again for all the code review on these two huge patch series.<br>
</div></div></div></div>