Unity_ what is draw call? What is batch?

Source: Internet
Author: User

When you start the game, you must be reminded to reduce the draw call and, of course, unity is no exception, open the Stats in the game window and see the numbers of draw calls and batched. But what exactly is Draw call? Is the effect coming from the CPU? or GPU? Let Unityin once tell you.

First, let's define what "Draw call" is:

"A Draw call, as called once DrawIndexedPrimitive (DX) or gldrawelements (OGL), as in a Batch"

People who have touched DirectX or OpenGL are not unfamiliar with the API for DrawIndexedPrimitive and gldrawelements. When we are ready to get the information (usually the vertex of the triangle), you must call this function when the GPU is planned. In other words, if there is a "wooden" chair on the screen, a "iron" table, then there will be two Draw call on the theory.

Have you seen special "wood" and "iron"? This means that two objects are using different material balls or different Shader. In DirectX or OpenGL, a description of different stickers or different Shader are assigned to different objects, and you will need to call draw calls twice. Procedure code is as follows:

Setshader ("diffuse");
SetTexture ("Iron");
DrawPrimitive (Deskvertexbuffer);

Setshader ("Vertexlight");
SetTexture ("Wood");
DrawPrimitive (Chairvertexbuffer);

Each time the more dynamic or the sahder of the map is basically a custom modification to the Rendering Pipeline, a different Draw call is required to complete the object's drawing. Now understand why in UNITY's official file, you are always using the same material to reduce the number of Draw call!

Speaking of Batch, it is another call to Draw calls. You can think of each Draw call will produce a batch, and batch is the object vertex information, batch by the CPU through the "driver" to send the vertex information to Gpu,gpu after taking over the object painting on the surface. The more Draw call,cpu, the busier the more. It's better to know that the Draw call number affects CPU performance, not the GPU.

NVIDIA at GDC has suggested that 25K batchs/sec will eat a 1GHz cpu,100% usage rate. So they introduced a formula to estimate how many Batch of the game might Run:

For example: If your goal is to play 30FPS, use 2GHz CPU, 20% of the workload flick to draw call, how many draw call can you have per second?

333 Batchs/frame = 25K * 2 * (0.2/30)

So since Batch is a box, with the vertex of the object in it, and according to our description above, it means that the same material or Shader object can be merged into a Batch to the GPU, which is the easiest way to put your arm around? Bingo! This is it!

UNITY has two features in Player Setting, Static batching and Dynamic batching. The functions are described as follows:

    1. The static batching is a static object that will be marked as stationary, and if, under the conditions of the same material sphere, UNITY will automatically help you to merge the two objects into a Batch and send them to the GPU for disposal. This function is very helpful in performance, so it is necessary to pay for it.
    2. The Dynamic batching is under the condition that the object is less than 300 sides (regardless of whether the object is static or mobile), and with the same material ball, unity will automatically help you merge into a Batch and send it to the GPU.

Below is another article on the Shore Master, as well as an topic from NVIDIA in GDC Ambassador, with three of them taking better results:

    • The Unity performance Optimization Draw call
    • "Batch, batch, batch:" What Does It really Mean?

Unity_ what is draw call? What is batch?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.