/** * Cross-mesh decoded-chunk cache arbitration. * * Every {@link StreamedSplatMesh} caps its own decoded-chunk cache, and in * `foveationMode: 'page-table'` that cap is `min(2 GiB, this capture's decoded * size)` - a number sized for *one* streamed scene. A scene of streamed additional meshes * therefore has no ceiling at all: thirteen extras plus a main are thirteen * plus one independent caps, and because each is sized to its own capture, a * desktop that fits them never evicts. The background sweep then runs to * completion against every one of them, pulling every capture in the scene into * RAM and keeping it there. * * This is the missing ceiling, at whole-mesh granularity: one budget shared by * every streamed mesh in a scene (the same sharing model as `SplatPool` and * {@link ChunkFetchScheduler}), splitting a scene total by the same * camera-projected weight a `CameraBudgetGovernor` already computes for drawing. * * It bounds **retention**, not prefetching. The sweep still runs and still warms * the cache; it simply stops at an allowance the whole scene agreed on rather * than at the size of each capture. A mesh the camera approaches gets a larger * allowance and resumes sweeping; one it leaves gives bytes back. * * The budget brokers **bytes**, never chunks: it does not know about * `ChunkLoader`, chunk ids or workers, which is what keeps the eviction policy * where it belongs - inside the frontier worker, which is the only place that * knows what the current cut still needs. */ /** A streamed mesh, as the cache budget sees it. */ export interface ChunkCacheClient { /** * This mesh's camera-projected weight - larger means more of the cache. * * Read on demand rather than pushed, so the budget never holds a stale * weight; a `CameraBudgetGovernor.weightOf` call is the intended source, and * is the same one {@link ChunkFetchScheduler} reads. Zero (hidden or * suspended) still keeps `perMeshFloorBytes`: a mesh whose coarse base has * been evicted draws nothing at all when the camera comes back to it. */ weight(): number; /** * The most this mesh could ever put to use - for a page-table mesh, * `min(PAGETABLE_CACHE_FLOOR_BYTES, estimateSceneDecodedBytes(scene))`. * * Bytes above it are handed to siblings that can use them, the way * `BudgetGovernor` waterfills past a member's `maxBudget`. Without it a scene * of one large capture and a dozen small additional meshes would reserve most of the * envelope for extras that cannot fill it. */ readonly ceilingBytes: number; /** * This mesh's allowance moved. The mesh forwards it to its frontier worker; * nothing is dropped synchronously, because only the worker's own eviction * pass knows which chunks the current cut still needs. */ onAllowanceChanged(bytes: number): void; } /** Options for {@link ChunkCacheBudget}. */ export interface ChunkCacheBudgetOptions { /** * Decoded-chunk bytes every registered mesh may hold **in total**. * * This is the number that decides whether the budget helps at all. Too low * and the focused mesh re-fetches chunks it just evicted; too high and it is * inert, because each mesh's own `ceilingBytes` becomes binding again. Size * it against the tab's heap, not against any one capture. */ totalBytes: number; /** * Bytes each mesh keeps regardless of weight. Default 32 MiB, matching * `resolveCpuCacheBytes`'s own minimum. * * Without a floor a far mesh evicts its own coarse base and re-fetches it on * the next reschedule, forever - the same thrash {@link * ChunkFetchScheduler.perMeshFloor} exists to prevent on the network side. */ perMeshFloorBytes?: number; /** * Minimum ms between weight-driven reallocations. Default 250, matching the * idle reschedule interval - there is no point re-splitting faster than the * meshes can act on it. Membership changes bypass it. */ minIntervalMs?: number; /** * Relative change from the last delivered allowance. Default 0.15. * Shares remain unchanged until any share crosses this threshold; then all * changed shares are delivered, decreases first. Membership and total-budget * changes bypass it. * * Every notification is a worker post and, indirectly, an eviction pass. A * camera drifting slowly would otherwise repost a 1% different number every * quarter second for no change in behaviour. */ deadband?: number; } /** * A mesh's registration. Opaque to callers: hold it from {@link * ChunkCacheBudget.register} and pass it back to read the allowance or * unregister. */ export interface ChunkCacheHandle { readonly client: ChunkCacheClient; } /** See the module comment. Construct one per scene and pass it to every mesh. */ export declare class ChunkCacheBudget { private readonly entries; private readonly perMeshFloorBytes; private readonly minIntervalMs; private readonly deadband; private totalBytesValue; private lastAllocationMs; private disposed; constructor(options: ChunkCacheBudgetOptions); /** Bytes shared across every registered mesh. */ get totalBytes(): number; /** * Resizes the scene envelope and re-splits immediately. For a host reacting * to a quality change or a device-memory signal. */ setTotalBytes(bytes: number): void; /** Meshes currently registered. */ get clientCount(): number; /** * Adds a mesh and re-splits at once, so the caller can read its opening * allowance out of {@link allowanceFor} before posting worker init. */ register(client: ChunkCacheClient): ChunkCacheHandle; /** Drops a mesh and hands its bytes back to the siblings. */ unregister(handle: ChunkCacheHandle): void; /** This mesh's current allowance in bytes, or 0 once unregistered. */ allowanceFor(handle: ChunkCacheHandle): number; /** * Re-splits after the camera moved. Call it once per frame, right beside * {@link ChunkFetchScheduler.weightsChanged} - the two read the same weights, * so cache and network follow the same measure. * * Rate-limited and dead-banded; calling it every frame is the intended use. */ weightsChanged(now?: number): void; /** * Releases every registration. Meshes are not disposed - the budget is shared * and does not own them, exactly as a shared `SplatPool` does not own its * meshes. */ dispose(): void; /** * Cap-aware waterfill: weight-proportional shares, floored so every mesh can * hold its coarse base, clamped at each mesh's `ceilingBytes`, and the surplus * from clamped meshes redistributed over the rest until it settles. * * The invariant callers depend on is `Σ allowance <= totalBytes`. It holds in * every branch, including the degenerate one where the floors alone exceed * the envelope - there the floors are scaled down proportionally rather than * silently overcommitting, because a budget that can be exceeded by * registering more meshes is the bug this class exists to fix. */ private allocate; /** Suppresses reposts for changes too small to alter any mesh's behaviour. */ private movedEnough; }