1

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.

Community
  • 1
  • 1
agrum
  • 407
  • 2
  • 16
  • 2
    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 May 15 '14 at 02:45
  • 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 May 15 '14 at 02:59
  • If I put the array subscript at the end of the block still, would it cover the binding 0 to n ? – agrum May 15 '14 at 03:03
  • It can, if you assign a name like `} foo [32];`... This array of 32 blocks will be assigned bindings in sequential order: **0** - **31** – Andon M. Coleman May 15 '14 at 03:14
  • Thank you sir. I'll write the answer now. – agrum May 15 '14 at 03:18
  • Curious -- what sort of thing were you going to use thousands of these buffers for? – Steven Lu May 15 '14 at 14:13
  • One pass SPH in unlimited 3D space. But now it's gonna be a multiple pass, one per cubic space. With the current limitations it may still work, I need 7 atomic and 34 storage buffer binded per pass. It's just that if there is only a few particles in a cube, it still gonna use one glDispatchCompute() call. – agrum May 15 '14 at 16:05
  • Or I actually just learned that atomic operations can be done on buffer and shared variables. So I don't even need atomic buffers. – agrum May 16 '14 at 01:22

1 Answers1

1

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.

agrum
  • 407
  • 2
  • 16