Say I have some struct MyUniform:
struct MyUniform {
/*...*/
};
and I have an array of 10 of them so on the host in C like:
MyUniform my_uniform_data[10] = /*...*/;
and I want to access all ten (as an array) from a shader.
In VkDescriptorSetLayoutBinding it has a field descriptorCount
:
descriptorCount is the number of descriptors contained in the binding, accessed in a shader as
an array.
So I assume at least one way to get this array to a shader is to set descriptorCount to 10, and then I would be able in GLSL to write:
layout(set = 2, binding = 4) uniform MyUniform {
/*...*/
} my_uniform_data[10];
Now when writing the VkDescriptorSet for this I would have a single buffer with 10 * sizeof(MyUniform)
bytes. So in a VkWriteDescriptorSet
I would also set descriptorCount
to 10, and then I would have to create an array of 10 VkDescriptorBufferInfo
:
VkDescriptorBufferInfo bi[10];
for (int i = 0; i < 10; i++) {
bi[i].buffer = my_buffer;
bi[i].offset = i*sizeof(MyUniform);
bi[i].range = sizeof(MyUniform);
}
This kind of arrangement clearly accomodates where each array element can come from a different buffer and offset.
Is there a way to arrange the descriptor layout and updating such that the entire array is written with a single descriptor?
Or is the only way to update a GLSL uniform array to use multiple descriptors in this fashion?
question from:
https://stackoverflow.com/questions/65949868/array-of-uniform-buffers-in-vulkan-glsl 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…