<!--
{
  "availability" : [
    "iOS: 9.0.0 -",
    "iPadOS: 9.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.11.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Metal",
  "identifier" : "/documentation/Metal/MTLSamplerDescriptor/compareFunction",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Property",
  "symbol" : {
    "kind" : "Instance Property",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "c:objc(cs)MTLSamplerDescriptor(py)compareFunction"
  },
  "title" : "compareFunction"
}
-->

# compareFunction

The sampler comparison function used when performing a sample compare operation on a depth texture.

```
var compareFunction: MTLCompareFunction { get set }
```

## Discussion

The default value is [`MTLCompareFunction.never`](/documentation/Metal/MTLCompareFunction/never).

The [`MTLFeatureSet.iOS_GPUFamily3_v1`](/documentation/Metal/MTLFeatureSet/iOS_GPUFamily3_v1) and [`MTLFeatureSet.iOS_GPUFamily1_v1`](/documentation/Metal/MTLFeatureSet/iOS_GPUFamily1_v1) feature sets allow you to define a framework-side sampler comparison function for an [`MTLSamplerState`](/documentation/Metal/MTLSamplerState) instance.
All feature sets support shader-side sampler comparison functions, as described in the
[Metal Shading Language Specification](https://developer.apple.com/metal/Metal-Shading-Language-Specification.pdf).

---

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)