5.4. 命令缓冲区的提交
可调用下列的命令把命令缓冲区提交到队列:
VkResult vkQueueSubmit(
VkQueue queue,
uint32_t submitCount,
const VkSubmitInfo* pSubmits,
VkFence fence);
-
queue
是命令缓冲区被提交到的队列。 -
submitCount
是pSubmits
数组元素的大小。 -
pSubmits
是一个指向 元素类型为VkSubmitInfo
的数组的指针,每一个元素都指定了一个命令缓冲区提交batch。 -
fence
是一个可选的handle,指向一个将被激发的fence。如果fence
不是VK_NULL_HANDLE
,它定义了一个 fence signal operation。
注意
提交可能是一个代价很高的操作,应用程序应该尝试批量的工作,尽量少的调用 |
vkQueueSubmit
是一个队列提交命令,每一批任务通过pSubmits
中由VkSubmitInfo
表示的一批任务定义。 pSubmits
中各批次的任务依出现的顺序执行,但是,完成的顺序可能是乱序的。
通过vkQueueSubmit
提交的栅栏和信号量操作和其他的命令提交有另外的顺序限制,依赖于队列中前后操作。 关于这些量外的限制的信息可以在“同步”一章的信号量 and 栅栏 小节中看到。
VkSubmitInfo
类型数据结构定义如下:
typedef struct VkSubmitInfo {
VkStructureType sType;
const void* pNext;
uint32_t waitSemaphoreCount;
const VkSemaphore* pWaitSemaphores;
const VkPipelineStageFlags* pWaitDstStageMask;
uint32_t commandBufferCount;
const VkCommandBuffer* pCommandBuffers;
uint32_t signalSemaphoreCount;
const VkSemaphore* pSignalSemaphores;
} VkSubmitInfo;
-
sType
是本数据结构的类型。 -
pNext
为NULL
或者指向拓展特定结构的指针。 -
waitSemaphoreCount
is the number of semaphores upon which to wait before executing the command buffers for the batch. -
pWaitSemaphores
is a pointer to an array of semaphores upon which to wait before the command buffers for this batch begin execution. If semaphores to wait on are provided, they define a semaphore wait operation. -
pWaitDstStageMask
is a pointer to an array of pipeline stages at which each corresponding semaphore wait will occur. -
commandBufferCount
is the number of command buffers to execute in the batch. -
pCommandBuffers
is a pointer to an array of command buffers to execute in the batch. -
signalSemaphoreCount
is the number of semaphores to be signaled once the commands specified inpCommandBuffers
have completed execution. -
pSignalSemaphores
is a pointer to an array of semaphores which will be signaled when the command buffers for this batch have completed execution. If semaphores to be signaled are provided, they define a semaphore signal operation.
命令缓冲区在pCommandBuffers
中出现的顺序决定了submission order, implicit ordering guarantees 也取决于这个顺序。 除了这些隐式的顺序保证 和其他的explicit synchronization primitives,这些命令缓冲区可能重叠或者乱序执行。
5.5. 队列发送进度(Queue Forward Progress)
应用程序必须保证在任何队列上没有剩下的操作时命令缓冲区提交将能够完成。 在vkQueueSubmit
调用之后,对等待一个信号量的每个排队等待者必须是一个比信号量更早的信号, 该信号量不会被一个不同的等待者消耗。
提交的命令缓冲区可以包含等待不会被队列中更早的命令所激发的事件的vkCmdWaitEvents
命令, 这些事件必须通过应用程序使用vkSetEvent
来激发,且等待这些事件的vkCmdWaitEvents
命令不能在一个render pass内。 Vulkan实现可能对命令缓冲区等待的时长有限制,以避免和设备的其他clients的工作进度有干扰。 如果没有这些限制条件下事件被激发了,结果是未定义的,可能包括设备丢失。