Clear stencil attachment ignores the stencil write mask

In opengl it is possible to clear some bits in the stencil buffer and keep other bits unchanged when I call

glStencilMask(mask ); before 

In Vulkan when I have a stencil buffer with some pixels = 0x80
and call

vkCmdSetStencilWriteMask with a mask = 0x7f 
vkCmdClearAttachment with clearvalue = 0,

then each bit will be cleared to 0. It seems, that the stencil write mask is ignored.

The last bounded pipeline has VK_DYNAMIC_STATE_STENCIL_WRITE_MASK enabled, but
I’m not sure, that vkCmdSetStencilWriteMask works only for draw commands or also for vkCmdClearAttachment.

Is it possible to clear only specified bits in the stencil buffer in Vulkan similarly to opengl, without a draw command ?

While the specification says that vkCmdClearAttachment is treated as a drawing command, that doesn’t mean it cares about the currently bound pipeline. It doesn’t:

The vkCmdClearAttachments command is not affected by the bound pipeline state.

And it is that pipeline state that does things like write masks.

In Vulkan, a clear command is a command that sets memory to a given value. If you want to do graphics pipeline operations (like stencil masking), then what you want is a rendering command, not a clearing command.

So you’re going to need to render something.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.