From d30b37bfbda61ce0057fb11f550f237245164a5b Mon Sep 17 00:00:00 2001 From: Grayson Riffe Date: Tue, 11 Feb 2025 19:45:47 -0600 Subject: [PATCH] Create command pool and allocate command buffer --- .../src/client/render/RenderEngine.cpp | 21 +++++++++++++++++++ NothinFancy/src/client/render/RenderEngine.h | 5 +++++ 2 files changed, 26 insertions(+) diff --git a/NothinFancy/src/client/render/RenderEngine.cpp b/NothinFancy/src/client/render/RenderEngine.cpp index eab5951..dfe7465 100644 --- a/NothinFancy/src/client/render/RenderEngine.cpp +++ b/NothinFancy/src/client/render/RenderEngine.cpp @@ -25,6 +25,8 @@ namespace nf::client::render { , m_swapchainFramebuffers() , m_pipelineLayoutOutput() , m_pipelineOutput() + , m_commandPool() + , m_commandBuffer() { NFLog("Initializing render engine"); m_window->setDisplay(m_display); @@ -36,6 +38,7 @@ namespace nf::client::render { createSwapchain(); createOutputRenderPass(); createOutputPipeline(); + createCommandBuffer(); m_window->show(); } @@ -377,7 +380,25 @@ namespace nf::client::render { } } + void RenderEngine::createCommandBuffer() { + VkCommandPoolCreateInfo commandPoolCI = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO }; + commandPoolCI.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; + commandPoolCI.queueFamilyIndex = m_queueFIGraphics; + + if (vkCreateCommandPool(m_device, &commandPoolCI, nullptr, &m_commandPool) != VK_SUCCESS) + NFError("Could not create command pool."); + + VkCommandBufferAllocateInfo commandBufferAI = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO }; + commandBufferAI.commandPool = m_commandPool; + commandBufferAI.commandBufferCount = 1; + + if (vkAllocateCommandBuffers(m_device, &commandBufferAI, &m_commandBuffer) != VK_SUCCESS) + NFError("Could not create command buffer."); + } + RenderEngine::~RenderEngine() { + vkDestroyCommandPool(m_device, m_commandPool, nullptr); + for (int i = 0; i < m_swapchainFramebuffers.size(); i++) vkDestroyFramebuffer(m_device, m_swapchainFramebuffers[i], nullptr); diff --git a/NothinFancy/src/client/render/RenderEngine.h b/NothinFancy/src/client/render/RenderEngine.h index 2cc6631..87c80fb 100644 --- a/NothinFancy/src/client/render/RenderEngine.h +++ b/NothinFancy/src/client/render/RenderEngine.h @@ -18,6 +18,7 @@ namespace nf::client::render { void createSwapchain(); void createOutputRenderPass(); void createOutputPipeline(); + void createCommandBuffer(); std::shared_ptr m_window; DisplayConfig m_display; @@ -41,5 +42,9 @@ namespace nf::client::render { // Pipelines VkPipelineLayout m_pipelineLayoutOutput; VkPipeline m_pipelineOutput; + + // Command buffers + VkCommandPool m_commandPool; + VkCommandBuffer m_commandBuffer; }; }