[Mesa-dev] [PATCH] GLSL: fix too eager constant variable optimization
Ian Romanick
idr at freedesktop.org
Fri Mar 1 11:06:48 PST 2013
On 03/01/2013 02:02 AM, Aras Pranckevicius wrote:
> Hi,
>
> opt_constant_variable was marking a variable as constant as long as
> there was exactly one constant assignment to it, but did not take into
> account that this assignment might be in a dynamic branch or a loop.
>
> Was happening on a fragment shader like this:
>
> uniform float mode;
> float func (float c) {
> if (mode == 2.0)
> return c; // was returning 0.1 after optimization!
> if (mode == 3.0)
> discard;
> if (mode == 10.0)
> c = 0.1;
> return c;
> }
> void main() {
> vec4 c = gl_FragCoord;
> c.x = func(c.x);
> gl_FragColor = c;
> }
>
>
> Now, looking further this optimization pass should also not mark
> variables as const if there was a dereference of them before that first
> assignment. I had code to do this (a hashtable that would track
> dereferences before assignment is done). But couldn't come up with a
> test case that would break the whole set of optimizations that Mesa does
> (lower jumps, or inlining, ... were getting in the way and hide the bug).
Good catch! There are a couple white-space issues in the patch, but I
can fix those when I push it. I'll wait a bit for other people to give
review comments. I'll probably also copy the above text into the commit
message.
> --
> Aras Pranckevičius
> work: http://unity3d.com
> home: http://aras-p.info
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
More information about the mesa-dev
mailing list