Skip to content

KDGpu::CommandRecorder

Module: Public API

Records GPU commands into a command buffer for submission. More...

#include <KDGpu/command_recorder.h>

Public Functions

Name
~CommandRecorder()
CommandRecorder(CommandRecorder && other)
CommandRecorder & operator=(CommandRecorder && other)
CommandRecorder(const CommandRecorder & ) =delete
CommandRecorder & operator=(const CommandRecorder & ) =delete
const Handle< CommandRecorder_t > & handle() const
bool isValid() const
operator Handle< CommandRecorder_t >() const
RenderPassCommandRecorder beginRenderPass(const RenderPassCommandRecorderOptions & options) const
RenderPassCommandRecorder beginRenderPass(const RenderPassCommandRecorderWithRenderPassOptions & options) const
RenderPassCommandRecorder beginRenderPass(const RenderPassCommandRecorderWithDynamicRenderingOptions & options) const
ComputePassCommandRecorder beginComputePass(const ComputePassCommandRecorderOptions & options ={}) const
RayTracingPassCommandRecorder beginRayTracingPass(const RayTracingPassCommandRecorderOptions & options ={}) const
TimestampQueryRecorder beginTimestampRecording(const TimestampQueryRecorderOptions & options ={}) const
void blitTexture(const TextureBlitOptions & options) const
void clearBuffer(const BufferClear & clear) const
void clearColorTexture(const ClearColorTexture & clear) const
void clearDepthStencilTexture(const ClearDepthStencilTexture & clear) const
void copyBuffer(const BufferCopy & copy) const
void copyBufferToTexture(const BufferToTextureCopy & copy) const
void copyTextureToBuffer(const TextureToBufferCopy & copy) const
void copyTextureToTexture(const TextureToTextureCopy & copy) const
void updateBuffer(const BufferUpdate & update) const
void memoryBarrier(const MemoryBarrierOptions & options) const
void bufferMemoryBarrier(const BufferMemoryBarrierOptions & options) const
void textureMemoryBarrier(const TextureMemoryBarrierOptions & options) const
void executeSecondaryCommandBuffer(const Handle< CommandBuffer_t > & secondaryCommandBuffer) const
void resolveTexture(const TextureResolveOptions & options) const
void buildAccelerationStructures(const BuildAccelerationStructureOptions & options) const
void beginDebugLabel(const DebugLabelOptions & options) const
void endDebugLabel() const
CommandBuffer finish() const

Protected Functions

Name
CommandRecorder(GraphicsApi * api, const Handle< Device_t > & device, const CommandRecorderOptions & options)

Protected Attributes

Name
GraphicsApi * m_api
Handle< Device_t > m_device
Handle< CommandRecorder_t > m_commandRecorder
CommandBufferLevel m_level

Friends

Name
class Device
class Queue

Detailed Description

1
class KDGpu::CommandRecorder;

Records GPU commands into a command buffer for submission.

Vulkan equivalent:VkCommandBuffer (in recording state)

CommandRecorder is the primary interface for recording GPU work. It provides methods to begin render passes, perform transfers, set barriers, and more. When finished, it produces a CommandBuffer that can be submitted to a Queue.

Key features:

  • Begin render, compute, and ray tracing passes
  • Copy buffers and textures
  • Pipeline barriers and synchronization
  • Clear operations
  • Secondary command buffer execution
  • Debug labels and markers

Lifetime: Create a CommandRecorder when you need to record work, then call finish() to get the CommandBuffer. The recorder itself can be discarded after finish().

Usage

Basic command recording:

1
    KDGpu::CommandRecorder recorder = device.createCommandRecorder();

Filename: kdgpu_doc_snippets.cpp

Recording render passes:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
    auto renderPass = recorder.beginRenderPass(KDGpu::RenderPassCommandRecorderOptions{
            .colorAttachments = {
                    {
                            .view = colorView,
                            .loadOperation = KDGpu::AttachmentLoadOperation::Clear,
                            .clearValue = { 0.2f, 0.3f, 0.3f, 1.0f },
                    },
            },
            .depthStencilAttachment = {
                    .view = depthView,
            },
    });

    // ... record drawing commands ...
    renderPass.end();

Filename: kdgpu_doc_snippets.cpp

Compute pass recording:

1
2
3
    auto computePass = recorder.beginComputePass();
    // ... record compute commands ...
    computePass.end();

Filename: kdgpu_doc_snippets.cpp

Buffer copies:

1
2
3
4
5
    recorder.copyBuffer(KDGpu::BufferCopy{
            .src = srcBuffer,
            .dst = dstBuffer,
            .byteSize = 1024,
    });

Filename: kdgpu_doc_snippets.cpp

Texture copies:

1
2
3
4
5
6
7
8
9
    recorder.copyTextureToTexture(KDGpu::TextureToTextureCopy{
            .srcTexture = srcTexture.handle(),
            .dstTexture = dstTexture.handle(),
            .regions = {
                    {
                            .extent = { 512, 512, 1 },
                    },
            },
    });

Filename: kdgpu_doc_snippets.cpp

Submitting commands:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
    auto submitRenderPass = recorder.beginRenderPass(KDGpu::RenderPassCommandRecorderOptions{
            .colorAttachments = {
                    {
                            .view = colorView,
                    },
            },
    });
    // ... record commands ...
    submitRenderPass.end();

    KDGpu::CommandBuffer commandBuffer = recorder.finish();
    queue.submit(KDGpu::SubmitOptions{
            .commandBuffers = { commandBuffer },
    });

Filename: kdgpu_doc_snippets.cpp

Recorder reuse:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
    KDGpu::CommandRecorder recorderReuse = device.createCommandRecorder();

    // Frame 1
    auto pass1 = recorderReuse.beginRenderPass(KDGpu::RenderPassCommandRecorderOptions{
            .colorAttachments = {
                    {
                            .view = colorView,
                    },
            },
    });
    pass1.end();
    KDGpu::CommandBuffer cmdBuffer1 = recorderReuse.finish();
    queue.submit(KDGpu::SubmitOptions{
            .commandBuffers = { cmdBuffer1 },
    });

    // Frame 2 - reuse recorder
    auto pass2 = recorderReuse.beginRenderPass(KDGpu::RenderPassCommandRecorderOptions{
            .colorAttachments = { {
                    .view = colorView,
            } },
    });
    pass2.end();
    KDGpu::CommandBuffer cmdBuffer2 = recorderReuse.finish();
    queue.submit(KDGpu::SubmitOptions{
            .commandBuffers = { cmdBuffer2 },
    });

Filename: kdgpu_doc_snippets.cpp

Vulkan mapping:

See also:

CommandRecorderOptions, CommandBuffer, RenderPassCommandRecorder, ComputePassCommandRecorder, Queue, Device

KDGpu API Overview

KDGpu to Vulkan API Mapping

Public Functions Documentation

function ~CommandRecorder

1
~CommandRecorder()

function CommandRecorder

1
2
3
CommandRecorder(
    CommandRecorder && other
)

function operator=

1
2
3
CommandRecorder & operator=(
    CommandRecorder && other
)

function CommandRecorder

1
2
3
CommandRecorder(
    const CommandRecorder & 
) =delete

function operator=

1
2
3
CommandRecorder & operator=(
    const CommandRecorder & 
) =delete

function handle

1
inline const Handle< CommandRecorder_t > & handle() const

function isValid

1
inline bool isValid() const

function operator Handle< CommandRecorder_t >

1
inline operator Handle< CommandRecorder_t >() const

function beginRenderPass

1
2
3
RenderPassCommandRecorder beginRenderPass(
    const RenderPassCommandRecorderOptions & options
) const

function beginRenderPass

1
2
3
RenderPassCommandRecorder beginRenderPass(
    const RenderPassCommandRecorderWithRenderPassOptions & options
) const

function beginRenderPass

1
2
3
RenderPassCommandRecorder beginRenderPass(
    const RenderPassCommandRecorderWithDynamicRenderingOptions & options
) const

function beginComputePass

1
2
3
ComputePassCommandRecorder beginComputePass(
    const ComputePassCommandRecorderOptions & options ={}
) const

function beginRayTracingPass

1
2
3
RayTracingPassCommandRecorder beginRayTracingPass(
    const RayTracingPassCommandRecorderOptions & options ={}
) const

function beginTimestampRecording

1
2
3
TimestampQueryRecorder beginTimestampRecording(
    const TimestampQueryRecorderOptions & options ={}
) const

function blitTexture

1
2
3
void blitTexture(
    const TextureBlitOptions & options
) const

function clearBuffer

1
2
3
void clearBuffer(
    const BufferClear & clear
) const

function clearColorTexture

1
2
3
void clearColorTexture(
    const ClearColorTexture & clear
) const

function clearDepthStencilTexture

1
2
3
void clearDepthStencilTexture(
    const ClearDepthStencilTexture & clear
) const

function copyBuffer

1
2
3
void copyBuffer(
    const BufferCopy & copy
) const

function copyBufferToTexture

1
2
3
void copyBufferToTexture(
    const BufferToTextureCopy & copy
) const

function copyTextureToBuffer

1
2
3
void copyTextureToBuffer(
    const TextureToBufferCopy & copy
) const

function copyTextureToTexture

1
2
3
void copyTextureToTexture(
    const TextureToTextureCopy & copy
) const

function updateBuffer

1
2
3
void updateBuffer(
    const BufferUpdate & update
) const

function memoryBarrier

1
2
3
void memoryBarrier(
    const MemoryBarrierOptions & options
) const

function bufferMemoryBarrier

1
2
3
void bufferMemoryBarrier(
    const BufferMemoryBarrierOptions & options
) const

function textureMemoryBarrier

1
2
3
void textureMemoryBarrier(
    const TextureMemoryBarrierOptions & options
) const

function executeSecondaryCommandBuffer

1
2
3
void executeSecondaryCommandBuffer(
    const Handle< CommandBuffer_t > & secondaryCommandBuffer
) const

function resolveTexture

1
2
3
void resolveTexture(
    const TextureResolveOptions & options
) const

function buildAccelerationStructures

1
2
3
void buildAccelerationStructures(
    const BuildAccelerationStructureOptions & options
) const

function beginDebugLabel

1
2
3
void beginDebugLabel(
    const DebugLabelOptions & options
) const

function endDebugLabel

1
void endDebugLabel() const

function finish

1
CommandBuffer finish() const

Protected Functions Documentation

function CommandRecorder

1
2
3
4
5
explicit CommandRecorder(
    GraphicsApi * api,
    const Handle< Device_t > & device,
    const CommandRecorderOptions & options
)

Protected Attributes Documentation

variable m_api

1
GraphicsApi * m_api { nullptr };

variable m_device

1
Handle< Device_t > m_device;

variable m_commandRecorder

1
Handle< CommandRecorder_t > m_commandRecorder;

variable m_level

1
CommandBufferLevel m_level;

Friends

friend Device

1
2
3
friend class Device(
    Device 
);

friend Queue

1
2
3
friend class Queue(
    Queue 
);

Updated on 2026-03-31 at 00:02:07 +0000