问题描述
我目前正在使用UBO在OpenGL 4.3中进行渲染,以将我所有的常量数据存储在GPU上. (类似材料描述,矩阵之类的东西).它可以工作,但是小尺寸的UBO(在我的实现中为64kB)迫使我多次切换缓冲区,从而减慢了渲染速度,我正在寻找一种类似的方式来存储一些MB.
i am currently doing so rendering in OpenGL 4.3 using UBOs to store all my constant data on the GPU. (Stuff like material descriptions, matrices, ...).It works however the small size of UBO (64kB on my implementation) forces me to switch buffers numerous times slowing rendering, i am looking for similar a way to store a few MB.
经过一番研究,我发现SSBO确实允许这样做,但也具有不需要的功能":它们可以从着色器写入,读取起来可能会较慢.
After a little research i saw that SSBO allow exactly that but also have unwanted 'features' : they can be written from the shader and might be slower to read.
是否有比SSBO更好的解决方案,可为着色器提供大块数据?我感觉好像丢失了一些东西,为什么在存在能够处理更多数据的更灵活的解决方案的情况下,为什么UBO应该限制在几kB?如果我要寻找着色器存储缓冲区,是否有办法确保着色器不会修改它们?
Is there a better solution than SSBO for supplying big chunks of data to shaders ? I feel like i am missing something, why should UBO be limited to a few kB while there exists a more flexible solution capable of handling much more data ? If shader storage buffers is what i am looking for, is there a way to ensure that they are not modified by the shaders ?
推荐答案
UBO和SSBO从根本上代表两个不同的硬件(通常).
UBOs and SSBOs fundamentally represent two different pieces of hardware (usually).
着色器是成组执行的,因此每个着色器都以锁定步骤执行.每组单独的着色器调用都可以访问一个内存块. UBO代表此内存.它相对较小(约千字节),但是访问速度非常快.执行渲染操作时,来自UBO的数据将复制到此着色器本地内存中.
Shaders are executed in groups, such that every shader executes in lock-step. Each group of individual shader invocations has access to a block of memory. This memory is what UBOs represent. It is relatively small (on the order of kilobytes), but accessing it is quite fast. When performing a rendering operation, data from UBOs are copied into this shader local memory.
SSBO代表全局内存.它们基本上是指针.这就是为什么它们通常没有存储限制的原因(最小GL要求是16 Mega 个字节,大多数实现返回的数字是GPU内存大小的顺序).
SSBOs represent global memory. They're basically pointers. That's why they generally have no storage limitations (the minimum GL requirement is 16 Megabytes, with most implementations returning a number on the order of the GPU's memory size).
访问它们的速度较慢,但这是因为它们存在的位置以及访问方式,而不是因为它们可能不是恒定的.全局内存是全局GPU内存,而不是局部常量内存.
They are slower to access, but this performance is because of where they exist and how they're accessed, not because they might not be constant. Global memory is global GPU memory rather than local constant memory.
如果着色器需要访问的数据量超出其着色器本地内存所能容纳的范围,则它需要使用全局内存.即使您有办法将SSBO声明为恒定",也无法解决此问题.
If a shader needs to access more data than can comfortably fit in its shader local memory, then it needs to use global memory. There's no getting around this, even if you had a way to declare an SSBO to be "constant".
:存在一些没有专用UBO存储的硬件(基于GCN的AMD硬件).该硬件将UBO实现为只读SSBO,因此所有UBO访问都是全局内存访问.该硬件本质上依赖于具有大容量的缓存来弥补性能差异,而UBO的使用模式往往使其可行.但是仍然有很多硬件具有专用于UBO存储的空间,因此,如果您的使用符合这些限制,则应使用它们.
: There is hardware that exists (GCN-based AMD hardware) which doesn't have dedicated UBO storage. This hardware implements UBOs as just a read-only SSBO, so all UBO accesses are global memory accesses. This hardware essentially relies on having large caches to make up for the performance difference, and the patterns of use for UBOs tend to make this viable. But there's still lots of hardware that has dedicated room for UBO storage, so if your use can fit within those limits, you should use them.
这篇关于SSBO是更大的UBO?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!