You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
70 lines
1.4 KiB
70 lines
1.4 KiB
// Copyright 2022 Simon Boyé
|
|
|
|
#include <vk/CommandBuffer.h>
|
|
#include <vk/Context.h>
|
|
|
|
#include <cassert>
|
|
|
|
|
|
namespace vk {
|
|
|
|
|
|
CommandBuffer::CommandBuffer() noexcept {
|
|
}
|
|
|
|
CommandBuffer::CommandBuffer(Context& context, VkCommandPool command_pool, VkCommandBufferLevel level)
|
|
: Wrapper(context)
|
|
, m_command_pool(command_pool)
|
|
{
|
|
assert(m_context);
|
|
assert(m_command_pool != VK_NULL_HANDLE);
|
|
|
|
VkCommandBufferAllocateInfo allocate_info {
|
|
.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO,
|
|
.commandPool = m_command_pool,
|
|
.level = level,
|
|
.commandBufferCount = 1,
|
|
};
|
|
if(vkAllocateCommandBuffers(
|
|
context.device(),
|
|
&allocate_info,
|
|
&m_command_buffer
|
|
) != VK_SUCCESS)
|
|
throw std::runtime_error("failed to allocate command pool");
|
|
}
|
|
|
|
CommandBuffer::CommandBuffer(CommandBuffer&& other) noexcept
|
|
{
|
|
swap(other);
|
|
}
|
|
|
|
CommandBuffer::~CommandBuffer() noexcept {
|
|
if(!is_null())
|
|
destroy();
|
|
}
|
|
|
|
|
|
CommandBuffer& CommandBuffer::operator=(CommandBuffer&& other) noexcept {
|
|
swap(other);
|
|
if(other)
|
|
other.destroy();
|
|
return *this;
|
|
}
|
|
|
|
|
|
void CommandBuffer::destroy() noexcept {
|
|
assert(!is_null());
|
|
assert(m_context);
|
|
|
|
vkFreeCommandBuffers(
|
|
m_context->device(),
|
|
m_command_pool,
|
|
1,
|
|
&m_command_buffer
|
|
);
|
|
|
|
m_command_buffer = nullptr;
|
|
}
|
|
|
|
|
|
}
|
|
|