Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Understanding UBO limitations in GLSL

Tags:

opengl

glsl

I'm about to implement some functionality which will use uniform buffer objects, and I'm trying to understand the limitations of UBOs before doing so. For example let's use these GL_MAX_* values and this simple fragment shader:

- GL_MAX_UNIFORM_BUFFER_BINDINGS -> 84
- GL_MAX_UNIFORM_BLOCK_SIZE -> 16384
- GL_MAX_VERTEX_UNIFORM_BLOCKS -> 14
#version 330 core
layout (location = 0) in vec3 aPos;

// UBO
layout (std140, binding = 0) uniform Matrices
{
    mat4 projection;
    mat4 view;
};

// Individual uniform variables
uniform mat4 model;
uniform vec3 camPos;

void main()
{
    gl_Position = projection * view * model * vec4(aPos, 1.0);
}  

Questions:

  1. Do individual uniform variables each consume one of the GL_MAX_VERTEX_UNIFORM_BLOCKS, or is there a default uniform block where these variables are stored (I'm guessing the later)?
  2. Is the GL_MAX_UNIFORM_BLOCK_SIZE the limit for all defined uniform blocks, or does each defined UBO have a max size of this parameter making in this example the max amount of uniform data allowed to be passed to the shader program 229,376 bytes (spread across multiple ubos)?
  3. If my assumption in question 1 is correct where individually defined uniform variables are contained in a default uniform buffer object:
    • A.) does this default buffer also adhere to the 16384 byte limit, meaning that the combined size of all individually defined uniform variables must not exceed 16384 bytes?
    • B.) does this default buffer consume a uniform block, leaving max available (before defining any other ubos) 13?
  4. Do individually defined uniform variables count toward the GL_MAX_UNIFORM_BUFFER_BINDINGS parameter, leaving 81 available binding locations in this example?
like image 593
whitwhoa Avatar asked Oct 17 '25 02:10

whitwhoa


1 Answers

Uniforms not declared in a block do not count against any uniform block limits. Nor do uniform block limits apply to them; non-block uniforms have their own, separate limitations.

like image 128
Nicol Bolas Avatar answered Oct 19 '25 00:10

Nicol Bolas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!