From: Thomas Helland <thomashellan...@gmail.com> This patch is a bit sketchy. It only handles float-constants, otherwise it bails. Also, ir_unop_saturate should be added here when support for it lands in the ir.
Signed-off-by: Thomas Helland <thomashellan...@gmail.com> --- src/glsl/opt_algebraic.cpp | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp index 230fb1b..90b6cae 100644 --- a/src/glsl/opt_algebraic.cpp +++ b/src/glsl/opt_algebraic.cpp @@ -647,6 +647,43 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir) break; + case ir_binop_min: { + 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 tempExpr; + /* 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 tempConst; + 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