#include "iwa/command.hpp" #include "iwa/device.hpp" namespace iwa { CommandPool::CommandPool(ObjectPtr 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 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); } // std::vector 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(count) // }); // } CommandBuffer::CommandBuffer(ObjectPtr 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