Jump to content
  • Advertisement
Sign in to follow this  
Nairb

Very Weird GLSL Problems

This topic is 3880 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

This may be more of a general programming question, but since it is related to GLSL I thought best to put it here. I'm doing some GPGPU stuff inside a geometry shader, and I'm coming up with two very obscure problems: (1) In one of my functions, if I use a variable to compute something, the function hangs indefinitely. If I replace that variable with the equivalent number, the function runs just fun. So it looks a bit like this:
void main() {
  currSize = gl_FrontColorIn[0];
  ...
  Repeat(0, 1, currSize[1]);
  ...

void Repeat(int axis, float size, float numRepeats)
  for (int i = 0; i < numRepeats; i++) {  //HANGS FOREVER
     ... 
     EmitVertex();
   }

In the above example, if I simply call Repeat(0,1,30), it works just fine and does exactly what I expect it to do. Further, if I comment out the 'EmitVertex' call, it proceeds to terminate normally (but obviously doesn't perform its intended function). (2) I have a function Subdiv which contains a for-loop and emits some vertices within that loop, similar to Repeat. Normally, Subdiv works fine. However, sometimes when I put Subdiv in, my GLSL program will fail to link. It's not giving me any coherent error messages to help me diagnose the problem. I'm suspecting maybe some funny loop unrolling going on, but (a)I'm not sure, and (b)no idea how to fix it if so. Has anyone seen/had problems similar to these, and might you know how to work around them? Cheers, --Brian

Share this post


Link to post
Share on other sites
Advertisement
Generally for loops with variable numbers of iterations don't work in GLSL (i.e. it has to use either a constant value or a uniform) I seem to recall reading that the 8800 series supports it, but don't quote me on that.

However, I recently saw a workaround on the forums here that involved hard coding a value into the for loop that was the maximum possible iterations and then using an if in the loop to break when it reached the variable number of iterations. That might take care of both of your problems.

Share this post


Link to post
Share on other sites
Hah. That took care of Problem 1, but not 2. Meanwhile, I'm using an 8800, so there's some confirmation that it can't support loops with a variable number of iterations.

Thanks,
--B

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!