-
Notifications
You must be signed in to change notification settings - Fork 1
Texture Data Cache
Texture data is stored in the GPU's VRAM. As such, for the CPU to be able to access it, it has to first download / upload it to / from RAM, which is a quite expensive operation. As such, Procedurline tries to cache texture data by default to speed up accesses. However, naively caching all data would result in quite a lot of memory usage, which can worsen the memory issues Celeste already faces on Windows.
Because of this, Celeste employs a cache eviction algorithm to try to determine which texture's data should be cached, and which shouldn't be. Texture data can be evicted on the fly when the space is needed for another texture.
The algorithm fundamentally tries to keep the total size of all cached textures below a maximum size. This maximum size is determined using the minimum of:
- a maximum size specified in a hidden settings options (256MB by default)
- the maximum amount of memory Celeste can use, minus the current amount of memory used plus some margin (configurable using a hidden settings option, 512MB by default)
An eviction sweep consists of the cache evictor going through all currently cached textures, ordered from least recently accessed to most recently accessed, and evicting textures from the cache one by one as long as the current total cache size exceeds the maximum size. These sweeps can be triggered by a variety of causes, including, but not limited to:
- texture data operations involving the cache
- level reloads / scene changes
- garbage collector generations
However, sometimes one wishes to force a TextureHandle
to cache its data. This can be accomplished by pinning the texture using TextureHandle.PinCache
, which obtains a TextureHandle.CachePinHandle
for the texture. As long as a pin handle is alive, the evictor will not evict the texture from the cache. The texture is still counted towards the total cache size though, as long as its size is below the maximum cache size. This last constraint is to prevent one big pinned texture causing the eviction of all other textures in the cache.