[Mesa-dev] [PATCH 10/12] glsl: Use vector-insert and vector-extract on elements of gl_ClipDistanceMESA

Ian Romanick idr at freedesktop.org
Mon Apr 8 15:24:41 PDT 2013


From: Ian Romanick <ian.d.romanick at intel.com>

Variable indexing into vectors using ir_dereference_array is being
removed, so this lowering pass has to generate something different.

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
Cc: Paul Berry <stereotype441 at gmail.com>
---
 src/glsl/lower_clip_distance.cpp | 36 ++++++++++++++++++++++++++++++++++--
 1 file changed, 34 insertions(+), 2 deletions(-)

diff --git a/src/glsl/lower_clip_distance.cpp b/src/glsl/lower_clip_distance.cpp
index 26a0feb..fd6e3f0 100644
--- a/src/glsl/lower_clip_distance.cpp
+++ b/src/glsl/lower_clip_distance.cpp
@@ -197,10 +197,17 @@ lower_clip_distance_visitor::handle_rvalue(ir_rvalue **rv)
 	 ir_rvalue *swizzle_index;
 	 this->create_indices(array->array_index, array_index, swizzle_index);
 	 void *mem_ctx = ralloc_parent(array);
-	 array->array =
+
+	 ir_dereference_array *const ClipDistanceMESA_deref =
 	    new(mem_ctx) ir_dereference_array(this->new_clip_distance_var,
 					      array_index);
-	 array->array_index = swizzle_index;
+
+	 ir_expression *const expr =
+	    new(mem_ctx) ir_expression(ir_binop_vector_extract,
+				       ClipDistanceMESA_deref,
+				       swizzle_index);
+
+	 *rv = expr;
       }
    }
 }
@@ -280,7 +287,32 @@ lower_clip_distance_visitor::visit_leave(ir_assignment *ir)
       return visit_continue;
    }
 
+   /* Handle the LHS as if it were an r-value.  This may cause the LHS to get
+    * replaced with an ir_expression or ir_binop_vector_extract.  If this
+    * occurs, replace it with a dereference of the vector, and replace the RHS
+    * with an ir_triop_vector_insert.
+    */
    handle_rvalue((ir_rvalue **)&ir->lhs);
+   if (ir->lhs->ir_type == ir_type_expression) {
+      ir_expression *const expr = (ir_expression *) ir->lhs;
+
+      /* The expression must be of the form:
+       *
+       *     (vector_extract gl_ClipDistanceMESA[i], j).
+       */
+      assert(expr->operation == ir_binop_vector_extract);
+      assert(expr->operands[0]->ir_type == ir_type_dereference_array);
+
+      ir_dereference *const new_lhs = (ir_dereference *) expr->operands[0];
+      ir->rhs = new(ctx) ir_expression(ir_triop_vector_insert,
+				       new_lhs->type,
+				       new_lhs->clone(ctx, NULL),
+				       ir->rhs,
+				       expr->operands[1]);
+      ir->set_lhs(new_lhs);
+      ir->write_mask = (1U << new_lhs->type->vector_elements) - 1;
+   }
+
    return rvalue_visit(ir);
 }
 
-- 
1.8.1.4



More information about the mesa-dev mailing list