This post covers best practices for clears on NVIDIA GPUs. To get a high and consistent frame rate in your applications, see all Advanced API Performance tips.
Surface clearing is a widely used accessory operation.
Recommended
- Use clear functions from the graphics API to clear resources.
- Use any clear color to clear render targets.
- Hardware optimizations improves the most clear operations.
- Use a suitable clear value when clearing the depth buffer.
- Prefer clear values within the range [0.0, 0.5) when using depth test functions
D3D12_COMPARISON_FUNC_GREATER
orD3D12_COMPARISON_FUNC_GREATER_EQUAL
- Prefer clear values within the range [0.5, 1.0] when using depth test functions
D3D12_COMPARISON_FUNC_LESS
orD3D12_COMPARISON_FUNC_LESS_EQUAL
.
- Prefer clear values within the range [0.0, 0.5) when using depth test functions
- Group clear operations into as few batches as possible.
- Batching reduces the performance overhead of each clear.
Not recommended
- Avoid using more than a few different clear colors for surface clearing.
- Clearing optimization limited to 25 clear colors per frame on NVIDIA Ampere Architecture GPUs.
- Clearing optimization limited to 10 clear colors per frame on NVIDIA Turing GPUs.
- Avoid interleaving single clear calls with rendering work.
- Group clears into batches whenever possible.
- Never use clear-shaders as a replacement for API clears.
- It disables hardware optimizations and negatively impacts both CPU and GPU performance.
- Exception: Overlapping a compute clear with neighboring compute work may give better performance.
Acknowledgments
Thanks to Michael Murphy, Maurice Harris, Dmitry Zhdan, and Patric Neil for their advice and feedback.