Home

depthStencil

DepthStencil, in computer graphics, refers to a depth-stencil buffer used by the rendering pipeline to control visibility and masking of fragments. The depth component stores, per pixel, the distance from the viewer to the closest surface (z-value) to enable depth testing. The stencil component holds a per-pixel value used to mask rendering operations and drive multi-pass effects, such as mirrors, shadows, outlines, and complex clipping.

Depth-stencil buffers are created as a resource with a depth-stencil format. Common formats include dense depth

During rendering, the pipeline can perform a depth test using a comparison function (for example, less-than

Depth-stencil resources are bound as depth-stencil targets and may be cleared at the start of a pass.

with
an
accompanying
stencil
bit,
such
as
24-bit
depth
with
8-bit
stencil
(D24S8)
or
32-bit
depth
(D32)
with
optional
stencil.
In
many
APIs,
the
depth
data
and
stencil
data
are
stored
in
a
single
buffer,
with
separate
views
or
state
controlling
how
they
are
accessed.
The
depth
aspect
is
typically
written
by
the
pipeline
during
depth
testing,
while
the
stencil
aspect
is
updated
through
stencil
operations.
or
less-or-equal)
and
may
write
depth
values
to
the
buffer.
If
stencil
testing
is
enabled,
a
per-pixel
stencil
test
is
performed
against
a
reference
value,
and
stencil
operations
specify
how
to
modify
the
stencil
value
when
tests
pass
or
fail
(e.g.,
keep,
zero,
replace,
increment,
decrement,
invert).
Two-sided
stencil
testing
can
apply
different
operations
for
front-facing
and
back-facing
polygons.
Depth-stencil
state
objects
control
whether
depth
and
stencil
tests
are
enabled,
their
comparison
functions,
and
write
masks.
Proper
use
of
depth
and
stencil
testing
is
essential
for
correct
occlusion,
masking,
and
many
post-processing
effects,
while
also
impacting
rendering
performance
and
memory
usage.