<!--
{
  "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

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

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

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

A stencil operation that sets a stencil value to zero.

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

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

[`MTLStencilOperation.incrementClamp`](/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.

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

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

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

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

[`MTLStencilOperation.incrementWrap`](/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.

[`MTLStencilOperation.decrementWrap`](/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.



---

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)