# Very Weird GLSL Problems

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

## 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 on other sites
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 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

1. 1
2. 2
3. 3
4. 4
Rutin
17
5. 5

• 12
• 9
• 12
• 37
• 12
• ### Forum Statistics

• Total Topics
631419
• Total Posts
2999984
×