Skip to content

KDGpu::RenderPassCommandRecorderWithDynamicRenderingOptions

Module: Public API

Modern render pass options using dynamic rendering (recommended) More...

#include <KDGpu/render_pass_command_recorder_options.h>

Public Attributes

Name
std::vector< ColorAttachment > colorAttachments
Color render targets (can be empty for depth-only passes)
DepthStencilAttachment depthStencilAttachment
Depth/stencil target (optional)
SampleCountFlagBits samples
MSAA sample count.
uint32_t viewCount
Number of views for multiview rendering (2 for stereo VR)
uint32_t framebufferWidth
Render area width (0 = infer from first attachment)
uint32_t framebufferHeight
Render area height (0 = infer from first attachment)
uint32_t framebufferArrayLayers
Array layers (0 = infer from first attachment)

Detailed Description

1
struct KDGpu::RenderPassCommandRecorderWithDynamicRenderingOptions;

Modern render pass options using dynamic rendering (recommended)

Dynamic rendering allows you to specify render targets directly when beginning a render pass, without pre-creating VkRenderPass and VkFramebuffer objects. This approach was introduced as VK_KHR_dynamic_rendering and promoted to Vulkan 1.3 core, superseding the legacy VkRenderPass/VkFramebuffer model.

Benefits of Dynamic Rendering

  • Simpler API: No need to create RenderPass objects upfront
  • More flexible: Easily change attachments between frames
  • Better performance: Eliminates RenderPass compatibility checks
  • Modern standard: Vulkan 1.3 core feature, replacing legacy render passes

Usage Example

 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
28
29
30
31
32
33
34
35
36
37
        // Using dynamic rendering (modern approach, promoted to Vulkan 1.3 core)
        KDGpu::RenderPassCommandRecorderWithDynamicRenderingOptions renderOptions{
            // Configure color attachment (e.g., swapchain image)
            .colorAttachments = {
                    KDGpu::ColorAttachment{
                            .view = colorView.handle(),
                            .loadOperation = KDGpu::AttachmentLoadOperation::Clear,
                            .storeOperation = KDGpu::AttachmentStoreOperation::Store,
                            .clearValue = { 0.1f, 0.2f, 0.3f, 1.0f }, // Clear to dark blue
                            .initialLayout = KDGpu::TextureLayout::Undefined,
                            .layout = KDGpu::TextureLayout::ColorAttachmentOptimal,
                            .finalLayout = KDGpu::TextureLayout::PresentSrc,
                    },
            },
            // Configure depth attachment
            .depthStencilAttachment = KDGpu::DepthStencilAttachment{
                    .view = depthView,
                    .depthLoadOperation = KDGpu::AttachmentLoadOperation::Clear,
                    .depthStoreOperation = KDGpu::AttachmentStoreOperation::DontCare,
                    .depthClearValue = 1.0f,
                    .initialLayout = KDGpu::TextureLayout::Undefined,
                    .layout = KDGpu::TextureLayout::DepthStencilAttachmentOptimal,
            },
        };

        // Begin render pass
        auto renderPass = commandRecorder->beginRenderPass(renderOptions);

        // Record rendering commands...
        renderPass.setPipeline(pipeline);
        renderPass.setVertexBuffer(0, vertexBuffer);
        renderPass.setIndexBuffer(indexBuffer);
        renderPass.setBindGroup(0, bindGroup);
        renderPass.drawIndexed({ .indexCount = 36 });

        // End the render pass
        renderPass.end();

Filename: kdgpu_doc_snippets.cpp

MSAA with Automatic Resolve

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
        // Multi-sample anti-aliasing with automatic resolve

        KDGpu::RenderPassCommandRecorderWithDynamicRenderingOptions msaaOptions{
            .colorAttachments = {
                    KDGpu::ColorAttachment{
                            .view = msaaColorView, // MSAA texture view
                            .resolveView = colorView, // Single-sample texture to resolve to
                            .loadOperation = KDGpu::AttachmentLoadOperation::Clear,
                            .storeOperation = KDGpu::AttachmentStoreOperation::DontCare, // MSAA buffer not needed after resolve
                            .clearValue = { 0.0f, 0.0f, 0.0f, 1.0f },
                    },
            },
            .samples = KDGpu::SampleCountFlagBits::Samples4Bit,
        };

        auto msaaRenderPass = commandRecorder->beginRenderPass(msaaOptions);
        // Render with MSAA...
        msaaRenderPass.end();

Filename: kdgpu_doc_snippets.cpp

Multi-View Rendering

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
        // Multi-view rendering for VR/stereo (renders to both eyes in a single pass)
        KDGpu::RenderPassCommandRecorderWithDynamicRenderingOptions multiviewOptions{
            .colorAttachments = {
                    KDGpu::ColorAttachment{
                            .view = arrayColorView, // Array texture with 2 layers
                            .loadOperation = KDGpu::AttachmentLoadOperation::Clear,
                            .storeOperation = KDGpu::AttachmentStoreOperation::Store,
                    },
            },
            .viewCount = 2, // Render to 2 views simultaneously
        };

        auto multiviewRenderPass = commandRecorder->beginRenderPass(multiviewOptions);
        // The vertex shader will run once per view using gl_ViewIndex
        multiviewRenderPass.end();

Filename: kdgpu_doc_snippets.cpp

Vulkan Mapping

In Vulkan, this maps to vkCmdBeginRendering() from VK_KHR_dynamic_rendering (Vulkan 1.3 core).

ColorAttachment, DepthStencilAttachment, RenderPassCommandRecorder

CommandRecorder::beginRenderPass()

Public Attributes Documentation

variable colorAttachments

1
std::vector< ColorAttachment > colorAttachments;

Color render targets (can be empty for depth-only passes)

variable depthStencilAttachment

1
DepthStencilAttachment depthStencilAttachment;

Depth/stencil target (optional)

variable samples

1
SampleCountFlagBits samples { SampleCountFlagBits::Samples1Bit };

MSAA sample count.

variable viewCount

1
uint32_t viewCount { 1 };

Number of views for multiview rendering (2 for stereo VR)

variable framebufferWidth

1
uint32_t framebufferWidth { 0 };

Render area width (0 = infer from first attachment)

variable framebufferHeight

1
uint32_t framebufferHeight { 0 };

Render area height (0 = infer from first attachment)

variable framebufferArrayLayers

1
uint32_t framebufferArrayLayers { 0 };

Array layers (0 = infer from first attachment)


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