Class CommandBuffer

Class Documentation

class inexor::vulkan_renderer::wrapper::CommandBuffer

RAII wrapper class for VkCommandBuffer.


Make trivially copyable (this class doesn’t really “own” the command buffer, more just an OOP wrapper).

Public Functions

CommandBuffer(const wrapper::Device &device, VkCommandPool command_pool, std::string name)

Default constructor.

  • device – The const reference to the device RAII wrapper class.

  • command_pool – The command pool from which the command buffer will be allocated.

  • name – The internal debug marker name of the command buffer. This must not be an empty string.

CommandBuffer(const CommandBuffer&) = delete
CommandBuffer(CommandBuffer&&) noexcept
~CommandBuffer() = default
CommandBuffer &operator=(const CommandBuffer&) = delete
CommandBuffer &operator=(CommandBuffer&&) = delete
void begin(VkCommandBufferUsageFlags flags = 0) const

Call vkBeginCommandBuffer.


Sometimes it’s useful to pass VK_COMMAND_BUFFER_USAGE_SIMULTANEOUS_USE_BIT to specify that a command buffer can be resubmitted to a queue while it is in the pending state, and recorded into multiple primary command buffers. Otherwise, synchronization must be done using a VkFence.


flags – The command buffer usage flags, 0 by default.

void bind_descriptor(const ResourceDescriptor &descriptor, VkPipelineLayout layout) const

Call vkCmdBindDescriptorSets.

  • descriptor – The const reference to the resource descriptor RAII wrapper instance.

  • layout – The pipeline layout which will be used to bind the resource descriptor.

void push_constants(VkPipelineLayout layout, VkShaderStageFlags stage, std::uint32_t size, void *data) const

Update push constant data.

  • layout – The pipeline layout

  • stage – The shader stage that will be accepting the push constants

  • size – The size of the push constant data in bytes

  • data – A pointer to the push constant data

void end() const

Call vkEndCommandBuffer.

void begin_render_pass(const VkRenderPassBeginInfo &render_pass_bi) const

Call vkCmdBeginRenderPass.


render_pass_bi – The const reference to the VkRenderPassBeginInfo which is used.

void bind_graphics_pipeline(VkPipeline pipeline) const

Call vkCmdBindPipeline.


pipeline – The graphics pipeline to bind.

void bind_index_buffer(VkBuffer buffer) const

Call vkCmdBindIndexBuffer.


Don’t hardcode 16 for index bit width here.


buffer – The index buffer to bind.

void bind_vertex_buffers(const std::vector<VkBuffer> &buffers) const

Call vkCmdBindVertexBuffers.


Expose more parameters from vkCmdBindVertexBuffers as method arguments.


buffers – A std::vector of vertex buffers to bind.

void draw(std::size_t vertex_count) const

Call vkCmdDraw.


vertex_count – The number of vertices to draw.

void draw_indexed(std::size_t index_count) const

Call vkCmdDrawIndexed.


index_count – The number of indices to draw.

void end_render_pass() const

Call vkCmdEndRenderPass.

inline VkCommandBuffer get() const
inline const VkCommandBuffer *ptr() const

Private Members

VkCommandBuffer m_command_buffer = {VK_NULL_HANDLE}
const wrapper::Device &m_device
std::string m_name