1
votes

I came up with an idea that requires to bind thousands of buffers (Atomic counters and Shader storage ones) to one GLSL program. I first checked if this would make any sense in the limitations of openGL and it seems possible for two reasons :

  1. On my laptop GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS and GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS both are around 32k. So openGL is enclined to let me bind thousands of buffers for one pass.
  2. openGL 4.4 comes up with :

    void BindBuffersBase(enum target, uint first, sizei count, const uint *buffers);

On the C code it seems easy, but I have no clue on how to do my shaders. When binding indexed buffers, we are supposed to use :

layout (std430, binding = 0) buffer Objects
{
  Object objects[];
};

When binding a couple of buffers it is ok. But in my case :

  1. I don't know in advance how many buffers will be bound
  2. Even if I knew, am I supposed to write some lines of code for EACH buffer and define in the layout binding 0, 1, 2, ..., n ?

The question is then : Is there a way to make the shader unaware of the number of buffer that will be bound to it ? Assuming they are ALL containing the same type of data.

Answer :

Thanks to Andon M. Coleman for the quick and clear answers.

First of all, I was wrong to assume my hardware supported thousands of bindings. Rookie mistakes, I took the defined value instead of the runtime one.

On my machine :

  1. GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS = 96
  2. GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS = 8
  3. GL_MAX_UNIFORM_BUFFER_BINDINGS = 84

Which is far from what I based my question on.

However, there is a mean to define multiple buffers in the shader :

A
{
  B b[];
}
layout (std430, binding = 0) buffer A a[32];

The amount of maximum bindings must be known in advance but those buffers will occupy the bindings from 0 to 31.

1
You did actually query those values at run-time rather than use the value of the constant, right? Most newer extensions have constants in that range. Also you have your array subscript in the wrong place, it needs to come after the end of the block.Andon M. Coleman
Absolutely not, Good guess from you. I just saw a post where someone said his limit was 96 so I checked at run time to be sure. 8 for atomic and 96 for storage. Which kills right here right now the deal.agrum
If I put the array subscript at the end of the block still, would it cover the binding 0 to n ?agrum
It can, if you assign a name like } foo [32];... This array of 32 blocks will be assigned bindings in sequential order: 0 - 31Andon M. Coleman
Thank you sir. I'll write the answer now.agrum

1 Answers

1
votes

Thanks to Andon M. Coleman for the quick and clear answers.

First of all, I was wrong to assume my hardware supported thousands of bindings. Rookie mistakes, I took the defined value instead of the runtime one.

On my machine :

  1. GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS = 96
  2. GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS = 8
  3. GL_MAX_UNIFORM_BUFFER_BINDINGS = 84

Which is far from what I based my question on.

However, there is a mean to define multiple buffers in the shader :

A
{
  B b[];
}
layout (std430, binding = 0) buffer A a[32];

The amount of maximum bindings must be known in advance but those buffers will occupy the bindings from 0 to 31.