Why are there two brackets [in C ++ vertex functions?

I am watching Apple's video presentation of Metal and MetalKit.

The sample code for the shaders has these double brackets, such as the arguments [[buffer(0)]] . Why are there two brackets? Does this mean anything or does it simply indicate the presence of the keyword "buffer"? There is no such construction in standard C ++, is there?

 vertex Vertex vertex_func(constant Vertex *vertices [[buffer(0)]], constant Uniforms &uniforms [[buffer(1)]], uint vid [[vertex_id]]) 

And what would be a good 1 or 2 week fun project as an introduction to the GP-GPU? Something manageable for a beginner with good math skills but no art skills.

+5
source share
2 answers

They are called attributes, and their syntax and behavior are defined in section 7.6.1 of the C ++ standard, attribute syntax and semantics. They look like this in grammar:

 attribute-specifier: [ [ attribute-list ] ] alignment-specifier 

The metal shading language defines a lot of attributes that allow you to associate various semantics with variables, struct / class members and function arguments (including variable table bindings, as in your question).

The metallic shade specification refers to the C ++ standard, so the C ++ standard is indeed a reference for reference:

The Metal programming language is based on the C ++ 14 specification (aka, ISO / IEC JTC1 / SC22 / WG21 N4431) with specific extensions and limitations. Please refer to the C ++ 14 Specification for a detailed description of the language grammar.

+5
source

With this [[x]], you declare an att that passes between the shaders and the CPU

I quote:

The syntax [[...]] is used to declare attributes such as resource locations, insert shaders, and built-in variables that are passed back and between shaders and the processor

+3
source

Source: https://habr.com/ru/post/1260786/


All Articles