Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

syntax

metal

What does float4 position [[position]]; do in the following snippet?

#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 [[position]] part and similar usage in the function definition especially.

like image 888
Anurag Avatar asked May 08 '17 18:05

Anurag


People also ask

What does two square brackets mean?

Answer and Explanation: Double brackets or [[]] in math refer to rounding off the value inside to its greatest integer less than or equal to the value. For example: [[7]]=7[[6.987]]=6[[3.225]]=3.

What do the brackets around an element mean?

If there's more than one complex ion in the compound, then brackets are needed. The reason is that you need to put a bracket around the complex ion to show how many of those whole complex ions there are in the compound. Examples: Mg(OH)2 Al2(SO4)3 (NH4)2SO4.

What do square brackets mean?

Square brackets, often just called brackets in American English, are a set of punctuation marks that are most often used to alter or add information to quoted material. Square brackets come in pairs as [ and ].

Why do we use double brackets?

The double brackets, [[ ]], were introduced in the Korn Shell as an enhancement that makes it easier to use in tests in shell scripts. We can think of it as a convenient alternative to single brackets. It's available in many shells like Bash and zsh.


1 Answers

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

In particular look at "Table 9" on page 68 of that document. There [[position]] is identified as an attribute qualifier for the return type of a Vertex Function. I assume that means that when your vertex shader returns the caller will use the values in that part of the struct to determine the positions of the vertices the shader would like to modify.

like image 75
Scott Thompson Avatar answered Nov 05 '22 12:11

Scott Thompson