Lets say I have multiple meshes I want to render with different materials. I know I can use push constants
for this example, but this question is more to understand how vkDescriptorset is suppose to work.
struct Material {
vec4 color;
vkDescriptorset descriptorSet;
VkDescriptorBufferInfo descriptorBufferInfo;
};
I only call vkUpdateDescriptorSets
for _descriptorBufferInfo
after the buffer for the data has been created. Everything works fine.
I tested another solution. Instead of having one vkDescriptorset
per material, I have only one for all of them. And inside the rendepass
I call vkUpdateDescriptorSets
for the each of the material VkDescriptorBufferInfo
.
vkDescriptorset globalDescriptorSet;
struct Material {
vec4 color;
VkDescriptorBufferInfo descriptorBufferInfo;
};
beginCommandBuffer
beginRenderPass
for (auto &mesh : meshes) {
...
writeDescriptorSets.dstSet = globalDescriptorSet;
writeDescriptorSets.pBufferInfo = &mesh.material.descriptorBufferInfo;
....
vkUpdateDescriptorSets(device, 1, &writeDescriptorSets, 0, nullptr);
renderMesh(mesh);
}
endRenderPass
endCommandBuffer
But when I do this, it does not work. The validation layer says you have to call beginCommandBuffer
before calling any of the commands, vkCmdBindDescriptorSets
, vkCmdBindPipeline
etc for second mesh I render.
So what is the problem here, can I not share an vkDescriptorset between multiple VkDescriptorBufferInfo, or can I not update it inside a renderPass?