vkQueuePresentKHR 在等待信号量时是否会阻止后续命令的执行?

Does vkQueuePresentKHR prevent later commands from executing while it is waiting on the semaphore?

这是 this question, and it is also based on the code provided by the same Vulkan tutorial 的后续问题。

这是一个简化的例子:

// Vulkan handles defined and initialized elsewhere
VkDevice device;
VkQueue queue;
VkSempahore semaphore;
VkSwapchain swapchain;
VkCommandBuffer cmd_buffer;

// Renderer code
uint32_t image_index;   // image acquisition is omitted

VkPresentInfoKHR present_info{};
present_info.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
present_info.waitSemaphoreCount = 1;
present_info.pWaitSemaphores = &semaphore;
present_info.swapchainCount = 1;
present_info.pSwapchains = &swapchain;
present_info.pImageIndices = &image_index;

VkSubmitInfo submit_info{};
submit_info.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
// ... irrelevant code omitted
submit_info.pCommandBuffers = &cmd_buffer;

vkQueuePresentKHR(queue, &present_info);
vkQueueSubmit(queue, 1, &submit_info, VK_NULL_HANDLE);

在上面的示例中,cmd_buffer 中的命令是否也必须等到 semaphore 发出信号?


我问这个是因为 a comment below the tutorial 提到:

However, if the graphics and present queue do end up being the same, then the renderFinished semaphore guarantees proper execution ordering. This is because the vkQueuePresentKHR command waits on that semaphore and it must begin before later commands in the queue begin (due to implicit ordering) and that only happens after rendering from the previous frame finished.

In the above example, will the commands in cmd_buffer also have to wait until semaphore is signaled?

仅当您将信号量用作稍后提交的 waitSemaphore 时。

This is because the vkQueuePresentKHR command waits on that semaphore and it must begin before later commands in the queue begin (due to implicit ordering) and that only happens after rendering from the previous frame finished.

我不相信这是真的。

相对于队列中的其他命令,命令以隐式顺序开始,但这是在 stage-to-stage 基础上进行流水线处理的。另请注意,规范的措辞是“按顺序开始”而不是“按顺序完成”,这是一种规范手法。硬件可以完全自由地重叠和 out-of-order 执行流中顺序的单个命令,除非流包含阻止它这样做的同步原语。