---
title: stencilCompareFunction
framework: metal
role: symbol
role_heading: Instance Property
path: metal/mtlstencildescriptor/stencilcomparefunction
---

# stencilCompareFunction

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

## Declaration

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

## Discussion

Discussion For example, if stencilCompareFunction is 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, 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 value before the comparison takes place. For more information on possible values, see MTLCompareFunction.

## See Also

### Related Documentation

- [setStencilReferenceValue(_:)](metal/mtlrendercommandencoder/setstencilreferencevalue(_:).md)

### Configuring stencil functions and operations

- [stencilFailureOperation](metal/mtlstencildescriptor/stencilfailureoperation.md)
- [depthFailureOperation](metal/mtlstencildescriptor/depthfailureoperation.md)
- [depthStencilPassOperation](metal/mtlstencildescriptor/depthstencilpassoperation.md)
- [MTLStencilOperation](metal/mtlstenciloperation.md)
