The Khronos Group - a non-profit industry consortium to develop, publish and promote open standard, royalty-free media authoring and acceleration standards for desktop and handheld devices, combined with conformance qualification programs for platform and device interoperability.

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Uniforms on a shader program used in multiple threads

This isn't really a question but rather something we've recently discovered about uniforms while making Qt's graphics sub-system threadable.

In Qt we use lots of shader programs and try to share them between contexts. So we have a library of compiled shaders which may be used by different but sharing contexts. E.g. Multiple top-level windows each have a separate context, but share a common pool of shader programs. This has never been a problem before because although an application can have multiple top-level windows, they are only rendered into one-at-a-time from a single thread. However, we have recently been trying to make Qt more threadable to enable E.g. splitting separate top-levels into their own thread.

Several features of OpenGL combine to give behavior which, while logical as described in the spec, may not be exactly what one would want in this admittedly quite unusual use case:

* Two OpenGL contexts can be current at the same time in two separate threads
* Two OpenGL contexts can be sharing some resources
* Shader programs are a resource which can be shared across contexts
* A shader program can therefore be use()'d in two contexts simultaneously
* Uniforms are part of a shader program's state (not the context's state)
* When one thread sets a uniform, it sets it for all threads

It's this last point which created an "huh?" moment in our office.

The issue is fairly easy to work around. I only post as I suspect it might be a use case which others might find interesting.