View Single Post
Old 03-27-07, 11:00 AM   #1
Registered User
Join Date: Dec 2002
Posts: 47
Default array initialisation bug with glsl on 8800 cards

Hello, i have experienced a strange bug in glsl fragment shader on 8800 cards.

The bug affect array of initialization.

If i declare an array of floats, and after i initialize the array to 0.0 :

float f[9];
 for (i=0; i<=8; i++) {
the compiler discards the code, because it thinks that underlying layer should already give a null initialized array.

if i replace f[i]=0 by f[i] = 0.000001, the compiler of course don't discard the code.

in the following code :

void main (void)
  float red[9], green[9], blue[9];
  int col, lin, i;

  /* This init is not be DONE !!!
     if we put 0.00001 instead of 0.0 for init value, it works */
  for (i=0; i<=8; i++) {
    red[i] = green[i] =blue[i] = 0.0;

  for (col=-1; col<=1; col++) {
    for (lin=-1; lin<=1; lin++) {
      if ((col == 0) && (lin ==0)) {
        vec3 color = vec3 (0.1, 0.1, 0.1);
        red[((col+1)*3)+lin+1] = color.r;
        green[((col+1)*3)+lin+1] = color.g;
        blue[((col+1)*3)+lin+1] = color.b;

  vec3 sum = vec3 (0.0, 0.0, 0.0);

  for (i=0; i<=8; i++) {
    sum+= vec3 (red[i], green[i], blue[i]);

  gl_FragColor.rgb = sum;
  gl_FragColor.a = 1;

the array is not alway nullified, so instead of having a uniform dark gray on the screen, i have some rubbish.

In fact, after a cold boot, the test app which use this shader behave correctly, but after launching some app which use big shader (shaders which need lot of temporary registry), the shader fail.

Of course the fix is easy, i just have to initialize the array to epsilon instead of 0.0, and all is correct.

Does anyone experienced similar bug in glsl ?

ps: driver version 9755.

alex31 is offline   Reply With Quote