Results 1 to 2 of 2

Thread: 1 uniform buffer - N meshes. How to reallocate?

  1. #1
    Newbie Newbie
    Join Date
    Nov 2018

    1 uniform buffer - N meshes. How to reallocate?

    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!

  2. #2
    Junior Member Newbie
    Join Date
    Oct 2018
    >> how should I go about resizing that memory

    you can only create new uniform buffer with new size and assign it to existing descriptor set, after that you need to update command buffer (VkCmdBeginCommandBuffer/VkCmdEndCommandBuffer)

    but with new size uniform buffer you need also update shader

    If you know inittially max objects that you need to draw you can use dynamic uniform buffer with size for max objects and update dynamic uniform buffer object related data

    But I think the best way is to create the uniq uniform buffer for each object

    Also you can in rendering/drawing loop update one uniform buffer for each object and call vkCmdDraw for each object in loop (loop(updateObjectData; vkCmdDraw ))

Similar Threads

  1. Why use a Uniform Buffer?
    By Septimra in forum OpenGL: Advanced Coding
    Replies: 11
    Last Post: 07-06-2015, 07:52 PM
  2. Corrupted data during mapped buffer! (Uniform Buffer Objects)
    By FrankBoltzmann in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 06-24-2014, 03:15 AM
  3. Replies: 1
    Last Post: 12-27-2013, 02:07 PM
  4. uniform buffer
    By selwakad in forum OpenGL: General
    Replies: 9
    Last Post: 03-04-2006, 10:15 AM
  5. how to use depth buffer to blend two meshes
    By Descartes in forum OpenGL: Advanced Coding
    Replies: 0
    Last Post: 05-04-2001, 07:44 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Proudly hosted by Digital Ocean