[Mesa-dev] [PATCH 48/56] glsl: Generate code for constant ir_triop_csel expressions

Dylan Baker dylan at pnwbakers.com
Fri Jul 22 22:20:50 UTC 2016


Quoting Ian Romanick (2016-07-19 12:25:07)
> From: Ian Romanick <ian.d.romanick at intel.com>
> 
> Signed-off-by: Ian Romanick <ian.d.romanick at intel.com>
> ---
>  src/compiler/glsl/ir_expression_operation.py | 24 +++++++++++++++++++++++-
>  1 file changed, 23 insertions(+), 1 deletion(-)
> 
> diff --git a/src/compiler/glsl/ir_expression_operation.py b/src/compiler/glsl/ir_expression_operation.py
> index 7161713..b1b7101 100644
> --- a/src/compiler/glsl/ir_expression_operation.py
> +++ b/src/compiler/glsl/ir_expression_operation.py
> @@ -357,6 +357,24 @@ constant_template_lrp = mako.template.Template("""\
>        break;
>     }""")
>  
> +# This template is for ir_triop_csel.  This expression is really unique
> +# because not all of the operands are the same type, and the second operand
> +# determines the type of the expression (instead of the first).
> +constant_template_csel = mako.template.Template("""\
> +   case ${op.get_enum_name()}:
> +      for (unsigned c = 0; c < components; c++) {
> +         switch (this->type->base_type) {
> +    % for (dst_type, src_types) in op.signatures():

nit: python doesn't requires braces around container explosions except
in some corner cases with nested containers. (you can take it or leave
it, though)

> +         case ${src_types[1].glsl_type}:
> +            data.${dst_type.union_field}[c] = ${op.get_c_expression(src_types)};
> +            break;
> +    % endfor
> +         default:
> +            assert(0);
> +         }
> +      }
> +      break;""")
> +
>  
>  vector_scalar_operation = "vector-scalar"
>  horizontal_operation = "horizontal"
> @@ -443,6 +461,8 @@ class operation(object):
>              return constant_template_vector_insert.render(op=self)
>           elif self.name == "lrp":
>              return constant_template_lrp.render(op=self)
> +         elif self.name == "csel":
> +            return constant_template_csel.render(op=self)
>           else:
>              return constant_template3.render(op=self)
>        elif self.num_operands == 4:
> @@ -700,7 +720,9 @@ ir_expression_operation = [
>     # component on vectors).
>     #
>     # See also lower_instructions_visitor::ldexp_to_arith
> -   operation("csel", 3),
> +   operation("csel", 3,
> +             all_signatures=zip(all_types, zip(len(all_types) * (bool_type,), all_types, all_types)),

The zip(len(all_types) * (bool_type,) bit is a little confusing at
first, it might deserve a comment.

Also, you might be able to use itertools.izip instead of zip here, it
will probably speed up the build, but it doesn't make a list, just an
iterator, so if internally operation() needs to iterate all_signatures
more than once it wont work.

> +             c_expression="{src0} ? {src1} : {src2}"),
>  
>     operation("bitfield_extract", 3,
>               all_signatures=((int_type, (uint_type, int_type, int_type)),
> -- 
> 2.5.5
> 
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: signature
URL: <https://lists.freedesktop.org/archives/mesa-dev/attachments/20160722/cb7b4bcf/attachment.sig>


More information about the mesa-dev mailing list