Skip to content
This repository has been archived by the owner on Jun 12, 2024. It is now read-only.

MSL vertex layout reordered #21

Open
ltjax opened this issue Mar 25, 2022 · 1 comment
Open

MSL vertex layout reordered #21

ltjax opened this issue Mar 25, 2022 · 1 comment

Comments

@ltjax
Copy link

ltjax commented Mar 25, 2022

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
Copy link
Author

ltjax commented Mar 31, 2022

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?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant