initCommandPoolAndBuffer

Creates a command pool and then allocates out of it a number of command buffers equal to the number of swapchain images

This function creates a command pool to reserve memory for the command buffers are created to execute commands.

After the command pool is created, command buffers are allocated from it. A number of command buffers equal to the number of images in the swapchain are needed, assuming the command buffers are used for rendering.

Populate a command pool info struct with the queue family that will be used and the intended usage behaviour of command buffers that can be allocated out of it.

 	VkCommandPoolCreateInfo commandPoolInfo = {};
 	commandPoolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
 	commandPoolInfo.pNext = nullptr;
 	commandPoolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
 	commandPoolInfo.queueFamilyIndex = appManager.graphicsQueueFamilyIndex;
 

Create the actual command pool.

 	vkCreateCommandPool(appManager.device, &commandPoolInfo, nullptr, &appManager.commandPool)
 

Resize the vector to have a number of elements equal to the number of swapchain images.

 	appManager.commandBuffers.resize(appManager.swapChainImages.size());
 

Populate a command buffer info struct with a reference to the command pool from which the memory for the command buffer is taken.

Notice the "level" parameter which ensures these will be primary command buffers.

 	VkCommandBufferAllocateInfo commandBufferAllocateInfo = {};
 	commandBufferAllocateInfo.pNext = nullptr;
 	commandBufferAllocateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
 	commandBufferAllocateInfo.commandPool = appManager.commandPool;
 	commandBufferAllocateInfo.commandBufferCount = static_cast<uint32_t>(appManager.commandBuffers.size());
 	commandBufferAllocateInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
 

Allocate the command buffers from the command pool.

 	vkAllocateCommandBuffers(appManager.device, &commandBufferAllocateInfo, appManager.commandBuffers.data())