---
title: MTLStencilDescriptor
framework: metal
role: symbol
role_heading: Class
path: metal/mtlstencildescriptor
---

# MTLStencilDescriptor

An object that defines the front-facing or back-facing stencil operations of a depth and stencil state object.

## Declaration

```swift
class MTLStencilDescriptor
```

## Overview

Overview A stencil test is a comparison between a masked reference value and a masked value stored in a stencil attachment. (A value is masked by performing a logical AND operation on it with the readMask value.) The MTLStencilDescriptor object defines how to update the contents of the stencil attachment, based on the results of the stencil test and the depth test. The stencilCompareFunction property defines the stencil test. The stencilFailureOperation, depthFailureOperation, and depthStencilPassOperation properties specify what to do to a stencil value stored in the stencil attachment for three different test outcomes: if the stencil test fails, if the stencil test passes and the depth test fails, or if both stencil and depth tests succeed, respectively. writeMask determines which stencil bits can be modified as the result of a stencil operation.

## Topics

### Configuring stencil functions and operations

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

### Configuring stencil bit mask properties

- [readMask](metal/mtlstencildescriptor/readmask.md)
- [writeMask](metal/mtlstencildescriptor/writemask.md)

## Relationships

### Inherits From

- [NSObject](objectivec/nsobject-swift.class.md)

### Conforms To

- [CVarArg](swift/cvararg.md)
- [CustomDebugStringConvertible](swift/customdebugstringconvertible.md)
- [CustomStringConvertible](swift/customstringconvertible.md)
- [Equatable](swift/equatable.md)
- [Hashable](swift/hashable.md)
- [NSCopying](foundation/nscopying.md)
- [NSObjectProtocol](objectivec/nsobjectprotocol.md)

## See Also

### Depth testing

- [Calculating primitive visibility using depth testing](metal/calculating-primitive-visibility-using-depth-testing.md)
- [MTLDepthStencilState](metal/mtldepthstencilstate.md)
- [MTLDepthStencilDescriptor](metal/mtldepthstencildescriptor.md)
