The depth test conditionally disables coverage of a sample based on the
outcome of a comparison between the fragment’s depth value at the sample
location and the sample’s depth value in the depth/stencil attachment at
location (xf,yf).
The comparison is enabled or disabled with the depthTestEnable
member
of the VkPipelineDepthStencilStateCreateInfo
structure.
When disabled, the depth comparison and subsequent possible updates to the
value of the depth component of the depth/stencil attachment are bypassed
and the fragment is passed to the next operation.
The stencil value, however, can be modified as indicated above as if the
depth test passed.
If enabled, the comparison takes place and the depth/stencil attachment
value can subsequently be modified.
The comparison is specified with the depthCompareOp
member of
VkPipelineDepthStencilStateCreateInfo
.
Let z
f be the incoming fragment’s depth value for a sample,
and let za be the depth/stencil attachment value in memory for that
sample.
The depth test passes under the following conditions:
VK_COMPARE_OP_NEVER
: the test never passes.
VK_COMPARE_OP_LESS
: the test passes when zf < za.
VK_COMPARE_OP_EQUAL
: the test passes when zf = za.
VK_COMPARE_OP_LESS_OR_EQUAL
: the test passes when zf ≤
za.
VK_COMPARE_OP_GREATER
: the test passes when zf > za.
VK_COMPARE_OP_NOT_EQUAL
: the test passes when zf ≠
za.
VK_COMPARE_OP_GREATER_OR_EQUAL
: the test passes when zf
≥ za.
VK_COMPARE_OP_ALWAYS
: the test always passes.
If depth clamping (see Primitive Clipping) is
enabled, before the incoming fragment’s z
f is compared to
z
a, z
f is clamped to [min(n,f),max(n,f)],
where n and f are the minDepth
and maxDepth
depth
range values of the viewport used by this fragment, respectively.
If the depth test fails, the sample’s coverage bit is cleared in the fragment. The stencil value at the sample’s location is updated according to the function currently in effect for depth test failure.
If the depth test passes, the sample’s (possibly clamped) z
f
value is conditionally written to the depth framebuffer attachment based on
the depthWriteEnable
member of
VkPipelineDepthStencilStateCreateInfo
.
If depthWriteEnable
is VK_TRUE
the value is written, and if it
is VK_FALSE
the value is not written.
The stencil value at the sample’s location is updated according to the
function currently in effect for depth test success.
If there is no depth framebuffer attachment, it is as if the depth test always passes.