Mesa (master): nir: Remove sRGB colorspace conversion round-trip.

Matt Turner mattst88 at kemper.freedesktop.org
Fri May 22 18:30:45 UTC 2015


Module: Mesa
Branch: master
Commit: 5614bcc416cf2ff1d816d52198e644565ca23bcd
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=5614bcc416cf2ff1d816d52198e644565ca23bcd

Author: Matt Turner <mattst88 at gmail.com>
Date:   Mon May 18 14:59:13 2015 -0700

nir: Remove sRGB colorspace conversion round-trip.

Some shaders in Civilization V and Beyond Earth do

   pow(pow(x, 2.2), 0.454545)

which is converting to and from sRGB colorspace.

A more general rule that replaces pow(pow(a, b), c) with pow(a, b * c)
actually regresses two shaders in Sun Temple in which the result of the
inner pow is used twice, once by another pow and once by another
instruction. Also, since 2.2 * 0.454545 isn't exactly one, the more
general pattern would have still left us with a pow, and I'm 2.2 *
0.454545 percent sure that's not what they want.

instructions in affected programs:     934 -> 886 (-5.14%)
helped:                                16

---

 src/glsl/nir/nir_opt_algebraic.py |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/glsl/nir/nir_opt_algebraic.py b/src/glsl/nir/nir_opt_algebraic.py
index fa03922..eace791 100644
--- a/src/glsl/nir/nir_opt_algebraic.py
+++ b/src/glsl/nir/nir_opt_algebraic.py
@@ -156,6 +156,8 @@ optimizations = [
    (('fpow', a, 2.0), ('fmul', a, a)),
    (('fpow', a, 4.0), ('fmul', ('fmul', a, a), ('fmul', a, a))),
    (('fpow', 2.0, a), ('fexp2', a)),
+   (('fpow', ('fpow', a, 2.2), 0.454545), a),
+   (('fpow', ('fabs', ('fpow', a, 2.2)), 0.454545), ('fabs', a)),
    (('fsqrt', ('fexp2', a)), ('fexp2', ('fmul', 0.5, a))),
    (('frcp', ('fexp2', a)), ('fexp2', ('fneg', a))),
    (('frsq', ('fexp2', a)), ('fexp2', ('fmul', -0.5, a))),




More information about the mesa-commit mailing list