[Mesa-dev] [PATCH 3/3] glsl: Optimize clamp(x, b, 1.0), where b > 0.0 as saturate(max(x, b))
Abdiel Janulgue
abdiel.janulgue at linux.intel.com
Mon Jun 23 22:32:30 PDT 2014
Signed-off-by: Abdiel Janulgue <abdiel.janulgue at linux.intel.com>
---
src/glsl/opt_algebraic.cpp | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp
index 0d694b6..ee52de7 100644
--- a/src/glsl/opt_algebraic.cpp
+++ b/src/glsl/opt_algebraic.cpp
@@ -593,6 +593,12 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
/* Found a min (max(x, 0.0) b), where b < 1.0 */
if ((outer_const->get_float_component(0) < 1.0f) && inner_val_b->is_zero())
return saturate(expr(ir_binop_min, inner_val_a, outer_const));
+
+ /* Found a min (max(x, b, 1.0), where b > 0.0 */
+ ir_constant *inner_const = inner_val_b->as_constant();
+ if (outer_const->is_one() &&
+ (inner_const && inner_const->get_float_component(0) > 0.0f))
+ return saturate(expr(ir_binop_max, inner_val_a, inner_val_b));
}
}
--
1.9.1
More information about the mesa-dev
mailing list