Unity Shader study notes - Draw Call

  After the process is finished, let’s talk about drawcall in detail. As mentioned above, drawcall is the CPU calling the image programming interface and ordering the GPU to perform rendering operations. The culprit of performance problems in drawcall is the CPU.

        How do CPU and GPU work in parallel?   

        Through the command buffer, the CPU adds commands to it, and the GPU reads commands from it, and the two are independent of each other.

        Why do more Draw Calls affect the frame rate? 

        Because before each drawcall is called, the CPU needs to send a lot of content to the GPU, including data, status, and commands. In this stage, the CPU needs to complete a lot of work, such as checking the rendering status. When the CPU completes these preparations, the GPU can start this current rendering. The GPU rendering capability is very strong, and rendering 200 and 2000 triangle meshes is usually There's no difference, so rendering tends to be faster than the CPU can submit commands. If there are too many drawcalls, the CPU will spend a lot of time submitting drawcalls, causing CPU overload.

        How to reduce draw calls?

        Use batch processing. Submitting a large number of small drawcalls will cause the CPU to spend a lot of time preparing drawcalls, so optimization is to combine many small drawcalls into one large drawcall, which is the idea of ​​batch processing.

        Batch processing is divided into two types, dynamic batch processing and static batch processing.

        Static batch processing is to batch process static objects that will not move. For example, the earth, stones, etc., we only need to merge these static objects once, and they have the same texture; if they are different textures, they can be packaged into an atlas; or reduce the reflected light on the light source and reduce the shadow area.

        Dynamic batch processing refers to the dynamics of Unity. Unity itself performs dynamic batch processing on similar resources, which has very strict requirements and requires many resources to be changed. And these objects are constantly moving, so each frame needs to be re-merged and sent to the GPU. So batch processing is more suitable for static objects.

Guess you like

Origin blog.csdn.net/weixin_45081191/article/details/129164580