<!--
{
  "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/MTLStencilOperation",
  "metadataVersion" : "0.1.0",
  "role" : "Enumeration",
  "symbol" : {
    "kind" : "Enumeration",
    "modules" : [
      "Metal"
    ],
    "preciseIdentifier" : "c:@E@MTLStencilOperation"
  },
  "title" : "MTLStencilOperation"
}
-->

# MTLStencilOperation

The operation performed on a currently stored stencil value when a comparison test passes or fails.

```
enum MTLStencilOperation
```

## Topics

### Stencil operations

[`MTLStencilOperationKeep`](/documentation/Metal/MTLStencilOperation/keep)

A stencil operation that doesn’t modify a stencil value.

[`MTLStencilOperationZero`](/documentation/Metal/MTLStencilOperation/zero)

A stencil operation that sets a stencil value to zero.

[`MTLStencilOperationReplace`](/documentation/Metal/MTLStencilOperation/replace)

A stencil operation that replaces a stencil value with a reference value.

[`MTLStencilOperationIncrementClamp`](/documentation/Metal/MTLStencilOperation/incrementClamp)

A stencil operation that increases a stencil value by one, but only when
the current value isn’t the maximum representable value.

[`MTLStencilOperationDecrementClamp`](/documentation/Metal/MTLStencilOperation/decrementClamp)

A stencil operation that decreases a nonzero stencil value by one.

[`MTLStencilOperationInvert`](/documentation/Metal/MTLStencilOperation/invert)

A stencil operation that applies a logical bitwise NOT to a stencil value.

[`MTLStencilOperationIncrementWrap`](/documentation/Metal/MTLStencilOperation/incrementWrap)

A stencil operation that decreases a nonzero stencil value by one,
or when it’s the maximum representable value, resets it to zero.

[`MTLStencilOperationDecrementWrap`](/documentation/Metal/MTLStencilOperation/decrementWrap)

A stencil operation that decreases a nonzero stencil value by one,
or when it’s zero, resets it to the maximum representable value.

## Relationships

### Conforms To

[`Sendable`](/documentation/Swift/Sendable)

[`SendableMetatype`](/documentation/Swift/SendableMetatype)

[`Hashable`](/documentation/Swift/Hashable)

[`Equatable`](/documentation/Swift/Equatable)

[`BitwiseCopyable`](/documentation/Swift/BitwiseCopyable)

[`RawRepresentable`](/documentation/Swift/RawRepresentable)

---

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)