0

In our OpenGL application SwapBuffers() https://msdn.microsoft.com/en-us/library/windows/desktop/dd369060(v=vs.85).aspx (defined in windows GDI wingdi.h) sometimes blocks over the duration of multiple (2-3) vSyncs and it's difficult for us to figure out what is the reason for it. Does anyone have ideas what could be causing such a behaviour or how to profile into the function to figure out what is going on?

matthias_buehlmann
  • 4,641
  • 6
  • 34
  • 76
  • Typically it's not the swapping but the finishing/flushing that typically accompanies a swap which causes a stall. Everything you do in GL in async -- until calls are made like flush or finish or swapping buffers at which point the system has to wait for everything to finish. As a result, it's often misleading but a profiling session will show the hotspot in swapping buffers even though it's typically caused by all the rendering work being done prior (ex: rendering a bunch of primitives with VBOs). –  Nov 28 '15 at 02:45
  • right, but the implicit glFlush is implemented in glutSwapBuffers and called right before the actual call to Windows' SwapBuffers. Still, it's SwapBuffers that stalls, not the glFlush before. The rendering work on the GPU is at that point finished a long time before (seeing this in NSIGHTS GPU profiling) – matthias_buehlmann Nov 28 '15 at 02:49
  • `glFlush` does not wait for all commands to finish. It merely flushes them to the GPU. You're confusing it with `glFinish`. The behavior you're seeing is `SwapBuffers` blocking till all commands have been processed. See here for a better explanation on `glFlush`: https://stackoverflow.com/a/38297697/1907004 – Tara Nov 15 '18 at 07:26

0 Answers0