Is using a dedicated thread just for sending gpu commands a good idea?
- by tigrou
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) ?