openglshader-storage-buffer

OpenGL: How is MAX_SHADER_STORAGE_BLOCK_SIZE related to the real limit of SSBO size?


From skimming through the OpenGL documentation I kinda assumed that MAX_SHADER_STORAGE_BLOCK_SIZE is the actual limit on the size an SSBO might have. On my GPU this value is reported as 128 MB. However, it's working fine to create and use much larger buffers (Gigabytes), as long as they fit into video memory.

A few lines of code to clarify:
In my compute shader the buffer is accessed via

layout(std430, binding=2) buffer renderedDataRed
{
    uint counts_SSBO[];
};

On the CPU side I'm creating the buffer with

glGenBuffers(1, &drawBuffer);
glBindBuffer(GL_SHADER_STORAGE_BUFFER, drawBuffer);
glBufferData(GL_SHADER_STORAGE_BUFFER, 4 * pixelCount, nullptr, GL_DYNAMIC_COPY);
glClearBufferData(GL_SHADER_STORAGE_BUFFER,GL_R8,GL_RED,GL_UNSIGNED_INT,nullptr);
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, drawBuffer);

As said, it's working fine to have pixelCounts leading to buffer sizes far beyond MAX_SHADER_STORAGE_BLOCK_SIZE...

So, is MAX_SHADER_STORAGE_BLOCK_SIZE supposed to be the actual SSBO size limit and my driver (mesa radeonsi) is just reporting wrong numbers, or did I misunderstand the documentation? Can it be that arrays that aren't explicitly sized do not count towards MAX_SHADER_STORAGE_BLOCK_SIZE?


Solution

  • The maximum storage block size is the maximum size of a storage block: the thing you define in GLSL that you hook a buffer object to. Since your storage block us entirely composed of a variable sized array, it has no defined size.

    There is otherwise no limit on the size of the bound range for a buffer object that is bound for use as an SSBO. So as far as the OpenGL specification is concerned, this should work.

    That being said, I would not rely on it. The Vulkan equivalent explicitly limits the size used in buffer descriptors for storage buffers. So clearly, such limitations exist.