Vulkan examples: vkQueueSubmit always follows vkWaitForFences?

In the API samples that come with Vulkan, it seems that after calling vkQueueSubmit there is always a call to vkWaitForFences , either directly or via execute_queue_command_buffer (in util_init.hpp). Calling vkWaitForFences block CPU execution until the GPU completes all work in the previous vkQueueSubmit . This actually does not allow you to simultaneously create multiple frames, which (theoretically) significantly limits performance.

Are these calls required, and if so, is there any other way not to require the GPU to be idle until a new frame is created?

+7
c ++ vulkan
source share
1 answer

The way we have reached several frames in flight is to have a fence for each swapchain frame buffer that you have. Then use vkWaitForFences , but wait for the ((n+1)%num_fences) fence.

Here is a sample code https://imgtec.com/tools/powervr-early-access-program/

 uint32_t current_buffer = num_swaps_ % swapchain_fences.size(); vkQueueSubmit(graphics_queue, 1, &submit_info, swapchain_fences[current_buffer]); // Wait for a queuesubmit to finish so we can continue rendering if we are n-2 frames behind if(num_swaps_ > swapchain_fences.size() - 1) { uint32_t fence_to_wait_for = (num_swaps_ + 1) % swapchain_fences.size(); vkWaitForFences(device, 1, &swapchain_fences[fence_to_wait_for], true, UINT64_MAX); vkResetFences(device, 1, &swapchain_fences[current_buffer]); } 
+4
source share

All Articles