diff options
author | Ian Romanick <[email protected]> | 2016-07-12 10:51:43 -0700 |
---|---|---|
committer | Ian Romanick <[email protected]> | 2016-08-30 16:28:02 -0700 |
commit | 0f87c54d1c6ae022c9884283052a7de9d6eec710 (patch) | |
tree | 84613513c6ae4a3bf332228184782e1ebe004b2d /src | |
parent | 8cf9157786ff6afa4bb8ce81755a9944dc79320d (diff) |
glsl: Generate code for constant unary expressions that don't assign the destination
These are operations like the pack functions that have separate
functions that assign multiple outputs from a single input.
v2: Correct the source and destination types. They were previously
transposed.
Signed-off-by: Ian Romanick <[email protected]>
Reviewed-by: Matt Turner <[email protected]>
Acked-by: Dylan Baker <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/glsl/ir_expression_operation.py | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/src/compiler/glsl/ir_expression_operation.py b/src/compiler/glsl/ir_expression_operation.py index 9e257f8f8a4..394626b503f 100644 --- a/src/compiler/glsl/ir_expression_operation.py +++ b/src/compiler/glsl/ir_expression_operation.py @@ -188,10 +188,18 @@ constant_template_horizontal_single_implementation = mako.template.Template("""\ data.${op.dest_type.union_field}[0] = ${op.c_expression['default']}; break;""") +# This template is for operations that are horizontal and do not assign the +# result. The various unpack operations are examples. +constant_template_horizontal_nonassignment = mako.template.Template("""\ + case ${op.get_enum_name()}: + ${op.c_expression['default']}; + break;""") + vector_scalar_operation = "vector-scalar" horizontal_operation = "horizontal" types_identical_operation = "identical" +non_assign_operation = "nonassign" class operation(object): def __init__(self, name, num_operands, printable_name = None, source_types = None, dest_type = None, c_expression = None, flags = None): @@ -230,7 +238,9 @@ class operation(object): return None if self.num_operands == 1: - if horizontal_operation in self.flags: + if horizontal_operation in self.flags and non_assign_operation in self.flags: + return constant_template_horizontal_nonassignment.render(op=self) + elif horizontal_operation in self.flags: return constant_template_horizontal_single_implementation.render(op=self) elif self.dest_type is not None and len(self.source_types) == 1: return constant_template2.render(op=self) @@ -351,11 +361,11 @@ ir_expression_operation = [ operation("pack_unorm_2x16", 1, printable_name="packUnorm2x16", source_types=(float_type,), dest_type=uint_type, c_expression="pack_2x16(pack_unorm_1x16, op[0]->value.f[0], op[0]->value.f[1])", flags=horizontal_operation), operation("pack_unorm_4x8", 1, printable_name="packUnorm4x8", source_types=(float_type,), dest_type=uint_type, c_expression="pack_4x8(pack_unorm_1x8, op[0]->value.f[0], op[0]->value.f[1], op[0]->value.f[2], op[0]->value.f[3])", flags=horizontal_operation), operation("pack_half_2x16", 1, printable_name="packHalf2x16", source_types=(float_type,), dest_type=uint_type, c_expression="pack_2x16(pack_half_1x16, op[0]->value.f[0], op[0]->value.f[1])", flags=horizontal_operation), - operation("unpack_snorm_2x16", 1, printable_name="unpackSnorm2x16"), - operation("unpack_snorm_4x8", 1, printable_name="unpackSnorm4x8"), - operation("unpack_unorm_2x16", 1, printable_name="unpackUnorm2x16"), - operation("unpack_unorm_4x8", 1, printable_name="unpackUnorm4x8"), - operation("unpack_half_2x16", 1, printable_name="unpackHalf2x16"), + operation("unpack_snorm_2x16", 1, printable_name="unpackSnorm2x16", source_types=(uint_type,), dest_type=float_type, c_expression="unpack_2x16(unpack_snorm_1x16, op[0]->value.u[0], &data.f[0], &data.f[1])", flags=frozenset((horizontal_operation, non_assign_operation))), + operation("unpack_snorm_4x8", 1, printable_name="unpackSnorm4x8", source_types=(uint_type,), dest_type=float_type, c_expression="unpack_4x8(unpack_snorm_1x8, op[0]->value.u[0], &data.f[0], &data.f[1], &data.f[2], &data.f[3])", flags=frozenset((horizontal_operation, non_assign_operation))), + operation("unpack_unorm_2x16", 1, printable_name="unpackUnorm2x16", source_types=(uint_type,), dest_type=float_type, c_expression="unpack_2x16(unpack_unorm_1x16, op[0]->value.u[0], &data.f[0], &data.f[1])", flags=frozenset((horizontal_operation, non_assign_operation))), + operation("unpack_unorm_4x8", 1, printable_name="unpackUnorm4x8", source_types=(uint_type,), dest_type=float_type, c_expression="unpack_4x8(unpack_unorm_1x8, op[0]->value.u[0], &data.f[0], &data.f[1], &data.f[2], &data.f[3])", flags=frozenset((horizontal_operation, non_assign_operation))), + operation("unpack_half_2x16", 1, printable_name="unpackHalf2x16", source_types=(uint_type,), dest_type=float_type, c_expression="unpack_2x16(unpack_half_1x16, op[0]->value.u[0], &data.f[0], &data.f[1])", flags=frozenset((horizontal_operation, non_assign_operation))), # Bit operations, part of ARB_gpu_shader5. operation("bitfield_reverse", 1, source_types=integer_types, c_expression="bitfield_reverse({src0})"), @@ -366,8 +376,8 @@ ir_expression_operation = [ operation("saturate", 1, printable_name="sat", source_types=(float_type,), c_expression="CLAMP({src0}, 0.0f, 1.0f)"), # Double packing, part of ARB_gpu_shader_fp64. - operation("pack_double_2x32", 1, printable_name="packDouble2x32"), - operation("unpack_double_2x32", 1, printable_name="unpackDouble2x32"), + operation("pack_double_2x32", 1, printable_name="packDouble2x32", source_types=(uint_type,), dest_type=double_type, c_expression="memcpy(&data.d[0], &op[0]->value.u[0], sizeof(double))", flags=frozenset((horizontal_operation, non_assign_operation))), + operation("unpack_double_2x32", 1, printable_name="unpackDouble2x32", source_types=(double_type,), dest_type=uint_type, c_expression="memcpy(&data.u[0], &op[0]->value.d[0], sizeof(double))", flags=frozenset((horizontal_operation, non_assign_operation))), operation("frexp_sig", 1), operation("frexp_exp", 1), |