The depth test compares the depth value za in the depth/stencil attachment at each sample’s framebuffer coordinates (xf ,yf) and sample index i against the sample’s depth value zf. If there is no depth attachment then the depth test is skipped.
The depth test occurs in three stages, as detailed in the following sections.
Depth Clamping and Range Adjustment
If VkPipelineRasterizationStateCreateInfo::depthClampEnable is enabled, zf is clamped to [zmin, zmax], where zmin = min(n,f), zmax = max(n,f)], and n and f are the minDepth and maxDepth depth range values of the viewport used by this fragment, respectively.
Following depth clamping:
- If zf is not in the range [zmin, zmax], then zf is undefined following this step.
Depth Comparison
If the depth test is not enabled, as specified by AfxCmdEnableDepthTest or VkPipelineDepthStencilStateCreateInfo::depthTestEnable, then this step is skipped.
The comparison operation performed is determined by the afxCompareOp value set by AfxCmdSetDepthCompareOp, or by VkPipelineDepthStencilStateCreateInfo::depthCompareOp during pipeline creation. zf and za are used as the reference and test values, respectively, in the operation specified by the afxCompareOp.
If the comparison evaluates to false, the coverage for the sample is set to 0.
Depth Attachment Writes
If depth writes are enabled, as specified by AfxCmdEnableDepthWrite or VkPipelineDepthStencilStateCreateInfo::depthWriteEnable, and the comparison evaluated to true, the depth attachment value za is set to the sample’s depth value zf. If there is no depth attachment, no value is written.
To dynamically enable or disable the depth test, call:
void AfxCmdEnableDepthTest
(
afxDrawScript dscr, /// is the command buffer into which the command will be recorded.
afxBool enabled /// specifies if the depth test is enabled.
);
This command sets the depth test enable for subsequent drawing commands when the graphics pipeline is created with VK_DYNAMIC_STATE_DEPTH_TEST_ENABLE set in VkPipelineDynamicStateCreateInfo::pDynamicStates. Otherwise, this state is specified by the VkPipelineDepthStencilStateCreateInfo::depthTestEnable value used to create the currently active pipeline.
To dynamically set the depth write enable, call:
void AfxCmdEnableDepthWrite
(
afxDrawScript dscr, /// is the command buffer into which the command will be recorded.
afxBool enabled /// specifies if depth writes are enabled.
);
This command sets the depth write enable for subsequent drawing commands when the graphics pipeline is created with VK_DYNAMIC_STATE_DEPTH_WRITE_ENABLE set in VkPipelineDynamicStateCreateInfo::pDynamicStates. Otherwise, this state is specified by the VkPipelineDepthStencilStateCreateInfo::depthWriteEnable value used to create the currently active pipeline.
Responses