Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Allocating a large chunk of memory for SSBO

  1. #1
    Newbie Newbie
    Join Date
    Aug 2017
    Posts
    2

    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 256*256*1024*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:
    Code :
    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:
    Code :
    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 256*256*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?

  2. #2
    Intern Contributor
    Join Date
    Oct 2014
    Posts
    74
    Quote Originally Posted by Zamfiry View Post
    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 256*256*1024*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:
    Code :
    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:
    Code :
    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 256*256*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?
    Can't really help you with the questions about the buffer object itself, but you said your buffer should have the size 256*256*1024*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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •