<html>
    <head>
      <base href="https://bugs.freedesktop.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Using array in structure results in wrong GLSL compilation output"
   href="https://bugs.freedesktop.org/show_bug.cgi?id=103955">103955</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Using array in structure results in wrong GLSL compilation output
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>Mesa
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>17.3
          </td>
        </tr>

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

        <tr>
          <th>OS</th>
          <td>Linux (All)
          </td>
        </tr>

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

        <tr>
          <th>Severity</th>
          <td>minor
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>medium
          </td>
        </tr>

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

        <tr>
          <th>Assignee</th>
          <td>mesa-dev@lists.freedesktop.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>mieabby@gmail.com
          </td>
        </tr>

        <tr>
          <th>QA Contact</th>
          <td>intel-3d-bugs@lists.freedesktop.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=135756" name="attach_135756" title="Windows port of the test program">attachment 135756</a> <a href="attachment.cgi?id=135756&action=edit" title="Windows port of the test program">[details]</a></span>
Windows port of the test program

Declaring a uniform structure, whose one member is an array of float, results
in wrong shader code. Consider the following fragment shader:


        struct Set {
                vec3 color;
                float arr[3];
        };

        uniform Set u_s;


        void main () {
                gl_FragColor = vec4(u_s.color * u_s.arr[0], 1.0);
                // gl_FragColor = vec4(u_s.color * vec3(1.0, 0.0, 0.0), 1.0);
        }


This fragment shader should output FragColor of white(that is `vec4(1.0, 1.0,
1.0, 1.0)`) if the value of `u_s.arr[0]` is 1.0. However, the shader compiled
by Mesa driver produces `vec4(1.0, 0.0, 0.0, ?)`, which is red. The alpha
component is disregarded since GL_BLEND is disabled in the test application.


I wanted to know if this bug is hardware related. The attachment is the
makeshift test program I wrote with an existing example(in the courtesy of
opengl-tutorial.org) to demonstrate the bug. I found this bug when I was
developing a WebGL web app, so I wrote the test web page as well.

   <a href="https://ashegoulding.github.io/attmnts/array_in_struct_uniform.html">https://ashegoulding.github.io/attmnts/array_in_struct_uniform.html</a>
   <a href="https://ashegoulding.github.io/attmnts/array_in_struct_uniform.zip">https://ashegoulding.github.io/attmnts/array_in_struct_uniform.zip</a>

I also ported the test program to Windows. The bug is not reproducible on
Windows in whichever way.

On Linux running the Mesa driver, Firefox, Google Chrome displays a red
framebuffer. The bug is still seen running the browsers/test app with
`LIBGL_ALWAYS_SOFTWARE=1`, except for Chrome[1]

I'd also like to mention that I ran the test program and the web page with
`MESA_GLSL=dump`, `MESA_GLSL=uniform` to see if there's any form of "shader
source translation" like ANGLE does on Windows. The dump of the source code and
uniform upload were identical.

The bug is still there on 17.3.0-rc5 and 17.2.6.



[1]
Chrome browser defaults to its own software renderer when a slower renderer(SW
or VBox GPU) is detected. The canvas is white with that renderer.</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>