# vkCmdSetStencilOp(3) Manual Page

## Name

vkCmdSetStencilOp - Set stencil operation dynamically for a command buffer

Loading… please wait.

## C Specification

To dynamically set the stencil operation, call:

    // Provided by VK_VERSION_1_3
    void vkCmdSetStencilOp(
        VkCommandBuffer                             commandBuffer,
        VkStencilFaceFlags                          faceMask,
        VkStencilOp                                 failOp,
        VkStencilOp                                 passOp,
        VkStencilOp                                 depthFailOp,
        VkCompareOp                                 compareOp);

or the equivalent command

    // Provided by VK_EXT_extended_dynamic_state, VK_EXT_shader_object
    void vkCmdSetStencilOpEXT(
        VkCommandBuffer                             commandBuffer,
        VkStencilFaceFlags                          faceMask,
        VkStencilOp                                 failOp,
        VkStencilOp                                 passOp,
        VkStencilOp                                 depthFailOp,
        VkCompareOp                                 compareOp);

## Parameters

- `commandBuffer` is the command buffer into which the command will be recorded.

- `faceMask` is a bitmask of VkStencilFaceFlagBits specifying the set of stencil state for which to update the stencil operation.

- `failOp` is a VkStencilOp value specifying the action performed on samples that fail the stencil test.

- `passOp` is a VkStencilOp value specifying the action performed on samples that pass both the depth and stencil tests.

- `depthFailOp` is a VkStencilOp value specifying the action performed on samples that pass the stencil test and fail the depth test.

- `compareOp` is a VkCompareOp value specifying the comparison operator used in the stencil test.

## Description

This command sets the stencil operation for subsequent drawing commands when when drawing using shader objects, or when the graphics pipeline is created with `VK_DYNAMIC_STATE_STENCIL_OP` set in VkPipelineDynamicStateCreateInfo::`pDynamicStates`. Otherwise, this state is specified by the corresponding `VkPipelineDepthStencilStateCreateInfo`::`failOp`, `passOp`, `depthFailOp`, and `compareOp` values used to create the currently active pipeline, for both front and back faces.

Valid Usage

- VUID-vkCmdSetStencilOp-None-08971
  At least one of the following must be true:

  - the `extendedDynamicState` feature is enabled

  - the `shaderObject` feature is enabled

  - the value of VkApplicationInfo::`apiVersion` used to create the VkInstance parent of `commandBuffer` is greater than or equal to Version 1.3

Valid Usage (Implicit)

- VUID-vkCmdSetStencilOp-commandBuffer-parameter
  `commandBuffer` must be a valid VkCommandBuffer handle

- VUID-vkCmdSetStencilOp-faceMask-parameter
  `faceMask` must be a valid combination of VkStencilFaceFlagBits values

- VUID-vkCmdSetStencilOp-faceMask-requiredbitmask
  `faceMask` must not be `0`

- VUID-vkCmdSetStencilOp-failOp-parameter
  `failOp` must be a valid VkStencilOp value

- VUID-vkCmdSetStencilOp-passOp-parameter
  `passOp` must be a valid VkStencilOp value

- VUID-vkCmdSetStencilOp-depthFailOp-parameter
  `depthFailOp` must be a valid VkStencilOp value

- VUID-vkCmdSetStencilOp-compareOp-parameter
  `compareOp` must be a valid VkCompareOp value

- VUID-vkCmdSetStencilOp-commandBuffer-recording
  `commandBuffer` must be in the recording state

- VUID-vkCmdSetStencilOp-commandBuffer-cmdpool
  The `VkCommandPool` that `commandBuffer` was allocated from must support graphics operations

- VUID-vkCmdSetStencilOp-videocoding
  This command must only be called outside of a video coding scope

Host Synchronization

- Host access to `commandBuffer` must be externally synchronized

- Host access to the `VkCommandPool` that `commandBuffer` was allocated from must be externally synchronized

Command Properties

Command Buffer Levels | Render Pass Scope | Video Coding Scope | Supported Queue Types | Command Type
--- | --- | --- | --- | ---
Primary Secondary | Both | Outside | Graphics | State

## See Also

VK_EXT_extended_dynamic_state, VK_EXT_shader_object, VK_VERSION_1_3, VkCommandBuffer, VkCompareOp, VkStencilFaceFlags, VkStencilOp

## Document Notes

For more information, see the Vulkan Specification

This page is extracted from the Vulkan Specification. Fixes and changes should be made to the Specification, not directly.

## Copyright

Copyright 2014-2024 The Khronos Group Inc.

SPDX-License-Identifier: CC-BY-4.0