Sign in to follow this  
Followers 0
Triad_prague

the cost of loop in glsl

5 posts in this topic

Hi all I plan to use hardware skinning, and thus I need to use loop inside the vertex shader. Last time I heard ut was bad to use loop inside shader and that I'd better unroll it. Also I heard looping and branching was badly supported. Is it true? any keyword for looking such info? thx
0

Share this post


Link to post
Share on other sites

I plan to use hardware skinning, and thus I need to use loop inside the vertex shader

 

Hardware skinning is usually done without loops by always skinning for a static number of bones per vertex, and using weights of 0.0 when less than that are needed for a particular vertex.

In general branching and looping on variables are bad, while looping over constants will be unrolled automatically by the shader compiler.

 

 

If you haven't written a skinning shader before, then start by writing one that works on your development system, and worry about support on other platforms later. If you know how to do it with loops then do it with loops, and then post the code here and people can comment on it.

Finding the information you need and iteratively changing your method will be easy once you've written one that works.

 

If you need information on how to start, then post information on your GLSL version and hardware so we can recommend a tutorial.

Edited by Erik Rufelt
1

Share this post


Link to post
Share on other sites

Erik Rufelt, on 06 Apr 2013 - 09:12, said:
If you haven't written a skinning shader before, then start by writing one that works on your development system, and worry about support on other platforms later. If you know how to do it with loops then do it with loops, and then post the code here and people can comment on it.

I do agree with first building a working version on your dev pc, before worrying about performance. However I just wanna toss my experience with writing dynamic loops on older gpu's. Don't, as i've had the gpu "optimize" the loop by unrolling it to the first value specified as the stop point. I.E. if you do this:
 
in int NbrBones;
void main(){
  for(int i=0;i<;NbrBones;i++)[
   //Do stuff.
  }
};
the gpu decided to unroll the loop to w/e my first value of NbrBones was, and had me scratching my head for a good while. Knowing this, i've tried to stay away from dynamic loops for the most part. Edited by slicer4ever
0

Share this post


Link to post
Share on other sites
to all, thx for the suggestion. I tried to gove +1 to all your comments, but I'm on mobile :(
anyway, I plan to use gl 2.0 to support a lil bit older hardwarr, and I heard the number of uniform is limited to 256*vec4. so I plan to pass quaternion as vec4 and position as vec3. I havent written the shader loader yet, no access to pc. I'm basically imprisoned in this barrack for the next 3 weeks. I'm curious if my quaternion multiplication will be faster than the built in mattix multiplication. I hope it would be.
0

Share this post


Link to post
Share on other sites

the gpu decided to unroll the loop to w/e my first value of NbrBones was, and had me scratching my head for a good while. Knowing this, i've tried to stay away from dynamic loops for the most part.

Nvidia drivers were known for doing stuff like this. Apparently this was a serious issue whenever an uniform was set to 0 or 1 because the driver would attempt to recompile the shader optimizing for that. No idea how much truth was in this, but yeah it isn't just loops the issue.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0