vkAllocateCommandBuffers
函数原型
VkResult vkAllocateCommandBuffers(
VkDevice device,
const VkCommandBufferAllocateInfo* pAllocateInfo,
VkCommandBuffer* pCommandBuffers);
描述
从命令缓冲池中分配命令缓冲区。
参数
device
: 包含命令缓冲池的逻辑设备。pAllocateInfo
:VkCommandBufferAllocateInfo
结构体指针,描述了如何分配命令缓冲区。pCommandBuffers
:VkCommandBuffer
句柄数组的指针,每个数组成员表示生成的命令缓冲区对象。数组的长度为pAllocateInfo.commandBufferCount。
补充
VkCommandBufferAllocateInfo
结构体定义:
typedef struct VkCommandBufferAllocateInfo {
VkStructureType sType;
const void* pNext;
VkCommandPool commandPool;
VkCommandBufferLevel level;
uint32_t commandBufferCount;
} VkCommandBufferAllocateInfo;
sType
: VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFOcommandPool
: 分配命令缓冲区的命令池level
:VkCommandBufferLevel
代表的命令缓冲级别
typedef enum VkCommandBufferLevel {
VK_COMMAND_BUFFER_LEVEL_PRIMARY = 0, //主命令缓冲区
VK_COMMAND_BUFFER_LEVEL_SECONDARY = 1, //辅助命令缓冲区
} VkCommandBufferLevel;
commandBufferCount
: 想从命令池中分配的命令缓冲区的数量
返回值
VK_SUCCESS
: 成功分配命令缓冲区。- 其他 : 分配命令缓冲区失败。
代码示例
VkCommandBuffer create_command_buffer(VkDevice device, VkCommandPool commandPool)
{
VkCommandBufferAllocateInfo cmd_buf_allocate_info = {};
cmd_buf_allocate_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
cmd_buf_allocate_info.commandPool = commandPool;
cmd_buf_allocate_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
cmd_buf_allocate_info.commandBufferCount = 1;
VkCommandBuffer command_buffer;
VK_CHECK(vkAllocateCommandBuffers(device, &cmd_buf_allocate_info, &command_buffer));
return command_buffer;
}