c++openglopengl-4uniformssbo

Can an SSBO binding point index be any value?


When you specify "location = x" in a shader to specify a shader storage or uniform buffer binding point, can that number be any value? Is this binding point independent of which shader is currently bound?

Would it be possible to bind all my ubos and ssbos before I bind my shaders, so long as the number of each type of buffer the shaders use is <= the max OpenGL allows to be used in a shader at once?

Could I bind 20 buffers and then specify which ones a shader is currently using by specifying the binding point index in the shader?


Solution

  • Every indexed buffer binding point (and pretty much every kind of binding in OpenGL) has an implementation-defined maximum number of available binding indices. This represents the maximum number of buffers that the hardware can use in that fashion during any one rendering operation.

    Furthermore, for buffer-backed interface blocks, there is an implementation-defined maximum number of blocks that can be used by the various shader stages. Note that these maxima are specified individually for each shader stage. The total that can be used in a rendering operation is generally (but not required to be) the sum of the number that can be used in each shader stage.

    For UBOs, the per-stage number is required to be at least 14, with the combined count required to be 14 * 6 (one for each shader stage). Some hardware supports 15, but no hardware supports more than that.

    For SSBOs, the per-stage number is only required to be 8, and even then, only fragment and compute shaders are required to have any such binding points at all. That is, an implementation can support SSBOs, but it isn't required to support them in every stage; just the fragment and compute stages.

    There's more variation in the number of SSBO binding points. But even there, it maxes out at 64 bindings.

    So unless the number of buffers is quite small, there's no way to just bind everything and let the shader pick. And that's good, because the cost of binding a buffer is typically less than the cost of changing shaders. It's better to change buffers than to change shaders.