Donner SVG main
0.8.0 ยท 382bd0190.8.0 main
SVG editor and embeddable C⁠+⁠+⁠20 engine.
Loading...
Searching...
No Matches
donner::geode::GeodeHandleRetirement Class Reference

Buffers and bind groups of one runtime device that were let go of where that device may not be used, kept until the context rendering through the device releases them on its own thread. More...

#include "donner/svg/renderer/geode/GeodeHandleRetirement.h"

Classes

struct  HeldCounts
 Handles waiting to be released, by kind. Test accessor. More...

Public Member Functions

 GeodeHandleRetirement (uint64_t runtimeDeviceId)
 GeodeHandleRetirement (const GeodeHandleRetirement &)=delete
GeodeHandleRetirement & operator= (const GeodeHandleRetirement &)=delete
std::size_t retire (std::vector< gpu::Buffer > &buffers, std::vector< gpu::BindGroup > &bindGroups)
 Takes every handle of this retirement's device in buffers and bindGroups, leaving the others where they are, and removes null handles.
void setWakeCallback (std::function< void()> callback)
 Wake the owning event loop when another thread hands it work. The callback runs under this mailbox's lock and must only post a nonblocking wake; clearing it waits for any call to end.
bool hasPending () const
 Whether an owner-thread idle pass has handles to release.
void release ()
 Releases everything held. Call on the thread of the context rendering through the device.
void close ()
 Releases everything held and marks the context gone. Call from the context's teardown, while its runtime device still exists.
bool closed () const
 Whether the context has closed this retirement: nothing renders through its device any more, so state kept for that device can be dropped.
uint64_t runtimeDeviceId () const
 gpu::Device::deviceId() of the runtime device whose handles this retirement takes.
HeldCounts heldCountsForTesting () const
 Handles waiting to be released. Test accessor.

Detailed Description

Buffers and bind groups of one runtime device that were let go of where that device may not be used, kept until the context rendering through the device releases them on its own thread.

A runtime device is single-threaded: releasing a handle returns its slot to the device's tables, which the device's own thread may be using at the same moment. State a document keeps for a device can be destroyed on whichever thread holds the document at the time - another device's render worker, or the thread destroying the document - so it hands its handles here instead of dropping them.

Retiring is thread-safe and takes only handles of this retirement's device. Only the context releases, on its own thread. Closing, at the context's teardown, releases what is held and marks the context gone. Handles retired after that stay here until the context's own teardown releases them, while it still can, or until this object is destroyed.

Whoever owns the runtime device must keep this object alive until the device is gone, and no longer than it needs to: the handles still held when this object is destroyed are dropped then, and a handle whose device is gone releases nothing (see donner/gpu/Handles.h). That is what keeps a late retirement from releasing into a device another thread is tearing down.

For the first context over a root, that owner is the root's physical-device owner, which keeps the root device alive for later contexts. So when that context closes while others still render through the root, handles retired to it afterwards keep their GPU memory until the owner goes, although nothing renders through the root device any more. That is bounded by what the closed context built.


Class Documentation

◆ donner::geode::GeodeHandleRetirement::HeldCounts

struct donner::geode::GeodeHandleRetirement::HeldCounts

Handles waiting to be released, by kind. Test accessor.

Class Members
size_t bindGroups = 0 Bind groups held.
size_t buffers = 0 Buffers held.

Constructor & Destructor Documentation

◆ GeodeHandleRetirement()

donner::geode::GeodeHandleRetirement::GeodeHandleRetirement ( uint64_t runtimeDeviceId)
inlineexplicit
Parameters
runtimeDeviceIdgpu::Device::deviceId() of the runtime device whose handles this retirement takes.

Member Function Documentation

◆ retire()

std::size_t donner::geode::GeodeHandleRetirement::retire ( std::vector< gpu::Buffer > & buffers,
std::vector< gpu::BindGroup > & bindGroups )
nodiscard

Takes every handle of this retirement's device in buffers and bindGroups, leaving the others where they are, and removes null handles.

Parameters
buffersBuffers to retire.
bindGroupsBind groups to retire.
Returns
Number of handles left with the caller because another device owns them.

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