ir_dereference *get_column(ir_variable *var, int col);
ir_rvalue *get_element(ir_variable *var, int col, int row);
- void do_mul_mat_mat(ir_variable *result_var,
- ir_variable *a_var, ir_variable *b_var);
- void do_mul_mat_vec(ir_variable *result_var,
- ir_variable *a_var, ir_variable *b_var);
- void do_mul_vec_mat(ir_variable *result_var,
- ir_variable *a_var, ir_variable *b_var);
- void do_mul_mat_scalar(ir_variable *result_var,
- ir_variable *a_var, ir_variable *b_var);
- void do_equal_mat_mat(ir_variable *result_var, ir_variable *a_var,
- ir_variable *b_var, bool test_equal);
+ void do_mul_mat_mat(ir_variable *result,
+ ir_variable *a, ir_variable *b);
+ void do_mul_mat_vec(ir_variable *result,
+ ir_variable *a, ir_variable *b);
+ void do_mul_vec_mat(ir_variable *result,
+ ir_variable *a, ir_variable *b);
+ void do_mul_mat_scalar(ir_variable *result,
+ ir_variable *a, ir_variable *b);
+ void do_equal_mat_mat(ir_variable *result, ir_variable *a,
+ ir_variable *b, bool test_equal);
void *mem_ctx;
bool made_progress;
void
ir_mat_op_to_vec_visitor::do_mul_mat_mat(ir_variable *result_var,
- ir_variable *a_var,
- ir_variable *b_var)
+ ir_variable *a,
+ ir_variable *b)
{
int b_col, i;
ir_assignment *assign;
ir_expression *expr;
- for (b_col = 0; b_col < b_var->type->matrix_columns; b_col++) {
+ for (b_col = 0; b_col < b->type->matrix_columns; b_col++) {
/* first column */
expr = new(mem_ctx) ir_expression(ir_binop_mul,
- get_column(a_var, 0),
- get_element(b_var, b_col, 0));
+ get_column(a, 0),
+ get_element(b, b_col, 0));
/* following columns */
- for (i = 1; i < a_var->type->matrix_columns; i++) {
+ for (i = 1; i < a->type->matrix_columns; i++) {
ir_expression *mul_expr;
mul_expr = new(mem_ctx) ir_expression(ir_binop_mul,
- get_column(a_var, i),
- get_element(b_var, b_col, i));
+ get_column(a, i),
+ get_element(b, b_col, i));
expr = new(mem_ctx) ir_expression(ir_binop_add,
expr,
mul_expr);
void
ir_mat_op_to_vec_visitor::do_mul_mat_vec(ir_variable *result_var,
- ir_variable *a_var,
- ir_variable *b_var)
+ ir_variable *a,
+ ir_variable *b)
{
int i;
ir_assignment *assign;
/* first column */
expr = new(mem_ctx) ir_expression(ir_binop_mul,
- get_column(a_var, 0),
- get_element(b_var, 0, 0));
+ get_column(a, 0),
+ get_element(b, 0, 0));
/* following columns */
- for (i = 1; i < a_var->type->matrix_columns; i++) {
+ for (i = 1; i < a->type->matrix_columns; i++) {
ir_expression *mul_expr;
mul_expr = new(mem_ctx) ir_expression(ir_binop_mul,
- get_column(a_var, i),
- get_element(b_var, 0, i));
+ get_column(a, i),
+ get_element(b, 0, i));
expr = new(mem_ctx) ir_expression(ir_binop_add, expr, mul_expr);
}
}
void
-ir_mat_op_to_vec_visitor::do_mul_vec_mat(ir_variable *result_var,
- ir_variable *a_var,
- ir_variable *b_var)
+ir_mat_op_to_vec_visitor::do_mul_vec_mat(ir_variable *result,
+ ir_variable *a,
+ ir_variable *b)
{
int i;
- for (i = 0; i < b_var->type->matrix_columns; i++) {
- ir_rvalue *result;
+ for (i = 0; i < b->type->matrix_columns; i++) {
+ ir_rvalue *column_result;
ir_expression *column_expr;
ir_assignment *column_assign;
- result = new(mem_ctx) ir_dereference_variable(result_var);
- result = new(mem_ctx) ir_swizzle(result, i, 0, 0, 0, 1);
+ column_result = new(mem_ctx) ir_dereference_variable(result);
+ column_result = new(mem_ctx) ir_swizzle(column_result, i, 0, 0, 0, 1);
column_expr = new(mem_ctx) ir_expression(ir_binop_dot,
- new(mem_ctx) ir_dereference_variable(a_var),
- get_column(b_var, i));
+ new(mem_ctx) ir_dereference_variable(a),
+ get_column(b, i));
- column_assign = new(mem_ctx) ir_assignment(result,
+ column_assign = new(mem_ctx) ir_assignment(column_result,
column_expr,
NULL);
base_ir->insert_before(column_assign);
}
void
-ir_mat_op_to_vec_visitor::do_mul_mat_scalar(ir_variable *result_var,
- ir_variable *a_var,
- ir_variable *b_var)
+ir_mat_op_to_vec_visitor::do_mul_mat_scalar(ir_variable *result,
+ ir_variable *a,
+ ir_variable *b)
{
int i;
- for (i = 0; i < a_var->type->matrix_columns; i++) {
+ for (i = 0; i < a->type->matrix_columns; i++) {
ir_expression *column_expr;
ir_assignment *column_assign;
column_expr = new(mem_ctx) ir_expression(ir_binop_mul,
- get_column(a_var, i),
- new(mem_ctx) ir_dereference_variable(b_var));
+ get_column(a, i),
+ new(mem_ctx) ir_dereference_variable(b));
- column_assign = new(mem_ctx) ir_assignment(get_column(result_var, i),
+ column_assign = new(mem_ctx) ir_assignment(get_column(result, i),
column_expr,
NULL);
base_ir->insert_before(column_assign);
void
ir_mat_op_to_vec_visitor::do_equal_mat_mat(ir_variable *result_var,
- ir_variable *a_var,
- ir_variable *b_var,
+ ir_variable *a,
+ ir_variable *b,
bool test_equal)
{
/* This essentially implements the following GLSL:
* a[3] != b[3]);
* }
*/
- const unsigned columns = a_var->type->matrix_columns;
+ const unsigned columns = a->type->matrix_columns;
const glsl_type *const bvec_type =
glsl_type::get_instance(GLSL_TYPE_BOOL, columns, 1);
for (unsigned i = 0; i < columns; i++) {
ir_expression *const cmp =
new(this->mem_ctx) ir_expression(ir_binop_any_nequal,
- get_column(a_var, i),
- get_column(b_var, i));
+ get_column(a, i),
+ get_column(b, i));
ir_dereference *const lhs =
new(this->mem_ctx) ir_dereference_variable(tmp_bvec);
{
ir_expression *orig_expr = orig_assign->rhs->as_expression();
unsigned int i, matrix_columns = 1;
- ir_variable *op_var[2];
+ ir_variable *op[2];
if (!orig_expr)
return visit_continue;
orig_assign->lhs->as_dereference_variable();
assert(lhs_deref);
- ir_variable *result_var = lhs_deref->var;
+ ir_variable *result = lhs_deref->var;
/* Store the expression operands in temps so we can use them
* multiple times.
for (i = 0; i < orig_expr->get_num_operands(); i++) {
ir_assignment *assign;
- op_var[i] = new(mem_ctx) ir_variable(orig_expr->operands[i]->type,
- "mat_op_to_vec",
- ir_var_temporary);
- base_ir->insert_before(op_var[i]);
+ op[i] = new(mem_ctx) ir_variable(orig_expr->operands[i]->type,
+ "mat_op_to_vec",
+ ir_var_temporary);
+ base_ir->insert_before(op[i]);
- lhs_deref = new(mem_ctx) ir_dereference_variable(op_var[i]);
+ lhs_deref = new(mem_ctx) ir_dereference_variable(op[i]);
assign = new(mem_ctx) ir_assignment(lhs_deref,
orig_expr->operands[i],
NULL);
/* OK, time to break down this matrix operation. */
switch (orig_expr->operation) {
case ir_unop_neg: {
- const unsigned mask = (1U << result_var->type->vector_elements) - 1;
+ const unsigned mask = (1U << result->type->vector_elements) - 1;
/* Apply the operation to each column.*/
for (i = 0; i < matrix_columns; i++) {
ir_assignment *column_assign;
column_expr = new(mem_ctx) ir_expression(orig_expr->operation,
- get_column(op_var[0], i));
+ get_column(op[0], i));
- column_assign = new(mem_ctx) ir_assignment(get_column(result_var, i),
+ column_assign = new(mem_ctx) ir_assignment(get_column(result, i),
column_expr,
NULL,
mask);
case ir_binop_sub:
case ir_binop_div:
case ir_binop_mod: {
- const unsigned mask = (1U << result_var->type->vector_elements) - 1;
+ const unsigned mask = (1U << result->type->vector_elements) - 1;
/* For most operations, the matrix version is just going
* column-wise through and applying the operation to each column
ir_assignment *column_assign;
column_expr = new(mem_ctx) ir_expression(orig_expr->operation,
- get_column(op_var[0], i),
- get_column(op_var[1], i));
+ get_column(op[0], i),
+ get_column(op[1], i));
- column_assign = new(mem_ctx) ir_assignment(get_column(result_var, i),
+ column_assign = new(mem_ctx) ir_assignment(get_column(result, i),
column_expr,
NULL,
mask);
break;
}
case ir_binop_mul:
- if (op_var[0]->type->is_matrix()) {
- if (op_var[1]->type->is_matrix()) {
- do_mul_mat_mat(result_var, op_var[0], op_var[1]);
- } else if (op_var[1]->type->is_vector()) {
- do_mul_mat_vec(result_var, op_var[0], op_var[1]);
+ if (op[0]->type->is_matrix()) {
+ if (op[1]->type->is_matrix()) {
+ do_mul_mat_mat(result, op[0], op[1]);
+ } else if (op[1]->type->is_vector()) {
+ do_mul_mat_vec(result, op[0], op[1]);
} else {
- assert(op_var[1]->type->is_scalar());
- do_mul_mat_scalar(result_var, op_var[0], op_var[1]);
+ assert(op[1]->type->is_scalar());
+ do_mul_mat_scalar(result, op[0], op[1]);
}
} else {
- assert(op_var[1]->type->is_matrix());
- if (op_var[0]->type->is_vector()) {
- do_mul_vec_mat(result_var, op_var[0], op_var[1]);
+ assert(op[1]->type->is_matrix());
+ if (op[0]->type->is_vector()) {
+ do_mul_vec_mat(result, op[0], op[1]);
} else {
- assert(op_var[0]->type->is_scalar());
- do_mul_mat_scalar(result_var, op_var[1], op_var[0]);
+ assert(op[0]->type->is_scalar());
+ do_mul_mat_scalar(result, op[1], op[0]);
}
}
break;
case ir_binop_all_equal:
case ir_binop_any_nequal:
- do_equal_mat_mat(result_var, op_var[1], op_var[0],
+ do_equal_mat_mat(result, op[1], op[0],
(orig_expr->operation == ir_binop_all_equal));
break;