nV News Forums

 
 

nV News Forums (http://www.nvnews.net/vbulletin/index.php)
-   NVIDIA Linux (http://www.nvnews.net/vbulletin/forumdisplay.php?f=14)
-   -   array initialisation bug with glsl on 8800 cards (http://www.nvnews.net/vbulletin/showthread.php?t=88793)

alex31 03-27-07 10:28 AM

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 :

Code:

float f[9];
 for (i=0; i<=8; i++) {
f[i]=0.0;
}

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 :


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 allway nullified, so instead of having a uniform dark greay 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 initialise the array to epsilon instead of 0.0, and all is correct.

Does anyone experienced similar bug in glsl ?

ps: driver version 9755.

Alexandre


All times are GMT -5. The time now is 05:23 PM.

Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright 1998 - 2014, nV News.