user1767754
user1767754

Reputation: 25094

Shader Storage Block vs Uniform Blocks

I've read now, that you can't write to uniform blocks, so shader storage block has an advantage over uniform blocks. Furthermore the size of a shader storage block (the upper limit) is much higher.

What i don't get is the atomic operations attribute of a shader Storage Block, when can this become handy? Is there a real-life example?

Furthermore When i would prefer one over the other?

Upvotes: 8

Views: 6737

Answers (1)

user755921
user755921

Reputation:

I think your question is ill-posed. It sounds like you are trying to figure out the difference between uniform buffers and shader storage buffers. Blocks are simply a way to organize your shader inputs and output.

As you noted, the biggest difference between uniform buffers and shader storage buffers is that you can write to shader storage buffers from your shader programs.

Asking why writing to a ssbo is handy is like asking why a variable is handy. Anytime you want to accumulate results or share data between render passes you can use the ssbo as "scratch memory".

In the old days (I believe) you would have had to do a render to texture if you wanted to share data, and that would have gone through the whole entire graphics pipeline with all the cost that that entails.

More about shader storage buffer objects here:

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

To really make sure you understand the difference, look up the various ways to supply shaders with data in chronological order:

  • Textures & Frame Buffer Objects
  • Uniforms
  • Uniform Buffer Objects
  • Texture Buffer Objects
  • Textures with Image Load/Store
  • Shader Storage Buffer Objects

This answer on SO has a nice overview of almost all of them:

Passing a list of values to fragment shader

Upvotes: 5

Related Questions