glslLangValidator: OpenGL / OpenGL ES Reference Compiler



glslLangValidator: OpenGL / OpenGL ES Reference Compiler

glslLangValidator is GLSL tool for Windows / Linux released by the Khronos Group. glslLangValidator is the official reference compiler front end for both OpenGL ES and OpenGL shading languages. It implements a strict interpretation of the specifications for these languages. It is open and free for anyone to use, either from a command line or programmatically.

More information about can be found here: OpenGL / OpenGL ES Reference Compiler. You can download the command line version from HERE.

I quickly tested glslLangValidator with the following GLSL 1.40 (OpenGL 3.1) vertex shader took from GLSL Hacker code sample pack.

#version 140
in vec4 gxl3d_Position;
in vec4 gxl3d_Color;
in vec4 gxl3d_Normal;
uniform mat4 gxl3d_ModelViewProjectionMatrix;
uniform mat4 gxl3d_ModelViewMatrix;
out vec4 Vertex_Color;
void main()
{
  gl_Position = gxl3d_ModelViewProjectionMatrix * gxl3d_Position;
  vec4 eye = gxl3d_ModelViewMatrix * gxl3d_Position; 
  float d = length(eye);
  gl_PointSize = 30.0 * 1.0/(0.0 + 0.04*d + 0.0001*d*d); 			
  Vertex_Color = gxl3d_Color;
}



To validate this vertex shader (file vs.vert), just use type this command:

glslangValidator.exe vs.vert

Here is the output:

Warning, version 140 is not yet complete; most features are present, but a few are missing.



I guess it means there’s no error.

Now if I remove the ; at the line 11, here is the output:

Warning, version 140 is not yet complete; most features are present, but a few are missing.
ERROR: 0:11: '' :  syntax error
ERROR: 1 compilation errors.  No code generated.



The current version of glslangValidator can be checked with

glslangValidator -v



The associated output is:

ESSL Version: OpenGL ES GLSL 3.00 glslang LunarG Khronos.24740 2014/01/11 12:29:55
GLSL Version: 4.20 glslang LunarG Khronos.24740 2014/01/11 12:29:55



According to the documentation, the current version of glslangValidator supports GLSL shaders up to GLSL #version 1.40 / OpenGL 3.1 (so why it tells that version 140 is not yet complete? Is it related to the machine I currently use to write this new?).

Using the -i option, you can generate the intermediate tree (glslang AST, AST is the not structured flow control representation of the GLSL shader). The tree of our vertex shader is:

0:? Sequence
0:8  Function Definition: main( (void)
0:8    Function Parameters: 
0:10    Sequence
0:10      move second child to first child (4-component vector of float)
0:10        'gl_Position' (gl_Position 4-component vector of float)
0:10        matrix-times-vector (4-component vector of float)
0:10          'gxl3d_ModelViewProjectionMatrix' (uniform 4X4 matrix of float)
0:10          'gxl3d_Position' (in 4-component vector of float)
0:11      Sequence
0:11        move second child to first child (4-component vector of float)
0:11          'eye' (4-component vector of float)
0:11          matrix-times-vector (4-component vector of float)
0:11            'gxl3d_ModelViewMatrix' (uniform 4X4 matrix of float)
0:11            'gxl3d_Position' (in 4-component vector of float)
0:12      Sequence
0:12        move second child to first child (float)
0:12          'd' (float)
0:12          length (float)
0:12            'eye' (4-component vector of float)
0:13      move second child to first child (float)
0:13        'gl_PointSize' (gl_PointSize float)
0:13        divide (float)
0:13          Constant:
0:13            30.000000
0:13          add (float)
0:13            add (float)
0:13              Constant:
0:13                0.000000
0:13              component-wise multiply (float)
0:13                Constant:
0:13                  0.040000
0:13                'd' (float)
0:13            component-wise multiply (float)
0:13              component-wise multiply (float)
0:13                Constant:
0:13                  0.000100
0:13                'd' (float)
0:13              'd' (float)
0:14      move second child to first child (4-component vector of float)
0:14        'Vertex_Color' (smooth out 4-component vector of float)
0:14        'gxl3d_Color' (in 4-component vector of float)
0:?   Linker Objects
0:?     'gxl3d_Position' (in 4-component vector of float)
0:?     'gxl3d_Color' (in 4-component vector of float)
0:?     'gxl3d_Normal' (in 4-component vector of float)
0:?     'gxl3d_ModelViewProjectionMatrix' (uniform 4X4 matrix of float)
0:?     'gxl3d_ModelViewMatrix' (uniform 4X4 matrix of float)
0:?     'Vertex_Color' (smooth out 4-component vector of float)
0:?     'gl_VertexID' (gl_VertexId int)
0:?     'gl_InstanceID' (gl_InstanceId int)



Related links