[Mesa-dev] [PATCH 2/9] i965: Fix textureGrad with cube samplers

Matt Turner mattst88 at gmail.com
Mon May 4 15:16:40 PDT 2015

On Tue, Feb 24, 2015 at 10:39 AM, Roland Scheidegger <sroland at vmware.com> wrote:
> As a side note (not really directly related to the patch) I think this
> could benefit from some optimization, unless there's some passes
> somewhere which can already do this.
> The non-scalar (non-cube) calculation does this:
> lod_info.lod = log2(max(sqrt(dot1), sqrt(dot2)))
> The second sqrt can be trivially eliminated:
> = log2(sqrt(max(dot1, dot2)))

I don't think that's valid, since sqrt(x) is greater than x for x < 1.0.

> And furthermore the remaining sqrt can be killed off too thanks to
> n*log2(x) = log2(x^n)
> = 0.5*log2(max(dot1, dot2)))
> I don't really know anything about the hw, but I would think this should
> be faster not only on the 1 mathbox-per-gpu ancient igps ;-).

FWIW, I implemented that optimization in NIR based on this email in

commit 099c729b4cb6863e8ddbdb9afe7fd7bd53c11ee1
Author: Matt Turner <mattst88 at gmail.com>
Date:   Thu Mar 26 10:07:58 2015 -0700

    nir: Add identities for the log function.

and it didn't find any instances of log(sqrt(x)) in our shader-db. :(

It did find some rcp(log(x)) though!

More information about the mesa-dev mailing list