Bug 100316 - Linking GLSL 1.30 shaders with invariant and deprecated variables triggers an 'mismatching invariant qualifiers' error
Summary: Linking GLSL 1.30 shaders with invariant and deprecated variables triggers an...
Status: RESOLVED FIXED
Alias: None
Product: Mesa
Classification: Unclassified
Component: glsl-compiler (show other bugs)
Version: 17.2
Hardware: All All
: medium normal
Assignee: mesa-dev
QA Contact: Intel 3D Bugs Mailing List
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-03-22 11:16 UTC by Olivier Lauffenburger
Modified: 2019-03-22 19:21 UTC (History)
2 users (show)

See Also:
i915 platform:
i915 features:


Attachments

Description Olivier Lauffenburger 2017-03-22 11:16:35 UTC
I have the following GLSL 1.30 vertex and pixel shaders:

* Vertex shader:

#version 130

flat out vec4 triangleColor;

invariant gl_Position;

void main()
{
	gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
	gl_ClipVertex = gl_ModelViewMatrix * gl_Vertex;
    
	triangleColor = vec4(1.0, 1.0, 0.0, 1.0);
}

* Fragment shader:

#version 130

precision highp float;

flat in vec4 triangleColor;

void main()
{
	gl_FragColor = gl_Color * triangleColor;
}

Compilation is OK but linking fails with error:

error: declarations for uniform `gl_ModelViewProjectionMatrix' have mismatching invariant qualifiers

Slightly different vertex shaders can produce the error:

error: declarations for shader input `gl_Vertex' have mismatching invariant qualifiers

There is no linking error anymore when I remove the "invariant gl_Position;" declaration.

Given that gl_Vertex and gl_ModelViewProjectionMatrix are not output variables for vertex shaders, I suppose that this behavior is not expected.

This error occurs with Mesa 17.0.2.
Comment 1 Daniel Gibson 2017-10-28 23:01:58 UTC
I ran into the same bug, on Ubuntu 17.04 with both Mesa 17.0.7-0ubuntu0.17.04.1 and 17.2.2+git20171019+17.2.23c08dab-0ubuntu0ricotz~17.04.1 (from the xorg-edgers ppa).
I have observed this bug both with Intel (Iris Pro 5200) and AMD (Radeon R7 370) GPUs.

It doesn't only happen with deprecated variables, but also when using a OpenGL core (3.2) context and corresponding shaders, by adding "invariant gl_Position;" to a vertex shader (doesn't seem to affect all vertex shaders, though).

It can be reproduced with this branch of Yamagi Quake2: https://github.com/DanielGibson/yquake2/tree/mesa-100316 (start with ./quake2 +set vid_renderer gl3)

The corresponding source is: https://github.com/DanielGibson/yquake2/blob/mesa-100316/src/client/refresh/gl3/gl3_shaders.c#L328-L329
(https://github.com/DanielGibson/yquake2/blob/mesa-100316/src/client/refresh/gl3/gl3_shaders.c#L261-L288 is also part of the shader)

When adding "invariant gl_Position;" into my simpler vertexSrc2D shader (https://github.com/DanielGibson/yquake2/blob/mesa-100316/src/client/refresh/gl3/gl3_shaders.c#L166), it does not create an error there.

As Olivier wrote, compiling the shader gives no errors, but linking the vertex- and fragment-shaders into a program fails.
The error message doesn't even mention gl_Position directly, but some other variable (in my case "error: declarations for uniform `transModel' have mismatching invariant qualifiers") - but when commenting the "invariant gl_Position;" line out, it works.
Comment 2 Rémi Verschelde 2017-12-03 13:57:16 UTC
We're hitting the same issue with `invariant gl_Position;` (as described by Daniel in comment 1) in Godot Engine, at least for AMD hardware. Godot uses OpenGL 3.3 Core Profile: https://github.com/godotengine/godot/issues/13450
Comment 3 Danylo 2018-09-07 08:13:56 UTC
I've sent the patch for more general manifestation of the issue: https://patchwork.freedesktop.org/patch/247067/
Comment 4 Jordan Justen 2019-03-14 22:55:29 UTC
(In reply to Danylo from comment #3)
> I've sent the patch for more general manifestation of the issue:
> https://patchwork.freedesktop.org/patch/247067/

Just noting that Danylo submitted a merge request for this patch:

https://gitlab.freedesktop.org/mesa/mesa/merge_requests/84
Comment 5 Jordan Justen 2019-03-22 19:21:45 UTC
Fixed by Danylo in:

commit ea9bde151f1394ff82b73d028c2a3a747723e525

    glsl: Cross validate variable's invariance by explicit invariance only


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.