GLSL:如何正确绑定数千个缓冲区? [英] GLSL : How to bind thousands of buffers properly?
问题描述
我想到了一个想法,要求将成千上万个缓冲区(原子计数器和Shader存储缓冲区)绑定到一个GLSL程序.我首先检查了这对openGL的限制是否有意义,并且似乎有两个原因:
I came up with an idea that requires to bind thousands of buffers (Atomic counters and Shader storage ones) to one GLSL program. I first checked if this would make any sense in the limitations of openGL and it seems possible for two reasons :
- 在我的笔记本电脑上GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS和GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS都在32k左右.因此,openGL被允许我一次通过绑定数千个缓冲区.
-
openGL 4.4附带了:
- On my laptop GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS and GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS both are around 32k. So openGL is enclined to let me bind thousands of buffers for one pass.
openGL 4.4 comes up with :
void BindBuffersBase(枚举目标,首先使用uint,sizei计数,使用const uint * buffers);
void BindBuffersBase(enum target, uint first, sizei count, const uint *buffers);
在C代码上,这似乎很容易,但是我对如何进行着色器一无所知.当绑定索引缓冲区时,我们应该使用:
On the C code it seems easy, but I have no clue on how to do my shaders. When binding indexed buffers, we are supposed to use :
layout (std430, binding = 0) buffer Objects
{
Object objects[];
};
绑定两个缓冲区时可以.但就我而言:
When binding a couple of buffers it is ok. But in my case :
- 我事先不知道将绑定多少个缓冲区
- 即使我知道,我是否应该为EACH缓冲区编写一些代码行并在布局绑定0、1、2,...,n中进行定义?
然后的问题是: 有没有办法使着色器不知道将要绑定到它的缓冲区的数量?假设它们全部包含相同类型的数据.
The question is then : Is there a way to make the shader unaware of the number of buffer that will be bound to it ? Assuming they are ALL containing the same type of data.
答案:
感谢安东·科尔曼,以获取快速,清晰的答案.
Thanks to Andon M. Coleman for the quick and clear answers.
首先,我以为我的硬件支持数千种绑定是错误的.新秀错误,我采用了定义的值,而不是运行时的值.
First of all, I was wrong to assume my hardware supported thousands of bindings. Rookie mistakes, I took the defined value instead of the runtime one.
在我的机器上:
- GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS = 96
- GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS = 8
- GL_MAX_UNIFORM_BUFFER_BINDINGS = 84
与我提出问题的依据相去甚远.
Which is far from what I based my question on.
但是,有一种方法可以在着色器中定义多个缓冲区:
However, there is a mean to define multiple buffers in the shader :
A
{
B b[];
}
layout (std430, binding = 0) buffer A a[32];
必须预先知道最大绑定数,但是这些缓冲区将占用0到31之间的绑定.
The amount of maximum bindings must be known in advance but those buffers will occupy the bindings from 0 to 31.
推荐答案
感谢安东·科尔曼(Andon M. Coleman)的快速明确的回答.
Thanks to Andon M. Coleman for the quick and clear answers.
首先,我以为我的硬件支持数千种绑定是错误的.新秀错误,我采用了定义的值,而不是运行时的值.
First of all, I was wrong to assume my hardware supported thousands of bindings. Rookie mistakes, I took the defined value instead of the runtime one.
在我的机器上:
- GL_MAX_SHADER_STORAGE_BUFFER_BINDINGS = 96
- GL_MAX_ATOMIC_COUNTER_BUFFER_BINDINGS = 8
- GL_MAX_UNIFORM_BUFFER_BINDINGS = 84
与我提出问题的依据相去甚远.
Which is far from what I based my question on.
但是,有一种方法可以在着色器中定义多个缓冲区:
However, there is a mean to define multiple buffers in the shader :
A
{
B b[];
}
layout (std430, binding = 0) buffer A a[32];
必须预先知道最大绑定数,但是这些缓冲区将占用0到31之间的绑定.
The amount of maximum bindings must be known in advance but those buffers will occupy the bindings from 0 to 31.
这篇关于GLSL:如何正确绑定数千个缓冲区?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!