void CommandBufferManager::WaitForCommandBufferCompletion(u32 index) { // Ensure this command buffer has been submitted. WaitForWorkerThreadIdle(); // Wait for this command buffer to be completed. VkResult res = vkWaitForFences(g_vulkan_context->GetDevice(), 1, &m_frame_resources[index].fence, VK_TRUE, UINT64_MAX); if (res != VK_SUCCESS) LOG_VULKAN_ERROR(res, "vkWaitForFences failed: "); // Clean up any resources for command buffers between the last known completed buffer and this // now-completed command buffer. If we use >2 buffers, this may be more than one buffer. const u64 now_completed_counter = m_frame_resources[index].fence_counter; u32 cleanup_index = (m_current_frame + 1) % NUM_COMMAND_BUFFERS; while (cleanup_index != m_current_frame) { FrameResources& resources = m_frame_resources[cleanup_index]; if (resources.fence_counter > now_completed_counter) break; if (resources.fence_counter > m_completed_fence_counter) { for (auto& it : resources.cleanup_resources) it(); resources.cleanup_resources.clear(); } cleanup_index = (cleanup_index + 1) % NUM_COMMAND_BUFFERS; } m_completed_fence_counter = now_completed_counter; }
void CommandBufferManager::WaitForGPUIdle() { WaitForWorkerThreadIdle(); vkDeviceWaitIdle(g_vulkan_context->GetDevice()); }