A simple D3D12 app for testing and observing Z culling behavior.
This app allows you to re-create various scenarios that may or may not interact with the hardware's ability to cull pixel/fragement shaders based on early depth testing. The results are visualized as two simple colored triangles for simplicity, and a pipeline stats query is used to measure and display the number of pixel shader invocations that occurred when drawing these two triangles. This invocation count is displayed in the window, which makes it possible to determine how many pixel shader theads were culled before they could be executed.
For more information, see the blog post that this app was made for.
Enable Depth Writes
- enables or disables depth writes in the depth/stencil state of the PSO (depth testing is always enabled)Reverse Triangle Order
- if disabled, the two triangles are drawn back-to-front. If enabled, the triangles are drawn front-to-back.Discard Mode
- controls whetherdiscard
is present in the pixel shader, and how it's used:NoDiscard
- nodiscard
is presentDiscardChecker
-discard
is used to kill pixels in a coarse 32x32 checkerboard patternDiscardNever
- adiscard
is put in a branch that is never taken
Depth Export Mode
- controls how the pixel shader outputs/exports a manual depth valueNoDepthExport
- no depth is output by the shaderArbitraryDepth
- the depth value is fully overriden by outputtingSV_Depth
ConservativeDepthMatching
- a conservative depth output is used where the inequality matches the depth test inequality (SV_DepthLessEqual
)ConservativeDepthOpposing
- a conservative depth output is used where the inequality opposes the depth test inequality (SV_DepthGreaterEqual
)
UAV Write Mode
- controls what sort of UAV write occurrs from the pixel shaderNoUAV
- no UAV writes are present in the pixel shader. The pixel shader outputs toSV_Target0
.StandardUAV
- the pixel shader outputs its color to aRWTexture2D<float4
ROV
- the pixel shader outputs its color to aRasterizerOrderedTexture2D<float4>
Force Early Z
- if enabled, the pixel shader forces the hardware to perform all depth tests before the pixel shader executes using the[earlydepthstencil]
attributeClear Depth To Zero
- clears the depth buffer to 0.0 instead of 1.0 before drawing the triangles, causing all drawn pixels to fail the depth test.Barrier Between Draws
- issues a global memory barrier between the two triangle draws to force a stall + flush
Open EarlyZTest\EarlyZTest.sln
, build the solution, and then run it.