Bug 74113 - GLSL: vectorize optimization does not take branches into account
Summary: GLSL: vectorize optimization does not take branches into account
Status: RESOLVED FIXED
Alias: None
Product: Mesa
Classification: Unclassified
Component: glsl-compiler (show other bugs)
Version: git
Hardware: All All
: medium normal
Assignee: Matt Turner
QA Contact: Intel 3D Bugs Mailing List
URL: http://patchwork.freedesktop.org/patc...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-27 11:05 UTC by Aras Pranckevicius
Modified: 2014-01-28 05:24 UTC (History)
0 users

See Also:
i915 platform:
i915 features:


Attachments

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.