Update to GLSL front-end source released

We released an updated version of the GLSL front-end source code. You can find it here: http://developer.3dlabs.com/downloads/glslcompiler/index.htm

This is the source code of the front-end we use in our GLSL compiler. We released this as open source in the hope that other vendors implementing OpenGL will use it (and several do). That in turn will promote portability of GLSL shaders across platforms.

Changes since the last release:

  • Source now compiles on gcc 3.4.4.
  • Fixed constant folding for ternary operator.
  • Non-dereferenced arrays not allowed in constructors. Other semantic error checking on arrays such as ++array, array1 = array2.
  • Max allowed index for gl_TexCoord is gl_MaxTextureCoords - 1.
  • Raise an error when one of the string passed to the parser is a NULL pointer.
  • Parser code tested to be portable on STLport stl.
  • Detect error when preprocessor directives does not begin at the start of the line.

Regards,

Barthold
3Dlabs

I forgot to add that we also released a new version of GLSLvalidate, to match the new GLSL front-end. You can get it here: http://developer.3dlabs.com/downloads/glslvalidate/index.htm

GLSLvalidate is a small application that allows you to quickly verify that your GLSL shader is written according to the OpenGL Shading Language specification. You do not need an OpenGL accelerator in your system in order to run this.

Barthold

Hi Barthold,

This is nice. I just saw all new stuff at 3DLabs and I must say that you are doing a great work to push OpenGL (I really like the new documentation for VStudio and the migration guide, congrats, we really needed a good doc more updated than the msdn’s one )
About the GLSL compiler, I will update it with this new version in the Shader Designer (as well as include a Collada scene importer)

Good work!

The link to the Windows installer seems to be broken.

I really like the idea of updated GL docs in MSVC, but it seems not to work on my machine though. :frowning:

It works perfectly to me. If you want I can send to you via email.

Originally posted by barthold:
[b]I forgot to add that we also released a new version of GLSLvalidate, to match the new GLSL front-end. You can get it here: http://developer.3dlabs.com/downloads/glslvalidate/index.htm

GLSLvalidate is a small application that allows you to quickly verify that your GLSL shader is written according to the OpenGL Shading Language specification. You do not need an OpenGL accelerator in your system in order to run this.

Barthold[/b]
it’s good news!
I modify old version to support MSVC-style error messages (with line number etc). And i can use GLSLvalidate as custom compile tool.
Can you make a version of GLSLvalidate with this feature? i think it will be very usefull for many peoples.

thx.
p.s. sorry for my english.

I am pretty sure that if all you want is the ability to click on a line to goto an error location, you already have two choices:

Shader Designer : http://www.typhoonlabs.com/ can use the GLSL validate tool.

GLIntercept: http://glintercept.nutty.org can use the shader editor in “offline” mode. This uses the 3D Labs validate tool with error line jumping.

thanx, i already use GLIntercept, but it’s not a tool for Radeons and i have some problem with reloading shaders after changing code.

and about GLvalidate, i modify new version and its work fine, thanx.

I have found that old and new version GLvalidate can’t compile my vertex shader right, if you interesting then shader is:

 
uniform vec3 GUN_LightSource0;
uniform vec3 GUN_ViewPosition;

#ifdef USE_SKINBONES
	uniform mat4 GUN_BonesMatrix[20];
#endif

varying vec2 uv;
#ifdef USE_MAT_DIFF_COLOR
	varying vec4 diffuseColor;
#endif

#ifdef USE_LIGHT0_POINT
	varying vec3 lightPosition;
#else
#ifdef USE_LIGHT0_DIRECT
	varying vec3 lightDirection;
#endif
#endif

#ifdef USE_SPECULAR
	varying vec3 eyePosition;
#else
#ifdef USE_PARALAX
	varying vec3 eyePosition;
#endif
#endif

#ifndef USE_BUMPMAP
	varying vec3 vertexNormal;
#endif


void main()
{
#ifdef USE_SKINBONES
	vec4 weight = gl_MultiTexCoord2;
	vec4 index = gl_MultiTexCoord3;
	vec3 new_normal = vec3(0,0,0);
	vec3 new_tangent = vec3(0,0,0);
	vec4 posObj = vec4(0,0,0,1);

	ivec4 curIndex = ivec4(index);
	vec4 curWeight = weight;

	posObj += (GUN_BonesMatrix[curIndex.x] * gl_Vertex) * curWeight.x;
	posObj += (GUN_BonesMatrix[curIndex.y] * gl_Vertex) * curWeight.y;
	posObj += (GUN_BonesMatrix[curIndex.z] * gl_Vertex) * curWeight.z;
	posObj += (GUN_BonesMatrix[curIndex.w] * gl_Vertex) * curWeight.w;
	
#ifdef USE_BEST_SKINLIGHTING
	// [0]
	mat3 m1 = mat3(GUN_BonesMatrix[curIndex.x][0].xyz, GUN_BonesMatrix[curIndex.x][1].xyz, GUN_BonesMatrix[curIndex.x][2].xyz);
	new_normal += (m1 * gl_Normal) * curWeight.x;
	new_tangent += (m1 * gl_MultiTexCoord1.xyz) * curWeight.x;
	// [1]
	mat3 m2 = mat3(GUN_BonesMatrix[curIndex.y][0].xyz, GUN_BonesMatrix[curIndex.y][1].xyz, GUN_BonesMatrix[curIndex.y][2].xyz);
	new_normal += (m2 * gl_Normal) * curWeight.y;
	new_tangent += (m2 * gl_MultiTexCoord1.xyz) * curWeight.y;
	// [2]
	mat3 m3 = mat3(GUN_BonesMatrix[curIndex.z][0].xyz, GUN_BonesMatrix[curIndex.z][1].xyz, GUN_BonesMatrix[curIndex.z][2].xyz);
	new_normal += (m3 * gl_Normal) * curWeight.z;
	new_tangent += (m3 * gl_MultiTexCoord1.xyz) * curWeight.z;
	// [3]
	mat3 m4 = mat3(GUN_BonesMatrix[curIndex.w][0].xyz, GUN_BonesMatrix[curIndex.w][1].xyz, GUN_BonesMatrix[curIndex.w][2].xyz);
	new_normal += (m4 * gl_Normal) * curWeight.w;
	new_tangent += (m4 * gl_MultiTexCoord1.xyz) * curWeight.w;
#else
	mat3 m1 = mat3(GUN_BonesMatrix[curIndex.x][0].xyz, GUN_BonesMatrix[curIndex.x][1].xyz, GUN_BonesMatrix[curIndex.x][2].xyz);
	new_normal += (m1 * gl_Normal);
	new_tangent += (m1 * gl_MultiTexCoord1.xyz);
#endif

	// output vertex position
    gl_Position = gl_ModelViewProjectionMatrix * vec4(posObj.xyz, 1);
#else
	vec3 new_normal = gl_Normal.xyz;
	vec3 new_tangent = gl_MultiTexCoord1.xyz;
	//gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
	gl_Position = ftransform();
#endif

	
    // output texture coordinates for decal and normal maps
    uv = gl_MultiTexCoord0.xy;
#ifdef USE_MAT_DIFF_COLOR
	// output color
	diffuseColor = gl_Color;
#endif
	// compute tangent space
	mat3 objToTangentSpace;
	vec3 new_binormal = cross(new_normal.xyz, new_tangent.xyz) * gl_MultiTexCoord1.w;
	objToTangentSpace[0] = vec3(new_tangent.x, new_binormal.x, new_normal.x);
	objToTangentSpace[1] = vec3(new_tangent.y, new_binormal.y, new_normal.y);
	objToTangentSpace[2] = vec3(new_tangent.z, new_binormal.z, new_normal.z);

#ifndef USE_BUMPMAP
  vertexNormal = new_normal * objToTangentSpace;
#endif

#ifdef USE_LIGHT0_POINT
	// Convert light position to obj space
	vec4 LocalLight = gl_ModelViewMatrixInverse * vec4(GUN_LightSource0, 1.0);
    // Convert light position to tangent space
    lightPosition = objToTangentSpace * (LocalLight.xyz - gl_Vertex.xyz);
#else
#ifdef USE_LIGHT0_DIRECT
    // Convert light direction to obj space
    mat3 invObj3 = mat3(gl_ModelViewMatrixInverse[0].xyz, gl_ModelViewMatrixInverse[1].xyz, gl_ModelViewMatrixInverse[2].xyz);
	vec3 LocalLight = invObj3 * normalize(GUN_LightSource0);
    // Convert light position to tangent space
    lightDirection = objToTangentSpace * LocalLight.xyz;
#endif
#endif

#ifdef USE_SPECULAR
	// Convert eye position to obj space
	vec4 LocalEye = gl_ModelViewMatrixInverse * vec4(GUN_ViewPosition, 1.0);
    // Convert eye position to tangent space
    eyePosition = objToTangentSpace * (LocalEye.xyz - gl_Vertex.xyz);
#else
#ifdef USE_PARALAX
	// Convert eye position to obj space
	vec4 LocalEye = gl_ModelViewMatrixInverse * vec4(GUN_ViewPosition, 1.0);
    // Convert eye position to tangent space
    eyePosition = objToTangentSpace * (LocalEye.xyz - gl_Vertex.xyz);
#endif
#endif  


}
 

the error messages:

 
Parsing vertex shader 'ObjectLighting_VS.glsl'....
Failure.

ERROR: 0:75: 'posObj' : undeclared identifier 
ERROR: 0:75: 'xyz' :  field selection requires structure, vector, or matrix on left hand side 
ERROR: 0:75: 'constructor' : not enough data provided for construction 
ERROR: 0:92: 'new_normal' : undeclared identifier 
ERROR: 0:92: 'xyz' :  field selection requires structure, vector, or matrix on left hand side 
ERROR: 0:92: 'new_tangent' : undeclared identifier 
ERROR: 0:92: 'xyz' :  field selection requires structure, vector, or matrix on left hand side 
ERROR: 0:92: 'cross' : no matching overloaded function found 
ERROR: 0:92: '=' :  cannot convert from 'float' to '3-component vector of float'
ERROR: 0:93: 'x' :  field selection requires structure, vector, or matrix on left hand side 
ERROR: 0:93: 'x' :  field selection requires structure, vector, or matrix on left hand side 
ERROR: 0:94: 'y' :  field selection requires structure, vector, or matrix on left hand side 
ERROR: 0:94: 'y' :  field selection requires structure, vector, or matrix on left hand side 
ERROR: 0:95: 'z' :  field selection requires structure, vector, or matrix on left hand side 
ERROR: 0:95: 'z' :  field selection requires structure, vector, or matrix on left hand side 
ERROR: 0:98: 'assign' :  cannot convert from '3X3 matrix of float' to 'varying 3-component vector of float'
ERROR: 16 compilation errors.  No code generated.
 

this shader also can’t run in hardware mode on Radeons, i think it’s bug of ati drivers, because i have similar shader in Cg that work on Radeons.

Add a #define USE_SKINBONES at the top and it compiles OK in the validator. (I used GLIntercept in offline mode)

What CybeRUS has is a nested #ifdef. I modified the code to get rid of the nesting and then it works.

Originally posted by CybeRUS:
this shader also can’t run in hardware mode on Radeons, i think it’s bug of ati drivers, because i have similar shader in Cg that work on Radeons.
This bug was recently fixed. In fact, I think I recognize that shader, in particular the misspelled “parallax”. :wink: It compiled fine with the latest builds.

Originally posted by V-man:
What CybeRUS has is a nested #ifdef. I modified the code to get rid of the nesting and then it works.
yes, nested #ifdef with #else don’t work fine

Humus:
Sorry for misspelled “parallax” :slight_smile: i fix it.
i sent this shader to ATi last year, Fix is very good news! Now we can use GLSL in all codepasses.

There isn’t specific mention in the spec for allowing nesting of #ifdef and #ifndef, but I think it would be nicer if it worked. Maybe someone with more authority can confirm if this is a bug or not.

Nested #ifdefs is valid. I think we had bug like that, but was fixed. I guess I should look that up.

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