Mesa (glsl2): ir_constant_expression: Add support for ir_binop_min and ir_binop_max.

Ian Romanick idr at kemper.freedesktop.org
Thu Jul 15 00:18:22 UTC 2010


Module: Mesa
Branch: glsl2
Commit: 79fed377f4625da9ce6a0a32c1e7277a2e90e914
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=79fed377f4625da9ce6a0a32c1e7277a2e90e914

Author: Kenneth Graunke <kenneth at whitecape.org>
Date:   Fri Jul  9 11:53:56 2010 -0700

ir_constant_expression: Add support for ir_binop_min and ir_binop_max.

These now work on scalar/vector combos. Semantically, if a is a scalar,
min(a, vec2(x,y)) == vec2(min(a,x), min(a,y))

---

 src/glsl/ir_constant_expression.cpp |   47 +++++++++++++++++++++++++++++++++++
 1 files changed, 47 insertions(+), 0 deletions(-)

diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp
index 437a380..7e276e1 100644
--- a/src/glsl/ir_constant_expression.cpp
+++ b/src/glsl/ir_constant_expression.cpp
@@ -38,6 +38,9 @@
 #include "ir_visitor.h"
 #include "glsl_types.h"
 
+#define min(x,y) (x) < (y) ? (x) : (y)
+#define max(x,y) (x) > (y) ? (x) : (y)
+
 /**
  * Visitor class for evaluating constant expressions
  */
@@ -414,6 +417,50 @@ ir_constant_visitor::visit(ir_expression *ir)
       }
 
       break;
+   case ir_binop_min:
+      assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar);
+      for (unsigned c = 0, c0 = 0, c1 = 0;
+	   c < components;
+	   c0 += c0_inc, c1 += c1_inc, c++) {
+
+	 switch (ir->operands[0]->type->base_type) {
+	 case GLSL_TYPE_UINT:
+	    data.u[c] = min(op[0]->value.u[c0], op[1]->value.u[c1]);
+	    break;
+	 case GLSL_TYPE_INT:
+	    data.i[c] = min(op[0]->value.i[c0], op[1]->value.i[c1]);
+	    break;
+	 case GLSL_TYPE_FLOAT:
+	    data.f[c] = min(op[0]->value.f[c0], op[1]->value.f[c1]);
+	    break;
+	 default:
+	    assert(0);
+	 }
+      }
+
+      break;
+   case ir_binop_max:
+      assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar);
+      for (unsigned c = 0, c0 = 0, c1 = 0;
+	   c < components;
+	   c0 += c0_inc, c1 += c1_inc, c++) {
+
+	 switch (ir->operands[0]->type->base_type) {
+	 case GLSL_TYPE_UINT:
+	    data.u[c] = max(op[0]->value.u[c0], op[1]->value.u[c1]);
+	    break;
+	 case GLSL_TYPE_INT:
+	    data.i[c] = max(op[0]->value.i[c0], op[1]->value.i[c1]);
+	    break;
+	 case GLSL_TYPE_FLOAT:
+	    data.f[c] = max(op[0]->value.f[c0], op[1]->value.f[c1]);
+	    break;
+	 default:
+	    assert(0);
+	 }
+      }
+
+      break;
    case ir_binop_add:
       assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar);
       for (unsigned c = 0, c0 = 0, c1 = 0;




More information about the mesa-commit mailing list