66 lines
1.9 KiB
C++
66 lines
1.9 KiB
C++
|
|
#include "iwa/command.hpp"
|
|
|
|
#include "iwa/device.hpp"
|
|
|
|
namespace iwa
|
|
{
|
|
CommandPool::CommandPool(ObjectPtr<Device> owner, CommandPoolCreationArgs args) : super_t(std::move(owner))
|
|
{
|
|
mHandle = getOwner()->getVkHandle().createCommandPool(vk::CommandPoolCreateInfo{
|
|
.flags = args.flags,
|
|
.queueFamilyIndex = args.queueFamilyIndex
|
|
});
|
|
}
|
|
|
|
CommandPool::~CommandPool() noexcept
|
|
{
|
|
IWA_DELETE_DEVICE_OBJECT(getOwner(), mHandle, destroyCommandPool);
|
|
}
|
|
|
|
ObjectPtr<CommandBuffer> CommandPool::allocateCommandBuffer(const CommandBufferAllocateArgs& args)
|
|
{
|
|
vk::CommandBuffer commandBuffer;
|
|
const vk::CommandBufferAllocateInfo allocateInfo
|
|
{
|
|
.commandPool = mHandle,
|
|
.level = args.level,
|
|
.commandBufferCount = 1
|
|
};
|
|
vk::resultCheck(getOwner()->getVkHandle().allocateCommandBuffers(&allocateInfo, &commandBuffer),
|
|
"vkAllocateCommandBuffers failed");
|
|
return createChild<CommandBuffer>(commandBuffer);
|
|
}
|
|
|
|
// std::vector<vk::CommandBuffer> CommandPool::allocateCommandBuffers(
|
|
// std::size_t count,
|
|
// const CommandBufferAllocateArgs& args) const noexcept
|
|
// {
|
|
// return getOwner()->getVkHandle().allocateCommandBuffers(vk::CommandBufferAllocateInfo{
|
|
// .commandPool = mHandle,
|
|
// .level = args.level,
|
|
// .commandBufferCount = static_cast<std::uint32_t>(count)
|
|
// });
|
|
// }
|
|
|
|
CommandBuffer::CommandBuffer(ObjectPtr<iwa::CommandPool> owner, vk::CommandBuffer handle)
|
|
: super_t(std::move(owner)), MixinVulkanObject(handle)
|
|
{
|
|
|
|
}
|
|
|
|
CommandBuffer::~CommandBuffer() noexcept
|
|
{
|
|
if (mHandle)
|
|
{
|
|
getOwner()->getOwner()->queueDelete([
|
|
poolHandle = getOwner()->getVkHandle(),
|
|
handle = mHandle,
|
|
device = getOwner()->getOwner()->getVkHandle()]
|
|
{
|
|
device.freeCommandBuffers(poolHandle, handle);
|
|
});
|
|
}
|
|
}
|
|
} // namespace iwa
|