Allocating a large chunk of memory for SSBO

Hi,

I want to create a SSBO buffer for my fragment shader to use, however, my application hangs and I’m not sure if I’m doing something wrong.

The SSBO size is 2562561024*4 = 256 MB (because I want to use it as a 3-dimentional array of vec4’s)

Note, that I only allocate the buffer once in the application (after loading the shader program) and use it as a static memory during the lifetime of the application.

I allocate it the following way:

glBufferStorage(GL_SHADER_STORAGE_BUFFER, 256*256*1024*2, NULL, 0); // flags is 0 for best optimization

Also, in my fragment shader I declared the SSBO the following way:

layout(std430, binding = 0) buffer object_map
{
    vec4 obj_map[256*256*1024];
};

I haven’t even used the buffer in the shader yet.

What I observe is the application runs until it needs to allocate the buffer, hangs and then crashes.

Also, a dumb question: Does OpenGL use the system RAM to allocate the buffers or there’s a special memory for that?
I’m a bit confused about the whole buffers storage.

P.S. I tried removing the 1024 multiplication, meaning my buffer is 256256*4 B in size it takes about 10~20s to allocate the buffer.
Is this normal and is there a way to optimize the buffer allocation?

[QUOTE=Zamfiry;1292168]Hi,

I want to create a SSBO buffer for my fragment shader to use, however, my application hangs and I’m not sure if I’m doing something wrong.

The SSBO size is 2562561024*4 = 256 MB (because I want to use it as a 3-dimentional array of vec4’s)

Note, that I only allocate the buffer once in the application (after loading the shader program) and use it as a static memory during the lifetime of the application.

I allocate it the following way:

glBufferStorage(GL_SHADER_STORAGE_BUFFER, 256*256*1024*2, NULL, 0); // flags is 0 for best optimization

Also, in my fragment shader I declared the SSBO the following way:

layout(std430, binding = 0) buffer object_map
{
    vec4 obj_map[256*256*1024];
};

I haven’t even used the buffer in the shader yet.

What I observe is the application runs until it needs to allocate the buffer, hangs and then crashes.

Also, a dumb question: Does OpenGL use the system RAM to allocate the buffers or there’s a special memory for that?
I’m a bit confused about the whole buffers storage.

P.S. I tried removing the 1024 multiplication, meaning my buffer is 256256*4 B in size it takes about 10~20s to allocate the buffer.
Is this normal and is there a way to optimize the buffer allocation?[/QUOTE]

Can’t really help you with the questions about the buffer object itself, but you said your buffer should have the size 2562561024*4 but in the code snippet there is a 2 in the end. Additionally, the size taken by glBufferStorage is in bytes (if I remember it correctly). A vec4 contains 4 floats. A float is 4 bytes. So the total size of a vec4 is 16 bytes. So instead of 2 or 4 you need to multiply it by 16. This mismatch might cause your program to freeze since you are generating an memory access violation. Can’t tell if there are other issues.

Greetings