diff options
author | Ian Romanick <[email protected]> | 2016-07-12 12:52:45 -0700 |
---|---|---|
committer | Ian Romanick <[email protected]> | 2016-08-30 16:28:02 -0700 |
commit | 9f1d7c52354d7ffbd58467bb4a91b9c9ffd31785 (patch) | |
tree | 75141d7678ed0c1f5fcc3277d8c4f9df7263770b | |
parent | d8dd49419aebf025fece1a2342dd880e7504c2e5 (diff) |
glsl: Generate code for constant ir_binop_vector_extract expressions
v2: 'for (a, b) in d' => 'for a, b in d'. Suggested by Dylan.
Signed-off-by: Ian Romanick <[email protected]>
Reviewed-by: Matt Turner <[email protected]>
Acked-by: Dylan Baker <[email protected]>
-rw-r--r-- | src/compiler/glsl/ir_expression_operation.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/compiler/glsl/ir_expression_operation.py b/src/compiler/glsl/ir_expression_operation.py index 7d82ea80dd2..b2bdb45cf34 100644 --- a/src/compiler/glsl/ir_expression_operation.py +++ b/src/compiler/glsl/ir_expression_operation.py @@ -270,6 +270,24 @@ constant_template_horizontal = mako.template.Template("""\ } break;""") +# This template is for ir_binop_vector_extract. +constant_template_vector_extract = mako.template.Template("""\ + case ${op.get_enum_name()}: { + const int c = CLAMP(op[1]->value.i[0], 0, + (int) op[0]->type->vector_elements - 1); + + 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[0]->value.${src_types[0].union_field}[c]; + break; + % endfor + default: + assert(0); + } + break; + }""") + vector_scalar_operation = "vector-scalar" horizontal_operation = "horizontal" @@ -337,6 +355,8 @@ class operation(object): elif self.num_operands == 2: if self.name == "mul": return constant_template_mul.render(op=self) + elif self.name == "vector_extract": + return constant_template_vector_extract.render(op=self) elif vector_scalar_operation in self.flags: return constant_template_vector_scalar.render(op=self) elif horizontal_operation in self.flags and types_identical_operation in self.flags: @@ -574,7 +594,7 @@ ir_expression_operation = [ # # operand0 is the vector # operand1 is the index of the field to read from operand0 - operation("vector_extract", 2), + operation("vector_extract", 2, source_types=all_types, c_expression="anything-except-None"), # Interpolate fs input at offset # |