takeMemoryReport function Assets and loading

MemoryReport takeMemoryReport()

Takes a MemoryReport of what the engine's shared caches are holding.

Cheap enough to poll (it walks the cache maps and reads each texture's reflected size), so it is reasonable to surface in a debug overlay.

Implementation

MemoryReport takeMemoryReport() {
  final textures = textureCacheFootprint();
  return MemoryReport([
    MemoryCategory(
      name: 'textures',
      bytes: textures.bytes,
      count: textures.count,
    ),
    // The render graph's transient attachments, across every live surface.
    // Counted by surface rather than by texture. The pool keys a ring per
    // attachment shape, so a texture count would say more about the shapes a
    // frame happened to need than about anything an app can act on.
    MemoryCategory(
      name: 'render targets',
      bytes: Surface.liveTransientBytes,
      count: Surface.liveCount,
    ),
    // A template's footprint is spread across the geometry, materials, and
    // textures it realized, which are not individually measurable from here
    // yet, so only the count is reported.
    MemoryCategory(
      name: 'scene templates',
      bytes: null,
      count: sceneTemplateCacheCount(),
    ),
  ]);
}