Skip to content

KDGpu::Device

Module: Public API

Represents a logical GPU device - the primary object for creating GPU resources. More...

#include <KDGpu/device.h>

Public Functions

Name
Device()
~Device()
Device(Device && other)
Device & operator=(Device && other)
Device(const Device & ) =delete
Device & operator=(const Device & ) =delete
Handle< Device_t > handle() const
Returns the handle used to retrieve the underlying API specific Device.
bool isValid() const
Convenience function to check whether the Device is actually referencing a valid API specific resource.
operator Handle< Device_t >() const
std::span< Queue > queues()
Returns the queues available on the device.
void waitUntilIdle()
Forces a CPU side blocking wait until the underlying device has completed execution of all its pending commands.
const Adapter * adapter() const
Swapchain createSwapchain(const SwapchainOptions & options)
Texture createTexture(const TextureOptions & options)
Buffer createBuffer(const BufferOptions & options, const void * initialData =nullptr)
ShaderModule createShaderModule(const std::vector< uint32_t > & code)
RenderPass createRenderPass(const RenderPassOptions & options)
PipelineLayout createPipelineLayout(const PipelineLayoutOptions & options =PipelineLayoutOptions())
PipelineCache createPipelineCache(const PipelineCacheOptions & options =PipelineCacheOptions())
GraphicsPipeline createGraphicsPipeline(const GraphicsPipelineOptions & options)
ComputePipeline createComputePipeline(const ComputePipelineOptions & options)
RayTracingPipeline createRayTracingPipeline(const RayTracingPipelineOptions & options)
CommandRecorder createCommandRecorder(const CommandRecorderOptions & options =CommandRecorderOptions())
GpuSemaphore createGpuSemaphore(const GpuSemaphoreOptions & options =GpuSemaphoreOptions())
TimelineSemaphore createTimelineSemaphore(const TimelineSemaphoreOptions & options =TimelineSemaphoreOptions())
BindGroupLayout createBindGroupLayout(const BindGroupLayoutOptions & options)
BindGroupPool createBindGroupPool(const BindGroupPoolOptions & options)
BindGroup createBindGroup(const BindGroupOptions & options)
Sampler createSampler(const SamplerOptions & options =SamplerOptions())
Fence createFence(const FenceOptions & options =FenceOptions())
AccelerationStructure createAccelerationStructure(const AccelerationStructureOptions & options =AccelerationStructureOptions())
YCbCrConversion createYCbCrConversion(const YCbCrConversionOptions & options)
GraphicsApi * graphicsApi() const

Friends

Name
class Adapter
class VulkanGraphicsApi

Detailed Description

1
class KDGpu::Device;

Represents a logical GPU device - the primary object for creating GPU resources.

Vulkan equivalent:VkDevice

The Device is the central object in KDGpu applications. It represents a logical connection to a physical GPU (Adapter) and is the factory for creating all GPU resources: buffers, textures, pipelines, command recorders, and synchronization objects.

Key responsibilities:

  • Create GPU resources (buffers, textures, images)
  • Create pipelines (graphics, compute, ray tracing)
  • Create shaders and pipeline layouts
  • Create command recorders for GPU work
  • Create synchronization primitives (fences, semaphores)
  • Create descriptor sets (bind groups)
  • Manage queues for submitting GPU commands

Lifetime: The Device should live for the entire time you need to render. All resources created from the device become invalid when the device is destroyed or moved. Typically you create one device at startup and keep it until shutdown.

Usage

Creating a device:

1
2
3
4
5
6
    KDGpu::Device device = adapter.createDevice(KDGpu::DeviceOptions{
            .requestedFeatures = {
                    .geometryShader = true,
                    .tessellationShader = true,
            },
    });

Filename: kdgpu_doc_snippets.cpp

Accessing queues:

1
    KDGpu::Queue queue = device.queues()[0]; // Get first queue

Filename: kdgpu_doc_snippets.cpp

Creating buffers:

1
2
3
4
5
    KDGpu::Buffer buffer = device.createBuffer(KDGpu::BufferOptions{
            .size = 1024,
            .usage = KDGpu::BufferUsageFlagBits::VertexBufferBit,
            .memoryUsage = KDGpu::MemoryUsage::CpuToGpu,
    });

Filename: kdgpu_doc_snippets.cpp

Creating textures:

1
2
3
4
5
6
7
    KDGpu::Texture texture = device.createTexture(KDGpu::TextureOptions{
            .type = KDGpu::TextureType::TextureType2D,
            .format = KDGpu::Format::R8G8B8A8_SRGB,
            .extent = { 1024, 1024, 1 },
            .mipLevels = 1,
            .usage = KDGpu::TextureUsageFlagBits::SampledBit,
    });

Filename: kdgpu_doc_snippets.cpp

Wait for GPU completion:

1
2
    // Finish all pending GPU work
    device.waitUntilIdle();

Filename: kdgpu_doc_snippets.cpp

Multiple queues:

1
2
3
4
5
6
7
8
9
    KDGpu::Device deviceMultiQueue = adapter.createDevice(KDGpu::DeviceOptions{
            .queues = {
                    { .queueTypeIndex = 0, .count = 1 }, // Graphics queue
                    { .queueTypeIndex = 1, .count = 1 }, // Compute queue
            },
    });

    KDGpu::Queue graphicsQueue = device.queues()[0];
    KDGpu::Queue computeQueue = device.queues()[1];

Filename: kdgpu_doc_snippets.cpp

Vulkan mapping:

KDGpu will try to request some device extensions by default KDGpu::getDefaultRequestedDeviceExtensions

See also:

Adapter, DeviceOptions, Queue, Buffer, Texture, GraphicsPipeline, CommandRecorder

KDGpu API Overview

KDGpu to Vulkan API Mapping

Public Functions Documentation

function Device

1
Device()

function ~Device

1
~Device()

function Device

1
2
3
Device(
    Device && other
)

function operator=

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

function Device

1
2
3
Device(
    const Device & 
) =delete

function operator=

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

function handle

1
inline Handle< Device_t > handle() const

Returns the handle used to retrieve the underlying API specific Device.

See: ResourceManager

function isValid

1
inline bool isValid() const

Convenience function to check whether the Device is actually referencing a valid API specific resource.

function operator Handle< Device_t >

1
inline operator Handle< Device_t >() const

function queues

1
inline std::span< Queue > queues()

Returns the queues available on the device.

function waitUntilIdle

1
void waitUntilIdle()

Forces a CPU side blocking wait until the underlying device has completed execution of all its pending commands.

function adapter

1
const Adapter * adapter() const

function createSwapchain

1
2
3
Swapchain createSwapchain(
    const SwapchainOptions & options
)

function createTexture

1
2
3
Texture createTexture(
    const TextureOptions & options
)

function createBuffer

1
2
3
4
Buffer createBuffer(
    const BufferOptions & options,
    const void * initialData =nullptr
)

function createShaderModule

1
2
3
ShaderModule createShaderModule(
    const std::vector< uint32_t > & code
)

function createRenderPass

1
2
3
RenderPass createRenderPass(
    const RenderPassOptions & options
)

function createPipelineLayout

1
2
3
PipelineLayout createPipelineLayout(
    const PipelineLayoutOptions & options =PipelineLayoutOptions()
)

function createPipelineCache

1
2
3
PipelineCache createPipelineCache(
    const PipelineCacheOptions & options =PipelineCacheOptions()
)

function createGraphicsPipeline

1
2
3
GraphicsPipeline createGraphicsPipeline(
    const GraphicsPipelineOptions & options
)

function createComputePipeline

1
2
3
ComputePipeline createComputePipeline(
    const ComputePipelineOptions & options
)

function createRayTracingPipeline

1
2
3
RayTracingPipeline createRayTracingPipeline(
    const RayTracingPipelineOptions & options
)

function createCommandRecorder

1
2
3
CommandRecorder createCommandRecorder(
    const CommandRecorderOptions & options =CommandRecorderOptions()
)

function createGpuSemaphore

1
2
3
GpuSemaphore createGpuSemaphore(
    const GpuSemaphoreOptions & options =GpuSemaphoreOptions()
)

function createTimelineSemaphore

1
2
3
TimelineSemaphore createTimelineSemaphore(
    const TimelineSemaphoreOptions & options =TimelineSemaphoreOptions()
)

function createBindGroupLayout

1
2
3
BindGroupLayout createBindGroupLayout(
    const BindGroupLayoutOptions & options
)

function createBindGroupPool

1
2
3
BindGroupPool createBindGroupPool(
    const BindGroupPoolOptions & options
)

function createBindGroup

1
2
3
BindGroup createBindGroup(
    const BindGroupOptions & options
)

function createSampler

1
2
3
Sampler createSampler(
    const SamplerOptions & options =SamplerOptions()
)

function createFence

1
2
3
Fence createFence(
    const FenceOptions & options =FenceOptions()
)

function createAccelerationStructure

1
2
3
AccelerationStructure createAccelerationStructure(
    const AccelerationStructureOptions & options =AccelerationStructureOptions()
)

function createYCbCrConversion

1
2
3
YCbCrConversion createYCbCrConversion(
    const YCbCrConversionOptions & options
)

function graphicsApi

1
GraphicsApi * graphicsApi() const

Friends

friend Adapter

1
2
3
friend class Adapter(
    Adapter 
);

friend VulkanGraphicsApi

1
2
3
friend class VulkanGraphicsApi(
    VulkanGraphicsApi 
);

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