Mesa (master): glsl: Drop constant 0.0 components from dot products.

Matt Turner mattst88 at kemper.freedesktop.org
Thu Oct 30 04:34:10 UTC 2014


Module: Mesa
Branch: master
Commit: d056863b3c535aeebfe5fcfc9468eb33a06ddb60
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=d056863b3c535aeebfe5fcfc9468eb33a06ddb60

Author: Matt Turner <mattst88 at gmail.com>
Date:   Fri Oct 17 20:32:58 2014 -0700

glsl: Drop constant 0.0 components from dot products.

Helps a small number of vertex shaders in the games Dungeon Defenders
and Shank, as well as an internal benchmark.

instructions in affected programs:     2801 -> 2719 (-2.93%)

Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>

---

 src/glsl/opt_algebraic.cpp |   27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/src/glsl/opt_algebraic.cpp b/src/glsl/opt_algebraic.cpp
index 0cdb8ec..c8d1ba1 100644
--- a/src/glsl/opt_algebraic.cpp
+++ b/src/glsl/opt_algebraic.cpp
@@ -553,6 +553,33 @@ ir_algebraic_visitor::handle_expression(ir_expression *ir)
 	 }
 	 return new(mem_ctx) ir_swizzle(ir->operands[0], component, 0, 0, 0, 1);
       }
+
+      for (int i = 0; i < 2; i++) {
+         if (!op_const[i])
+            continue;
+
+         unsigned components[4] = { 0 }, count = 0;
+
+         for (unsigned c = 0; c < op_const[i]->type->vector_elements; c++) {
+            if (op_const[i]->value.f[c] == 0.0)
+               continue;
+
+            components[count] = c;
+            count++;
+         }
+
+         /* No channels had zero values; bail. */
+         if (count >= op_const[i]->type->vector_elements)
+            break;
+
+         /* Swizzle both operands to remove the channels that were zero. */
+         return new(mem_ctx)
+            ir_expression(ir_binop_dot, glsl_type::float_type,
+                          new(mem_ctx) ir_swizzle(ir->operands[0],
+                                                  components, count),
+                          new(mem_ctx) ir_swizzle(ir->operands[1],
+                                                  components, count));
+      }
       break;
 
    case ir_binop_less:




More information about the mesa-commit mailing list