GLSL loop crashes on ATI


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?


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.

If you use
int n = 3;
instead of
const int n = 3;
then it will run in software mode, so avoid it.

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.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.