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

# stencilCompareFunction

The comparison that is performed between the masked reference value and a masked value in the stencil attachment.

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

## Discussion

For example, if `stencilCompareFunction` is [`MTLCompareFunction.less`](/documentation/Metal/MTLCompareFunction/less), then the stencil test passes if the masked reference value is less than the masked stored stencil value. The default value is [`MTLCompareFunction.always`](/documentation/Metal/MTLCompareFunction/always), which indicates that the stencil test always passes.

The stored stencil value and the reference value are both *masked* by performing a logical AND operation with the [`readMask`](/documentation/Metal/MTLStencilDescriptor/readMask) value before the comparison takes place. For more information on possible values, see [`MTLCompareFunction`](/documentation/Metal/MTLCompareFunction).

## See Also

[`setStencilReferenceValue(_:)`](/documentation/Metal/MTLRenderCommandEncoder/setStencilReferenceValue(_:))

Configures the same comparison value for front- and back-facing primitives.



---

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)