# Driver bug (GLSL)?

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

## Recommended Posts

I'm not sure if I've come across a driver bug or if I've over looked something when it comes to structures, loops and conditionals in GLSL.

Here's the problem narrowed down (it's in the fragment shader, I didn't test in others yet):
uniform struct { vec3 b; int a; } val[2]; //... for (int Loop = 0; Loop < 2; Loop++) { if (val[Loop].a == 1) { /* Won't get run even if it is true and any references to val[Loop].a afterwards even if index is constant won't work either. Though if the comparison is removed it would work. */ } }

Now by simply changing the type of 'b' to the same type as 'a' it works.

On a side note, I do know it's suggested to stay away from conditional jumps and loops, but I just wanted to compare speed with another shader of mine to see if on certain cases it would be better to use the other. But I guess this problem answered that question.

##### Share on other sites
It may be *your specific* driver for your card. Back a while I was doing work with both ATI and NVidia and we had similar code using arrays indexed by variable which failed silently on one of the cards (can't remember which). The driver didn't report a compile error, but the code didn't run as expected on the GPU.

I didn't bother investigating a lot, because I was under time pressure, I just decided not to mess about with loop variables used as indexes in future..

Another thing to bear in mind is that depending on your card/driver combination, GSLS's support for integers is sometimes a little bit interesting -- particularly with passing them in through unif/attrb. Again, we adopted a rule that we pass in all uniform/attributes as float and convert them inside the shader into integers rather than spend the entire of the rest of our lives trying to understand exactly what the flakiness was.

##### Share on other sites
Yes that's what I was thinking, especially since it's a rather old Nvidia card.Though I haven't tested it on any equivalent systems yet to see for sure. But if it doesn't work on one, then not much point me spending time on it since all I want is portability, or as close to as I can get.

As far as avoiding variable index arrays in general, what about circumstances where there is no obvious way to avoid them. Is it better to just unroll the loop yourself either manually or runtime depending on the scenario, or just trust that the driver will be able to handle it correctly?

And thanks for mentioning about the integers. I didn't realize that could be an issue, and I think that it very well could be the reason why one of my shaders has been giving strange results.

1. 1
2. 2
3. 3
Rutin
16
4. 4
5. 5
A4L
12

• 11
• 26
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
633723
• Total Posts
3013541
×