float4 position [[position]];以下代码段做什么?
#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];
}
Run Code Online (Sandbox Code Playgroud)
我[[position]]对函数定义中的部分和类似用法感到困惑。
金属着色语言的文档位于https://developer.apple.com/metal/metal-shading-language-specification.pdf
请特别查看该文档第 68 页的“表 9”。[[position]] 被标识为顶点函数返回类型的属性限定符。我认为这意味着当顶点着色器返回时,调用者将使用结构体该部分中的值来确定着色器想要修改的顶点的位置。