From: Ian Romanick Date: Tue, 12 Jul 2016 19:30:19 +0000 (-0700) Subject: glsl: Generate code for constant ir_triop_fma and ir_triop_bitfield_extract expressions X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=8954a019f7e9098738c7cc25ed097e7f85c24def;p=mesa.git glsl: Generate code for constant ir_triop_fma and ir_triop_bitfield_extract expressions ir_triop_bitfield_extract is a little weird because the second and third operand and aways int, so they may differ in type from the first operand. Signed-off-by: Ian Romanick Reviewed-by: Matt Turner Acked-by: Dylan Baker --- diff --git a/src/compiler/glsl/ir_expression_operation.py b/src/compiler/glsl/ir_expression_operation.py index 9d4d59e8e39..de3b866bb96 100644 --- a/src/compiler/glsl/ir_expression_operation.py +++ b/src/compiler/glsl/ir_expression_operation.py @@ -181,7 +181,7 @@ constant_template_vector_scalar = mako.template.Template("""\ 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}[c] = ${op.get_c_expression(src_types, ("c0", "c1"))}; + data.${dst_type.union_field}[c] = ${op.get_c_expression(src_types, ("c0", "c1", "c2"))}; break; % endfor default: @@ -297,18 +297,22 @@ class operation(object): return constant_template5.render(op=self) else: return constant_template3.render(op=self) + elif self.num_operands == 3: + return constant_template3.render(op=self) return None - def get_c_expression(self, types, indices=("c", "c")): + def get_c_expression(self, types, indices=("c", "c", "c")): src0 = "op[0]->value.{}[{}]".format(types[0].union_field, indices[0]) src1 = "op[1]->value.{}[{}]".format(types[1].union_field, indices[1]) if len(types) >= 2 else "ERROR" + src2 = "op[2]->value.{}[{}]".format(types[2].union_field, indices[2]) if len(types) >= 3 else "ERROR" expr = self.c_expression[types[0].union_field] if types[0].union_field in self.c_expression else self.c_expression['default'] return expr.format(src0=src0, - src1=src1) + src1=src1, + src2=src2) def signatures(self): @@ -533,7 +537,7 @@ ir_expression_operation = [ operation("interpolate_at_sample", 2), # Fused floating-point multiply-add, part of ARB_gpu_shader5. - operation("fma", 3), + operation("fma", 3, source_types=real_types, c_expression="{src0} * {src1} + {src2}"), operation("lrp", 3), @@ -545,7 +549,11 @@ ir_expression_operation = [ # See also lower_instructions_visitor::ldexp_to_arith operation("csel", 3), - operation("bitfield_extract", 3), + operation("bitfield_extract", 3, + all_signatures=((int_type, (uint_type, int_type, int_type)), + (int_type, (int_type, int_type, int_type))), + c_expression={'u': "bitfield_extract_uint({src0}, {src1}, {src2})", + 'i': "bitfield_extract_int({src0}, {src1}, {src2})"}), # Generate a value with one field of a vector changed #