When do these shaders fail? At compile, link or run time?
At run time, they all compile fine.
Anyway:
2. This one fails because the compiler does not understand that "int n" is a constant. Try "const int n" instead (probably won't work either).
Notice how the examples where n is not actually used, only passed, works. Anyway, this is not really important, the loop problem is...
3. This one probably fails because you're surpassing the maximum instruction count on R420 (512 math + 512 tex instructions iirc).
Yes, this is what I thought too, so that's why I included test 4. Test 3 and 4 are both running the same number of instructions. However, now it seems like the compiler optimized this likeness away, so it looks like you are right...
Do you know if nVidia has similar problems, and if there are any known workarounds on ATI? My program really needs more instructions than that...
4. Probably the compiler figures out you're passing the same parameter and optimizes away the last two calls. Try doing this:
test(100);
test(101);
test(99);
That worked fine, but it looks like you are right. I made a more torough test, which failed.
Updated test 4:
void test1(int n)
{
float s=0.0;
for (int i=0;i<100;i++)
{
s++;
}
}
void test2(int n)
{
float s=0.0;
for (int i=0;i<100;i++)
{
s++;
}
}
void test3(int n)
{
float s=0.0;
for (int i=0;i<100;i++)
{
s++;
}
}
void main()
{
test1(100);
test2(100);
test3(100);
gl_FragColor = vec4(1.0,1.0,1.0,1.0);
}
So, the compiler does some smart things, although not too smart, or it would also be able to omit the first call to a method that is not doing anything.

Btw, what you're doing is generally a bad idea. What for do you need such a big loop?
The examples are just constructed to highlight the problems I found. The actual code has less than ten loops, but with more instructions in each one. It runs at excellent framerates, until the above illustrated problem kills the shader...
