This appendix describes ways to deterministically lay out buffers that are shared among multiple readers or writers. It has the following major sections:
• “Using Standard Layout Qualifiers”
When you group a number of variables in a uniform buffer or shader storage buffer, and you want to read or write their values outside a shader, you need to know the offset of each one. You can query these offsets, but for large collections of uniforms, this process requires many queries and is cumbersome. As an alternative, the standard layout qualifiers request that the GLSL shader compiler organize the variables according to a set of rules, where you can predictably compute the offset of any member in the block.
In order to qualify a block to use the std140
layout, you need to add a layout directive to its declaration as follows:
layout (std140) uniform UniformBlock {
// declared variables
};
This std140
qualification also works for shader storage buffer objects. The layout qualifier std430
is available only for shader storage buffer objects, as follows:
layout (std430) buffer BufferBlock {
// declared variables
};
To use either of the following std140
or std430
rules, the offset of a member in the block is the accumulated total of the alignment and sizes of the previous members in the block (those declared before the variable in question), bumped up to the alignment of the member. The starting offset of the first member is always zero.
The set of rules shown in Table H.1 are used by the GLSL compiler to place members in an std140
-qualified uniform block. This feature is available only with GLSL Version 1.40 or greater.
The set of rules shown in Table H.2 are used by the GLSL compiler to place members in an std430
-qualified uniform block. This feature is available only with GLSL Version 4.30 or greater.
18.117.142.128