Overv / VulkanTutorial

Tutorial for the Vulkan graphics and compute API
https://vulkan-tutorial.com
Creative Commons Attribution Share Alike 4.0 International
3.15k stars 515 forks source link

Question regarding buffer upload synchronization #301

Open Desperado17 opened 2 years ago

Desperado17 commented 2 years ago

Greetings, I have a question regarding one of the tutorials. I'd have used disqus but the registration doesn't work for me so this is my only remaining option, sorry.

In your tutorial you have a createVertexBuffer function which creates a staging buffer, maps, writes and unmaps it then copies it to the final gpu memory buffer:

https://github.com/Overv/VulkanTutorial/blob/12566173461bc940e0d610ae6663b2c3effd184a/code/30_multisampling.cpp#L1176

The copy uses endSingleTimeCommands which itself uses an vkQueueWaitIdle to ait on the graphics queue.

I have an OpenGL application that uploads small buffers to the gpu per frame. It is using merely glMapBuffer/glUnmapBuffer with unsynchronized access at a point where it knows the buffer is not used by the gpu.

Now when I port this to Vulkan I have a measurable wait time at this vkQueueWaitIdle. In a high load test where 500 frames are allowed, the OpenGL app produces almost 500 while the Vulkan version produces 300. Cause seems to be a delay in the Linux poll() function caused by the above mentioned vkQueueWaitIdle which can be up to 10 ms which is just too much (X64 Ubuntu, Nvidia driver).

My question is if a separate command buffer and vkQueueWaitIdle is really necessary if I know the buffer is not in use at the moment. Can't I just drop all command in the same command buffer the drawcall that uses this VBO goes to?

Regards