Created a command buffer and command pool object for managing and tracking as well as wrapping vulkan functions to reduce boilerplate

This commit is contained in:
2025-07-07 22:56:53 +10:00
parent b687d74e32
commit c65d7fd4e3
2 changed files with 217 additions and 0 deletions

View File

@@ -0,0 +1,59 @@
#pragma once
#include "vulkan/basalt_pipeline.h"
namespace basalt
{
class CommandPool;
class CommandBuffer
{
public:
CommandBuffer(const CommandBuffer&) = delete;
CommandBuffer& operator =(const CommandBuffer&) = delete;
CommandBuffer(CommandBuffer&& other) noexcept;
CommandBuffer& operator =(CommandBuffer&& other) noexcept;
CommandBuffer(VkCommandBuffer buffer, CommandPool* pool);
~CommandBuffer();
// TODO:
// Break renderpass stuff out of start/end and into its own start/end function
void start(basalt::RenderPass& render_pass, VkFramebuffer framebuffer, VkRect2D render_area);
void bind_pipeline(basalt::Pipeline& pipeline, VkPipelineBindPoint bind);
void set_viewport(VkViewport port);
void set_scissor(VkRect2D scissor);
void stop (void);
void reset(void);
VkCommandBuffer vk = VK_NULL_HANDLE;
CommandPool* pool = nullptr;
bool should_free = true;
};
class CommandPool
{
public:
CommandPool(const CommandPool&) = delete;
CommandPool& operator =(const CommandPool&) = delete;
CommandPool(CommandPool&&) noexcept;
CommandPool& operator =(CommandPool&&) noexcept;
CommandPool(basalt::Device& device, u32 index);
~CommandPool();
// TODO:
//void get_buffers(VkCommandBufferLevel level, u32 num_buffers, CommandBuffer** buffers_out);
//basalt::darray<CommandBuffer> get_buffers(VkCommandBufferLevel level, u32 num_buffers);
CommandBuffer get_buffer(VkCommandBufferLevel level);
basalt::Device* device;
VkCommandPool vk;
u32 index;
u32 num_active_buffers : 31;
u32 should_free : 1;
};
}