What it does

Stencil Test compares stored screen-space markers to decide where drawing is allowed. Reference supplies the comparison value, ReadMask selects the relevant bits, and the comparison function defines the condition. Stencil write operations can update markers afterward.

Figure: Write one first, then compare against one in a later draw. Writer and reader states differ.
Figure: Write one first, then compare against one in a later draw. Writer and reader states differ.

How to use it

ReadMask selects the stored/reference bits compared by Comp. WriteMask instead selects bits that operations may update; these roles are different.

A concrete example

ReadMask one, reference one and Equal test the lowest bit. A reader that should not modify data needs the intended Keep/write-mask behavior.

How to check it

  1. Verify writer-before-reader order, shared stencil target and intervening clears.
    Testing and writing are separate settings
    Testing and writing are separate settings
  2. Allocate bits deliberately across masks and pipeline features to avoid overwriting unrelated state.
    Testing and writing are separate settings
    Testing and writing are separate settings

Limitations

Avoid collisions with other masks and pipeline-reserved bits.

References