opengl: glFlush() vs. glFinish()

前端 未结 8 1171
感情败类
感情败类 2020-12-02 06:40

I\'m having trouble distinguishing the practical difference between calling glFlush() and glFinish().

The docs say that glFlush()

相关标签:
8条回答
  • 2020-12-02 07:02

    The question is: do you want your code to continue running while the OpenGL commands are being executed, or only to run after your OpenGL commands has been executed.

    This can matter in cases, like over network delays, to have certain console output only after the images have been drawn or the such.

    0 讨论(0)
  • 2020-12-02 07:04

    If you did not see any performance difference, it means you're doing something wrong. As some others mentioned, you don't need to call either, but if you do call glFinish, then you're automatically losing the parallelism that the GPU and CPU can achieve. Let me dive deeper:

    In practice, all the work you submit to the driver is batched, and sent to the hardware potentially way later (e.g. at SwapBuffer time).

    So, if you're calling glFinish, you're essentially forcing the driver to push the commands to the GPU (that it batched till then, and never asked the GPU to work on), and stall the CPU until the commands pushed are completely executed. So during the whole time the GPU works, the CPU does not (at least on this thread). And all the time the CPU does its work (mostly batching commands), the GPU does not do anything. So yeah, glFinish should hurt your performance. (This is an approximation, as drivers may start having the GPU work on some commands if a lot of them were already batched. It's not typical though, as the command buffers tend to be big enough to hold quite a lot of commands).

    Now, why would you call glFinish at all then ? The only times I've used it were when I had driver bugs. Indeed, if one of the commands you send down to the hardware crashes the GPU, then your simplest option to identify which command is the culprit is to call glFinish after each Draw. That way, you can narrow down what exactly triggers the crash

    As a side note, APIs like Direct3D don't support a Finish concept at all.

    0 讨论(0)
提交回复
热议问题