xo-imgui: refactor ex4a: create_command_buffers()

This commit is contained in:
Roland Conybeare 2025-11-11 10:28:16 -05:00
commit adb97b12c8
2 changed files with 25 additions and 17 deletions

View file

@ -322,4 +322,20 @@ MinimalImGuiVulkan::create_command_pool()
}
}
void
MinimalImGuiVulkan::create_command_buffers()
{
command_buffers_.resize(MAX_FRAMES_IN_FLIGHT);
VkCommandBufferAllocateInfo alloc_info{};
alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
alloc_info.commandPool = command_pool_;
alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
alloc_info.commandBufferCount = static_cast<uint32_t>(command_buffers_.size());
if (vkAllocateCommandBuffers(device_, &alloc_info, command_buffers_.data()) != VK_SUCCESS) {
throw std::runtime_error("Failed to allocate command buffers!");
}
}
/* end VulkanApp.cpp */

View file

@ -72,19 +72,10 @@ private:
*/
void create_command_pool();
void create_command_buffers() {
commandBuffers.resize(MAX_FRAMES_IN_FLIGHT);
VkCommandBufferAllocateInfo allocInfo{};
allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
allocInfo.commandPool = command_pool_;
allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
allocInfo.commandBufferCount = static_cast<uint32_t>(commandBuffers.size());
if (vkAllocateCommandBuffers(device_, &allocInfo, commandBuffers.data()) != VK_SUCCESS) {
throw std::runtime_error("Failed to allocate command buffers!");
}
}
/*
* populate @ref command_buffers_
*/
void create_command_buffers();
void create_sync_objects() {
imageAvailableSemaphores.resize(MAX_FRAMES_IN_FLIGHT);
@ -245,8 +236,8 @@ private:
vkResetFences(device_, 1, &inFlightFences[currentFrame]);
vkResetCommandBuffer(commandBuffers[currentFrame], 0);
recordCommandBuffer(commandBuffers[currentFrame], imageIndex);
vkResetCommandBuffer(command_buffers_[currentFrame], 0);
recordCommandBuffer(command_buffers_[currentFrame], imageIndex);
VkSubmitInfo submitInfo{};
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
@ -258,7 +249,7 @@ private:
submitInfo.pWaitDstStageMask = waitStages;
submitInfo.commandBufferCount = 1;
submitInfo.pCommandBuffers = &commandBuffers[currentFrame];
submitInfo.pCommandBuffers = &command_buffers_[currentFrame];
VkSemaphore signalSemaphores[] = {renderFinishedSemaphores[currentFrame]};
submitInfo.signalSemaphoreCount = 1;
@ -453,7 +444,8 @@ private:
VkCommandPool command_pool_;
std::vector<VkCommandBuffer> commandBuffers;
std::vector<VkCommandBuffer> command_buffers_;
std::vector<VkSemaphore> imageAvailableSemaphores;
std::vector<VkSemaphore> renderFinishedSemaphores;
std::vector<VkFence> inFlightFences;