Vulkan:在多个命令缓冲区中排序图像内存屏障

Vulkan: ordering image memory barriers in multiple command buffers

对于资源转换,您需要知道资源的 'before' 和 'after' VkImageLayout(例如,在 VkImageMemoryBarrier 传递给 vkCmdPipelineBarrier ). Vulkan 不保证命令缓冲区的任何执行顺序,除非在 API 文档中明确说明(来自 answer). However, vkCmdPipelineBarrier 确实明确表示它在调用之前和之后在命令缓冲区中的命令之间创建依赖关系. 因此可以 'know' 在单个命令缓冲区中转换图像时在任何时候的布局。

但是,vkQueueSumbit 不强制命令缓冲区的执行顺序。如果有两个命令缓冲区,每个缓冲区都有 vkCmdPipelineBarrier 调用将同一图像转换为不同的布局,这两个操作之间是否存在任何依赖关系,或者在这种情况下是否需要显式同步?

第 2.2.1 节说:

Command buffer boundaries, both between primary command buffers of the same or different batches or submissions as well as between primary and secondary command buffers, do not introduce any implicit ordering constraints. In other words, submitting the set of command buffers (which can include executing secondary command buffers) between any semaphore or fence operations plays back the recorded commands as if they had all been recorded into a single primary command buffer, except that the current state is reset on each boundary.

在6.4节中,说明了用于同步的命令对包括:

First set: commands before a pipeline barrier.

Second set: commands after that pipeline barrier in the same queue (possibly limited to within the same subpass).

请注意,它说的是“在同一个队列中”,而不是“在同一个命令缓冲区中”。

这两个语句都清楚地表明管道障碍会影响队列的命令执行。执行依赖不限于单个命令缓冲区的命令。