[Mesa-dev] [PATCH] nir/algebraic: Remove imprecise flog2 optimizations

Matt Turner mattst88 at gmail.com
Mon Jun 20 18:08:52 UTC 2016


On Sat, Jun 18, 2016 at 12:42 PM, Jason Ekstrand <jason at jlekstrand.net> wrote:
> While mathematically correct, these two optimizations result in an
> expression with substantially lower precision than the original.  For any
> positive finite floating-point value, log2(x) is well-defined and finite.
> More precisely, it is in the range [-150, 150] so any sum of logarithms
> log2(a) + log2(b) is also well-defined and finite as long as a and b are
> both positive and finite.  However, if a and b are either very small or
> very large, their product may get flushed to infinity or zero causing
> log2(a * b) to be nowhere close to log2(a) + log2(b).
>
> This imprecision was causing incorrect rendering in Talos Principal because
> part of its HDR rendering process involves doing 8 texture operations,
> clamping the result to [0, 65000], taking a dot-product with a constant,
> and then taking the log2.  This is done 6 or 8 times and summed to produce
> the final result which is written to a red texture.  In cases where you
> have a region of the screen that is very dark, it can end up getting a
> result value of -inf which is not what is intended.
>
> Signed-off-by: Jason Ekstrand <jason at jlekstrand.net>
> Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=96425
> Cc: Matt Turner <mattst88 at gmail.com>

Ah, that's too bad.

Reviewed-by: Matt Turner <mattst88 at gmail.com>


More information about the mesa-dev mailing list