Unity study notes Draw Call and performance

——Read the notes of "Introduction to Unity Shader"

Draw Call is simply understood as a command for the CPU to call the image programming interface.

A common misunderstanding is that the culprit of performance problems in Draw Call is the GPU. It is thought that the state switching on the GPU is time-consuming, but it is not. The real drag is actually the CPU.

How CPU and GPU work in parallel

The CPU and GPU can work in parallel through the command buffer. The command buffer contains a command queue. The CPU adds commands to it, and the GPU reads the names from it. The processes of adding and reading are independent of each other.
insert image description here

Why does too many Draw Calls affect the frame rate?

Before each call to Draw Call, the CPU needs to send a lot of content to the GPU, including data, status, and commands. At this stage, the CPU needs to do a lot of work, such as checking the rendering state, etc. Once the CPU has completed these preparations, the GPU can start rendering this time. The rendering capability of the GPU is very strong, and the rendering speed is often faster than the speed of the CPU submitting commands. That is to say, if the number of Draw Calls is too large, the CPU will spend a lot of time in submitting the Draw Calls, causing the CPU to be overloaded, and the CPU will spend time preparing for the Draw Calls.

So how to reduce Draw Call?

The number of Draw Calls required for each frame can be reduced by using the batching method.
Since we need to merge the meshes in the CPU memory, and the merging process is time-consuming, batch processing technology is more suitable for static objects, such as non-moving ground, stones, etc., for these static objects only need to be merged once That's it. Of course, batch processing can also be performed on dynamic objects, but because the objects are constantly moving, each frame needs to be re-merged and then sent to the GPU, which will have a certain impact on space and time.
During the development process, you should pay attention to:

  1. Avoid using a lot of very small meshes. But when it is unavoidable to use small mesh structures, consider whether they can be merged.
  2. Avoid using too many materials. Try to share the same material between different meshes.

Guess you like

Origin blog.csdn.net/weixin_42358083/article/details/122750617