<html>
    <head>
      <base href="https://bugs.freedesktop.org/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Priority</th>
          <td>medium
          </td>
        </tr>

        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - GLSL: vectorize optimization does not take branches into account"
   href="https://bugs.freedesktop.org/show_bug.cgi?id=74113">74113</a>
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>idr@freedesktop.org
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>GLSL: vectorize optimization does not take branches into account
          </td>
        </tr>

        <tr>
          <th>QA Contact</th>
          <td>intel-3d-bugs@lists.freedesktop.org
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>aras@unity3d.com
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>git
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>glsl-compiler
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>Mesa
          </td>
        </tr></table>
      <p>
        <div>
        <pre>"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.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the QA Contact for the bug.</li>
      </ul>
    </body>
</html>