Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Page 2 of 3 FirstFirst 123 LastLast
Results 11 to 20 of 28

Thread: unbound sampler declaration andd GLSL shader code

  1. #11
    Junior Member Regular Contributor
    Join Date
    Jul 2010
    Posts
    132
    Quote Originally Posted by GClements View Post
    The type doesn't matter.
    Ok on that part. int or vec3, who cares, they're both uniform values. Fine.

    Quote Originally Posted by GClements View Post
    Because GLSL assumes (and GPUs implement) a SIMD architecture, a conditional is typically executed by executing both branches but ignoring state changes in whichever branch wasn't selected by the condition. But if a non-selected branch results in an error, it can still effect the overall execution of the shader.
    GPUs do not have a branch prediction unit, do they? Therefore they don't speculatively execute the code of the wrong branch.
    Even if my condition is "if (gl_FragCoord.x > 10000)" which is not a dynamic-uniform (as you said), I don't see any reason why the GPU would choose to evaluate the wrong block of code. On a CPU it's because of the branch prediction unit (or maybe because of out-of-order execution), but on a GPU, I don't get it.

  2. #12
    Junior Member Regular Contributor
    Join Date
    Jul 2010
    Posts
    132
    Quote Originally Posted by malexander View Post
    I found with the AMD drivers, if I left a samplerBuffer unbound it would crash even if I didn't sample from it.
    I can't find anywhere on the web a paragraph that says that shader samplers MUST be bound.

    EDIT: I only found your post here: http://www.opengl.org/discussion_boa...=1#post1223479
    Last edited by fred_em; 06-25-2013 at 11:56 PM.

  3. #13
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    I have been using dynamic subroutines to choose whether to load the fragment colour from different sources including a uniform, texture, multiple textures etc. If I am, for example, loading from a uniform, I do not bind a texture and I have had no problems with either the AMD nor nVidia drivers. One of my subroutines even has if tests inside it where some paths will load a texture and other won't.

  4. #14
    Junior Member Regular Contributor
    Join Date
    Jul 2010
    Posts
    132
    You are right, shader subroutines are a more appropriate way of instructing the driver which block of code is or is not used at runtime, and therefore the driver might not complain about unbound samplers if it knows the block of code does not access the (unbound) samplers.
    Still, I would appreciate if the GL spec specified that unbound samplers are indeed valid or not, and under which conditions/circumstances.

  5. #15
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,128
    Quote Originally Posted by malexander
    I found with the AMD drivers, if I left a samplerBuffer unbound it would crash even if I didn't sample from it.
    Are you absolutely sure that the sampler wasn't active? Otherwise I would suggest that this is a driver bug because active samplers should be properly detected at link time.

    fred_em: is there any chance you can factor your shader into two separate shaders? don't underestimate the fact that you do additional function calls with subroutines.
    Last edited by thokra; 06-26-2013 at 05:41 AM.

  6. #16
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    thorka is right to suggest separate subroutines where practical. My benchmarking (while not as scientific as I might like) showed dynamic subroutines do not come for free. I only use them in shaders that have a lot of branching options that the user can change at their whim and so in the program logic it is easier to dynamically create the shader.

  7. #17
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,128
    Quote Originally Posted by tonyo
    thorka is right to suggest separate subroutines where practical
    Separate shaders.

  8. #18
    Senior Member OpenGL Pro
    Join Date
    Jan 2012
    Location
    Australia
    Posts
    1,117
    sorry

  9. #19
    Member Regular Contributor malexander's Avatar
    Join Date
    Aug 2009
    Location
    Ontario
    Posts
    319
    Quote Originally Posted by thokra View Post
    Are you absolutely sure that the sampler wasn't active? Otherwise I would suggest that this is a driver bug because active samplers should be properly detected at link time.
    It was the same situation as fred_em originally posted - a texelFetch() in a conditional clause that was never taken due to a uniform-valued condition (if(uniform_val == 0) texelFetch()). The sampleBuffer without a corresponding TBO bound crashed, likely due to predicated execution of the fetch/assignment. I was suggesting that leaving a unbound texture unit for an active sampler is not terribly safe.

  10. #20
    Senior Member OpenGL Pro
    Join Date
    Apr 2010
    Location
    Germany
    Posts
    1,128
    I was suggesting that leaving a unbound texture unit for an active sampler is not terribly safe
    Although quite easily deducible that this is undefined behavior, the GL/GLSL specs actually don't seem to state as much and certainly don't warn of potential program termination. The question is, is this worth being mentioned in the spec?

Posting Permissions

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