Why are atomic counters and images referred as uniforms when they are actually not uniform?

给你一囗甜甜゛ 提交于 2019-12-14 02:48:13

问题


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

Why are they called uniforms then?


回答1:


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.



来源:https://stackoverflow.com/questions/24052164/why-are-atomic-counters-and-images-referred-as-uniforms-when-they-are-actually-n

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!