Why does SwapBuffers take up so much cpu time?


why does SwapBuffers(hDC) take up so much cpu time? it takes up 16 milliseconds when i use double buffer.

It’s probably because allot of synchronization stuff happen when you swap buffers. I’m not sure though, maybe someone has a more concrete answer than mine.

This is for D3D but it covers the equivalent operation: http://tomsdxfaq.blogspot.com/2006_04_01_archive.html#114482869432550076

With “up to 16 ms” wait time you may also have vsync enabled.

60 frames per second is the monitor refresh rate and is equal to 16.6ms per frame – definitely vsync enabled.

Yeah, just look for a setting called “Sync to VBlank” or similar in your driver documentation, and disable it. Then you can get a clearer picture of how long your frame is actually taking to render. On NVidia/Linux, you can set in nvidia-settings, or set __GL_SYNC_TO_VBLANK=0 in the environment of the GL process before creating a context.

Also, it’s common practice to call glFinish() right after SwapBuffers to force the GPU to wait until it’s finished all the computation for that frame. Then you can get a pretty clear picture of exactly how much time each frame is taking (otherwise, the driver is doing work for the next frame in this frame, messing up your timings).

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.