opengl: glFlush() vs. glFinish()

前端 未结 8 1324
感情败类
感情败类 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 06:52

    There doesn't seem to be a way of querying the status of the buffer. There is this Apple extension which could serve the same purpose, but it doesn't seem cross-platform (haven't tried it.) At it quick glance, it seems prior to flush you'd push the fence command in; you can then query the status of that fence as it moves through the buffer.

    I wonder if you could use flush prior to buffering up commands, but prior to beginning to render the next frame you call finish. This would allow you to begin processing the next frame as the GPU works, but if it's not done by the time you get back, finish will block to make sure everything's in a fresh state.

    I haven't tried this, but I will shortly.

    I have tried it on an old application that has pretty even CPU & GPU use. (It originally used finish.)

    When I changed it to flush at end and finish at begin, there were no immediate problems. (Everything looked fine!) The responsiveness of the program increased, probably because the CPU wasn't stalled waiting on the GPU. Definitely a better method.

    For comparison, I removed finished from the start of the frame, leaving flush, and it performed the same.

    So I would say use flush and finish, because when the buffer is empty at the call to finish, there is no performance hit. And I'm guessing if the buffer were full you should want to finish anyway.

提交回复
热议问题