From 637ca5af7c587209e315db14444522c82003d8f5 Mon Sep 17 00:00:00 2001 From: Alexey Ozeritskiy Date: Sun, 4 Jun 2023 20:39:01 +0300 Subject: [PATCH] Work on command pool --- compute/vulkan/command_pool.cpp | 18 +++++++++++++++++- compute/vulkan/command_pool.h | 1 + compute/vulkan/compute.h | 2 ++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/compute/vulkan/command_pool.cpp b/compute/vulkan/command_pool.cpp index 9f8bcbc..d60f2fb 100644 --- a/compute/vulkan/command_pool.cpp +++ b/compute/vulkan/command_pool.cpp @@ -18,9 +18,25 @@ CommandPool::CommandPool(Device& dev, uint32_t family /* compute family*/) } } +CommandPool::~CommandPool() +{ + vkDestroyCommandPool(dev_.dev(), pool_, NULL); +} + VkCommandBuffer CommandPool::acquire() { - return {}; + VkCommandBuffer buffer; + VkCommandBufferAllocateInfo info = { + .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, + .commandPool = pool_, + .level = VK_COMMAND_BUFFER_LEVEL_PRIMARY, + .commandBufferCount = 1 + }; + + if (vkAllocateCommandBuffers(dev_.dev(), &info, &buffer) != VK_SUCCESS) { + throw std::runtime_error("Failed to allocate command buffers"); + } + return buffer; } void CommandPool::reset() diff --git a/compute/vulkan/command_pool.h b/compute/vulkan/command_pool.h index a5d648d..2937286 100644 --- a/compute/vulkan/command_pool.h +++ b/compute/vulkan/command_pool.h @@ -7,6 +7,7 @@ namespace NVulkan { class CommandPool { public: CommandPool(Device& dev, uint32_t family); + ~CommandPool(); VkCommandBuffer acquire(); void reset(); diff --git a/compute/vulkan/compute.h b/compute/vulkan/compute.h index 448dc55..08948fd 100644 --- a/compute/vulkan/compute.h +++ b/compute/vulkan/compute.h @@ -1,6 +1,7 @@ #pragma once #include "device.h" +#include "command_pool.h" namespace NVulkan { @@ -9,6 +10,7 @@ class Compute { Compute(); private: + CommandPool commandPool_; VkCommandBuffer commandBuffer_; VkSemaphore semaphore_; };