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

Document-scoped cache of unique glyph outlines and their GPU residence. More...

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

Public Member Functions

 GeodeGlyphCache (uint64_t deviceId, std::shared_ptr< GeodeDocumentGeometryBudget > budget=nullptr)
 Create an empty cache bound to deviceId.
 GeodeGlyphCache (const GeodeGlyphCache &)=delete
GeodeGlyphCache & operator= (const GeodeGlyphCache &)=delete
uint64_t owningDeviceId () const
 Device this cache's residence was built on.
GeodeGlyphResidentEntry * find (const GlyphGeometryKey &key)
 Look up key, returning null on a miss. Does not mark the entry used; the caller does that once it commits to drawing.
GeodeGlyphResidentEntry * insert (const GlyphGeometryKey &key, Path &&outline, EncodedPath &&encoded)
 Insert an entry for key, taking ownership of outline and its encode. The returned address is stable for the entry's lifetime.
GeodeGlyphResidentEntry * insertWithinBudget (const GlyphGeometryKey &key, Path &&outline, EncodedPath &&encoded, uint64_t oldestOpenFrame, size_t maxEntries, uint64_t maxRetainedBytes, size_t *evictedOut=nullptr)
 Insert through the per-cache entry/byte envelope after evicting entries old enough to be safe. The family reservation in insert remains the aggregate cross-document admission gate. Closes admission for the rest of the frame when eviction cannot make room.
bool admissionOpen () const
 Whether this frame may still add entries. See closeAdmission.
void closeAdmission ()
 Stop admitting entries until the next beginFrame. Called once an eviction pass leaves only entries an open frame still uses: nothing more can be evicted this frame, so every further admission would rescan the whole cache and fail.
size_t size () const
 Number of live entries.
uint64_t encodedBytes () const
 Summed GeodeGlyphResidentEntry::encodedBytes over live entries.
uint64_t retainedBytes () const
 Total CPU bytes retained by cached entries, outlines, and encodes.
size_t beginFrame (uint64_t frameIndex, uint64_t oldestOpenFrame, size_t maxEntries, uint64_t maxRetainedBytes)
 Trim to budget at most once per frame. The frame-index guard makes the call idempotent no matter how many times a frame touches the cache, so the caller can put it on the accessor and cover every draw entry point. Returns the number of entries dropped.
size_t evictToBudget (uint64_t oldestOpenFrame, size_t maxEntries, uint64_t maxRetainedBytes)
 Drop entries until the cache fits the budget, oldest-unused first.

Static Public Attributes

static constexpr uint64_t kDefaultMaxRetainedBytes = 8u << 20
 Default cap on summed retained entry bytes. The entry count is capped by the renderer's glyph cap; this cap bounds a document that animates font-size continuously, where every frame mints new keys.
static constexpr uint64_t kEntryOverheadBytes
 Bytes one entry retains besides its outline and encode vectors: the entry, and the map node holding its key, owning pointer, cached hash, and bucket link. Charging it keeps entries with empty outlines inside the byte cap.

Detailed Description

Document-scoped cache of unique glyph outlines and their GPU residence.

Bound to one device exactly like GeodeResidentSlab: a document rendered by several devices keeps one cache per device, so no entry can hand one device's buffer or bind group to another device's render pass.

Eviction is generation-based rather than strictly ordered: entries carry the frame index of their last use, and when the cache is over budget the oldest unused entries are dropped first. Dropping an entry destroys its GeodeResidentSlot, which returns the slab range through the slab's deferred free list, so the range only becomes reusable at the NEXT frame's merge - never inside the frame whose recorded draws still reference it. Entries used in the current frame are never candidates for the same reason.

Not thread-safe; the renderer serializes one frame per device at a time.

Member Function Documentation

◆ evictToBudget()

size_t donner::geode::GeodeGlyphCache::evictToBudget ( uint64_t oldestOpenFrame,
size_t maxEntries,
uint64_t maxRetainedBytes )
inline

Drop entries until the cache fits the budget, oldest-unused first.

An entry last used at or after oldestOpenFrame is never dropped: some frame that touched it has not submitted, its recorded draws still read that geometry, and dropping the entry would return the slab range for a later allocation to overwrite. oldestOpenFrame is device-scoped, so an offscreen pass nested inside an outer frame cannot free the outer frame's geometry out from under it. Returns the number of entries dropped.

Member Data Documentation

◆ kEntryOverheadBytes

uint64_t donner::geode::GeodeGlyphCache::kEntryOverheadBytes
staticconstexpr
Initial value:
=
sizeof(GeodeGlyphResidentEntry) + sizeof(GlyphGeometryKey) + 4u * sizeof(void*)
One unique glyph outline: the CPU outline, its analytic encode, and its GPU residence.
Definition GeodeGlyphResidency.h:139
Identity of one unique glyph outline: every input that can change the encoded geometry,...
Definition GeodeGlyphResidency.h:68

Bytes one entry retains besides its outline and encode vectors: the entry, and the map node holding its key, owning pointer, cached hash, and bucket link. Charging it keeps entries with empty outlines inside the byte cap.


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