glslcc icon indicating copy to clipboard operation
glslcc copied to clipboard

MSL vertex layout reordered

Open ltjax opened this issue 2 years ago • 1 comments

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.

ltjax avatar Mar 25 '22 13:03 ltjax

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?

ltjax avatar Mar 31 '22 18:03 ltjax