Questions tagged [shader-storage-buffer]

A Shader Storage Buffer Object (SSBO) is an indexed Buffer Object available since OpenGL 4.3. It can be used to read/write arbitrarily structured data from shaders.

SSBOs work similar to Uniform Buffer Objects but can be much larger, like Buffer Textures but with the benefit of being defined with an arbitrary structure:

struct StructureName {
    vec4 position;
    float length;
    int count;
};

layout(std430, binding=0) buffer BlockName {
   StructureName variableName;
   int indices[]; 
};

As seen in the above example they allow for a trailing array member that expands to the remaining size of the bound buffer. The number of elements in the array can be retrieved via the indices.length(). The type of the array elements can also be a struct.

In compare to Uniform Buffer Objects, Shader Storage Buffer Objects are writable.

33 questions
7
votes
1 answer

glGetBufferSubData and glMapBufferRange for GL_SHADER_STORAGE_BUFFER very slow on NVIDIA GTX960M

I've been having some issues with transfering a GPU buffer into CPU for performing sorting operations. The buffer is a GL_SHADER_STORAGE_BUFFER composed of 300.000 float values. The transfer operation with glGetBufferSubData is taking around 10ms,…
jpaguerre
  • 1,130
  • 1
  • 13
  • 20
6
votes
0 answers

OpenGL 4.5 - Shader storage buffer objects layout

I'm trying my hand at shader storage buffer objects (aka Buffer Blocks) and there are a couple of things I don't fully grasp. What I'm trying to do is to store the (simplified) data of an indeterminate number of lights n in them, so my shader can…
Carlos Romero
  • 698
  • 8
  • 18
5
votes
0 answers

GLSL: Passing variable length buffer array to function

I am interested in passing a variable length array (attached SSBO) to a function, i.e.: layout(std430) buffer ssbo { type buffer[]; }; void func(buffer) { buffer[...] } func(buffer); EDIT: The extension spec clearly states that this is…
unexpectedvalue
  • 6,079
  • 3
  • 38
  • 62
4
votes
1 answer

Is it legal to reuse Bindings for several Shader Storage Blocks

Suppose that I have one shader storage buffer and want to have several views into it, e.g. like this: layout(std430,binding=0) buffer FloatView { float floats[]; }; layout(std430,binding=0) buffer IntView { int ints[]; }; Is this legal…
3
votes
1 answer

Dynamic-length arrays as Shader Storage Buffer Objects

Let's say I have a dynamic number of "balls" which I want to access in my OpenGL shaders. In C++ the data might be like this: struct Ball { glm::vec3 position; glm:vec3 colour; float size; }; std::vector all_balls; If I want to…
spraff
  • 32,570
  • 22
  • 121
  • 229
3
votes
1 answer

How do I query the alignment/stride for an SSBO struct?

I'm not sure which structure layout is most suited for my application: shared, packed,std140, std430. I'm not asking for an explanation of each, that information is easy to find, it's just hard to figure out the impact each will have on vendor…
Mr. Smith
  • 4,288
  • 7
  • 40
  • 82
3
votes
1 answer

Make a shader storage buffer in different shader programs accessible

What layout and binding do i have to do to make a (working) shader storage buffer readable in a second shader program? I set up and populated a SSBO which i bound successfully and used in a geometry shader. That shader reads and writes to that SSBO…
prox
  • 31
  • 5
3
votes
1 answer

How to acquire the sampler2D type from a Shader Storage Buffer Object inside a shader?

I am trying to get a variable of type sampler2D into my shaders without using an uniform variable. Instead, I want to hand it over using a Shader Storage Buffer Object (SSBO). What type of variable must be declared in the structure to hand over? How…
dagute
  • 93
  • 8
3
votes
1 answer

Getting data back from compute shader

I'm fairly new to opengl and I found myself in situation where I need to get data from compute shader but as I miss some critical knowledge I can't get it to work. So I came here, so that maybe you can give me some hints. Say I have a compute shader…
2
votes
2 answers

The intersection shader reads zeroes out of an SSBO

My intersection shader always reads just zeroes from the SSBO I have. I tried using debugPrintEXT, but it wouldn't print out from within the intersection shader. However, when I try to output any value via the ray payload as the hit colour, all I…
VP.
  • 15,509
  • 17
  • 91
  • 161
2
votes
1 answer

Can I make a GLSL struct have std140 layout?

I just tried to do this C++ struct PointLight { glm::vec4 position; glm::vec4 colour; }; std::vector lights_array; GLSL 320 ES: layout (std140) struct PointLight { vec4 position; vec4 colour; }; layout (std140) buffer…
spraff
  • 32,570
  • 22
  • 121
  • 229
2
votes
1 answer

OpenGL 4.5 - Shader storage: write in vertex shader, read in fragment shader

Both my fragment and vertex shaders contain the following two guys: struct Light { mat4 view; mat4 proj; vec4 fragPos; }; layout (std430, binding = 0) buffer Lights { Light lights[]; }; My problem is that that last field, fragPos, is…
1
vote
1 answer

Async SSBO Readback

When I call GetBufferSubData with my Shader Storage Buffer Object there is typically a 4ms delay. Is it possible for my application to do work during that time? // start GetBufferSubData // do client/app/CPU work // (wait if needed) // read results…
1
vote
0 answers

Is there an efficient way to append values in an SSB in a compute shader with GLSL?

I have an OpenGL compute shader that generates an undefined number of vertices and stores them in a shader storage buffer (SSB). The SSB capacity is big enough so that the compute shader never generates a number of vertices that exceeds its…
Krafpy
  • 336
  • 3
  • 8
1
vote
1 answer

Do I need a memory barrier between initializing an SSBO storage and filling it?

I've got code that looks like this: uint ssboId; glGenBuffers(1, &ssboId); glBindBuffer(GL_SHADER_STORAGE_BUFFER, ssboId); //initialize glBufferData(GL_SHADER_STORAGE_BUFFER, size, 0, GL_STATIC_DRAW); // memory barrier here? //…
Mr. Smith
  • 4,288
  • 7
  • 40
  • 82
1
2 3