Search code examples
openglmemoryoptimizationglsl

What is the fastest writable memory in the shaders?


Options to locally store information that will be discarded after the execution of a shading program include:

  • C like memory declarations: example, int array[100]; in global scope.
  • Textures
  • SSBOs

There may be others I am unaware off.

EDIT:

Each shader works on its own data, this is on the normal rendering pipeline.

Which of these would provide the fastest access taking into account that the data will be discarded once the program ends. And each fragment will be agnostic to every other fragment (they do not need to share data).


Solution

  • If the arrays you declare are not too big, local or global variables (C-like) in the shader will be the fastest. These variables are stored in registers or the memory that is nearest (so fastest) to the shader unit.

    The other options (textures and SSBOs) you mentioned all use slower memory. They are meant for data that can be visible to different shaders or shader invocations. If the execution data you work with is too big to fit in a regular variable, they can provide a fallback "scratch space". Expect much slower performance though.

    Also, since you asked this question, I'm very curious to know which kind of algorithm you are working on that requires so much temporary storage.