glslcc
glslcc copied to clipboard
MSL vertex layout reordered
It seems that glslcc is reordering the vertex layout according to usage when transpiling to MSL:
#version 450
layout (location = 0) in vec2 Position;
layout (location = 1) in vec2 UV;
layout (location = 2) in vec4 Color;
/* uniforms and outputs here... */
void main()
{
Frag_UV = UV;
Frag_Color = Color;
gl_Position = Projection * vec4(Position.xy,0,1);
}
Gives me this input in MSL:
struct main0_in
{
float2 UV [[attribute(0)]];
float4 Color [[attribute(1)]];
float2 Position [[attribute(2)]];
};
The attribute order is the usage order in the code, not the original location. If I change the source's main() to:
void main()
{
gl_Position = Projection * vec4(Position.xy,0,1);
Frag_UV = UV;
Frag_Color = Color;
}
I get the 'correct' order.
I've been digging into the source code and saw comments indicating that this behaviour is intentional, and that the order in the reflection data can be used to create a suitable mapping. However, it will not be as obvious when vertex formats can be shared. Can you elaborate on why glslcc is doing this?