From: Ian Romanick Date: Mon, 11 Jul 2016 17:19:31 +0000 (-0700) Subject: glsl: Generate code for constant binary expressions that have one operand type X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=f81b1c7fa7f5392ea0b950b888db6f023769af52;p=mesa.git glsl: Generate code for constant binary expressions that have one operand type 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 27412d2e461..d086366cbe3 100644 --- a/src/compiler/glsl/ir_expression_operation.py +++ b/src/compiler/glsl/ir_expression_operation.py @@ -89,8 +89,8 @@ signed_numeric_types = (int_type, float_type, double_type) integer_types = (uint_type, int_type) real_types = (float_type, double_type) -# This template is for unary operations that can only have operands of a -# single type. ir_unop_logic_not is an example. +# This template is for unary and binary operations that can only have operands +# of a single type. ir_unop_logic_not is an example. constant_template0 = mako.template.Template("""\ case ${op.get_enum_name()}: assert(op[0]->type->base_type == ${op.source_types[0].glsl_type}); @@ -180,12 +180,16 @@ class operation(object): return constant_template1.render(op=self) else: return constant_template3.render(op=self) + elif self.num_operands == 2: + if len(self.source_types) == 1: + return constant_template0.render(op=self) return None def get_c_expression(self, types): src0 = "op[0]->value.{}[c]".format(types[0].union_field) + src1 = "op[1]->value.{}[c]".format(types[1].union_field) if len(types) >= 2 else "ERROR" expr = self.c_expression[types[0].union_field] if types[0].union_field in self.c_expression else self.c_expression['default'] @@ -366,15 +370,15 @@ ir_expression_operation = [ operation("bit_xor", 2, printable_name="^"), operation("bit_or", 2, printable_name="|"), - operation("logic_and", 2, printable_name="&&"), - operation("logic_xor", 2, printable_name="^^"), - operation("logic_or", 2, printable_name="||"), + operation("logic_and", 2, printable_name="&&", source_types=(bool_type,), c_expression="{src0} && {src1}"), + 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("min", 2), operation("max", 2), - operation("pow", 2), + operation("pow", 2, source_types=(float_type,), c_expression="powf({src0}, {src1})"), # Load a value the size of a given GLSL type from a uniform block. #