Skip to content

KDGpu::GraphicsPipeline

Module: Public API

Represents a complete graphics rendering pipeline state. More...

#include <KDGpu/graphics_pipeline.h>

Public Functions

Name
GraphicsPipeline()
~GraphicsPipeline()
GraphicsPipeline(GraphicsPipeline && other)
GraphicsPipeline & operator=(GraphicsPipeline && other)
GraphicsPipeline(const GraphicsPipeline & ) =delete
GraphicsPipeline & operator=(const GraphicsPipeline & ) =delete
const Handle< GraphicsPipeline_t > & handle() const
bool isValid() const
operator Handle< GraphicsPipeline_t >() const

Friends

Name
class Device
KDGPU_EXPORT bool operator==(const GraphicsPipeline & a, const GraphicsPipeline & b)

Detailed Description

1
class KDGpu::GraphicsPipeline;

Represents a complete graphics rendering pipeline state.

Vulkan equivalent:VkPipeline (graphics)

GraphicsPipeline encapsulates all state needed for a draw call: shaders, vertex input layout, rasterization state, depth/stencil testing, blending, and more. In KDGpu, pipelines are immutable once created.

Key components:

  • Shader stages (vertex, fragment, geometry, etc.)
  • Vertex input layout and attributes
  • Primitive topology (triangles, lines, points)
  • Viewport and scissor configuration
  • Rasterization state (culling, polygon mode)
  • Depth and stencil testing
  • Color blending and write masks
  • Pipeline layout (descriptor sets, push constants)

Lifetime: Pipelines are created by Device and must remain valid while referenced by render passes. They use RAII and clean up automatically.

Usage

Creating a simple pipeline:

1
2
3
4
5
struct Vertex {
    float position[3];
    float color[3];
    float texCoord[2];
};

Filename: kdgpu_doc_snippets.cpp

 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
38
39
40
    KDGpu::GraphicsPipeline pipeline = device.createGraphicsPipeline(KDGpu::GraphicsPipelineOptions{
            .shaderStages = {
                    {
                            .shaderModule = vertexShader,
                            .stage = KDGpu::ShaderStageFlagBits::VertexBit,
                    },
                    {
                            .shaderModule = fragmentShader,
                            .stage = KDGpu::ShaderStageFlagBits::FragmentBit,
                    },
            },
            .layout = pipelineLayout.handle(),
            .vertex = {
                    .buffers = {
                            {
                                    .binding = 0,
                                    .stride = sizeof(Vertex),
                            },
                    },
                    .attributes = {
                            {
                                    .location = 0,
                                    .binding = 0,
                                    .format = KDGpu::Format::R32G32B32_SFLOAT,
                                    .offset = offsetof(Vertex, position),
                            },
                            {
                                    .location = 1,
                                    .binding = 0,
                                    .format = KDGpu::Format::R32G32B32_SFLOAT,
                                    .offset = offsetof(Vertex, color),
                            },
                    },
            },
            .renderTargets = {
                    {
                            .format = swapchainFormat,
                    },
            },
    });

Filename: kdgpu_doc_snippets.cpp

Pipeline with depth testing:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
    KDGpu::GraphicsPipeline depthPipeline = device.createGraphicsPipeline(KDGpu::GraphicsPipelineOptions{
            .shaderStages = {
                    {
                            .shaderModule = vertexShader,
                            .stage = KDGpu::ShaderStageFlagBits::VertexBit,
                    },
                    {
                            .shaderModule = fragmentShader,
                            .stage = KDGpu::ShaderStageFlagBits::FragmentBit,
                    },
            },
            .layout = pipelineLayout,
            .vertex = { /* ... */ },
            .renderTargets = { {
                    .format = swapchainFormat,
            } },
            .depthStencil = {
                    .format = KDGpu::Format::D32_SFLOAT,
                    .depthWritesEnabled = true,
                    .depthCompareOperation = KDGpu::CompareOperation::Less,
            },
    });

Filename: kdgpu_doc_snippets.cpp

Alpha blending:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
    KDGpu::GraphicsPipeline blendPipeline = device.createGraphicsPipeline(KDGpu::GraphicsPipelineOptions{
            .shaderStages = { /* ... */ },
            .layout = pipelineLayout,
            .vertex = { /* ... */ },
            .renderTargets = {
                    KDGpu::RenderTargetOptions{
                            .format = swapchainFormat,
                            .blending = KDGpu::BlendOptions{
                                    .blendingEnabled = true,
                                    .color = KDGpu::BlendComponent{
                                            .operation = KDGpu::BlendOperation::Add,
                                            .srcFactor = KDGpu::BlendFactor::SrcAlpha,
                                            .dstFactor = KDGpu::BlendFactor::OneMinusSrcAlpha,
                                    },
                                    .alpha = KDGpu::BlendComponent{
                                            .operation = KDGpu::BlendOperation::Add,
                                            .srcFactor = KDGpu::BlendFactor::One,
                                            .dstFactor = KDGpu::BlendFactor::Zero,
                                    },
                            },
                    },
            },
    });

Filename: kdgpu_doc_snippets.cpp

Culling configuration:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
    KDGpu::GraphicsPipeline cullPipeline = device.createGraphicsPipeline(KDGpu::GraphicsPipelineOptions{
            .shaderStages = { /* ... */ },
            .layout = pipelineLayout,
            .vertex = { /* ... */ },
            .renderTargets = {
                    {
                            .format = swapchainFormat,
                    },
            },
            .primitive = {
                    .topology = KDGpu::PrimitiveTopology::TriangleList,
                    .cullMode = KDGpu::CullModeFlagBits::BackBit,
                    .frontFace = KDGpu::FrontFace::CounterClockwise,
            },
    });

Filename: kdgpu_doc_snippets.cpp

Multisampling:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
    KDGpu::GraphicsPipeline msaaPipeline = device.createGraphicsPipeline(KDGpu::GraphicsPipelineOptions{
            .shaderStages = { /* ... */ },
            .layout = pipelineLayout,
            .vertex = { /* ... */ },
            .renderTargets = { {
                    .format = swapchainFormat,
            } },
            .multisample = {
                    .samples = KDGpu::SampleCountFlagBits::Samples4Bit,
            },
    });

Filename: kdgpu_doc_snippets.cpp

Vulkan mapping:

  • GraphicsPipeline creation -> vkCreateGraphicsPipelines()
  • Bound with vkCmdBindPipeline(VK_PIPELINE_BIND_POINT_GRAPHICS)

See also:

Device, GraphicsPipelineOptions, PipelineLayout, ShaderModule, ComputePipeline

KDGpu API Overview

KDGpu to Vulkan API Mapping

Public Functions Documentation

function GraphicsPipeline

1
GraphicsPipeline()

function ~GraphicsPipeline

1
~GraphicsPipeline()

function GraphicsPipeline

1
2
3
GraphicsPipeline(
    GraphicsPipeline && other
)

function operator=

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

function GraphicsPipeline

1
2
3
GraphicsPipeline(
    const GraphicsPipeline & 
) =delete

function operator=

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

function handle

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

function isValid

1
inline bool isValid() const

function operator Handle< GraphicsPipeline_t >

1
inline operator Handle< GraphicsPipeline_t >() const

Friends

friend Device

1
2
3
friend class Device(
    Device 
);

friend operator==

1
2
3
4
5
friend KDGPU_EXPORT bool operator==(
    const GraphicsPipeline & a,

    const GraphicsPipeline & b
);

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