Vulkan样本:vkQueueSubmit后面跟着vkWaitForFences?

时间:2016-02-22 21:04:14

标签: c++ vulkan

在Vulkan附带的API-Samples中,在vkWaitForFences致电vkQueueSubmit之后,无论是直接还是通过execute_queue_command_buffer,我都会打电话给vkWaitForFences util_init.hpp)。对vkQueueSubmit的调用将阻止CPU执行,直到GPU完成前一个if(board[x][y]==0){ //set piece }else{ //handle already occupied case } 中的所有工作。这实际上不允许同时构造多个帧,这(理论上)显着地限制了性能。

是否需要这些调用,如果需要,还有另一种方法可以在构造新帧之前不要求GPU空闲吗?

1 个答案:

答案 0 :(得分:4)

我们在飞行中实现多个帧的方式是为每个交换链帧缓冲区设置一个栅栏。然后仍然使用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]);
}