Donner SVG 0.8.0
0.8.0 ยท ebf353960.8.0 main
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
GeodeCallbackState.h File Reference

Lifetime helpers for asynchronous WebGPU callback userdata. More...

#include <memory>
#include <utility>
#include <webgpu/webgpu.hpp>
Include dependency graph for GeodeCallbackState.h:

Namespaces

namespace  donner
 Top-level Donner namespace, which is split into different sub-namespaces such as donner::svg and donner::css.

Functions

template<typename State>
void * donner::geode::retainWgpuCallbackState (const std::shared_ptr< State > &state)
 Retains callback state independently of the initiating stack frame.
template<typename State>
std::shared_ptr< State > donner::geode::takeWgpuCallbackState (void *userdata)
 Transfers ownership retained by retainWgpuCallbackState into the callback.
template<typename State>
void donner::geode::notifyWhenSubmittedWorkDone (const wgpu::Queue &queue, const std::shared_ptr< State > &state)
 Registers a submitted-work-done callback for all work currently submitted to queue, in the AllowSpontaneous callback mode. State must expose onWorkDone(), which runs exactly once when the queue drains, typically during a device.poll(...) (it may also run on submit or during another thread's poll), on whichever thread drives the queue at that point.

Detailed Description

Lifetime helpers for asynchronous WebGPU callback userdata.

Function Documentation

◆ notifyWhenSubmittedWorkDone()

template<typename State>
void donner::geode::notifyWhenSubmittedWorkDone ( const wgpu::Queue & queue,
const std::shared_ptr< State > & state )

Registers a submitted-work-done callback for all work currently submitted to queue, in the AllowSpontaneous callback mode. State must expose onWorkDone(), which runs exactly once when the queue drains, typically during a device.poll(...) (it may also run on submit or during another thread's poll), on whichever thread drives the queue at that point.

Parameters
queueQueue whose currently-submitted work is observed.
stateShared callback state; retained until the callback runs.

◆ retainWgpuCallbackState()

template<typename State>
void * donner::geode::retainWgpuCallbackState ( const std::shared_ptr< State > & state)

Retains callback state independently of the initiating stack frame.

WebGPU callbacks may run after a bounded wait returns, and on another thread. The callback owns the returned userdata until it calls takeWgpuCallbackState, so releasing the initiating frame cannot leave WebGPU with a dangling pointer.

Parameters
stateShared callback state to retain.
Returns
Opaque userdata owned by the eventual callback.

◆ takeWgpuCallbackState()

template<typename State>
std::shared_ptr< State > donner::geode::takeWgpuCallbackState ( void * userdata)

Transfers ownership retained by retainWgpuCallbackState into the callback.

Parameters
userdataOpaque userdata returned by retainWgpuCallbackState.
Returns
Shared callback state owned by the callback invocation.