<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 - linker error "fragment shader input ... has no matching output in the previous stage" when previous stage's output declaration in a separate shader object"
   href="https://bugs.freedesktop.org/show_bug.cgi?id=105731">105731</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>linker error "fragment shader input ... has no matching output in the previous stage" when previous stage's output declaration in a separate shader object
          </td>
        </tr>

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

        <tr>
          <th>Version</th>
          <td>git
          </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>quisquilia@gmx.de
          </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=138342" name="attach_138342" title="C/OpenGL code to trigger the issue">attachment 138342</a> <a href="attachment.cgi?id=138342&action=edit" title="C/OpenGL code to trigger the issue">[details]</a></span>
C/OpenGL code to trigger the issue

GLSL spec (using version 4.30 here, section "4.3.4 Input variables", page 43f)
states that there should be no link error if an input variable is used for
which there is no static use in the previous stage, but a valid output
declaration.

Mesa's linker seems to adhere to this not in every case. If the declaration is
in a separate shader object, it fails to link. See the attached example code.
The key point is the following vertex shader:

    static const char *vs_part1=
        "out vec4 foo;\n"
        "void unused() {foo=vec4(1);}\n";

    static const char *vs_part2=
        "in vec4 pos;\n"
        "void main() { gl_Position = pos; }\n";

used in conjunction with this fragment shader:
    static const char *fs_part1=
        "in vec4 foo;\n"
        "out vec4 color;\n"
        "void main() {color=foo;}\n";

When this is created as a single GL_VERTEX_SHADER with both strings
concatenated (via glShaderSource), the resulting program will link, just with a
warning

    warning: fragment shader varying foo not written by vertex shader

which is conforming behavior.

However, when vs_part1 and vs_part2 are compiled as separate shader objects,
the final link fails with

    error: fragment shader input `foo' has no matching output in the previous 
           stage

which (in my interpretation of the spec) should not happen.

Tested with:
OpenGL vendor string: Intel Open Source Technology Center
OpenGL renderer string: Mesa DRI Intel(R) Haswell Mobile 
OpenGL core profile version string: 4.5 (Core Profile) Mesa 17.1.1
(git-092c485)

as well as:
OpenGL vendor string: Intel Open Source Technology Center
OpenGL renderer string: Mesa DRI Intel(R) Haswell Mobile 
OpenGL core profile version string: 4.5 (Core Profile) Mesa 18.1.0-devel
(git-ff0e3fa1fe)</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>