[Mesa-dev] [PATCH 5/7] nir/algebraic: Support specifying variable as constant or by type

Jason Ekstrand jason at jlekstrand.net
Thu Jan 29 17:06:43 PST 2015


On Thu, Jan 29, 2015 at 5:00 PM, Kenneth Graunke <kenneth at whitecape.org>
wrote:

> On Thursday, January 29, 2015 12:50:20 PM Jason Ekstrand wrote:
> > ---
> >  src/glsl/nir/nir_algebraic.py     | 20 +++++++++++++++++---
> >  src/glsl/nir/nir_opt_algebraic.py | 12 +++++++++---
> >  2 files changed, 26 insertions(+), 6 deletions(-)
> >
> > diff --git a/src/glsl/nir/nir_algebraic.py
> b/src/glsl/nir/nir_algebraic.py
> > index 75436f4..6e7973d 100644
> > --- a/src/glsl/nir/nir_algebraic.py
> > +++ b/src/glsl/nir/nir_algebraic.py
> > @@ -28,6 +28,7 @@ import itertools
> >  import struct
> >  import sys
> >  import mako.template
> > +import re
> >
> >  # Represents a set of variables, each with a unique id
> >  class VarSet(object):
> > @@ -65,6 +66,8 @@ static const ${val.c_type} ${val.name} = {
> >     { ${hex(val)} /* ${val.value} */ },
> >  % elif isinstance(val, Variable):
> >     ${val.index}, /* ${val.var_name} */
> > +   ${'true' if val.is_constant else 'false'},
> > +   nir_type_${'void' if val.required_type is None else
> val.required_type},
>
>    nir_type_${val.required_type or 'void'}
>

done.


>
> >  % elif isinstance(val, Expression):
> >     nir_op_${val.opcode},
> >     { ${', '.join(src.c_ptr for src in val.sources)} },
> > @@ -111,12 +114,23 @@ class Constant(Value):
> >        else:
> >           assert False
> >
> > +_var_name_re =
> re.compile(r"(?P<const>#)?(?P<name>\w+)(?:@(?P<type>\w+))?")
> > +
> >  class Variable(Value):
> >     def __init__(self, val, name, varset):
> >        Value.__init__(self, name, "variable")
> > -      self.var_name = val
> > -      self.index = varset[val]
> > -      self.name = name
> > +
> > +      m = _var_name_re.match(val)
> > +      assert m and m.group('name') is not None
> > +
> > +      self.var_name = m.group('name')
> > +      self.is_constant = m.group('const') is not None
> > +      self.required_type = m.group('type')
> > +
> > +      if self.required_type is not None:
> > +         assert self.required_type in ('float', 'bool', 'int',
> 'unsigned')
> > +
> > +      self.index = varset[self.var_name]
> >
> >  class Expression(Value):
> >     def __init__(self, expr, name_base, varset):
> > diff --git a/src/glsl/nir/nir_opt_algebraic.py
> b/src/glsl/nir/nir_opt_algebraic.py
> > index 9c62b28..1dea42a 100644
> > --- a/src/glsl/nir/nir_opt_algebraic.py
> > +++ b/src/glsl/nir/nir_opt_algebraic.py
> > @@ -36,9 +36,15 @@ d = 'd'
> >  # and <replace> is either an expression or a value.  An expression is
> >  # defined as a tuple of the form (<op>, <src0>, <src1>, <src2>, <src3>)
> >  # where each source is either an expression or a value.  A value can be
> > -# either a numeric constant or a string representing a variable name.
> For
> > -# constants, you have to be careful to make sure that it is the right
> type
> > -# because python is unaware of the source and destination types of the
> > +# either a numeric constant or a string representing a variable name.
> > +#
> > +# Variable names are specified as "[#]name[@type]" where "#" inicates
> that
> > +# the given variable will only match constants and thpe type indicates
> that
>
>                                                  typo ^^^^
>

fixed.


>
> > +# the given variable will only match values from ALU instructions with
> the
> > +# given output type.
> > +#
> > +# For constants, you have to be careful to make sure that it is the
> right
> > +# type because python is unaware of the source and destination types of
> the
> >  # opcodes.
> >
> >  optimizations = [
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20150129/10640d6a/attachment.html>


More information about the mesa-dev mailing list