在Vulkan附带的API-Samples中,似乎在调用vkWaitForFences
之后总是vkQueueSubmit
直接或通过execute_queue_command_buffer
(在util_init.hpp中)调用.调用vkWaitForFences
将阻止CPU执行,直到GPU完成之前的所有工作vkQueueSubmit
.这实际上不允许同时构造多个帧,这(理论上)显着地限制了性能.
是否需要这些调用,如果是这样,是否有另一种方法在构造新帧之前不要求GPU空闲?
我们在飞行中实现多个帧的方法是为您拥有的每个交换链帧缓冲区设置一个围栏。然后仍然使用vkWaitForFences
但等待((n+1)%num_fences)
围栏。
这里有示例代码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]);
}
Run Code Online (Sandbox Code Playgroud)