summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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 1cf88ada165..b3a283306df 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 deb2f952bfc..24717a2183d 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 6d899132861..fcf5deced8d 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 790173ed6be..9d7af2dcabc 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 c0fe47067bd..ca834978f47 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 6ecc6d317c7..f99a1fc4508 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);