user1364743
user1364743

Reputation: 5661

How to know max buffer storage size (using OpenGL) on a specific device?

I did some researches on the topic responding to the question : How to know the maximum size (in bytes) a buffer (XXX Buffer Object) can contains depending the device (GPU) where the application is executed ?

For example about the vertices storage I use a Vertex Buffer Object (VBO) and the only way to know if I can allocate a certain size is to check if the function glGetError() returns the error GL_OUT_OF_MEMORY. So, if this exception occurs I will need to store the rest of my data within an other VBO (It's apparently the same thing concerning Index Buffer Objects (IBO)).

Now, to store my matrices I use Texture Buffer Object (TBO) and for my Materials and Lights parameters I use Uniform Buffer Objects (UBO).

About TBO, it exists a way to know the maximum size : the defined value GL_MAX_TEXTURE_BUFFER_SIZE​ (the texture (or here matrix data) can only access up to GL_MAX_TEXTURE_BUFFER_SIZE​ texels).

So, to know the max storage size in bytes, do I have to apply the equation ?

TBO(maxByteSize) = GL_MAX_TEXTURE_BUFFER_SIZE * sizeof(glm::vec4) (I believe a texel is defined on a 32 bytes array -> glm::vec4). Is that right ?

My device is the following:

GeForce GTX 780M (I have laptop)

Here's the values of the deferent macros respectively for TBO max size in texels, TBO max size converted in bytes and the sames for UBO and SSBO:

std::cout << "TBO(texels): " << GL_MAX_TEXTURE_BUFFER_SIZE << std::endl;
std::cout << "TBO(bytes): " << GL_MAX_TEXTURE_BUFFER_SIZE * sizeof(glm::vec4)<< std::endl;
std::cout << "UBO: " << GL_MAX_UNIFORM_BLOCK_SIZE << std::endl;
std::cout << "SSBO: " << GL_MAX_SHADER_STORAGE_BLOCK_SIZE << std::endl;

The output:

TBO(texels): 35 883 texels
TBO(bytes): 574 128 bytes (0.5 MByte)
UBO: 35 376 bytes (0.03 MByte)
SSBO: 37 086 bytes (0.03 MByte)

However I refered to the following website :

http://rastergrid.com/blog/2010/01/uniform-buffers-vs-texture-buffers/

The author says the max size of a UBO is AT LEAST 64 KBytes (65 536 Bytes) and for a TBO the value is AT LEAST 128 MBytes (134 217 728 Bytes!).

I also refered to the following website (concerning SSBO max storage size):

https://www.opengl.org/wiki/Shader_Storage_Buffer_Object

The author says the maximum size for a SSBO is AT LEAST 16 MBytes (16 777 216 Bytes).

So, What is wrong with the information I logged above ?

Is these macros don't contains the max size values in bytes ?

Upvotes: 5

Views: 6612

Answers (1)

albuscrow
albuscrow

Reputation: 61

You should do like this:

GLint size;
glGetIntegerv(GL_MAX_SHADER_STORAGE_BLOCK_SIZE, &size);
std::cout << "GL_MAX_SHADER_STORAGE_BLOCK_SIZE is " << size << " bytes." << endl;

Output in my computer is:

GL_MAX_SHADER_STORAGE_BLOCK_SIZE is 2147483647 bytes.

Upvotes: 6

Related Questions