This chapter is an overview of the Location and Component Assignment chapter to help give examples, especially around some of the more extreme edge cases.
The simplest way to think about a Location is that it is made up of four 32-bit Component.
This means a vec4/float4/uvec4/etc will fit perfectly in a single Location.
Multiple variables can be packed into the same Location if their Componens do not overlap.
Locations are used for both the Input and Output to interface between shaders stages when possible.
For most people, this chapter is much deeper into edge cases compared who developers generally use the Location interface. For those developers, the simple advise to take away is:
-
Use less
Locationif possible. -
If you need many
Location, make sure you are under the limits.
The following attempt to have multiple variables alias the same component is not allowed.
layout(location=0) in vec2 in_a; // Components 0 and 1
layout(location=0, component=1) in float in_f; // Invalid: overlaps component 1The following modification would make it legal as multiple variable can share a Location, just not a Component
layout(location=0) in vec2 in_a;
// Change in_f to use component 2 instead
- layout(location=0, component=1) in float in_f;
+ layout(location=0, component=2) in float in_f;An element of an array will consume all every Component in a Location that it would consume as a non-arrayed value, with each subsequent element consuming the next available Location.
For example:
layout(location=0) in float a[3];As seen, using a scalar or something such as a vec2/float2 will leave many Component slots unused.
It is allowed to use any other Component in a Location that is being consumed by an array
|
Note
|
This behavior is guaranteed to work correctly with CTS 1.4.4.0 and higher compliant drivers. |
layout(location=0) in float a[3];
layout(location=2, component=2) in float b;float b is still valid because the array consumes only the first part of Location 2.
|
Note
|
Some shader stages, like geometry shaders, have an array around its interface matching, this array is disregarded for the above examples. |
A matrix is stored as an array of vector, this means something like
layout(location = 0) in mat3x2 a;consumes locations and components identically to
// N == 3
// Arrays is stride is per Location
layout(location = 0) in vec2 a[3];which in turn is stored identically to
// Each vector consumes only the first 2 components of each location
layout(location = 0) vec2 a0;
layout(location = 1) vec2 a1;
layout(location = 2) vec2 a2;This means the following is allowed:
layout(location = 0) in mat3x2 a;
layout(location = 1, component = 2) in float b;
layout(location = 2, component = 2) in float c;The b and c float are still valid here.
|
Note
|
Unlike arrays or independent vectors, matrices cannot be decorated with |