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

Buffers, bind groups and textures 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 Types

using TextureReleaseListener = std::function<void(const gpu::ResourceIdentity& texture)>
 Called on the releasing thread with each held texture's identity just before Release lets go of it.

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.
std::size_t retireTextures (std::vector< gpu::Texture > &textures)
 Takes every texture of this retirement's device in textures, leaving the others where they are, and removes null handles.
void setTextureReleaseListener (TextureReleaseListener listener, std::function< bool()> isLive)
 Have listener told of every texture Release lets go of, before it does, so state that holds views of the texture can drop them first.
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, bind groups and textures 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.
size_t textures = 0 Textures 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.

◆ retireTextures()

std::size_t donner::geode::GeodeHandleRetirement::retireTextures ( std::vector< gpu::Texture > & textures)
nodiscard

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

Parameters
texturesTextures to retire.
Returns
Number of textures left with the caller because another device owns them.

◆ setTextureReleaseListener()

void donner::geode::GeodeHandleRetirement::setTextureReleaseListener ( TextureReleaseListener listener,
std::function< bool()> isLive )

Have listener told of every texture Release lets go of, before it does, so state that holds views of the texture can drop them first.

There is one listener: the device's one live texture pool. A new listener may replace an earlier one only once that one reports itself gone (see isLive); replacing a live one is a programming error, asserted in debug builds. The listener runs on the thread calling Release, without this object's lock, and must not call back into this object.

Parameters
listenerCallback receiving each released texture's identity.
isLiveWhether listener's owner still exists; consulted when a later call replaces it.

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