I'm currently trying to render multiple cubes efficiently, so I'd like to know how to use this "Instanced Rendering" in Vulkan.
I currently know of only 2 ways of rendering a lot of (identical) objects:
1) Multiple DescriptorSets;
2) Single DescriptorSet with Dynamic Uniforms / dynamic offsets;
In the first case, a lot of memory is wasted because the cubes only need a different model matrix each, but still using an entire DescriptorSet each: also, because I'm registering a new command buffer each frame, every cube cost me 2 'Cmd' calls:
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, descriptorSet, 0, nullptr);
vkCmdDraw(commandBuffer, numberOfVertices, 1, 0, 0);
But, for a lot of cubes, this results in a not insignificant CPU load, and a waste of memory.
In the second case, I only need a single DescriptorSet, registering the model matrix as a Dynamic Uniform and filling it with all the model matrices; However, I still need (with little modifications) the same 2 'Cmd' calls for each cube:
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipelineLayout, 0, 1, descriptorSet, 1, index);
vkCmdDraw(commandBuffer, numberOfVertices, 1, 0, 0);
As before, for a lot of cubes, despite the huge memory save for using a unique DescriptorSet, the CPU load still bothers me.
So I heard about this "Instanced rendering", that should somehow tell with a single command to draw all the cubes, providing it a collection of model matrices (Probably still a Buffer).
How to do this, preventing my program to register thousands of 'Cmd' in a single command buffer, using a single call? Thanks.