Files
OpenVulkano/openVulkanoCpp/Vulkan/CommandHelper.hpp
2025-01-06 16:28:27 +01:00

53 lines
1.2 KiB
C++

/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
*/
#pragma once
#include <vulkan/vulkan.hpp>
namespace OpenVulkano
{
namespace Vulkan
{
struct CommandHelper final
{
vk::Device device;
vk::CommandPool cmdPool;
vk::CommandBuffer cmdBuffer;
vk::CommandBufferLevel level;
CommandHelper() = default;
~CommandHelper() { if (cmdPool) CommandHelper::Close(); }
void Init(vk::Device device, uint32_t queueIndex, vk::CommandBufferLevel level = vk::CommandBufferLevel::eSecondary)
{
this->level = level;
this->device = device;
cmdPool = device.createCommandPool(vk::CommandPoolCreateInfo({}, queueIndex));
vk::CommandBufferAllocateInfo bufferAllocInfo = { cmdPool, level, 1 };
cmdBuffer = device.allocateCommandBuffers(bufferAllocInfo)[0];
}
void Reset() const
{
device.resetCommandPool(cmdPool, {});
}
vk::CommandBufferLevel GetLevel() const
{
return level;
}
void Close()
{
device.freeCommandBuffers(cmdPool, 1, &cmdBuffer);
device.destroyCommandPool(cmdPool);
cmdPool = nullptr;
}
};
}
}