summaryrefslogtreecommitdiffstats
path: root/src/compiler/glsl/ir_expression_operation.py
diff options
context:
space:
mode:
authorIan Romanick <ian.d.romanick@intel.com>2016-07-12 12:30:04 -0700
committerIan Romanick <ian.d.romanick@intel.com>2016-08-30 16:28:02 -0700
commitda61c94db8bb26bac61565a3c6a3f6a3f5e1eab6 (patch)
tree909c99effd2189379f4719e9ae72f4ca77d8f7db /src/compiler/glsl/ir_expression_operation.py
parent13106e1041c254a80c7e2df392efea93dcbb215f (diff)
downloadexternal_mesa3d-da61c94db8bb26bac61565a3c6a3f6a3f5e1eab6.zip
external_mesa3d-da61c94db8bb26bac61565a3c6a3f6a3f5e1eab6.tar.gz
external_mesa3d-da61c94db8bb26bac61565a3c6a3f6a3f5e1eab6.tar.bz2
glsl: Generate code for constant ir_binop_dot expressions
v2: 'for (a, b) in d' => 'for a, b in d'. Suggested by Dylan. Signed-off-by: Ian Romanick <ian.d.romanick@intel.com> Reviewed-by: Matt Turner <mattst88@gmail.com> Acked-by: Dylan Baker <dylan@pnwbakers.com>
Diffstat (limited to 'src/compiler/glsl/ir_expression_operation.py')
-rw-r--r--src/compiler/glsl/ir_expression_operation.py19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/compiler/glsl/ir_expression_operation.py b/src/compiler/glsl/ir_expression_operation.py
index 1cb9734..9d4d59e 100644
--- a/src/compiler/glsl/ir_expression_operation.py
+++ b/src/compiler/glsl/ir_expression_operation.py
@@ -205,6 +205,21 @@ constant_template_horizontal_nonassignment = mako.template.Template("""\
${op.c_expression['default']};
break;""")
+# This template is for binary operations that are horizontal. That is, the
+# operation consumes a vector and produces a scalar.
+constant_template_horizontal = mako.template.Template("""\
+ case ${op.get_enum_name()}:
+ switch (op[0]->type->base_type) {
+ % for dst_type, src_types in op.signatures():
+ case ${src_types[0].glsl_type}:
+ data.${dst_type.union_field}[0] = ${op.get_c_expression(src_types)};
+ break;
+ % endfor
+ default:
+ assert(0);
+ }
+ break;""")
+
vector_scalar_operation = "vector-scalar"
horizontal_operation = "horizontal"
@@ -274,6 +289,8 @@ class operation(object):
return constant_template_vector_scalar.render(op=self)
elif horizontal_operation in self.flags and types_identical_operation in self.flags:
return constant_template_horizontal_single_implementation.render(op=self)
+ elif horizontal_operation in self.flags:
+ return constant_template_horizontal.render(op=self)
elif len(self.source_types) == 1:
return constant_template0.render(op=self)
elif self.dest_type is not None:
@@ -478,7 +495,7 @@ ir_expression_operation = [
operation("logic_xor", 2, printable_name="^^", source_types=(bool_type,), c_expression="{src0} != {src1}"),
operation("logic_or", 2, printable_name="||", source_types=(bool_type,), c_expression="{src0} || {src1}"),
- operation("dot", 2),
+ operation("dot", 2, source_types=real_types, c_expression={'f': "dot_f(op[0], op[1])", 'd': "dot_d(op[0], op[1])"}, flags=horizontal_operation),
operation("min", 2, source_types=numeric_types, c_expression="MIN2({src0}, {src1})", flags=vector_scalar_operation),
operation("max", 2, source_types=numeric_types, c_expression="MAX2({src0}, {src1})", flags=vector_scalar_operation),