瀏覽代碼

glsl: Add a helper constructor for expressions that works out result type.

This doesn't cover all expressions or all operand types, but it will
complain if you overreach and it allows for much greater slack on the
programmer's part.
tags/android-x86-2.2
Eric Anholt 15 年之前
父節點
當前提交
6b937465d4
共有 2 個文件被更改,包括 104 次插入0 次删除
  1. 102
    0
      src/glsl/ir.cpp
  2. 2
    0
      src/glsl/ir.h

+ 102
- 0
src/glsl/ir.cpp 查看文件

@@ -231,6 +231,108 @@ ir_expression::ir_expression(int op, const struct glsl_type *type,
this->operands[3] = op3;
}

ir_expression::ir_expression(int op, ir_rvalue *op0)
{
this->ir_type = ir_type_expression;

this->operation = ir_expression_operation(op);
this->operands[0] = op0;
this->operands[1] = NULL;
this->operands[2] = NULL;
this->operands[3] = NULL;

assert(op <= ir_last_unop);

switch (this->operation) {
case ir_unop_bit_not:
case ir_unop_logic_not:
case ir_unop_neg:
case ir_unop_abs:
case ir_unop_sign:
case ir_unop_rcp:
case ir_unop_rsq:
case ir_unop_sqrt:
case ir_unop_exp:
case ir_unop_log:
case ir_unop_exp2:
case ir_unop_log2:
case ir_unop_trunc:
case ir_unop_ceil:
case ir_unop_floor:
case ir_unop_fract:
case ir_unop_round_even:
case ir_unop_cos:
case ir_unop_dFdx:
case ir_unop_dFdy:
this->type = op0->type;
break;

case ir_unop_any:
this->type = glsl_type::bool_type;
break;

default:
assert(!"not reached: missing automatic type setup for ir_expression");
this->type = op0->type;
break;
}
}

ir_expression::ir_expression(int op, ir_rvalue *op0, ir_rvalue *op1)
{
this->ir_type = ir_type_expression;

this->operation = ir_expression_operation(op);
this->operands[0] = op0;
this->operands[1] = op1;
this->operands[2] = NULL;
this->operands[3] = NULL;

assert(op > ir_last_unop);

switch (this->operation) {
case ir_binop_all_equal:
case ir_binop_any_nequal:
this->type = glsl_type::bool_type;
break;

case ir_binop_add:
case ir_binop_sub:
case ir_binop_min:
case ir_binop_max:
case ir_binop_pow:
case ir_binop_mul:
if (op0->type->is_scalar()) {
this->type = op1->type;
} else if (op1->type->is_scalar()) {
this->type = op0->type;
} else {
/* FINISHME: matrix types */
assert(!op0->type->is_matrix() && !op1->type->is_matrix());
assert(op0->type == op1->type);
this->type = op0->type;
}
break;

case ir_binop_logic_and:
case ir_binop_logic_or:
if (op0->type->is_scalar()) {
this->type = op1->type;
} else if (op1->type->is_scalar()) {
this->type = op0->type;
}
break;

case ir_binop_dot:
this->type = glsl_type::float_type;
break;

default:
assert(!"not reached: missing automatic type setup for ir_expression");
this->type = glsl_type::float_type;
}
}

unsigned int
ir_expression::get_num_operands(ir_expression_operation op)
{

+ 2
- 0
src/glsl/ir.h 查看文件

@@ -842,12 +842,14 @@ public:
* Constructor for unary operation expressions
*/
ir_expression(int op, const struct glsl_type *type, ir_rvalue *);
ir_expression(int op, ir_rvalue *);

/**
* Constructor for binary operation expressions
*/
ir_expression(int op, const struct glsl_type *type,
ir_rvalue *, ir_rvalue *);
ir_expression(int op, ir_rvalue *op0, ir_rvalue *op1);

/**
* Constructor for quad operator expressions

Loading…
取消
儲存