当原子计数器和图像实际上不统一时,为什么将它们称为统一? [英] Why are atomic counters and images referred as uniforms when they are actually not uniform?

查看:47
本文介绍了当原子计数器和图像实际上不统一时,为什么将它们称为统一?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

原子计数器和图像可以在着色器中写入...因此它们不是恒定的(均匀的).

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

那他们为什么叫制服呢?

Why are they called uniforms then?

推荐答案

您是从错误的角度考虑uniform.

尽管制服是恒定的,但他们更重要的特征是它们在着色器的所有调用中提供... 制服变量存储.毕竟uniform只是一个存储限定符,与inout相同.

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.

  1. atomic_uint

    • 引用着色器存储缓冲区中的位置以用作原子计数器

  1. atomic_uint

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

  • 引用图像数据的绑定位置

实际上,您永远不会在着色器运行时修改分配给任何不透明数据类型的引用.因此,它们需要inuniform存储资格.而是将引用传递给修改实际引用资源的函数(可以是纹理资源或着色器存储缓冲区).

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).

您应该已经非常熟悉此范例,例如,sampler2D可能是您在GLSL中使用的第一个不透明数据类型.这样的制服不会存储您要采样的纹理,而是存储纹理/采样器状态的绑定位置.

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.

它们被称为制服",因为着色器调用无法更改atomic_uintimage2D存储的引用.当然,您可以使用适当的功能(例如 imageStore (...)atomicCounterIncrement (...))修改引用的数据,但不能重新分配引用本身.

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.

这篇关于当原子计数器和图像实际上不统一时,为什么将它们称为统一?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆