Annotations
Annotations appear immediately before the declaration they annotate. Multiple annotations can be stacked.
@location
Specifies the layout location for interface block fields.
@location(0) vec3 a_pos;
@location(1) vec2 a_uv;Emits:
layout(location = 0) vec3 a_pos;
layout(location = 1) vec2 a_uv;Applies to: Interface block fields (inputs/outputs)
@binding
Specifies the binding point for uniforms and buffers.
@binding(0) uniform mat4 u_mvp;
@binding(1) uniform sampler2D u_texture;Emits:
layout(binding = 0) uniform mat4 u_mvp;
layout(binding = 1) uniform sampler2D u_texture;Applies to: Uniform declarations, uniform blocks, buffer blocks
@std430
Specifies the std430 memory layout for uniform/buffer blocks. This is the packed layout typically used for SSBOs (Shader Storage Buffer Objects).
@std430 @binding(0) buffer InstanceBuffer {
mat4 models[];
} instances;Emits:
layout(std430, binding = 0) buffer InstanceBuffer {
mat4 models[];
} instances;Applies to: Uniform blocks, buffer blocks
@std140
Specifies the std140 memory layout for uniform blocks. This is the standard layout with strict alignment rules, typically used for UBOs (Uniform Buffer Objects).
@std140 @binding(0) uniform CameraData {
mat4 view;
mat4 projection;
} camera;Emits:
layout(std140, binding = 0) uniform CameraData {
mat4 view;
mat4 projection;
} camera;Applies to: Uniform blocks, buffer blocks
@set
Reserved for Vulkan descriptor sets. Not currently emitted.
@set(0) @binding(1) uniform sampler2D u_tex;Status: Reserved, not implemented
@push_constant
Reserved for Vulkan push constants. Not currently emitted.
@push_constant uniform PushConstants {
mat4 model;
} push;Status: Reserved, not implemented
Multiple Annotations
Annotations can be stacked in any order:
@std430
@binding(2)
buffer DataBuffer {
float values[];
} data;They are combined into a single layout(...) qualifier in the order they appear:
layout(std430, binding = 2) buffer DataBuffer {
float values[];
} data;Annotation Combination
Complete Annotation Flow
Annotation Order
The order of annotations matters when they are emitted to GLSL. By convention, memory layout qualifiers (@std430, @std140) should appear before binding qualifiers:
Recommended:
@std430 @binding(0)Also valid:
@binding(0) @std430Both emit valid GLSL, but the first form is more conventional.
Complete Example
@version 450;
@stage vertex {
// Input attributes with locations
in Attributes {
@location(0) vec3 a_pos;
@location(1) vec2 a_uv;
@location(2) vec3 a_normal;
} a;
// Uniform with binding
@binding(0) uniform mat4 u_mvp;
// Buffer with layout and binding
@std430 @binding(1) buffer InstanceBuffer {
mat4 models[];
} instances;
void main() {
gl_Position = u_mvp * instances.models[gl_InstanceID] * vec4(a.a_pos, 1.0);
}
}