From: Eric Anholt Date: Tue, 13 Jul 2010 22:37:57 +0000 (-0700) Subject: glsl2: Make cross() be an expression operation. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=9be7f638130f46a9df2bfbcd4a03b36de9e4f3aa;p=mesa.git 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. --- 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);