We are doing multithreaded GL using a (shared) context per-thread with 3.2 core profile. The main thread renders and worker threads create and fill textures, vertex buffers, etc. The question is when a worker thread is done preparing a GL resource, should it call glFlush or glFinish so it can be used by the main thread?
After reading (and re-reading) this, I am convinced you only need to call glFlush. This works, as best as unit tests can show, on several different machines with different flavors of Windows and NVIDIA/ATI cards.
On one machine, it does not work consistently, e.g., textures have wrong colors. Although, it does work consistently if we replace glFlush with glFinish. This machine has 4 hyperthreaded cores, Windows 7 64, and NVIDIA drivers 197.45. We think there is a race condition somewhere that is most commonly exposed when the level of parallelism goes up.
We hope this is a problem in our code but it could be an issue in the drivers since even very simple tests can fail, e.g.:
- Create context for worker thread on the main thread
- Create shared context for main thread and set current
- Spawn worker thread
---- Set context current
---- Create and fill texture
---- glFlush (glFinish works!)
- Main thread blocks until worker thread is finished
- Verify texture contents - fails!
Source for this is here: TextureMultiThreadingTests and TextureFactory
So, should we be able to use glFlush? If not, is glFinish going to kill performance? It is certainty a problem in the single threaded world.