<!--
{
  "documentType" : "article",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/adding-mipmap-filtering-to-samplers",
  "metadataVersion" : "0.1.0",
  "role" : "article",
  "title" : "Adding mipmap filtering to samplers"
}
-->

# Adding mipmap filtering to samplers

Specify how the GPU samples mipmaps in your textures.

## Discussion

By default, samplers sample data only from mipmap `0`. If your texture contains more than one mipmap, and you want it to sample the lower-level mipmaps, you need to specify this behavior when you create the texture sampler.

### Create the sampler in your app

If you’re creating an [`MTLSamplerState`](/documentation/Metal/MTLSamplerState) instance, create the [`MTLSamplerDescriptor`](/documentation/Metal/MTLSamplerDescriptor) instance and set its [`mipFilter`](/documentation/Metal/MTLSamplerDescriptor/mipFilter) property. The following code uses linear filtering for the minification and magnification filter, and uses linear filtering for mipmaps. This combination is usually called *trilinear filtering*. With this configuration, the GPU chooses the two mipmaps nearest in size and generates a sample by linearly filtering four pixels from each mipmap. Then it blends those two values with a linear interpolation to generate the final sample.

```swift
let descriptor = MTLSamplerDescriptor()
descriptor.minFilter = MTLSamplerMinMagFilter.linear
descriptor.magFilter = MTLSamplerMinMagFilter.linear
descriptor.mipFilter = MTLSamplerMipFilter.linear

let sampler = device.makeSamplerState(descriptor: descriptor)
```

Alternatively, any of these filters could filter from the nearest pixel, instead of a linear filter, resulting in fewer sampled pixels but lower quality. Ultimately, you need to decide the right tradeoffs between sampling performance and quality for your app.

### Create the sampler in your shader

If you prefer to create samplers in your shader, specify the mipmap filtering there instead of in your app:

```metal
constexpr sampler s(filter::linear, mip_filter::linear)
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)