0

I'm learning the Vulkan API, and I came across a little "problem":

Currently my program is able to draw, using the Projection-View-Model matrix transformation, a cube at the axis origin:

I'm using 3 images/imageViews/framebuffers, so for each transformation matrix I have a vector of size 3 that holds them, and everything work perfectly (no errors from the validation layers etc)... the problem is:

I now want to draw another object near my cube, so I thought I just had to update the model matrix twice every frame, the first time to position the cube, the second time for the other object, but this cannot work because the cube isn't drawn immediately when registering the command buffer, but when submitting it, so in the end the command buffer would simply use the second update of the model matrix for both the cube and the other object:

How to handle this situation?

Thanks.

ShockCoding
  • 216
  • 2
  • 12
  • Possible duplicate of [How to repeatedly update a uniform data for number of objects inside a single Vulkan render pass and make the update synchronized?](https://stackoverflow.com/questions/54103399/how-to-repeatedly-update-a-uniform-data-for-number-of-objects-inside-a-single-vu) – Jesse Hall Jan 22 '19 at 21:34

1 Answers1

0

Make the uniform buffer bigger put the second matrix after the first and point the second draw to the correct offset in the uniform buffer.

You can use either separate descriptors or dynamic offsets.

ratchet freak
  • 47,288
  • 5
  • 68
  • 106
  • Nice! I doubled the size of the model matrix UBO (now is 128) and I'm able to update both the section (0-63, 64-127), but I don't know how to use the second block (I probably have to change something in the command buffer creation, but I don't know where to put the offset so it can use the 64-127 block for the second object..) – ShockCoding Jan 22 '19 at 14:33
  • Also, does my buffer need to be declared DYNAMIC? Currently, it is a plain UBO. – ShockCoding Jan 22 '19 at 14:53
  • In VkDescriptorBufferInfo there is a offset member you can or, or in bind descriptorsets you can set the pDynamicOffsets, for dynamic you must use a dynamic descriptor. – ratchet freak Jan 22 '19 at 15:12
  • I created the UBO with a 128 size, but I set the VkDescriptorBufferInfo offset to 0 and range to 64, is this right? I then called vkCmdBindDescriptorSets first with a dynamic offset of 0, drawn, then with 64, and drawn again. And it works! I get the two object correctly drawn on screen, but i dont know why. Shouldnt the dynamic offset invalidate the other UBOs I'm using? I mean, only the model UBO actually has data after the 63th byte, so why does the second object get drawn correctly? It should be reading the other UBO incorrectly... – ShockCoding Jan 22 '19 at 15:32
  • I think I just understood how this works: First, it counts how many dynamic UBOs are present, then in vkCmdBindDescriptorSets I indicate exactly how many there are, and pass to it that number of offsets, and it applies them to the choosen descriptor set: If, for example, I have 3 UBOs, and the first and the third are dynamic, then if I'll pass a {64, 64} dynamic offsets to vkCmdBindDescriptorSets, then it will simply ignore the second UBO, and apply those to the first and third... did i get it right? – ShockCoding Jan 22 '19 at 15:43