GL_MAX_UNIFORM_BLOCK_SIZE meaning?

Hey. I’m finally thinking of making the move to uniform buffers, but I’m a bit confused by the spec, specifically the limitations imposed by GL_MAX_UNIFORM_BLOCK_SIZE.

According to the wiki this limitation applies to the uniform buffer size.

[quote]There is also a limitation on the available storage per uniform buffer. This is queried through GL_MAX_UNIFORM_BLOCK_SIZE. This is in basic machine units (ie: bytes).
[/quote]
That means that the biggest uniform buffer I can ever create is 16kbs, which would severely limit my ability to pack the uniforms for a large number of draw calls in the same buffer. Having model+view+projection matrices alone limits me to 85 draw calls without any other uniforms limits me to 85 draw calls per buffer. This is really annoying.

The spec however says this about GL_MAX_UNIFORM_BLOCK_SIZE:

[quote]Max size in basic machine units of a uniform block
[/quote]
That would mean that I could create a uniform buffer as big as I want as long as no uniform block is bigger than 16kbs, which I won’t ever get close to. And indeed, the Nvidia driver throws no error when I create an almost 2GB big uniform buffer, just kindly informing me that it was placed in video memory.

The wiki must be wrong here, right? I just want to rule out that this is an Nvidia quirk.

While I chilled out on working w/ modern GL while waiting for Vulkan to drop I don’t have firsthand experience, but dug up these links / info.

It seems GL_MAX_UNIFORM_BLOCK_SIZE is the limit of what can be bound and is addressable and you can have a much larger buffer allocated; see ‘TheChubu’ comment here:
http://www.gamedev.net/topic/673534-instancing-and-the-various-ways-to-supply-per-instance-data/

Also good discussion between vendors here:
http://www.yosoygames.com.ar/wp/2015/01/uniform-buffers-vs-texture-buffers-the-2015-edition/

Are you getting 16 kB for GL_MAX_UNIFORM_BLOCK_SIZE w/ NVidia card? Seems like the common NVidia value is 64kB.

Good luck!

I dunno why you’re persevering with trying to extract all the clever from the later versions of OpenGL when the prevailing wind tells me that we’ll all desert it for Vulkan long before even GL4.0+ becomes a viable target for the mass market…

Cas :slight_smile:

Thanks, that’s what I thought. I am getting 64kB on my Nvidia card, but some Intel cards only support 16kB or 32kB, and the spec only mandates 16kB, so that’s what I’ll have to roll with.

Vulkan won’t be supported by OpenGL 3 cards, so a fallback to catch the 15+% of people that only have a DX10 GPU is a good idea. Part of the goal with my code is to abstract away the graphics API used. Since everything will be handled with buffers in Vulkan, my abstractions will hopefully work pretty well for implementing a Vulkan back-end for our entire game. With automatic GLSL to SPIR-V conversion and an abstract Graphics class I should be able to switch between the two APIs without a single change noticeable for the user of my code.