Suppose I’m rendering simple cubes at random positions.
Having 3 of them as the starting number of cubes, the application acquires a VkBuffer handle and binds it to a VkDeviceMemory in order to store the model matrices of all cubes consecutively in it, and which is later on accessed by the shader via the descriptor set. Let’s say the VkDeviceMemory has just enough memory for those 3 cubes.
What I want to do is, every time the user presses a key, a new cube should pop up somewhere. My question is, how should I go about resizing that memory? Could you provide an overview of the steps I should go through?
I realize I could use separate VkBuffer/VkDeviceMemory for each cube but I do not want to do that. Everywhere I read it is stated that’s sort of an anti-pattern. I could also allocate more and more buffers, and bind them all sequentially when drawing - but again, as stated somewhere, the number of buffers should not grow with the number of meshes.
I also realize that allocating many small chunks is a bad idea. I’m just using small numbers for the sake of argument, what really is making me scratch my head is the actual process of reallocation, and how to do it. I’m pretty sure I need to do some synchronization while the newly allocated buffer gets swapped with the previous one but… that’s how far I reach.
Could you provide an overview on how to handle it? Besides the uniform buffer, I am guessing the descriptor set is involved as well…
Thank you!