KDGpu::ComputePipeline
Module: Public API
Represents a compute shader pipeline for general GPU computation. More...
#include <KDGpu/compute_pipeline.h>
Public Functions
Friends
Detailed Description
| class KDGpu::ComputePipeline;
|
Represents a compute shader pipeline for general GPU computation.
Vulkan equivalent:VkPipeline (compute)
ComputePipeline encapsulates a compute shader and its associated resources. Compute shaders run on the GPU outside of the graphics pipeline, enabling general-purpose GPU computation (GPGPU).
Key features:
- Parallel computation on GPU
- Access to buffers and images for read/write
- Work group based execution model
- Shared memory within work groups
Lifetime: Compute pipelines are created by Device and must remain valid while referenced by compute passes. They use RAII and clean up automatically.
Usage
Creating a compute pipeline:
| KDGpu::ComputePipeline pipeline = device.createComputePipeline(KDGpu::ComputePipelineOptions{
.layout = pipelineLayout,
.shaderStage = {
.shaderModule = computeShader,
},
});
|
Filename: kdgpu_doc_snippets.cpp
Dispatching compute work:
| auto computePass = recorder.beginComputePass();
computePass.setPipeline(pipeline);
computePass.setBindGroup(0, bindGroup);
computePass.dispatchCompute(KDGpu::ComputeCommand{
.workGroupX = 256,
.workGroupY = 1,
.workGroupZ = 1,
});
computePass.end();
|
Filename: kdgpu_doc_snippets.cpp
Particle system example:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 | // Compute shader updates particle positions
KDGpu::ComputePipeline particlePipeline = device.createComputePipeline(KDGpu::ComputePipelineOptions{
.layout = pipelineLayout,
.shaderStage = {
.shaderModule = computeShader,
},
});
uint32_t particleCount = 10000;
uint32_t workGroupSize = 256;
uint32_t workGroupCount = (particleCount + workGroupSize - 1) / workGroupSize;
auto particleComputePass = recorder.beginComputePass();
particleComputePass.setPipeline(particlePipeline);
particleComputePass.setBindGroup(0, bindGroup);
particleComputePass.dispatchCompute(KDGpu::ComputeCommand{
.workGroupX = workGroupCount,
});
particleComputePass.end();
|
Filename: kdgpu_doc_snippets.cpp
Specialization constants:
| KDGpu::ComputePipeline specializationPipeline = device.createComputePipeline(KDGpu::ComputePipelineOptions{
.layout = pipelineLayout.handle(),
.shaderStage = {
.shaderModule = computeShader.handle(),
.specializationConstants = {
{ .constantId = 0, .value = 256u }, // WORK_GROUP_SIZE
{ .constantId = 1, .value = 1.0f }, // TIME_STEP
},
},
});
|
Filename: kdgpu_doc_snippets.cpp
Image processing:
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
41
42
43
44
45
46
47
48 | // Image processing compute shader
KDGpu::Texture inputTexture, outputTexture;
KDGpu::TextureView inputView = inputTexture.createView();
KDGpu::TextureView outputView = outputTexture.createView();
KDGpu::BindGroupLayout imageLayout = device.createBindGroupLayout(KDGpu::BindGroupLayoutOptions{
.bindings = {
{
.binding = 0,
.resourceType = KDGpu::ResourceBindingType::SampledImage,
},
{
.binding = 1,
.resourceType = KDGpu::ResourceBindingType::StorageImage,
},
},
});
KDGpu::BindGroup imageBindGroup = device.createBindGroup(KDGpu::BindGroupOptions{
.layout = imageLayout,
.resources = {
{
.binding = 0,
.resource = KDGpu::TextureViewBinding{
.textureView = inputView,
},
},
{
.binding = 1,
.resource = KDGpu::ImageBinding{
.textureView = outputView,
},
},
},
});
uint32_t imageWidth = 1920, imageHeight = 1080;
uint32_t localSizeX = 16, localSizeY = 16;
auto imageComputePass = recorder.beginComputePass();
imageComputePass.setPipeline(pipeline);
imageComputePass.setBindGroup(0, imageBindGroup);
imageComputePass.dispatchCompute(KDGpu::ComputeCommand{
.workGroupX = (imageWidth + localSizeX - 1) / localSizeX,
.workGroupY = (imageHeight + localSizeY - 1) / localSizeY,
.workGroupZ = 1,
});
imageComputePass.end();
|
Filename: kdgpu_doc_snippets.cpp
Vulkan mapping:
- ComputePipeline creation -> vkCreateComputePipelines()
- Bound with vkCmdBindPipeline(VK_PIPELINE_BIND_POINT_COMPUTE)
- Dispatched with vkCmdDispatch()
See also:
Device, ComputePipelineOptions, PipelineLayout, ShaderModule, ComputePassCommandRecorder, GraphicsPipeline
KDGpu API Overview
KDGpu to Vulkan API Mapping
Public Functions Documentation
function ComputePipeline
function ~ComputePipeline
function ComputePipeline
| ComputePipeline(
ComputePipeline && other
)
|
function operator=
| ComputePipeline & operator=(
ComputePipeline && other
)
|
function ComputePipeline
| ComputePipeline(
const ComputePipeline &
) =delete
|
function operator=
| ComputePipeline & operator=(
const ComputePipeline &
) =delete
|
function handle
| inline const Handle< ComputePipeline_t > & handle() const
|
function isValid
| inline bool isValid() const
|
function operator Handle< ComputePipeline_t >
| inline operator Handle< ComputePipeline_t >() const
|
Friends
friend Device
| friend class Device(
Device
);
|
friend operator==
| friend KDGPU_EXPORT bool operator==(
const ComputePipeline & a,
const ComputePipeline & b
);
|
Updated on 2026-03-31 at 00:02:07 +0000