KDGpu::Fence
Module: Public API
Synchronization primitive for CPU-GPU synchronization. More...
#include <KDGpu/fence.h>
Public Functions
Friends
Detailed Description
Synchronization primitive for CPU-GPU synchronization.
Vulkan equivalent:VkFence
Fence is used to synchronize CPU and GPU execution. The GPU signals a fence when it completes work, and the CPU can wait for that signal. This is essential for knowing when GPU operations have finished.
Key features:
- CPU-side waiting for GPU completion
- Signaling when GPU work is done
- Resetting for reuse
- Checking status without blocking
Lifetime: Fences are created by Device and should remain valid while GPU work that signals them is in flight. They use RAII and clean up automatically.
Usage
Basic fence usage:
| KDGpu::Fence fence = device.createFence();
|
Filename: kdgpu_doc_snippets.cpp
Submit and wait:
| queue.submit(KDGpu::SubmitOptions{
.commandBuffers = { commandBuffer },
.signalFence = fence,
});
fence.wait(); // Block until GPU work completes
|
Filename: kdgpu_doc_snippets.cpp
Checking status:
1
2
3
4
5
6
7
8
9
10
11
12 | queue.submit(KDGpu::SubmitOptions{
.commandBuffers = { commandBuffer },
.signalFence = fence,
});
// Do other work while GPU executes...
if (fence.status() == KDGpu::FenceStatus::Signalled) {
std::cout << "GPU work complete" << std::endl;
} else {
std::cout << "GPU still working" << std::endl;
}
|
Filename: kdgpu_doc_snippets.cpp
CPU-GPU synchronization:
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 | // Example showing pattern for synchronizing CPU and GPU per frame
KDGpu::Fence frameFence = device.createFence(KDGpu::FenceOptions{
.createSignalled = true, // allowing us to wait initially
});
auto renderFrame = [&]() {
// 1. Wait for previous frame to complete
frameFence.wait();
// 2. Update resources
// ... upload new data ...
// 3. Record and submit commands
KDGpu::CommandRecorder recorder = device.createCommandRecorder();
// ... record rendering ...
KDGpu::CommandBuffer cmdBuffer = recorder.finish();
frameFence.reset(); // Unsignal fence
queue.submit(KDGpu::SubmitOptions{
.commandBuffers = { cmdBuffer },
.signalFence = frameFence,
});
};
while (true) {
renderFrame();
}
|
Filename: kdgpu_doc_snippets.cpp
Resetting fences:
| fence.wait(); // Wait for signal
fence.reset(); // Return to unsignaled state
queue.submit(KDGpu::SubmitOptions{
.commandBuffers = { commandBuffer },
.signalFence = fence, // Reuse fence
});
|
Filename: kdgpu_doc_snippets.cpp
Vulkan mapping:
See also:
FenceOptions, Queue, GpuSemaphore, Device
KDGpu API Overview
KDGpu to Vulkan API Mapping
Public Functions Documentation
function Fence
function ~Fence
function Fence
function operator=
| Fence & operator=(
Fence && other
)
|
function Fence
| Fence(
const Fence &
) =delete
|
function operator=
| Fence & operator=(
const Fence &
) =delete
|
function handle
| inline const Handle< Fence_t > & handle() const
|
function isValid
| inline bool isValid() const
|
function operator Handle< Fence_t >
| inline operator Handle< Fence_t >() const
|
function reset
function wait
function status
| FenceStatus status() const
|
function externalFenceHandle
| HandleOrFD externalFenceHandle() const
|
Friends
friend Device
| friend class Device(
Device
);
|
friend Queue
| friend class Queue(
Queue
);
|
friend operator==
| friend KDGPU_EXPORT bool operator==(
const Fence & a,
const Fence & b
);
|
Updated on 2026-03-31 at 00:02:07 +0000