[Mesa-dev] [RFC PATCH] nir/algebraic: Simplify max(abs(a), 0.0) -> abs(a)

Elie Tournier tournier.elie at gmail.com
Fri May 24 12:59:24 UTC 2019


On Thu, May 23, 2019 at 10:54:38PM -0400, Ilia Mirkin wrote:
> How does max(NaN, 0) work? IIRC there's some provision that this
> becomes 0, while abs(NaN) = NaN.

Yes max(NaN, 0) should return 0.
At least it's what we do with i965.
See https://gitlab.freedesktop.org/mesa/mesa/blob/a42163cbbc1abe02b7db4ade74b569f455942d1a/src/compiler/glsl/float64.glsl#L1739
> 
> On Thu, May 23, 2019 at 10:47 PM Alyssa Rosenzweig <alyssa at rosenzweig.io> wrote:
> >
> > I noticed this pattern in glmark's jellyfish scene.
> >
> > Assuming this is correct (it should be...?), could someone do a
> > shader-db run? Thank you!
> >
> > Signed-off-by: Alyssa Rosenzweig <alyssa at rosenzweig.io>
> > Cc: Ian Romanick <ian.d.romanick at intel.com>
> > ---
> >  src/compiler/nir/nir_opt_algebraic.py | 1 +
> >  1 file changed, 1 insertion(+)
> >
> > diff --git a/src/compiler/nir/nir_opt_algebraic.py b/src/compiler/nir/nir_opt_algebraic.py
> > index 89d07aa1261..abd0b6591ce 100644
> > --- a/src/compiler/nir/nir_opt_algebraic.py
> > +++ b/src/compiler/nir/nir_opt_algebraic.py
> > @@ -377,6 +377,7 @@ optimizations = [
> >     (('imax', a, a), a),
> >     (('umin', a, a), a),
> >     (('umax', a, a), a),
> > +   (('fmax', ('fabs', a), 0.0), ('fabs', a)),
> >     (('fmax', ('fmax', a, b), b), ('fmax', a, b)),
> >     (('umax', ('umax', a, b), b), ('umax', a, b)),
> >     (('imax', ('imax', a, b), b), ('imax', a, b)),
> > --
> > 2.20.1
> >
> > _______________________________________________
> > mesa-dev mailing list
> > mesa-dev at lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/mesa-dev
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/mesa-dev


More information about the mesa-dev mailing list