Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 2 of 2

Thread: Resetting uniforms during active shader program: Good practice?

  1. #1
    Intern Contributor
    Join Date
    Jun 2001
    Posts
    52

    Resetting uniforms during active shader program: Good practice?

    Hello,

    I was wondering if it is good or bad practice to reset a uniform multiple times in an active shader program. Reason is that I have to change certain behaviours on my fragment shader because my geometry as different properties. Passing along a flag to my shader with
    Code :
    glExt_glUniform1i
    apparently works but perf shows many gpu stalls especially on nvidia devices.

    I've also played around with coherent mapped UBOs but that didn't work at all because of synchronization issues between the cpu and gpu and I havent figured out how to efficiently do the synchronization inbetween swaps.

    Would it be better to rebind the shader using
    Code :
    glUseProgram
    every time I have to change a uniform instead of passing uniforms along multiple times? What is more expensive in terms of stalls and performance drops?

    Any ideas?

  2. #2
    Senior Member OpenGL Guru Dark Photon's Avatar
    Join Date
    Oct 2004
    Location
    Druidia
    Posts
    4,124
    Quote Originally Posted by saski View Post
    I was wondering if it is good or bad practice to reset a uniform multiple times in an active shader program.
    This is fine, and in most cases should be fairly cheap for ordinary uniforms (e.g. scalars, vectors, etc.)

    Quote Originally Posted by saski View Post
    What is more expensive in terms of stalls and performance drops?
    I think we're going to need more detail on what you're doing to be able to offer targeted advice.

    The answer to the "what is more expensive" question is going to depend on the hardware, the driver, and the app (i.e. how the driver is being used). However, in general, changing the bound program is one of the most expensive things you'd typically do in a frame (not as expensive as changing the bound render target though). So I wouldn't add any more program binds than you absolutely have to have.

    I'm not sure what stage you're at, but I think the first thing is determining what you're most bottlenecked on. Grab your favorite profiler. Measure your frame time, and try disabling things (render passes, shader binds, texture binds, uniform updates, etc.). What nets you the biggest change in your frame time? Look careful at things you're doing a lot of, and consider whether there's an efficient way to do it with fewer calls and updates.

    In terms of relative cost, since you mentioned NVidia, see pg 48 here:

    * Beyond Porting (2014)
    Last edited by Dark Photon; 07-08-2017 at 01:50 PM.

Posting Permissions

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