glslang Error: Overlapping Binding Numbers in GLSL
When compiling GLSL shaders with glslang, assigning the
same binding location to multiple interface blocks within the same scope
results in a compilation failure. This article covers the specific
diagnostic error produced by glslang, explains why the
collision occurs under OpenGL and Vulkan specifications, provides a
reproducing code example, and details how to resolve the issue.
The Diagnostic Error
When two interface blocks (such as uniform blocks or
buffer storage blocks) share an identical
binding index within the same descriptor set,
glslang terminates compilation and raises the following
diagnostic error:
ERROR: <line_number>: 'binding' : overlapping binding numbers
In typical output from glslangValidator, the error
message specifies the exact source file or ID, line number, the layout
qualifier key ('binding'), and the explanation
'overlapping binding numbers'.
Why the Error Occurs
In both OpenGL (via GL_ARB_shading_language_420pack /
core GLSL 4.20+) and Vulkan SPIR-V generation, binding indices identify
the specific slot where resource descriptors connect to pipeline
stages.
The OpenGL and Vulkan GLSL specifications enforce that binding qualifiers must not alias:
- Under Vulkan (
-Vmode), each resource must have a unique(set, binding)tuple across the shader stage. If nosetqualifier is provided, resources default toset = 0. - Under OpenGL, binding points for uniform blocks or shader storage buffer objects (SSBOs) must be unique within the active stage.
If two interface blocks occupy the same set and
binding, the compiler cannot generate unambiguous
descriptor decorations in the resulting SPIR-V binary or GLSL AST,
triggering the diagnostic.
Reproducing Example
The following code illustrates a collision between two uniform interface blocks:
#version 450
layout(set = 0, binding = 0) uniform CameraData {
mat4 viewProjection;
};
// Error: binding 0 is already occupied in set 0
layout(set = 0, binding = 0) uniform ObjectData {
mat4 modelMatrix;
};
void main() {
// Shader logic
}Compiling this shader via
glslangValidator -V shader.vert generates:
ERROR: 0:8: 'binding' : overlapping binding numbers
ERROR: 1 compilation errors. No code generated.
How to Fix the Error
To fix the issue, assign each interface block a distinct binding index, or isolate the blocks into separate descriptor sets if targeting Vulkan:
Solution 1: Use Unique Binding Indices
Assign incremented or unique binding numbers within the same set:
layout(set = 0, binding = 0) uniform CameraData {
mat4 viewProjection;
};
layout(set = 0, binding = 1) uniform ObjectData {
mat4 modelMatrix;
};Solution 2: Assign Different Descriptor Sets (Vulkan)
If the resources represent different update frequencies (for example, per-frame data versus per-draw data), place them in separate sets:
layout(set = 0, binding = 0) uniform CameraData {
mat4 viewProjection;
};
layout(set = 1, binding = 0) uniform ObjectData {
mat4 modelMatrix;
};Using unique (set, binding) coordinates satisfies
glslang layout validation rules and allows successful
compilation to SPIR-V.