summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Anholt <eric@anholt.net>2010-07-13 15:37:57 -0700
committerEric Anholt <eric@anholt.net>2010-07-18 18:12:12 -0700
commit9be7f638130f46a9df2bfbcd4a03b36de9e4f3aa (patch)
tree5db2a2e0c0198c2960bfcb3051ffbeeda8757573
parent87a2ee8db6222006480bd0e0ac58b77795c5d951 (diff)
glsl2: Make cross() be an expression operation.
ARB_fp, ARB_vp, Mesa IR, and the 965 vertex shader all have instructions for cross. Shaves 12 Mesa instructions off of a 66-instruction shader I have.
-rw-r--r--src/glsl/builtin_function.cpp12
-rw-r--r--src/glsl/builtins/110/cross12
-rw-r--r--src/glsl/ir.cpp2
-rw-r--r--src/glsl/ir.h1
-rw-r--r--src/glsl/ir_constant_expression.cpp11
-rw-r--r--src/mesa/shader/ir_to_mesa.cpp5
6 files changed, 21 insertions, 22 deletions
diff --git a/src/glsl/builtin_function.cpp b/src/glsl/builtin_function.cpp
index 1cf88ada16..b3a283306d 100644
--- a/src/glsl/builtin_function.cpp
+++ b/src/glsl/builtin_function.cpp
@@ -486,17 +486,7 @@ static const char *builtins_110_cross = {
" (parameters\n"
" (declare (in) vec3 arg0)\n"
" (declare (in) vec3 arg1))\n"
- " ((declare () vec3 t)\n"
- " (assign (constant bool (1)) (swiz x (var_ref t))\n"
- " (expression float - (expression float * (swiz y (var_ref arg0)) (swiz z (var_ref arg1)))\n"
- " (expression float * (swiz y (var_ref arg1)) (swiz z (var_ref arg0)))))\n"
- " (assign (constant bool (1)) (swiz y (var_ref t))\n"
- " (expression float - (expression float * (swiz z (var_ref arg0)) (swiz x (var_ref arg1)))\n"
- " (expression float * (swiz z (var_ref arg1)) (swiz x (var_ref arg0)))))\n"
- " (assign (constant bool (1)) (swiz z (var_ref t))\n"
- " (expression float - (expression float * (swiz x (var_ref arg0)) (swiz y (var_ref arg1)))\n"
- " (expression float * (swiz x (var_ref arg1)) (swiz y (var_ref arg0)))))\n"
- " (return (var_ref t))))\n"
+ " ((return (expression vec3 cross (var_ref arg0) (var_ref arg1)))))\n"
"))\n"
};
diff --git a/src/glsl/builtins/110/cross b/src/glsl/builtins/110/cross
index deb2f952bf..24717a2183 100644
--- a/src/glsl/builtins/110/cross
+++ b/src/glsl/builtins/110/cross
@@ -3,15 +3,5 @@
(parameters
(declare (in) vec3 arg0)
(declare (in) vec3 arg1))
- ((declare () vec3 t)
- (assign (constant bool (1)) (swiz x (var_ref t))
- (expression float - (expression float * (swiz y (var_ref arg0)) (swiz z (var_ref arg1)))
- (expression float * (swiz y (var_ref arg1)) (swiz z (var_ref arg0)))))
- (assign (constant bool (1)) (swiz y (var_ref t))
- (expression float - (expression float * (swiz z (var_ref arg0)) (swiz x (var_ref arg1)))
- (expression float * (swiz z (var_ref arg1)) (swiz x (var_ref arg0)))))
- (assign (constant bool (1)) (swiz z (var_ref t))
- (expression float - (expression float * (swiz x (var_ref arg0)) (swiz y (var_ref arg1)))
- (expression float * (swiz x (var_ref arg1)) (swiz y (var_ref arg0)))))
- (return (var_ref t))))
+ ((return (expression vec3 cross (var_ref arg0) (var_ref arg1)))))
))
diff --git a/src/glsl/ir.cpp b/src/glsl/ir.cpp
index 6d89913286..fcf5deced8 100644
--- a/src/glsl/ir.cpp
+++ b/src/glsl/ir.cpp
@@ -104,6 +104,7 @@ ir_expression::get_num_operands(ir_expression_operation op)
2, /* ir_binop_logic_or */
2, /* ir_binop_dot */
+ 2, /* ir_binop_cross */
2, /* ir_binop_min */
2, /* ir_binop_max */
@@ -163,6 +164,7 @@ static const char *const operator_strs[] = {
"^^",
"||",
"dot",
+ "cross",
"min",
"max",
"pow",
diff --git a/src/glsl/ir.h b/src/glsl/ir.h
index 790173ed6b..9d7af2dcab 100644
--- a/src/glsl/ir.h
+++ b/src/glsl/ir.h
@@ -609,6 +609,7 @@ enum ir_expression_operation {
ir_binop_logic_or,
ir_binop_dot,
+ ir_binop_cross,
ir_binop_min,
ir_binop_max,
diff --git a/src/glsl/ir_constant_expression.cpp b/src/glsl/ir_constant_expression.cpp
index c0fe47067b..ca834978f4 100644
--- a/src/glsl/ir_constant_expression.cpp
+++ b/src/glsl/ir_constant_expression.cpp
@@ -459,8 +459,19 @@ ir_constant_visitor::visit(ir_expression *ir)
assert(0);
}
}
+ break;
+ case ir_binop_cross:
+ assert(op[0]->type == glsl_type::vec3_type);
+ assert(op[1]->type == glsl_type::vec3_type);
+ data.f[0] = (op[0]->value.f[1] * op[1]->value.f[2] -
+ op[1]->value.f[1] * op[0]->value.f[2]);
+ data.f[1] = (op[0]->value.f[2] * op[1]->value.f[0] -
+ op[1]->value.f[2] * op[0]->value.f[0]);
+ data.f[2] = (op[0]->value.f[0] * op[1]->value.f[1] -
+ op[1]->value.f[0] * op[0]->value.f[1]);
break;
+
case ir_binop_add:
assert(op[0]->type == op[1]->type || op0_scalar || op1_scalar);
for (unsigned c = 0, c0 = 0, c1 = 0;
diff --git a/src/mesa/shader/ir_to_mesa.cpp b/src/mesa/shader/ir_to_mesa.cpp
index 6ecc6d317c..f99a1fc450 100644
--- a/src/mesa/shader/ir_to_mesa.cpp
+++ b/src/mesa/shader/ir_to_mesa.cpp
@@ -781,6 +781,11 @@ ir_to_mesa_visitor::visit(ir_expression *ir)
op[0], op[1]);
}
break;
+
+ case ir_binop_cross:
+ ir_to_mesa_emit_op2(ir, OPCODE_XPD, result_dst, op[0], op[1]);
+ break;
+
case ir_unop_sqrt:
ir_to_mesa_emit_scalar_op1(ir, OPCODE_RSQ, result_dst, op[0]);
ir_to_mesa_emit_scalar_op1(ir, OPCODE_RCP, result_dst, result_src);