Does GL_SHADER_STORAGE_BUFFER locations collide with other shaders locations?

Viewed 152

I have multiple glsl files that use shader storage bufffer. If I bind buffer bases with other shader files, but they have same locations in storage buffer, they seem to affect each other. Does this mean that I have to unbind it somehow? When I chose other locations for each files, they didn't seem to have impact to the code.

for example

first.vs

layout(std430, binding = 0) buffer texture_coordinate_layout 
{
    vec2 texture_coordinates[];
};

second.vs

layout(std430, binding = 0) buffer vertices_layout
{
    vec2 vertices[];
};

when having two different shader programs, when I bind with each like so

first shader program

glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, m_vertex_ssbo);

second shader program

glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, m_texture_coordiante_ssbo);
1 Answers

Buffer bindings are part of context state, not the shader program. Index 0 in the context is index 0; it's not associated with any program directly.

The program only specifies which indexed binding point is used for that particular variable when the program gets used for rendering purposes. If you need to use a particular buffer object for a particular variable in a program, then before rendering, you need to ensure that the particular buffer is bound to the context at the index which the program will read. Always.

Related