strange OGLSL problem with 66.93 NVIDIA's driver

I have a NV 6800 GT.

I had writed a physics simulation on the GPU in OGLSL. This application seemed to correctly run on both
ATI’s & NVIDIA’s graphic boards until nowaday. Now i need to make the textures’ lookup from my vertex program and
this is possible in OGLSL only with the latest Nvidia’s driver(66.93). Actually the textures’ lookup seems to go…
but all the rest of the application is dead…
In particular the run-time in nvoglnt.dll throws an “division by zero” exception…

I try to debug the fragment shader incrementally quoting the code and all i have got is the hell…
The uniform variable declared in the fragment shader appear and disappear without any logic(the following is
a fragment shader without any really sense…only for show the problem).

Ex.

if i write:

uniform bool drawpos;

void main(void)
{
      if(!drawpos)
      { 
         vec4 i = vec4(0.0);
      }
      else
      {
         vec4 j = vec4(0.0);
      }
      gl_FragColor = vec4(0.0);
}

and in the application:

glUseProgramObjectARB(pobj);
GLint hvar = glGetUniformLocationARB(pobj,"drawpos");
glUniform1fARB(hvar,true);  

the hvar value is -1(drawpos variable not found)

even if i write:

uniform bool drawpos;

void main(void)
{
      if(!drawpos)
      { 
         gl_FragColor = vec4(0.0);
      }
      else
      {
         gl_FragColor = vec4(1.0);
      }
}

the hvar value is a correct handle for the drawpos varible…

From the NVidia site i have got the 61.77 driver and with this all two version of the fragment program goes right…

the following is a toy-exemple of my complete program including the c++,vertex and fragment code:

C++ CODE:

#include<string>

using namespace std;

GLhandleARB vsh = NULL;
GLhandleARB fsh = NULL;
GLhandleARB pobj = NULL;

const char** vt;
const char** ft;

void Init(void)
{	 	
	string s("/*varying vec2 texcoord;*/ void main(void){/*texcoord = gl_MultiTexCoord1.st;*/gl_Position = ftransform();}");
	vt =(const char**) malloc(s.length() * sizeof(char));
	(*vt) = s.c_str(); 

	string s1("uniform bool drawpos;/*varying vec2 texcoord;*/void main(void){if(!drawpos){ vec4 i = vec4(0.0);} else { vec4 j  = vec4(0.0);} gl_FragColor = vec4(0.0);}");
	ft =(const char**) malloc(s1.length() * sizeof(char));
	(*ft) = s1.c_str(); 
	glEnable(GL_TEXTURE_2D);
	glClearColor(0.0,0.0,0.0,0);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glOrtho(0.0,1.0,0.0,1.0,-20,20);
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	
	vsh = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
	glShaderSourceARB(vsh,1,vt,NULL);
	glCompileShaderARB(vsh);

	fsh = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
	glShaderSourceARB(fsh,1,ft,NULL);
	glCompileShaderARB(fsh);

	pobj =  glCreateProgramObjectARB();

	glAttachObjectARB(pobj,vsh);
	glAttachObjectARB(pobj,fsh);
	
	glLinkProgramARB(pobj);
	glColor3f(1.0f,1.0f,1.0f);
}

void display()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	glUseProgramObjectARB(pobj);
	GLint hvar = glGetUniformLocationARB(pobj,"drawpos");
	glUniform1fARB(hvar,true);
	glutSwapBuffers();
	glFlush();
}

void idle()
{
	glutPostRedisplay();
}

void keyboardFunc(unsigned char key, int x, int y)
{
	switch(key)
	{
	case 27:
		{
			exit(0);
			break;
		}
	}
}

int main(int argc,char** argv)
{ 
	glutInit(&argc,argv);
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
	glutInitWindowSize(800,800);
	int in = glutCreateWindow("Springs Chain");
	OGLSL::Init(in);
	Init();
	//glutFullScreen();
	glutDisplayFunc(display);
	//glutSpecialFunc(SpecialKey);
	//glutMouseFunc(mouseFunc);
	//glutMotionFunc(mouseMotionFunc);
	//glutPassiveMotionFunc(passiveMotionFunc);
	glutKeyboardFunc(keyboardFunc);
	glutIdleFunc(idle);
	glutMainLoop();
	return 0;
}  

VERTEX PROGRAM CODE:

/*varying vec2 texcoord;*/

void main(void)
{
   /*texcoord = gl_MultiTexCoord1.st;*/
   gl_Position = ftransform();
}

FRAGMENT PROGRAM CODE:

uniform bool drawpos;

/*varying vec2 texcoord;*/

void main(void)
{
      if(!drawpos)
      { 
		vec4 i = vec4(0.0);
      }
      else
      {
         vec4 j  = vec4(0.0);
      }
      gl_FragColor = vec4(0.0);
}

Are there some errors in my code???

THANKS…

I don’t know if your problem is related to mine, but I had problems with 66.xx drivers and glsl with GeForce 6800GT (it doesn’t happen in GeforceFX family) that crashes the computer. It doesn’t happen with 61.77 and doesn’t happen with 70.41
I sent a demo program to NVIDIA and they have been able to reproduce the problem so hopefully they have investigated it.
Try searching for 70.41 with google and try if your problem is still there.
Hope this helps.

uniform bool drawpos;

void main(void)
{
if(!drawpos)
{
vec4 i = vec4(0.0);
}
else
{
vec4 j = vec4(0.0);
}
gl_FragColor = vec4(0.0);
}

the hvar value is -1(drawpos variable not found)
This is the correct behavior because drawpos is never actually used in your shader. The compiler will just optimize out that entire if statement because it doesn’t effect any output from the shader.

I haven’t here all the code…but i assure you that there are many other situation in which i obtain a very similar problem…

However in this case it’s surely possible that for optimization the drawpos variable would be discarded …even if with the previous version of the driver the same code seemed to work well…also with ATI cards…

I have forgotten to add that using the “software rasterization”'s check box in nvemulate the application(the real application…i have not tested the toy-example code…) run well…very slow but well…

Hi ,
i think the example code shows a documented shortcoming in nvidias current compiler tech ... IIRC currently you may not loop or have conditionals based on uniform variables ... Theres a pdf on nvidia.com which describes the state if nvidia`s GLSL imp so far … have a look …
Martin Kraus

Thanks CAB…probabily we had the same problem!!!

I’m going to increase your rating…