[Mesa-dev] [PATCH 4/6] glsl: Expand get_range to include sin/cos/sign
Thomas Helland
thomashelland90 at gmail.com
Wed Oct 29 18:11:19 PDT 2014
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 <thomashelland90 at 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
More information about the mesa-dev
mailing list