KDGpu::Device
Module: Public API
Represents a logical GPU device - the primary object for creating GPU resources. More...
#include <KDGpu/device.h>
Public Functions
Friends
Detailed Description
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:
| KDGpu::Device device = adapter.createDevice(KDGpu::DeviceOptions{
.requestedFeatures = {
.geometryShader = true,
.tessellationShader = true,
},
});
|
Filename: kdgpu_doc_snippets.cpp
Accessing queues:
| KDGpu::Queue queue = device.queues()[0]; // Get first queue
|
Filename: kdgpu_doc_snippets.cpp
Creating buffers:
| KDGpu::Buffer buffer = device.createBuffer(KDGpu::BufferOptions{
.size = 1024,
.usage = KDGpu::BufferUsageFlagBits::VertexBufferBit,
.memoryUsage = KDGpu::MemoryUsage::CpuToGpu,
});
|
Filename: kdgpu_doc_snippets.cpp
Creating textures:
| 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:
| // Finish all pending GPU work
device.waitUntilIdle();
|
Filename: kdgpu_doc_snippets.cpp
Multiple queues:
| 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
function ~Device
function Device
| Device(
Device && other
)
|
function operator=
| Device & operator=(
Device && other
)
|
function Device
| Device(
const Device &
) =delete
|
function operator=
| Device & operator=(
const Device &
) =delete
|
function handle
| inline Handle< Device_t > handle() const
|
Returns the handle used to retrieve the underlying API specific Device.
See: ResourceManager
function isValid
| inline bool isValid() const
|
Convenience function to check whether the Device is actually referencing a valid API specific resource.
function operator Handle< Device_t >
| inline operator Handle< Device_t >() const
|
function queues
| inline std::span< Queue > queues()
|
Returns the queues available on the device.
function waitUntilIdle
Forces a CPU side blocking wait until the underlying device has completed execution of all its pending commands.
function adapter
| const Adapter * adapter() const
|
function createSwapchain
| Swapchain createSwapchain(
const SwapchainOptions & options
)
|
function createTexture
| Texture createTexture(
const TextureOptions & options
)
|
function createBuffer
| Buffer createBuffer(
const BufferOptions & options,
const void * initialData =nullptr
)
|
function createShaderModule
| ShaderModule createShaderModule(
const std::vector< uint32_t > & code
)
|
function createRenderPass
| RenderPass createRenderPass(
const RenderPassOptions & options
)
|
function createPipelineLayout
| PipelineLayout createPipelineLayout(
const PipelineLayoutOptions & options =PipelineLayoutOptions()
)
|
function createPipelineCache
| PipelineCache createPipelineCache(
const PipelineCacheOptions & options =PipelineCacheOptions()
)
|
function createGraphicsPipeline
| GraphicsPipeline createGraphicsPipeline(
const GraphicsPipelineOptions & options
)
|
function createComputePipeline
| ComputePipeline createComputePipeline(
const ComputePipelineOptions & options
)
|
function createRayTracingPipeline
| RayTracingPipeline createRayTracingPipeline(
const RayTracingPipelineOptions & options
)
|
function createCommandRecorder
| CommandRecorder createCommandRecorder(
const CommandRecorderOptions & options =CommandRecorderOptions()
)
|
function createGpuSemaphore
| GpuSemaphore createGpuSemaphore(
const GpuSemaphoreOptions & options =GpuSemaphoreOptions()
)
|
function createTimelineSemaphore
| TimelineSemaphore createTimelineSemaphore(
const TimelineSemaphoreOptions & options =TimelineSemaphoreOptions()
)
|
function createBindGroupLayout
| BindGroupLayout createBindGroupLayout(
const BindGroupLayoutOptions & options
)
|
function createBindGroupPool
| BindGroupPool createBindGroupPool(
const BindGroupPoolOptions & options
)
|
function createBindGroup
| BindGroup createBindGroup(
const BindGroupOptions & options
)
|
function createSampler
| Sampler createSampler(
const SamplerOptions & options =SamplerOptions()
)
|
function createFence
| Fence createFence(
const FenceOptions & options =FenceOptions()
)
|
function createAccelerationStructure
| AccelerationStructure createAccelerationStructure(
const AccelerationStructureOptions & options =AccelerationStructureOptions()
)
|
function createYCbCrConversion
| YCbCrConversion createYCbCrConversion(
const YCbCrConversionOptions & options
)
|
function graphicsApi
| GraphicsApi * graphicsApi() const
|
Friends
friend Adapter
| friend class Adapter(
Adapter
);
|
friend VulkanGraphicsApi
| friend class VulkanGraphicsApi(
VulkanGraphicsApi
);
|
Updated on 2026-03-31 at 00:02:07 +0000