<div dir="ltr">On 3 May 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: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>
Variable indexing into vectors using ir_dereference_array is being<br>
removed, so this lowering pass has to generate something different.<br>
<br>
v2: Convert tabs to spaces.  Suggested by Eric.<br>
<br>
Signed-off-by: Ian Romanick <<a href="mailto:ian.d.romanick@intel.com">ian.d.romanick@intel.com</a>><br>
Cc: Paul Berry <<a href="mailto:stereotype441@gmail.com">stereotype441@gmail.com</a>><br>
---<br>
 src/glsl/lower_clip_distance.cpp | 36 ++++++++++++++++++++++++++++++++++--<br>
 1 file changed, 34 insertions(+), 2 deletions(-)<br>
<br>
diff --git a/src/glsl/lower_clip_distance.cpp b/src/glsl/lower_clip_distance.cpp<br>
index 19068fb..c93c821e 100644<br>
--- a/src/glsl/lower_clip_distance.cpp<br>
+++ b/src/glsl/lower_clip_distance.cpp<br>
@@ -197,10 +197,17 @@ lower_clip_distance_visitor::handle_rvalue(ir_rvalue **rv)<br>
          ir_rvalue *swizzle_index;<br>
          this->create_indices(array->array_index, array_index, swizzle_index);<br>
          void *mem_ctx = ralloc_parent(array);<br>
-         array->array =<br>
+<br>
+         ir_dereference_array *const ClipDistanceMESA_deref =<br>
             new(mem_ctx) ir_dereference_array(this->new_clip_distance_var,<br>
                                               array_index);<br>
-         array->array_index = swizzle_index;<br>
+<br>
+         ir_expression *const expr =<br>
+            new(mem_ctx) ir_expression(ir_binop_vector_extract,<br>
+                                       ClipDistanceMESA_deref,<br>
+                                       swizzle_index);<br>
+<br>
+         *rv = expr;<br>
       }<br>
    }<br>
 }<br>
@@ -280,7 +287,32 @@ lower_clip_distance_visitor::visit_leave(ir_assignment *ir)<br>
       return visit_continue;<br>
    }<br>
<br>
+   /* Handle the LHS as if it were an r-value.  This may cause the LHS to get<br>
+    * replaced with an ir_expression or ir_binop_vector_extract.  If this<br>
+    * occurs, replace it with a dereference of the vector, and replace the RHS<br>
+    * with an ir_triop_vector_insert.<br>
+    */<br>
    handle_rvalue((ir_rvalue **)&ir->lhs);<br>
+   if (ir->lhs->ir_type == ir_type_expression) {<br>
+      ir_expression *const expr = (ir_expression *) ir->lhs;<br>
+<br>
+      /* The expression must be of the form:<br>
+       *<br>
+       *     (vector_extract gl_ClipDistanceMESA[i], j).<br>
+       */<br>
+      assert(expr->operation == ir_binop_vector_extract);<br>
+      assert(expr->operands[0]->ir_type == ir_type_dereference_array);<br>
+<br>
+      ir_dereference *const new_lhs = (ir_dereference *) expr->operands[0];<br>
+      ir->rhs = new(ctx) ir_expression(ir_triop_vector_insert,<br>
+                                       new_lhs->type,<br>
+                                       new_lhs->clone(ctx, NULL),<br>
+                                       ir->rhs,<br>
+                                       expr->operands[1]);<br>
+      ir->set_lhs(new_lhs);<br>
+      ir->write_mask = (1U << new_lhs->type->vector_elements) - 1;<br></blockquote><div><br></div><div>We know that the LHS is always a vec4, so I think it would be clearer to just say:<br><br></div><div>
ir->write_mask = 0xf;<br></div><div><br></div><div>But I don't feel terribly strongly about it.<br><br></div><div>Regardless of whether you decide to make this 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>
    return rvalue_visit(ir);<br>
 }<br>
<span class="HOEnZb"><font color="#888888"><br>
--<br>
1.8.1.4<br>
<br>
</font></span></blockquote></div><br></div></div>