1
votes

Atomic counters and images can be written to in shaders... so they are not constant(uniform).

Why are they called uniforms then?

1

1 Answers

4
votes

You are thinking of uniform from the wrong perspective.

While true that uniforms are constant, their more important characteristic is that they provide... uniform variable storage across all invocations of a shader. uniform is after all, nothing but a storage qualifier, the same as in or out.

Both of the data types you mention belong to a special class GLSL refers to as opaque:

  1. atomic_uint

    • References a location within a Shader Storage Buffer to serve as an atomic counter

  2. image2D

    • References a binding location for image data

You actually never modify the reference assigned to any opaque data type at shader run-time; hence they require in or uniform storage qualification. Instead, you pass the reference to a function that modifies the actual referenced resource (be it a texture or shader storage buffer).

You should be quite familiar with this paradigm already, sampler2D, for instance is probably the first opaque data type you ever used in GLSL. Such a uniform does not store the texture you are sampling, it stores the binding location for the texture/sampler state.


To answer your question:

They are "called uniforms" because shader invocations cannot change the reference that an atomic_uint or image2D stores. You can certainly modify the data referenced with the appropriate functions (e.g. imageStore (...) or atomicCounterIncrement (...)), but you cannot re-assign the reference itself.