This gets rid of extra instructions in some
shaders I purposefully wrote to test this.
Works for shaders similar to the following:

vec3 c = {8, 8, 8};
gl_FragColor.rgb = max(sin(d), c);

Signed-off-by: Thomas Helland <thomashellan...@gmail.com>
---
 src/glsl/opt_minmax.cpp | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/src/glsl/opt_minmax.cpp b/src/glsl/opt_minmax.cpp
index b21daca..0b9ddc2 100644
--- a/src/glsl/opt_minmax.cpp
+++ b/src/glsl/opt_minmax.cpp
@@ -272,6 +272,10 @@ get_range(ir_rvalue *rval)
    minmax_range r0;
    minmax_range r1;
 
+   void *mem_ctx = ralloc_parent(rval);
+   ir_constant *low;
+   ir_constant *high;
+
    if(expr) {
       switch(expr->operation) {
       case ir_binop_min:
@@ -279,6 +283,19 @@ get_range(ir_rvalue *rval)
          r0 = get_range(expr->operands[0]);
          r1 = get_range(expr->operands[1]);
          return combine_range(r0, r1, expr->operation == ir_binop_min);
+
+      case ir_unop_sin:
+      case ir_unop_sin_reduced:
+      case ir_unop_cos:
+      case ir_unop_cos_reduced:
+      case ir_unop_sign:
+         high = new(mem_ctx) ir_constant(1.0f);
+         low = new(mem_ctx) ir_constant(-1.0f);
+         return minmax_range(low, high);
+
+      default:
+         break;
+      }
    }
 
    ir_constant *c = rval->as_constant();
-- 
2.0.3

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to