Vulkan规范:第五章 5.2

来源:互联网 发布:淘宝返利源码 编辑:程序博客网 时间:2024/06/06 01:50

5.2. 命令缓冲区的分配和管理

可调用如下命令来分配命令缓冲区:

VkResult vkAllocateCommandBuffers(    VkDevice                                    device,    const VkCommandBufferAllocateInfo*          pAllocateInfo,    VkCommandBuffer*                            pCommandBuffers);
  • device 是拥有命令缓存池的逻辑设备。

  • pAllocateInfo 是一个指向 VkCommandBufferAllocateInfo 类型数据结构实例的指针,描述了分配行为的参数。

  • pCommandBuffers 是一个指针,执行一个元素类型为VkCommandBuffer handle的数组,以接收被返回的命令缓冲区对象。 数组的长度至少为pAllocateInfo 的成员 commandBufferCount 指定的大小。每一个分配的命令缓冲区都处于初始状态。

Valid Usage (Implicit)
  • device must be a valid VkDevice handle

  • pAllocateInfo must be a pointer to a valid VkCommandBufferAllocateInfo structure

  • pCommandBuffers must be a pointer to an array of pAllocateInfo::commandBufferCount VkCommandBuffer handles

Host Synchronization
  • Host access to pAllocateInfo::commandPool must be externally synchronized

Return Codes
Success
  • VK_SUCCESS

Failure
  • VK_ERROR_OUT_OF_HOST_MEMORY

  • VK_ERROR_OUT_OF_DEVICE_MEMORY

VkCommandBufferAllocateInfo 类型数据结构定义如下:

typedef struct VkCommandBufferAllocateInfo {    VkStructureType         sType;    const void*             pNext;    VkCommandPool           commandPool;    VkCommandBufferLevel    level;    uint32_t                commandBufferCount;} VkCommandBufferAllocateInfo;
  • sType 是这个数据结构的类型。

  • pNext 是 NULL 或者一个指向拓展特定的数据结构的指针。

  • commandPool 是分配出命令缓冲区的命令缓存池。

  • level 决定命令缓冲区是主缓冲区还是次缓冲区。 可选值包括:

    typedef enum VkCommandBufferLevel {    VK_COMMAND_BUFFER_LEVEL_PRIMARY = 0,    VK_COMMAND_BUFFER_LEVEL_SECONDARY = 1,} VkCommandBufferLevel;
  • commandBufferCount is the number of command buffers to allocate from the pool.

正确使用
  • commandBufferCount 必须: 大于 0

Valid Usage (Implicit)
  • sType must be VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO

  • pNext must be NULL

  • commandPool must be a valid VkCommandPool handle

  • level must be a valid VkCommandBufferLevel value

可调用下列命令啦重置命令缓冲区:

VkResult vkResetCommandBuffer(    VkCommandBuffer                             commandBuffer,    VkCommandBufferResetFlags                   flags);
  • commandBuffer 是需要被重置的命令缓冲区。命令缓冲区可以处于任何状态,并把它设置到初始状态。

  • flags 是一个bit标志位,控制重置操作。 可选的bit位包括:

    typedef enum VkCommandBufferResetFlagBits {    VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT = 0x00000001,} VkCommandBufferResetFlagBits;

    If flags includes VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT, then most or all memory resources currently owned by the command buffer should be returned to the parent command pool. If this flag is not set, then the command buffer may hold onto memory resources and reuse them when recording commands.

正确使用
  • commandBuffer must not currently be pending execution

  • commandBuffer must have been allocated from a pool that was created with the VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT

Valid Usage (Implicit)
  • commandBuffer must be a valid VkCommandBuffer handle

  • flags must be a valid combination of VkCommandBufferResetFlagBits values

Host Synchronization
  • Host access to commandBuffer must be externally synchronized

Return Codes
Success
  • VK_SUCCESS

Failure
  • VK_ERROR_OUT_OF_HOST_MEMORY

  • VK_ERROR_OUT_OF_DEVICE_MEMORY

可调用下列命令来释放命令缓冲区

void vkFreeCommandBuffers(    VkDevice                                    device,    VkCommandPool                               commandPool,    uint32_t                                    commandBufferCount,    const VkCommandBuffer*                      pCommandBuffers);
  • device 是拥有该命令缓存池的逻辑设备。

  • commandPool 是分配出命令缓冲区的命令缓存池。

  • commandBufferCount 是 pCommandBuffers 数组的长度。

  • pCommandBuffers 是需要被释放的命令缓冲区handle的数组。

正确使用
  • All elements of pCommandBuffers must not be pending execution

  • pCommandBuffers must be a pointer to an array of commandBufferCount VkCommandBuffer handles, each element of which must either be a valid handle or NULL

Valid Usage (Implicit)
  • device must be a valid VkDevice handle

  • commandPool must be a valid VkCommandPool handle

  • commandBufferCount must be greater than 0

  • commandPool must have been created, allocated, or retrieved from device

  • Each element of pCommandBuffers that is a valid handle must have been created, allocated, or retrieved from commandPool

Host Synchronization
  • Host access to commandPool must be externally synchronized

  • Host access to each member of pCommandBuffers must be externally synchronized

原创粉丝点击