Why do the order of uniforms gets changed by the compiler?
- by Aybe
I have the following shader, everything works fine when setting the value of one of the matrices but I've discovered that getting a value back is incorrect for View and Projection, they are in reverse order.
#version 430
precision highp float;
layout (location = 0) uniform mat4 Model;
layout (location = 1) uniform mat4 View;
layout (location = 2) uniform mat4 Projection;
layout (location = 0) in vec3 in_position;
layout (location = 1) in vec4 in_color;
out vec4 out_color;
void main(void)
{
gl_Position = Projection * View * Model * vec4(in_position, 1.0);
out_color = in_color;
}
When querying their location they are effectively reversed, I did a small test by renaming View to Piew which puts it before Projection if sorted alphabetically and the order is correct.
Now if I do remove layout (location = ...) from the uniforms, the problem disappears !?
I am starting to think that this is a driver bug as explained in the wiki.
Do you know why the order of the uniforms is changed whenever the shader is compiled ?
(using an AMD HD7850)