summaryrefslogtreecommitdiffstats
path: root/src/glsl/opt_algebraic.cpp
diff options
context:
space:
mode:
authorDave Airlie <airlied@gmail.com>2015-02-05 11:58:05 +0200
committerIlia Mirkin <imirkin@alum.mit.edu>2015-02-19 00:28:34 -0500
commit8609b5371641b303fac0a928376b344dbd7096fa (patch)
tree381ccac818de3d7b7a5a3e71c8de6a42ea56784b /src/glsl/opt_algebraic.cpp
parent41e9adfd83a35d3c147768b80b6b4c0b10c3a379 (diff)
downloadexternal_mesa3d-8609b5371641b303fac0a928376b344dbd7096fa.zip
external_mesa3d-8609b5371641b303fac0a928376b344dbd7096fa.tar.gz
external_mesa3d-8609b5371641b303fac0a928376b344dbd7096fa.tar.bz2
glsl: Add support doubles in optimization passes
Signed-off-by: Dave Airlie <airlied@redhat.com> Reviewed-by: Matt Turner <mattst88@gmail.com> Reviewed-by: Ilia Mirkin <imirkin@alum.mit.edu>
Diffstat (limited to 'src/glsl/opt_algebraic.cpp')
-rw-r--r--src/glsl/opt_algebraic.cpp26
1 files changed, 22 insertions, 4 deletions
diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp
index 7bc65da..6784242 100644
--- a/src/glsl/opt_algebraic.cpp
+++ b/src/glsl/opt_algebraic.cpp
@@ -119,6 +119,8 @@ is_valid_vec_const(ir_constant *ir)
static inline bool
is_less_than_one(ir_constant *ir)
{
+ assert(ir->type->base_type == GLSL_TYPE_FLOAT);
+
if (!is_valid_vec_const(ir))
return false;
@@ -134,6 +136,8 @@ is_less_than_one(ir_constant *ir)
static inline bool
is_greater_than_zero(ir_constant *ir)
{
+ assert(ir->type->base_type == GLSL_TYPE_FLOAT);
+
if (!is_valid_vec_const(ir))
return false;
@@ -559,7 +563,9 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
break;
case ir_binop_div:
- if (is_vec_one(op_const[0]) && ir->type->base_type == GLSL_TYPE_FLOAT) {
+ if (is_vec_one(op_const[0]) && (
+ ir->type->base_type == GLSL_TYPE_FLOAT ||
+ ir->type->base_type == GLSL_TYPE_DOUBLE)) {
return new(mem_ctx) ir_expression(ir_unop_rcp,
ir->operands[1]->type,
ir->operands[1],
@@ -580,7 +586,7 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
unsigned components[4] = { 0 }, count = 0;
for (unsigned c = 0; c < op_const[i]->type->vector_elements; c++) {
- if (op_const[i]->value.f[c] == 0.0)
+ if (op_const[i]->is_zero())
continue;
components[count] = c;
@@ -596,7 +602,7 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
/* Swizzle both operands to remove the channels that were zero. */
return new(mem_ctx)
- ir_expression(op, glsl_type::float_type,
+ ir_expression(op, ir->type,
new(mem_ctx) ir_swizzle(ir->operands[0],
components, count),
new(mem_ctx) ir_swizzle(ir->operands[1],
@@ -833,7 +839,19 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
return mul(ir->operands[1], ir->operands[2]);
} else if (is_vec_zero(op_const[1])) {
unsigned op2_components = ir->operands[2]->type->vector_elements;
- ir_constant *one = new(mem_ctx) ir_constant(1.0f, op2_components);
+ ir_constant *one;
+
+ switch (ir->type->base_type) {
+ case GLSL_TYPE_FLOAT:
+ one = new(mem_ctx) ir_constant(1.0f, op2_components);
+ break;
+ case GLSL_TYPE_DOUBLE:
+ one = new(mem_ctx) ir_constant(1.0, op2_components);
+ break;
+ default:
+ unreachable("unexpected type");
+ }
+
return mul(ir->operands[0], add(one, neg(ir->operands[2])));
}
break;