I’m starting to explore the use of multiple threads communicating with
the OpenGL driver. Several questions have come up that I hope you can
answer. As background, my application makes heavy use of OpenGL based
GPGPU and OpenCL to perform computations. My goal is to have these
computations performed in the background in separate threads, while
having my GUI remain responsive to the user. Additionally, my main
GUI thread also uses OpenGL to perform various visualizations. I’m
developing on Linux with an NVIDIA GPU.
On to the questions:
-
Given an application with multiple threads, each thread with its
own context, and each thread actively sending commands to its
context, what is the execution order of these commands across
contexts:-
Do all of the commands in a context execute, then the GPU moves
to the next context? -
Is some sort of time-slicing done between contexts? For example,
if we have 2 contexts, each with 200 built-up commands, does the
GPU run 20 commands from context 1, then 20 commands from context
2, then 20 more commands from context 1, etc?
-
-
If I have an application with 48 threads, each of which wants to
communicate with OpenGL, should I:-
Have 48 GL contexts?
-
Have 2 contexts? One for the main GUI thread, and another for
computation. In this second thread, it would be up to me to
serialize all OpenGL commands to the context. -
Have a single context? If so, how do I keep the GUI thread
responsive if I’m performing long running OpenGL GPGPU tasks in
the same thread?
-
-
If my application has 16 contexts, and the GPU is currently
processing a single command in the current context that takes 60
seconds to complete, will the GPU wait until the long running
command completes before switching to another context, or will the
GPU recognize that the command is taking a long time, pause the
command, and switch to another context in a effort to keep the
system responsive? -
When using a thread/context pair to load texture data; after a call
to glTexImage, will the texture data be immediately available to
other shared contexts? If not, should I use ARB_sync or some other
method for synchronization? If I use PBO’s to upload the texture,
does the answer to this question change? -
If I create a shader in a thread/context pair, is it immediately
available in other shared contexts? -
If I upload a uniform to a shader, is it immediately available in
other shared contexts? -
Are shader uniforms and texture state (such as a texture’s wrap
mode) shared across contexts if the contexts are shared? -
Is it possible to cancel the rendering requests for a context.
Any help is greatly appreciated. Thank you for your time.