From: Thomas Helland <thomashellan...@gmail.com> This also only handles floats. ir_unop_saturate should also be added when the support for this lands in the ir.
Signed-off-by: Thomas Helland <thomashellan...@gmail.com> --- src/glsl/opt_algebraic.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp index 90b6cae..deaa49e 100644 --- a/src/glsl/opt_algebraic.cpp +++ b/src/glsl/opt_algebraic.cpp @@ -684,6 +684,44 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir) break; } + case ir_binop_max: { + ir_rvalue *tempExpr; + ir_rvalue *tempConst; + + if (op_expr[0] && op_const[1]) { + tempExpr = ir->operands[0]; + tempConst = ir->operands[1]; + } else if (op_expr[1] && op_const[0]) { + tempExpr = ir->operands[1]; + tempConst = ir->operands[0]; + } else { + break; + } + + if(tempConst->type->is_float()) { + float constValue = *(tempConst->constant_expression_value()->value.f); + switch(tempExpr->as_expression()->operation) { + case ir_unop_cos: + case ir_unop_sin: + case ir_unop_sign: + /* If we are comparing an expression bound between -1 and 1 + * with a const >= 1 we know that const will be the largest + */ + if(constValue >= 1.0f) + return tempConst; + /* If we are comparing an expression bound between -1 and 1 + * with a const <= -1 we know that const will be the smallest + */ + if(constValue <= -1.0f) + return tempExpr; + break; + default: + break; + } + } + break; + } + case ir_unop_rcp: if (op_expr[0] && op_expr[0]->operation == ir_unop_rcp) return op_expr[0]->operands[0]; -- 2.0.0 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev