金属语言中“位置”两边的方括号是什么意思?

Anu*_*rag 5 syntax metal

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]]对函数定义中的部分和类似用法感到困惑。

Sco*_*son 4

金属着色语言的文档位于https://developer.apple.com/metal/metal-shading-language-specification.pdf

请特别查看该文档第 68 页的“表 9”。[[position]] 被标识为顶点函数返回类型的属性限定符。我认为这意味着当顶点着色器返回时,调用者将使用结构体该部分中的值来确定着色器想要修改的顶点的位置。

  • 我只能根据我在上面的文档中读到的内容以及我对着色语言的了解。[[ ]] 语法标识其所附加的实体的“属性”。有关变量或字段的元信息,对其在着色器中扮演的角色有意义。 (2认同)