Textures
Create and manage typed data your app uses to exchange information with its shader functions.
Overview
MTLTexture instances can serve as input and output resources to shader functions, as well as render pass destinations, or render attachments. Unlike buffers, textures define the underlying pixel type and structure. Textures can:
Store 1-, 2-, or 3-dimensional data
Contain several faces or layers
Work as an array of texture data
Apps typically use textures to render details onto the surfaces in a scene or a 3D model. You can also use textures for post-processing pipelines, such as adding an advanced visual effect to an image before presenting it to a display.
Although textures can consume large amounts of memory, they also offer strategies, such as texture compression, that can save storage and memory bandwidth. Apple silicon GPUs support memoryless textures for transient render attachments that only need to exist for the duration of a render pass.
Topics
Texture basics
Understanding color-renderable pixel format sizesOptimizing texture dataMTLTextureMTLTextureCompressionTypeMTLTextureDescriptorMTKTextureLoaderMTLSharedTextureHandleMTLPixelFormat
Texture samplers
Creating and sampling texturesMTLSamplerStateMTLSamplerDescriptorMTLSamplePositionMTLSamplerReductionMode
Texture mipmapping
Improving texture sampling quality and performance with mipmapsCreating a mipmapped textureCopying data into or out of mipmapsGenerating mipmap dataAdding mipmap filtering to samplersRestricting access to specific mipmapsPredicting which mips the GPU samples with level-of-detail queriesDynamically adjusting texture level of detail
Sparse textures
Managing sparse texture memoryCreating sparse heaps and sparse texturesConverting between pixel regions and sparse tile regionsAssigning memory to sparse texturesReading and writing to sparse texturesEstimating how often a texture region is accessedMTLResourceStatePassDescriptorMTLResourceStatePassSampleBufferAttachmentDescriptorMTLResourceStatePassSampleBufferAttachmentDescriptorArrayMTLResourceStateCommandEncoderMTLMapIndirectArguments