View Full Version : GLSL loop crashes on ATI

11-02-2006, 11:22 AM

I have a ludicrous problem with loops in glsl
see the follow code

for(int i = 0; i < 3; i++){
}it works fine, but when i change the for condition with a variable this crashes

int n = 3;
for(int i = 0; i < n; i++){
}I'm using an ATI X600 PciExpress mobile

somebody know how to fix this bug?


11-02-2006, 01:39 PM
Make 'n' a constant (const int n=3;)?

Complain to ATi, filing a bug report?

Or, accept that your card can't do dynamic looping, so don't try it.

11-03-2006, 03:43 AM
If you use
int n = 3;
instead of
const int n = 3;
then it will run in software mode, so avoid it.

11-06-2006, 10:07 AM
Your example embodies the difference between unrolling a loop and having genuine flow control/branching support in hardware. The variable in your example means that the itterations are unpredictable and require a little bit of additional smarts in the compiler to detect the '3' and see that it doesn't change, (making it const basically tells the computer that it will not change, i.e. it's not really variable). Of course the motivation for the 3 is the desire to have a genuinely variable number of itterations and that is the root problem, without some form of flow control it cannot be done unless software fallback or some other inefficient approach is taken.