Bug 74113

Summary: GLSL: vectorize optimization does not take branches into account
Product: Mesa Reporter: Aras Pranckevicius <aras>
Component: glsl-compilerAssignee: Matt Turner <mattst88>
Status: RESOLVED FIXED QA Contact: Intel 3D Bugs Mailing List <intel-3d-bugs>
Severity: normal    
Priority: medium    
Version: git   
Hardware: All   
OS: All   
URL: http://patchwork.freedesktop.org/patch/18837/
Whiteboard:
i915 platform: i915 features:

Description Aras Pranckevicius 2014-01-27 11:05:43 UTC
"Vectorize multiple scalar assignments" optimization (added in 4bd6e0d7c69 on master) does not take possible branches into account.

For example, on a fragment shader like this:

uniform sampler2D maintex;
uniform float factor;
varying vec2 uv;
void main()
{
    vec4 c = texture2D (maintex, uv);
    vec2 coord = c.xy;
    bool cond = c.w >= 0.5;
    if (!cond)
        coord.x += factor;
    if (cond)
        coord.y += factor;
    gl_FragColor = vec4(coord,0,0);
}

It does try to merge both coord.x and coord.y assignments into one, even if they are under different branch conditions. Effectively it ends up with "if (cond) coord.xy += ..." which is wrong.

Real-life shaders like FXAA3.11 have a code very similar to the above, and it regresses under this optimization.

As a simple stop-gap solution the optimization could just never go into any branch-like structures (return visit_continue_with_parent from visit_enter(ir_if) etc.
Comment 1 Matt Turner 2014-01-27 17:32:51 UTC
Thanks for the report. I'll try to fix this today.
Comment 2 Matt Turner 2014-01-27 18:56:08 UTC
Patch on the list. It fixes it for me.
Comment 3 Matt Turner 2014-01-27 19:10:09 UTC
New piglit test as well: http://patchwork.freedesktop.org/patch/18838/
Comment 4 Matt Turner 2014-01-28 05:24:17 UTC
Updated patch committed as

http://cgit.freedesktop.org/mesa/mesa/commit/?id=37f1903e007e30892ce39e6e2493c9e88dacf7cc

Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.