Glfinish () and Glflush () functions

Source: Internet
Author: User

Client-server mode, the command issued by the client does not require an immediate response from the server, if the client and the server in a network, one command will appear inefficient, so the command will be cached in the client and then sent together, so the client needs a mechanism to confirm that the server has completed the execution of the command, Given that OpenGL ES is multithreaded, the execution of thread A is important to synchronize the execution of individual threads, such as thread B's execution, depending on the execution of thread A. The Flush command sends an execution instruction to the server, but does not wait for the instruction to complete, and if it needs to wait for the instruction to complete, use the finish command. Generally do not agree with the use of finish, unless necessary, finish will wait for the client to complete the execution of the command and then return, forcing the client and the server to execute synchronously.

one, Glfinish () function


Oengl Manual on Glfinish:

Name
Glfinish-block until all GL execution are complete

C specification
void Glfinish (void);


Description

Glfinish does not return until the effects of all previously CALLEDGL commands is complete. Such effects include allchanges to GL state, all changes to connection state, and allchanges to the frame buffer contents.

Notes
Glfinish requires a round trip to the server.

Errors
Gl_invalid_operation is generated if glfinish is executed betweenthe execution of Glbegin and the Correspondingexecution o F Glend.


Glfinish () takes the instruction of the buffer immediately to the hardware execution, but waits until the hardware has finished executing these instructions before returning.

If you draw directly to the front buffer, you need to call this function before you can save the screenshot to make sure the drawing is complete.

If you use double buffering, this function does not have much effect.



Second, Glflush ()


Name
Glflush-force execution of GL commands in finite time

C specification
void Glflush ();

Description

Different GL implementations buffer commands in severaldifferent locations, including network Buffersand the Grap Hics Accelerator itself. Glflushempties all of these buffers, causing all issued commands tobe executed as quickly as they is accepted by the Actual rendering engine. Though this execution could notbe completed in any particular time period, itdoes complete in finite time.

Because any GL program might is executed Overa network, or on a accelerator that buffers Commands,all programs should cal L Glflush whenever Theycount on have all of their previously issuedcommands completed. For example, call Glflushbefore waiting for user input, this depends on the generatedimage.

Notes
Glflush can return at any time. It does not wait until theexecution of all previously issued GL commandsis complete.

Errors
Gl_invalid_operation is generated if Glflush is executed betweenthe execution of Glbegin and the correspondingexecution of Glend.


Glflush () empties the buffer and sends the instruction to the slow hardware for immediate execution, but it returns immediately after the command is delivered, without waiting for the instruction to complete. These instructions will be executed within a limited time.

If you draw directly to the front buffer, there will be no delay in drawing OpenGL. Imagine a complex scene with a lot of objects that need to be drawn. When Glflush is called, the object appears on the screen one by one. However, if you use double buffering, this function will have no effect because the change will not manifest until the buffer is swapped.


If you are using double buffering, you may not need to use either of these functions. The buffer exchange operation implicitly sends the command to execute.


iii. The difference between Glfinish and Glflush


It looks like the two functions are similar, but there are still differences.

In general, the purpose of using Glflush is to ensure that the CPU does not have OpenGL-related things to do after the call-the command is sent to the hardware execution. The purpose of calling Glfinish is to ensure that no related work remains to be done after the return.


Glfinish can cause performance degradation

If you call Glfinish, you usually get a performance penalty. Because it would be the loss of parallelism between the GPU and the CPU.

In general, the tasks we submit to the driver are grouped and then sent to the hardware (when the buffer is exchanged). If you call Glfinish, force the driver to send the command to the GPU. The CPU then waits until all the delivered commands have been executed. This way, the CPU is not working (at least on this thread) during the entire period of the GPU's work. The GPU does not work while the CPU is working (usually in the grouping of commands). This results in a decrease in performance.

Therefore, you should minimize the use of this function. One application of this function is to debug a bug. If one of the commands I transfer to the hardware caused the GPU to crash, the simple way to find out which instruction is causing the GPU to crash is to call this function after each drawing operation. This makes it possible to pinpoint the command that caused the crash.

In addition, the Direct3D does not support the finish concept.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.