Donner SVG 0.8.0-pre
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
donner::gpu::Handle< Tag > Class Template Reference

Move-only RAII handle to a device resource. More...

#include "donner/gpu/Handles.h"

Public Member Functions

 Handle ()=default
 Constructs a null handle.
 ~Handle ()
 Destructor; releases the resource if this handle still owns it and the device is alive.
 Handle (const Handle &)=delete
Handleoperator= (const Handle &)=delete
 Handle (Handle &&other) noexcept
 Move constructor; other becomes null.
Handleoperator= (Handle &&other) noexcept
 Move assignment; releases the currently owned resource (if any), then takes ownership from other, which becomes null.
bool isValid () const
 Returns true if this handle is non-null. The device generation check is authoritative for whether the resource is still alive.
uint32_t slotIndex () const
 Resource table slot index, for backend use.
uint32_t generation () const
 Slot generation at creation time, for backend use. Zero for null handles.
uint64_t deviceId () const
 Identity of the owning device (see Device::deviceId()), for backend use. Zero for null handles.

Static Public Member Functions

static Handle CreateForBackend (uint32_t slotIndex, uint32_t generation, uint64_t deviceId, std::weak_ptr< Device * > deviceAlive={})
 Mints a live handle; called by device backends only.

Friends

bool operator== (const Handle &handle, std::nullptr_t)
 Compares against null: true if the handle is null.

Detailed Description

template<typename Tag>
class donner::gpu::Handle< Tag >

Move-only RAII handle to a device resource.

A handle carries a (slot, generation) pair plus the identity of the owning device. The device validates all three on every use, so a null handle, a stale handle (the resource was destroyed, possibly with its slot reused), or a handle from a different device fails closed with GpuErrorType::InvalidHandle / GpuErrorType::DeviceMismatch instead of reaching a backend. Validation runs in release builds too.

Destroying a live handle releases the resource through the owning device (see the file comment for the teardown-ordering contract). A default-constructed or moved-from handle is null (isValid() returns false) and releases nothing.

Template Parameters
TagTag type identifying the resource type; provides Tag::kName for diagnostics.

Constructor & Destructor Documentation

◆ Handle()

template<typename Tag>
donner::gpu::Handle< Tag >::Handle ( Handle< Tag > && other)
inlinenoexcept

Move constructor; other becomes null.

Parameters
otherHandle to move from.

Member Function Documentation

◆ CreateForBackend()

template<typename Tag>
Handle donner::gpu::Handle< Tag >::CreateForBackend ( uint32_t slotIndex,
uint32_t generation,
uint64_t deviceId,
std::weak_ptr< Device * > deviceAlive = {} )
inlinestatic

Mints a live handle; called by device backends only.

Parameters
slotIndexResource table slot index.
generationSlot generation at creation time; must be nonzero.
deviceIdIdentity of the owning device.
deviceAliveDevice-alive token (see Device); when empty, the handle is inert - its destructor never self-releases. Device always supplies the token; the empty default exists for handle-shape unit tests that have no device.

◆ operator=()

template<typename Tag>
Handle & donner::gpu::Handle< Tag >::operator= ( Handle< Tag > && other)
inlinenoexcept

Move assignment; releases the currently owned resource (if any), then takes ownership from other, which becomes null.

Parameters
otherHandle to move from.

◆ operator==

template<typename Tag>
bool operator== ( const Handle< Tag > & handle,
std::nullptr_t  )
friend

Compares against null: true if the handle is null.

Parameters
handleHandle to test.

The documentation for this class was generated from the following file: