|
|
|
@ -2,7 +2,7 @@ |
|
|
|
|
#include "application.hpp" |
|
|
|
|
#include "vulkan/instance.hpp" |
|
|
|
|
|
|
|
|
|
CommandPool::CommandPool(uint32_t queueFamilyIndex, uint32_t bufferCount) { |
|
|
|
|
CommandPool::CommandPool(uint32_t queueFamilyIndex, uint32_t bufferCount) : queueFamilyIndex(queueFamilyIndex) { |
|
|
|
|
VkCommandPoolCreateInfo poolInfo {}; |
|
|
|
|
poolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; |
|
|
|
|
poolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
|
|
|
@ -10,10 +10,10 @@ CommandPool::CommandPool(uint32_t queueFamilyIndex, uint32_t bufferCount) { |
|
|
|
|
|
|
|
|
|
vkCreateCommandPool(Instance::GetDevice(), &poolInfo, nullptr, &handle); |
|
|
|
|
|
|
|
|
|
allocateBuffers(bufferCount); |
|
|
|
|
allocateInitialBuffers(bufferCount); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void CommandPool::allocateBuffers(uint32_t count) { |
|
|
|
|
void CommandPool::allocateInitialBuffers(uint32_t count) { |
|
|
|
|
VkCommandBufferAllocateInfo allocateInfo {}; |
|
|
|
|
allocateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
|
|
|
|
allocateInfo.commandPool = handle; |
|
|
|
@ -28,3 +28,36 @@ CommandPool::~CommandPool() { |
|
|
|
|
vkFreeCommandBuffers(Instance::GetDevice(), handle, buffers.size(), buffers.data()); |
|
|
|
|
vkDestroyCommandPool(Instance::GetDevice(), handle, nullptr); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
VkCommandBuffer CommandPool::beginSingleTimeCommandBuffer() { |
|
|
|
|
VkCommandBufferAllocateInfo allocateInfo {}; |
|
|
|
|
allocateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; |
|
|
|
|
allocateInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; |
|
|
|
|
allocateInfo.commandPool = handle; |
|
|
|
|
allocateInfo.commandBufferCount = 1; |
|
|
|
|
|
|
|
|
|
VkCommandBuffer commandBuffer; |
|
|
|
|
vkAllocateCommandBuffers(Instance::GetDevice(), &allocateInfo, &commandBuffer); |
|
|
|
|
|
|
|
|
|
VkCommandBufferBeginInfo beginInfo {}; |
|
|
|
|
beginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO; |
|
|
|
|
beginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
|
|
|
|
|
|
|
|
|
vkBeginCommandBuffer(commandBuffer, &beginInfo); |
|
|
|
|
|
|
|
|
|
return commandBuffer; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void CommandPool::endSingleTimeCommandBuffer(VkCommandBuffer commandBuffer, VkQueue queue) { |
|
|
|
|
vkEndCommandBuffer(commandBuffer); |
|
|
|
|
|
|
|
|
|
VkSubmitInfo submitInfo {}; |
|
|
|
|
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; |
|
|
|
|
submitInfo.commandBufferCount = 1; |
|
|
|
|
submitInfo.pCommandBuffers = &commandBuffer; |
|
|
|
|
|
|
|
|
|
vkQueueSubmit(queue, 1, &submitInfo, VK_NULL_HANDLE); |
|
|
|
|
vkQueueWaitIdle(queue); |
|
|
|
|
|
|
|
|
|
vkFreeCommandBuffers(Instance::GetDevice(), handle, 1, &commandBuffer); |
|
|
|
|
} |
|
|
|
|