Is using a dedicated thread just for sending gpu commands a good idea?
        Posted  
        
            by 
                tigrou
            
        on Game Development
        
        See other posts from Game Development
        
            or by tigrou
        
        
        
        Published on 2012-07-06T20:09:35Z
        Indexed on 
            2012/07/06
            21:25 UTC
        
        
        Read the original article
        Hit count: 313
        
The most basic game loop is like this :
while(1)
{
   update();
   draw();    
   swapbuffers();
}
This is very simple but have a problem : some drawing commands can be blocking and cpu will wait while he could do other things (like processing next update() call).
Another possible solution i have in mind would be to use two threads :
one for updating and preparing commands to be sent to gpu, and one for sending these commands to the gpu :
//first thread
while(1)
{
   update();
   render(); // use gamestate to generate all needed triangles and commands for gpu 
             // put them in a buffer, no command is send to gpu
             // two buffers will be used, see below
   pulse(); //signal the other thread data is ready
}
//second thread
while(1)
{
   wait();              // wait for second thread for data to come
   send_data_togpu();   // send prepared commands from buffer to graphic card
   swapbuffers();      
}
also : two buffers would be used, so one buffer could be filled with gpu commands while the other would be processed by gpu.
Do you thing such a solution would be effective ? What would be advantages and disadvantages of such a solution (especially against a simpler solution (eg : single threaded with triple buffering enabled) ?
© Game Development or respective owner