Take direct control of memory allocation for texture data by using sparse textures.
When you create a texture, by default, Metal allocates memory to hold the texture's pixel data. In some cases, such as when you are implementing texture streaming, you generally use only a fraction of this memory. When you use sparse textures, you take ownership of memory management for texture data and decide when to allocate and deallocate memory for a texture. In this way, sparse textures help you to use memory more efficiently.
To use sparse textures, allocate a sparse heap from which to allocate memory, and then create sparse textures from this heap. Initially, a texture has no storage. To add storage to a region inside the texture, ask the GPU to map memory from the heap for that region. A memory allocation is called a sparse tile (not to be confused with the tiles used in tile-based rendering). Sparse tiles are conceptually similar to virtual memory pages. When you don't need a region to have storage, you can unmap its sparse tile and recover that memory.
Because sparse textures work closely with texture mipmaps, you should be familiar with mipmaps before using sparse textures. For more information, see Improving Filtering Quality and Sampling Performance.
Check for Sparse Texture Support
Not all GPUs support sparse textures. Check for support on the device object before attempting to use sparse textures: