드로우 콜(draw call)을 줄여야 하는 이유
2022. 6. 10. 11:59ㆍComputer Graphics
드로우 콜을 줄여야 하는 이유는, 각 드로우 콜마다 GPU에 제공되는 데이터가 적을 경우 CPU가 상태(쉐이더 등)를 설정하고 GPU에 데이터를 제출하기 까지 걸리는 시간 보다 GPU가 렌더링하는 시간이 훨씬 빠를 것이기 때문이다.
이 경우, 적은 데이터를 가진 드로우 콜들로 인해 CPU가 빠르게 GPU에 데이터를 제공할 수 없기 때문에 GPU를 충분히 활용할 수 없게되며, GPU가 유휴(idle) 상태에 놓여있는 시간이 많아진다.
그래서 각 드로우 콜에 많은 데이터를 담아 드로우 콜을 줄이고, GPU가 유휴 상태에 놓이지 않도록 하는 것이 중요하다.
참고 (https://stackoverflow.com/questions/4853856/why-are-draw-calls-expensive)
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.