diff options
Diffstat (limited to 'mesalib/src/glsl/lower_vec_index_to_swizzle.cpp')
-rw-r--r-- | mesalib/src/glsl/lower_vec_index_to_swizzle.cpp | 37 |
1 files changed, 15 insertions, 22 deletions
diff --git a/mesalib/src/glsl/lower_vec_index_to_swizzle.cpp b/mesalib/src/glsl/lower_vec_index_to_swizzle.cpp index 264d6dc07..d5ad692c2 100644 --- a/mesalib/src/glsl/lower_vec_index_to_swizzle.cpp +++ b/mesalib/src/glsl/lower_vec_index_to_swizzle.cpp @@ -46,7 +46,7 @@ public: progress = false; } - ir_rvalue *convert_vec_index_to_swizzle(ir_rvalue *val); + ir_rvalue *convert_vector_extract_to_swizzle(ir_rvalue *val); virtual ir_visitor_status visit_enter(ir_expression *); virtual ir_visitor_status visit_enter(ir_swizzle *); @@ -59,20 +59,14 @@ public: }; ir_rvalue * -ir_vec_index_to_swizzle_visitor::convert_vec_index_to_swizzle(ir_rvalue *ir) +ir_vec_index_to_swizzle_visitor::convert_vector_extract_to_swizzle(ir_rvalue *ir) { - ir_dereference_array *deref = ir->as_dereference_array(); - ir_constant *ir_constant; - - if (!deref) - return ir; - - if (deref->array->type->is_matrix() || deref->array->type->is_array()) + ir_expression *const expr = ir->as_expression(); + if (expr == NULL || expr->operation != ir_binop_vector_extract) return ir; - assert(deref->array_index->type->base_type == GLSL_TYPE_INT); - ir_constant = deref->array_index->constant_expression_value(); - if (!ir_constant) + ir_constant *const idx = expr->operands[1]->constant_expression_value(); + if (idx == NULL) return ir; void *ctx = ralloc_parent(ir); @@ -92,10 +86,10 @@ ir_vec_index_to_swizzle_visitor::convert_vec_index_to_swizzle(ir_rvalue *ir) * The ir_swizzle constructor gets angry if the index is negative or too * large. For simplicity sake, just clamp the index to [0, size-1]. */ - const int i = MIN2(MAX2(ir_constant->value.i[0], 0), - ((int) deref->array->type->vector_elements - 1)); + const int i = CLAMP(idx->value.i[0], 0, + (int) expr->operands[0]->type->vector_elements - 1); - return new(ctx) ir_swizzle(deref->array, i, 0, 0, 0, 1); + return new(ctx) ir_swizzle(expr->operands[0], i, 0, 0, 0, 1); } ir_visitor_status @@ -104,7 +98,7 @@ ir_vec_index_to_swizzle_visitor::visit_enter(ir_expression *ir) unsigned int i; for (i = 0; i < ir->get_num_operands(); i++) { - ir->operands[i] = convert_vec_index_to_swizzle(ir->operands[i]); + ir->operands[i] = convert_vector_extract_to_swizzle(ir->operands[i]); } return visit_continue; @@ -117,7 +111,7 @@ ir_vec_index_to_swizzle_visitor::visit_enter(ir_swizzle *ir) * the result of indexing a vector is. But maybe at some point we'll end up * using swizzling of scalars for vector construction. */ - ir->val = convert_vec_index_to_swizzle(ir->val); + ir->val = convert_vector_extract_to_swizzle(ir->val); return visit_continue; } @@ -125,8 +119,7 @@ ir_vec_index_to_swizzle_visitor::visit_enter(ir_swizzle *ir) ir_visitor_status ir_vec_index_to_swizzle_visitor::visit_enter(ir_assignment *ir) { - ir->set_lhs(convert_vec_index_to_swizzle(ir->lhs)); - ir->rhs = convert_vec_index_to_swizzle(ir->rhs); + ir->rhs = convert_vector_extract_to_swizzle(ir->rhs); return visit_continue; } @@ -136,7 +129,7 @@ ir_vec_index_to_swizzle_visitor::visit_enter(ir_call *ir) { foreach_iter(exec_list_iterator, iter, *ir) { ir_rvalue *param = (ir_rvalue *)iter.get(); - ir_rvalue *new_param = convert_vec_index_to_swizzle(param); + ir_rvalue *new_param = convert_vector_extract_to_swizzle(param); if (new_param != param) { param->replace_with(new_param); @@ -150,7 +143,7 @@ ir_visitor_status ir_vec_index_to_swizzle_visitor::visit_enter(ir_return *ir) { if (ir->value) { - ir->value = convert_vec_index_to_swizzle(ir->value); + ir->value = convert_vector_extract_to_swizzle(ir->value); } return visit_continue; @@ -159,7 +152,7 @@ ir_vec_index_to_swizzle_visitor::visit_enter(ir_return *ir) ir_visitor_status ir_vec_index_to_swizzle_visitor::visit_enter(ir_if *ir) { - ir->condition = convert_vec_index_to_swizzle(ir->condition); + ir->condition = convert_vector_extract_to_swizzle(ir->condition); return visit_continue; } |