"position" 两边的双方括号在 Metal 语言中是什么意思?
What do double square brackets around "position" mean in the Metal language?
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];
}
我对 [[position]]
部分和函数定义中的类似用法感到困惑。
金属着色语言记录在 https://developer.apple.com/metal/metal-shading-language-specification.pdf
请特别查看该文档第 68 页的 "Table 9"。 [[position]] 被标识为 return 类型的顶点函数的属性限定符。我假设这意味着当你的顶点着色器 returns 调用者将使用结构的那部分中的值来确定着色器想要修改的顶点的位置。
我没有足够的声誉来回应您关于括号名称的评论,但 [[]] 括号是从 C++11 中获取的属性语法。
Metal 基于 C++,这只是 C++11 中属性的语法。有关语法的更多详细信息,请参阅 this。
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];
}
我对 [[position]]
部分和函数定义中的类似用法感到困惑。
金属着色语言记录在 https://developer.apple.com/metal/metal-shading-language-specification.pdf
请特别查看该文档第 68 页的 "Table 9"。 [[position]] 被标识为 return 类型的顶点函数的属性限定符。我假设这意味着当你的顶点着色器 returns 调用者将使用结构的那部分中的值来确定着色器想要修改的顶点的位置。
我没有足够的声誉来回应您关于括号名称的评论,但 [[]] 括号是从 C++11 中获取的属性语法。
Metal 基于 C++,这只是 C++11 中属性的语法。有关语法的更多详细信息,请参阅 this。