cesium-native icon indicating copy to clipboard operation
cesium-native copied to clipboard

Cache images across glTFs to avoid duplication

Open azrogers opened this issue 7 months ago • 8 comments

As described in #497, sometimes tilesets contain multiple tiles that point to the same image resources. At the moment, these images are loaded once for every tile that uses them, meaning a tileset with 1,000 tiles that use the same image will load that image 1,000 times (and the runtimes will allocate video memory for each of them). This change adds a SharedAssetDepot class that stores images across tiles, and a SharedAsset smart pointer type for tracking and cleaning up the images.

SharedAssetDepot is set up so that in the future, if we need, we can extend this feature to handle glTF buffers as well.

There's a few TODO items currently (besides the runtime implementations):

  • Every copy of the image is still counted towards memory used, making the metric inaccurate.
  • Currently, the SharedAsset contains either a pointer to a stored asset and counter, or it contains the asset itself if no SharedAssetDepot was provided. This means that the "smart pointer" is at least 96 bytes (the size of ImageCesium), even if it does contain a pointer, which is unacceptable. I'm not sure what to do about this, short of just requiring the use of a SharedAssetDepot - but this would increase the number of necessary code changes to other projects that use CesiumGltf besides the native runtimes.
  • The way I've laid out namespaces and usings in SharedAssetDepot.h is almost certainly not compatible with the style guide (I started it before the meeting) so I need to fix that.

azrogers avatar Jul 23 '24 18:07 azrogers