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 to share