<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 29, 2015 at 5:00 PM, Kenneth Graunke <span dir="ltr"><<a href="mailto:kenneth@whitecape.org" target="_blank">kenneth@whitecape.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span>On Thursday, January 29, 2015 12:50:20 PM Jason Ekstrand wrote:<br>
> ---<br>
> src/glsl/nir/nir_algebraic.py | 20 +++++++++++++++++---<br>
> src/glsl/nir/nir_opt_algebraic.py | 12 +++++++++---<br>
> 2 files changed, 26 insertions(+), 6 deletions(-)<br>
><br>
> diff --git a/src/glsl/nir/nir_algebraic.py b/src/glsl/nir/nir_algebraic.py<br>
> index 75436f4..6e7973d 100644<br>
> --- a/src/glsl/nir/nir_algebraic.py<br>
> +++ b/src/glsl/nir/nir_algebraic.py<br>
> @@ -28,6 +28,7 @@ import itertools<br>
> import struct<br>
> import sys<br>
> import mako.template<br>
> +import re<br>
><br>
> # Represents a set of variables, each with a unique id<br>
> class VarSet(object):<br>
> @@ -65,6 +66,8 @@ static const ${val.c_type} ${<a href="http://val.name" target="_blank">val.name</a>} = {<br>
> { ${hex(val)} /* ${val.value} */ },<br>
> % elif isinstance(val, Variable):<br>
> ${val.index}, /* ${val.var_name} */<br>
> + ${'true' if val.is_constant else 'false'},<br>
> + nir_type_${'void' if val.required_type is None else val.required_type},<br>
<br>
</span> nir_type_${val.required_type or 'void'}<br></blockquote><div><br></div><div>done.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div><br>
> % elif isinstance(val, Expression):<br>
> nir_op_${val.opcode},<br>
> { ${', '.join(src.c_ptr for src in val.sources)} },<br>
> @@ -111,12 +114,23 @@ class Constant(Value):<br>
> else:<br>
> assert False<br>
><br>
> +_var_name_re = re.compile(r"(?P<const>#)?(?P<name>\w+)(?:@(?P<type>\w+))?")<br>
> +<br>
> class Variable(Value):<br>
> def __init__(self, val, name, varset):<br>
> Value.__init__(self, name, "variable")<br>
> - self.var_name = val<br>
> - self.index = varset[val]<br>
> - <a href="http://self.name" target="_blank">self.name</a> = name<br>
> +<br>
> + m = _var_name_re.match(val)<br>
> + assert m and m.group('name') is not None<br>
> +<br>
> + self.var_name = m.group('name')<br>
> + self.is_constant = m.group('const') is not None<br>
> + self.required_type = m.group('type')<br>
> +<br>
> + if self.required_type is not None:<br>
> + assert self.required_type in ('float', 'bool', 'int', 'unsigned')<br>
> +<br>
> + self.index = varset[self.var_name]<br>
><br>
> class Expression(Value):<br>
> def __init__(self, expr, name_base, varset):<br>
> diff --git a/src/glsl/nir/nir_opt_algebraic.py b/src/glsl/nir/nir_opt_algebraic.py<br>
> index 9c62b28..1dea42a 100644<br>
> --- a/src/glsl/nir/nir_opt_algebraic.py<br>
> +++ b/src/glsl/nir/nir_opt_algebraic.py<br>
> @@ -36,9 +36,15 @@ d = 'd'<br>
> # and <replace> is either an expression or a value. An expression is<br>
> # defined as a tuple of the form (<op>, <src0>, <src1>, <src2>, <src3>)<br>
> # where each source is either an expression or a value. A value can be<br>
> -# either a numeric constant or a string representing a variable name. For<br>
> -# constants, you have to be careful to make sure that it is the right type<br>
> -# because python is unaware of the source and destination types of the<br>
> +# either a numeric constant or a string representing a variable name.<br>
> +#<br>
> +# Variable names are specified as "[#]name[@type]" where "#" inicates that<br>
> +# the given variable will only match constants and thpe type indicates that<br>
<br>
</div></div> typo ^^^^<br></blockquote><div><br></div><div>fixed.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div><div><br>
> +# the given variable will only match values from ALU instructions with the<br>
> +# given output type.<br>
> +#<br>
> +# For constants, you have to be careful to make sure that it is the right<br>
> +# type because python is unaware of the source and destination types of the<br>
> # opcodes.<br>
><br>
> optimizations = [</div></div></blockquote></div><br></div></div>