Skip to content

KDGpu::GpuSemaphore

Module: Public API

GPU-to-GPU synchronization primitive for command buffer dependencies. More...

#include <KDGpu/gpu_semaphore.h>

Public Functions

Name
GpuSemaphore()
~GpuSemaphore()
GpuSemaphore(GpuSemaphore && other)
GpuSemaphore & operator=(GpuSemaphore && other)
GpuSemaphore(const GpuSemaphore & ) =delete
GpuSemaphore & operator=(const GpuSemaphore & ) =delete
const Handle< GpuSemaphore_t > & handle() const
bool isValid() const
operator Handle< GpuSemaphore_t >() const
HandleOrFD externalSemaphoreHandle() const

Friends

Name
class Device

Detailed Description

1
class KDGpu::GpuSemaphore;

GPU-to-GPU synchronization primitive for command buffer dependencies.

Vulkan equivalent:VkSemaphore

GpuSemaphore synchronizes GPU operations without CPU involvement. Unlike Fence (which synchronizes CPU and GPU), semaphores coordinate work between queue submissions and swapchain operations.

Key features:

  • GPU-only synchronization (no CPU waiting)
  • Signal/wait between queue submissions
  • Swapchain image acquisition and presentation
  • Cross-queue synchronization

Lifetime: Semaphores are created by Device and must remain valid while GPU operations reference them. They use RAII and clean up automatically.

Usage

Basic semaphore usage:

1
    KDGpu::GpuSemaphore semaphore = device.createGpuSemaphore();

Filename: kdgpu_doc_snippets.cpp

Queue synchronization:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
    // Submit compute work, signal semaphore when done
    computeQueue.submit(KDGpu::SubmitOptions{
            .commandBuffers = { computeCommands },
            .signalSemaphores = { semaphore },
    });

    // Wait for compute before starting graphics
    graphicsQueue.submit(KDGpu::SubmitOptions{
            .commandBuffers = { graphicsCommands },
            .waitSemaphores = { semaphore },
    });

Filename: kdgpu_doc_snippets.cpp

Chaining multiple operations:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
    uint32_t imageIndex;
    // getNextImageIndex will signal imageAvailableSemaphore
    KDGpu::AcquireImageResult result = swapchain.getNextImageIndex(imageIndex, imageAvailableSemaphore);

    graphicsQueue.submit(KDGpu::SubmitOptions{
            .commandBuffers = { graphicsCommands },
            .waitSemaphores = { imageAvailableSemaphore }, // awaits imageAvailableSemaphore
            .signalSemaphores = { renderCompleteSemaphore }, // signals renderCompleteSemaphore
    });

    graphicsQueue.present(KDGpu::PresentOptions{
            .waitSemaphores = { renderCompleteSemaphore }, // awaits renderCompleteSemaphore
            .swapchainInfos = {
                    {
                            .swapchain = swapchain,
                            .imageIndex = imageIndex,
                    },
            },
    });

Filename: kdgpu_doc_snippets.cpp

Multi-queue pipeline:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
    KDGpu::GpuSemaphore geometryDone = device.createGpuSemaphore();
    KDGpu::GpuSemaphore shadingDone = device.createGpuSemaphore();

    // Geometry processing on compute queue
    computeQueue.submit(KDGpu::SubmitOptions{
            .commandBuffers = { geometryCommands },
            .signalSemaphores = { geometryDone },
    });

    // Shading on graphics queue, waits for geometry
    graphicsQueue.submit(KDGpu::SubmitOptions{
            .commandBuffers = { shadingCommands },
            .waitSemaphores = { geometryDone },
            .signalSemaphores = { shadingDone },
    });

    // Post-processing, waits for shading
    graphicsQueue.submit(KDGpu::SubmitOptions{
            .commandBuffers = { postProcessCommands },
            .waitSemaphores = { shadingDone },
    });

Filename: kdgpu_doc_snippets.cpp

Vulkan mapping:

  • GpuSemaphore creation -> vkCreateSemaphore()
  • Used in vkQueueSubmit() wait/signal arrays
  • Used in vkAcquireNextImageKHR()
  • Used in vkQueuePresentKHR()

See also:

GpuSemaphoreOptions, Fence, Queue, Swapchain, Device

KDGpu API Overview

KDGpu to Vulkan API Mapping

Public Functions Documentation

function GpuSemaphore

1
GpuSemaphore()

function ~GpuSemaphore

1
~GpuSemaphore()

function GpuSemaphore

1
2
3
GpuSemaphore(
    GpuSemaphore && other
)

function operator=

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

function GpuSemaphore

1
2
3
GpuSemaphore(
    const GpuSemaphore & 
) =delete

function operator=

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

function handle

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

function isValid

1
inline bool isValid() const

function operator Handle< GpuSemaphore_t >

1
inline operator Handle< GpuSemaphore_t >() const

function externalSemaphoreHandle

1
HandleOrFD externalSemaphoreHandle() const

Friends

friend Device

1
2
3
friend class Device(
    Device 
);

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