SSBO as bigger UBO?

落花浮王杯 提交于 2020-01-20 04:56:06

问题


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.

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.

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 ?


回答1:


UBOs and SSBOs fundamentally represent two different pieces of hardware (usually)1.

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.

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

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.

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

1: 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.



来源:https://stackoverflow.com/questions/33589784/ssbo-as-bigger-ubo

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