Jump to content
  • Advertisement
Sign in to follow this  
tigerking

GLSL shader dynamic flow control performance question

This topic is 3817 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all, I have a strange problem regarding my simple GLSL shader. Basically it's like uniform int flag; uniform sampler2DRect Tex; void main(void) { vec2 coord; if( flag == 0){ coord = ... //compute coord for case flag == 0; } else if( flag == 1){ coord = ... //compute coord for case flag == 1; } else{ coord = ... //compute coord for other cases; } gl_FragColor = texture2DRect(Tex, coord );" } My problem is that when I render a simple geometry using such a shader, the performance of the first call is always very bad (can take up to 200ms). After the first call, the following calls run much faster (less than 1ms). I am just wondering if someone happens to know the reason. I know it's related dynamic flow control since if I get rid of it, the performance is always same. But such a big difference is not normal to me :) Thanks. tiger

Share this post


Link to post
Share on other sites
Advertisement
the IHV's shader compiler seems to be clever enough to detect your to corner cases (flag 1/0)
looks like during the first frame it just happily compiles 2 versions of your shader; one with flag=1 and one with flag=0; flow control gets optmized out of these 2 version

i had a lot of trouble with small stalls during my engine when the graphics driver decided to recompile the shader depending on a uniform value


there's been a thread about this on opengl.org

cheers

Share this post


Link to post
Share on other sites
Wow, so fast to get the answer :)

I read the post you referred. Yes, that's the reason I think. I will dig more to see if it can be avoid.

Many thanks.

tiger

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!