Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

why are draw calls expensive?

assuming the texture, vertex, and shader data are already on the graphics card, you don't need to send much data to the card. there's a few bytes to identify the data, and presumably a 4x4 matrix, and some assorted other parameters.

so where is all of the overhead coming from? do the operations require a handshake of some sort with the gpu?

why is sending a single mesh containing a bunch of small models, calculated on the CPU, often faster than sending the vertex id and transformation matrices? (the second option looks like there should be less data sent, unless the models are smaller than a 4x4 matrix)

like image 604
notallama Avatar asked Jan 31 '11 17:01

notallama


People also ask

How many draw calls is a lot?

"A modern desktop game can handle approximately 500-5,000 draw calls per frame. While mobile devices can handle around 40 to 60 Draw Calls and for latest mobile devices you can go up to 120 to 160 Draw Calls." While Draw Calls can be a big bottleneck!

How do I minimize draw calls?

Open the Player Settings. - Select Player Settings from "File > Build Settings" in the Unity menu. If Dynamic Batching is disabled among the items in Other Settings, draw calls are not optimized. Turn on Dynamic Batching.

What counts as a draw call?

A draw call is a call to the graphics API to draw objects (e.g., draw a triangle), while a batch is a group of draw calls to be drawn together. Batching objects together minimizes the state changes needed to draw each object inside the batch.

How do drawing calls work?

Draw calls = how many objects are being drawn to the screen. You want to keep this number down to maintain good performance, so watch out for pixel lights as they make objects get drawn as many times as there are lights affecting them. Use the Rendering statistics window in the editor to get the number of draw calls.


1 Answers

First of all, I'm assuming that with "draw calls", you mean the command that tells the GPU to render a certain set of vertices as triangles with a certain state (shaders, blend state and so on).

Draw calls aren't necessarily expensive. In older versions of Direct3D, many calls required a context switch, which was expensive, but this isn't true in newer versions.

The main reason to make fewer draw calls is that graphics hardware can transform and render triangles much faster than you can submit them. If you submit few triangles with each call, you will be completely bound by the CPU and the GPU will be mostly idle. The CPU won't be able to feed the GPU fast enough.

Making a single draw call with two triangles is cheap, but if you submit too little data with each call, you won't have enough CPU time to submit as much geometry to the GPU as you could have.

There are some real costs with making draw calls, it requires setting up a bunch of state (which set of vertices to use, what shader to use and so on), and state changes have a cost both on the hardware side (updating a bunch of registers) and on the driver side (validating and translating your calls that set state).

But the main cost of draw calls only apply if each call submits too little data, since this will cause you to be CPU-bound, and stop you from utilizing the hardware fully.

Just like Josh said, draw calls can also cause the command buffer to be flushed, but in my experience that usually happens when you call SwapBuffers, not when submitting geometry. Video drivers generally try to buffer as much as they can get away with (several frames sometimes!) to squeeze out as much parallelism from the GPU as possible.

You should read the nVidia presentation Batch Batch Batch!, it's fairly old but covers exactly this topic.

like image 163
Joakim Hårsman Avatar answered Oct 19 '22 09:10

Joakim Hårsman