Results 1 to 2 of 2

Thread: Uniforms on a shader program used in multiple threads

  1. #1
    Junior Member
    Join Date
    May 2008
    Posts
    23

    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.


    Cheers,

    Tom

  2. #2
    Junior Member
    Join Date
    Sep 2010
    Posts
    12

    Re: Uniforms on a shader program used in multiple threads

    You should be rendering everything in one OpenGL context.

Similar Threads

  1. Incrementing value from multiple threads
    By clamport in forum OpenCL
    Replies: 3
    Last Post: 03-24-2010, 11:15 AM
  2. How can we use same VGPath in multiple threads
    By srastogi in forum OpenVG and VGU
    Replies: 3
    Last Post: 09-17-2009, 08:48 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •