[Mesa-dev] [PATCH 05/12] glsl: Lower ir_binop_vector_extract to conditional moves

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


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

Lower ir_binop_vector_extract with a non-constant index to a series of
conditional moves.  This is exactly like ir_dereference_array of a
vector with a non-constant index.

Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
---
 src/glsl/lower_vec_index_to_cond_assign.cpp | 45 +++++++++++++++++++++++++----
 1 file changed, 39 insertions(+), 6 deletions(-)

diff --git a/src/glsl/lower_vec_index_to_cond_assign.cpp b/src/glsl/lower_vec_index_to_cond_assign.cpp
index 6572cc4..2cd540c 100644
--- a/src/glsl/lower_vec_index_to_cond_assign.cpp
+++ b/src/glsl/lower_vec_index_to_cond_assign.cpp
@@ -55,7 +55,10 @@ public:
    ir_rvalue *convert_vec_index_to_cond_assign(ir_rvalue *val);
    ir_rvalue *convert_vec_index_to_cond_assign(void *mem_ctx,
 					       ir_rvalue *orig_vector,
-					       ir_rvalue *orig_index);
+					       ir_rvalue *orig_index,
+					       const glsl_type *type);
+
+   ir_rvalue *convert_vector_extract_to_cond_assign(ir_rvalue *ir);
 
    virtual ir_visitor_status visit_enter(ir_expression *);
    virtual ir_visitor_status visit_enter(ir_swizzle *);
@@ -70,7 +73,8 @@ public:
 ir_rvalue *
 ir_vec_index_to_cond_assign_visitor::convert_vec_index_to_cond_assign(void *mem_ctx,
 								      ir_rvalue *orig_vector,
-								      ir_rvalue *orig_index)
+								      ir_rvalue *orig_index,
+								      const glsl_type *type)
 {
    ir_assignment *assign, *value_assign;
    ir_variable *index, *var, *value;
@@ -98,7 +102,7 @@ ir_vec_index_to_cond_assign_visitor::convert_vec_index_to_cond_assign(void *mem_
    list.push_tail(value_assign);
 
    /* Temporary where we store whichever value we swizzle out. */
-   var = new(base_ir) ir_variable(ir->type, "vec_index_tmp_v",
+   var = new(base_ir) ir_variable(type, "vec_index_tmp_v",
 				  ir_var_temporary);
    list.push_tail(var);
 
@@ -113,7 +117,7 @@ ir_vec_index_to_cond_assign_visitor::convert_vec_index_to_cond_assign(void *mem_
    /* Generate a conditional move of each vector element to the temp. */
    for (i = 0; i < orig_vector->type->vector_elements; i++) {
       ir_rvalue *condition_swizzle =
-	 new(base_ir) ir_swizzle(cond_deref->clone(ir, NULL), i, 0, 0, 0, 1);
+	 new(base_ir) ir_swizzle(cond_deref->clone(mem_ctx, NULL), i, 0, 0, 0, 1);
 
       /* Just clone the rest of the deref chain when trying to get at the
        * underlying variable.
@@ -152,7 +156,22 @@ ir_vec_index_to_cond_assign_visitor::convert_vec_index_to_cond_assign(ir_rvalue
 
    return convert_vec_index_to_cond_assign(ralloc_parent(ir),
 					   orig_deref->array,
-					   orig_deref->array_index);
+					   orig_deref->array_index,
+					   ir->type);
+}
+
+ir_rvalue *
+ir_vec_index_to_cond_assign_visitor::convert_vector_extract_to_cond_assign(ir_rvalue *ir)
+{
+   ir_expression *const expr = ir->as_expression();
+
+   if (expr == NULL || expr->operation != ir_binop_vector_extract)
+      return ir;
+
+   return convert_vec_index_to_cond_assign(ralloc_parent(ir),
+					   expr->operands[0],
+					   expr->operands[1],
+					   ir->type);
 }
 
 ir_visitor_status
@@ -162,6 +181,7 @@ ir_vec_index_to_cond_assign_visitor::visit_enter(ir_expression *ir)
 
    for (i = 0; i < ir->get_num_operands(); i++) {
       ir->operands[i] = convert_vec_index_to_cond_assign(ir->operands[i]);
+      ir->operands[i] = convert_vector_extract_to_cond_assign(ir->operands[i]);
    }
 
    return visit_continue;
@@ -175,6 +195,7 @@ ir_vec_index_to_cond_assign_visitor::visit_enter(ir_swizzle *ir)
     * using swizzling of scalars for vector construction.
     */
    ir->val = convert_vec_index_to_cond_assign(ir->val);
+   ir->val = convert_vector_extract_to_cond_assign(ir->val);
 
    return visit_continue;
 }
@@ -188,8 +209,12 @@ ir_vec_index_to_cond_assign_visitor::visit_leave(ir_assignment *ir)
    unsigned i;
 
    ir->rhs = convert_vec_index_to_cond_assign(ir->rhs);
-   if (ir->condition)
+   ir->rhs = convert_vector_extract_to_cond_assign(ir->rhs);
+
+   if (ir->condition) {
       ir->condition = convert_vec_index_to_cond_assign(ir->condition);
+      ir->condition = convert_vector_extract_to_cond_assign(ir->condition);
+   }
 
    /* Last, handle the LHS */
    ir_dereference_array *orig_deref = ir->lhs->as_dereference_array();
@@ -279,6 +304,12 @@ ir_vec_index_to_cond_assign_visitor::visit_enter(ir_call *ir)
 
       if (new_param != param) {
 	 param->replace_with(new_param);
+      } else {
+	 new_param = convert_vector_extract_to_cond_assign(param);
+
+	 if (new_param != param) {
+	    param->replace_with(new_param);
+	 }
       }
    }
 
@@ -290,6 +321,7 @@ ir_vec_index_to_cond_assign_visitor::visit_enter(ir_return *ir)
 {
    if (ir->value) {
       ir->value = convert_vec_index_to_cond_assign(ir->value);
+      ir->value = convert_vector_extract_to_cond_assign(ir->value);
    }
 
    return visit_continue;
@@ -299,6 +331,7 @@ ir_visitor_status
 ir_vec_index_to_cond_assign_visitor::visit_enter(ir_if *ir)
 {
    ir->condition = convert_vec_index_to_cond_assign(ir->condition);
+   ir->condition = convert_vector_extract_to_cond_assign(ir->condition);
 
    return visit_continue;
 }
-- 
1.8.1.4



More information about the mesa-dev mailing list