5.3. 命令缓冲区的记录
可调用下列命令来开始记录命令缓冲区:
VkResult vkBeginCommandBuffer(
VkCommandBuffer commandBuffer,
const VkCommandBufferBeginInfo* pBeginInfo);
-
commandBuffer是需要被置为记录状态的命令缓冲区的handle。 -
pBeginInfois an instance of theVkCommandBufferBeginInfostructure, which defines additional information about how the command buffer begins recording.
VkCommandBufferBeginInfo 数据类型定义如下:
typedef struct VkCommandBufferBeginInfo {
VkStructureType sType;
const void* pNext;
VkCommandBufferUsageFlags flags;
const VkCommandBufferInheritanceInfo* pInheritanceInfo;
} VkCommandBufferBeginInfo;
-
sType是这个数据结构的类型。 -
pNext为NULL或者指向拓展特定结构的指针 -
flags是一个标志位,用来表示命令缓冲区被使用时的行为。 Bits which can be set include:typedef enum VkCommandBufferUsageFlagBits { VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT = 0x00000001, VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BIT = 0x00000002, VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT = 0x00000004, } VkCommandBufferUsageFlagBits;-
VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BITindicates that each recording of the command buffer will only be submitted once, and the command buffer will be reset and recorded again between each submission. -
VK_COMMAND_BUFFER_USAGE_RENDER_PASS_CONTINUE_BITindicates that a secondary command buffer is considered to be entirely inside a render pass. If this is a primary command buffer, then this bit is ignored. -
Setting
VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BITallows the command buffer to be resubmitted to a queue or recorded into a primary command buffer while it is pending execution.-
pInheritanceInfois a pointer to aVkCommandBufferInheritanceInfostructure, which is used ifcommandBufferis a secondary command buffer. If this is a primary command buffer, then this value is ignored.
-
-
若命令缓冲区是次级命令缓冲区,那么VkCommandBufferInheritanceInfo 数据结构定义了从主命令缓冲区继承而来的任何状态:
typedef struct VkCommandBufferInheritanceInfo {
VkStructureType sType;
const void* pNext;
VkRenderPass renderPass;
uint32_t subpass;
VkFramebuffer framebuffer;
VkBool32 occlusionQueryEnable;
VkQueryControlFlags queryFlags;
VkQueryPipelineStatisticFlags pipelineStatistics;
} VkCommandBufferInheritanceInfo;
-
sType是数据结构的类型。 -
pNext是NULL或者一个指向拓展特定的数据结构的指针。 -
renderPassis aVkRenderPassobject defining which render passes theVkCommandBufferwill be compatible with and can be executed within. If theVkCommandBufferwill not be executed within a render pass instance,renderPassis ignored. -
subpassis the index of the subpass within the render pass instance that theVkCommandBufferwill be executed within. If theVkCommandBufferwill not be executed within a render pass instance,subpassis ignored. -
framebufferoptionally refers to theVkFramebufferobject that theVkCommandBufferwill be rendering to if it is executed within a render pass instance. It can beVK_NULL_HANDLEif the framebuffer is not known, or if theVkCommandBufferwill not be executed within a render pass instance.注意指定次级命令缓冲区将被执行的命令缓冲区将导致该缓冲区执行时有更好的性能。
-
occlusionQueryEnableindicates whether the command buffer can be executed while an occlusion query is active in the primary command buffer. If this isVK_TRUE, then this command buffer can be executed whether the primary command buffer has an occlusion query active or not. If this isVK_FALSE, then the primary command buffer must not have an occlusion query active. -
queryFlagsindicates the query flags that can be used by an active occlusion query in the primary command buffer when this secondary command buffer is executed. If this value includes theVK_QUERY_CONTROL_PRECISE_BITbit, then the active query can return boolean results or actual sample counts. If this bit is not set, then the active query must not use theVK_QUERY_CONTROL_PRECISE_BITbit. -
pipelineStatisticsindicates the set of pipeline statistics that can be counted by an active query in the primary command buffer when this secondary command buffer is executed. If this value includes a given bit, then this command buffer can be executed whether the primary command buffer has a pipeline statistics query active that includes this bit or not. If this value excludes a given bit, then the active pipeline statistics query must not be from a query pool that counts that statistic.
主命令缓冲区被认为是从使用vkQueueSubmit提交命令开始、直到提交操作完成之前,都处于暂停执行的状态。
次命令缓冲区被认为从它的执行被记录到主缓冲区()到主缓冲区提交到队列完成的最终时刻,是出于暂停执行状态的。 如果,在主缓冲区完成了,次缓冲区被记录到另外一个主缓冲区上执行,第一个主缓冲区不能被再次提交,直到通过vkResetCommandBuffer 被重置,除非次命令缓冲区以VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT 标志被记录。
如果没有在次命令缓冲区上设置VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT,那么那个命令缓冲区就不能在 指定主命令缓冲区上使用多次。 还有,如果不带有VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT的次命令缓冲区被记录到一个带有 VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT标志位的主命令缓冲区上执行,那么这个主缓冲区不能被多次暂停执行。
|
注意
在一些Vulkan实现上,不使用 |
如果一个命令缓冲区处于可执行状态,且命令缓冲区带有VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT标志位 从缓存池中分配而来,那么vkBeginCommandBuffer将隐式的重置命令缓冲区,就如同不带有VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT参数调用了vkResetCommandBuffer。 然而它把命令缓冲区置为记录中的状态。
Once recording starts, an application records a sequence of commands (vkCmd*) to set state in the command buffer, draw, dispatch, and other commands.
可调用下来命令来结束记录命令缓冲区:
VkResult vkEndCommandBuffer(
VkCommandBuffer commandBuffer);
-
commandBufferis the command buffer to complete recording. The command buffer must have been in the recording state, and is moved to the executable state.
If there was an error during recording, the application will be notified by an unsuccessful return code returned by vkEndCommandBuffer. If the application wishes to further use the command buffer, the command buffer must be reset.
当命令缓冲区处于可执行状态时,它可以被提交到队列等待执行。
本文介绍了Vulkan API中命令缓冲区的记录过程,包括如何开始和结束命令缓冲区的记录,以及在记录过程中需要注意的一些关键事项。文章还详细解释了主命令缓冲区和次命令缓冲区的区别,并给出了有效使用的建议。
5431

被折叠的 条评论
为什么被折叠?



