Lifetime helpers for asynchronous WebGPU callback userdata.
More...
#include <memory>
#include <utility>
#include <webgpu/webgpu.hpp>
|
| 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, centralizing the wgpu-native vs emdawnwebgpu callback-signature difference (emdawnwebgpu's WGPUQueueWorkDoneCallback carries an extra WGPUStringView message parameter) and the AllowSpontaneous callback mode both consumers use. State must expose onWorkDone(), which runs exactly once when the queue drains (driven by device.poll(...) on native and by Asyncify-yielding poll on Emscripten).
|
Lifetime helpers for asynchronous WebGPU callback userdata.
◆ 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, centralizing the wgpu-native vs emdawnwebgpu callback-signature difference (emdawnwebgpu's WGPUQueueWorkDoneCallback carries an extra WGPUStringView message parameter) and the AllowSpontaneous callback mode both consumers use. State must expose onWorkDone(), which runs exactly once when the queue drains (driven by device.poll(...) on native and by Asyncify-yielding poll on Emscripten).
- Parameters
-
| queue | Queue whose currently-submitted work is observed. |
| state | Shared 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. The callback owns the returned userdata until it calls takeWgpuCallbackState, so releasing the initiating frame cannot leave WebGPU with a dangling pointer.
- Parameters
-
| state | Shared 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
-
| userdata | Opaque userdata returned by retainWgpuCallbackState. |
- Returns
- Shared callback state owned by the callback invocation.