What do the double square brackets around "position" mean in Metal?

What does float4 position [[position]];

the next snippet do?

#include <metal_stdlib>
using namespace metal;

struct Vertex
{
    float4 position [[position]];
    float4 color;
};

vertex Vertex vertex_main(device Vertex *vertices [[buffer(0)]], uint vid [[vertex_id]])
{
    return vertices[vid];
}

      

I am confused by the part [[position]]

and similar usage in the function definition.

+5


source to share


3 answers


The metal shading language is documented at https://developer.apple.com/metal/metal-shading-language-specification.pdf



In particular, take a look at โ€œTable 9โ€ on page 68 of this document. There [[position]] is identified as an attribute attribute for the return type of the vertex function. I assume this means that when the vertex shader returns, the caller will use the values โ€‹โ€‹in that part of the structure to determine the vertex positions that the shader would like to change.

+4


source


I don't have enough reputation to answer your comment regarding the name of the brackets, but the brackets [[]] are attribute syntax taken from C ++ 11.



+1


source


Metal is based on C ++ and this is just the attribute syntax in C ++ 11. For details on the grammar, see

+1


source







All Articles