Bug in nvidia glsl compiler?

void main()
{
	gl_Position = ftransform();
#if 1
	float d = gl_ProjectionMatrix[3][2]*gl_Normal.x-gl_ProjectionMatrix[2][2];
#else
	float d = -gl_ProjectionMatrix[2][2]+gl_ProjectionMatrix[3][2]*gl_Normal.x;
#endif
	gl_FrontColor = vec4( d );
} 

Both variants of calculation of d should give same result, isn’t it? With second variant ‘-’ operator is ignored. Just try it yorself - by changing ‘#if 1’ to ‘#if 0’.

driver version: 77.72

Is anybody able to reproduce it?

these two shaders produce same asm output.

Shader 1:

void main()
{
	gl_Position = ftransform();
	float d = gl_ProjectionMatrix[2][2]+gl_ProjectionMatrix[3][2]*gl_Normal.x;
	gl_FrontColor = vec4( d );
} 

Shader 2:

void main()
{
	gl_Position = ftransform();
	float d = -gl_ProjectionMatrix[2][2]+gl_ProjectionMatrix[3][2]*gl_Normal.x;
	gl_FrontColor = vec4( d );
} 

Asm output (enabled in nvemulate) for both:

!!VP2.0
# cgc version 1.3.0001, build date Jun 15 2005 17:58:26
# command line args: 
#vendor NVIDIA Corporation
#version 1.0.02
#profile vp30
#program main
#semantic gl_ProjectionMatrix
#semantic gl_ModelViewProjectionMatrixTranspose
#var float3 gl_Normal : $vin.NORMAL : ATTR2 : -1 : 1
#var float4 gl_Vertex : $vin.POSITION : ATTR0 : -1 : 1
#var float4 gl_Position : $vout.POSITION : HPOS : -1 : 1
#var float4 gl_FrontColor : $vout.COLOR0 : COL0 : -1 : 1
#var float4x4 gl_ProjectionMatrix :  : c[0], 4 : -1 : 1
#var float4x4 gl_ModelViewProjectionMatrixTranspose :  : c[4], 4 : -1 : 1
BB1:
DP4   o[HPOS].w, v[0], c[7];
DP4   o[HPOS].z, v[0], c[6];
DP4   o[HPOS].y, v[0], c[5];
DP4   o[HPOS].x, v[0], c[4];
MUL   R0.x, v[2], c[3].z;
ADD   o[COL0], R0.x, c[2].z;
END
# 6 instructions, 1 R-regs

If it looks like a bug, acts like a bug, it is a …

It certainly appears it is just ignoring the -(negate operator)

I think you are going to need cass or another nvidia guy to give a difinite answer. (Have you emailed them about it?)

Have you tried assigning the uniforms to a tempoary value before using them. It should not make any difference but who knows…

Consider trying beta drivers from ie. www.guru3d.com… BETA 80.40 seem to have quite good behaving GLSL implementation. (and luckily only one which works for me at the moment) YMMV.

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