Possible GLSL errors are as follows:
- Internal compiler error
-
Indicates an error that is not exposed via another specific error code, or indicates an internal problem with the operation of the compiler.
- Compiler memory error - shader exceeds x bytes
-
Long running programs can cause problems on some hardware, thus the GLSL compiler takes some measures to prevent these programs from running. One of the measures taken is to examine the length of the shader after the preprocessor has run. If this length is too long, then the shader is rejected.
- Syntax error - x
-
The syntax at the given location did not match the required syntax of GLSL. There are a large number of reasons for why this can occur in both the preprocessing stage and the GLSL language stage. Here is a simple example:
GLSLattribute int int;
Since an identifier is expected after a type, this is an invalid declaration.
- Undeclared identifier x
-
Identifiers must be declared before they can be used. The most common cause of this error is misspelling an identifier name, or using an identifier from an extension without enabling the extension. For example:
GLSLint x; y = 1;
- Invalid arguments passed to function x
-
A function was called with the incorrect number of arguments or with one or more of the arguments of the wrong type. Check that the number of arguments and their types in the function call match those of the declaration or definition of the function. For example:
GLSLvoid exampleFunction1(int x); void exampleFunction2() { exampleFunction1(1, 2); }
- Postfix expression cannot be indexed
-
This error indicates that the indexing operator [] has been applied to an expression which does not support being indexed. The following code demonstrates how this error can occur:
GLSLint bar; return bar[0];
- Index out of range
-
The compiler has determined that an index is out of range for the variable as it was declared.
In some cases (such as indexing a vector or an array) the bounds are known, and if the index is an expression that the compiler can calculate, it can determine if the index is out of range. The following code demonstrates how this error can occur:
GLSLint bar[3]; int baz = bar[4];
- Incompatible index expression. For non-uniforms, the index must be an expression formed of the loop_index and integer constants. For uniforms, the index must be an integer constant.
-
There are restrictions to what kind of index is allowed on both uniform and non-uniform variables. For a uniform variable, the index must be an integer constant expression. The following code demonstrates how this error can occur:
GLSL// The indexing of nonuniform vectors and arrays with expressions is illegal: vec4 b; float a; int c = 0; a = b[c]; // For fragment shader code, the indexing of uniform vectors and arrays with index expressions is illegal: uniform vec4 b; float a; int c = 0; a = b[c];
If the variable is not a unifom, then the index can include a loop index variable.
- Index must be a constant
-
An index is not a constant in the shader code. The following shader code demonstrates how this error can occur:
GLSLuniform float myArray[100]; int i = 0; float a; a = myArray[i];
- Argument x is not a sampler
-
An argument is not a sampler in the shader code. A sampler is a set of GLSL uniform variable types that represent a particular texture used for texture sampling. Samplers are not allowed to be declared using a non-uniform type.
GLSLfloat my2dSampler; // Should be "uniform sample2D my2dSampler". vec2 coord; v4 returnData; returnData = texture2D(my2dSampler, coord); // Note that texture2D() is a built-in function.
- Invalid macro name - cannot start with 'GL_' or contain '__'
-
Invalid macro name used in the shader code. The following code demonstrates how this error can occur:
GLSL#define get__squared(x) ( x * x )
- Incompatible types in expression
-
Incompatible types in expression used within the shader code. The following code demonstrates how this error can occur:
GLSLfloat a; float b; if (a || b) { // Causes the error because the IF statement inputs are not Boolean. a = 1.0; }
- Expression in if statement does not evaluate to a boolean
-
Invalid if expression used in shader code. The following code demonstrates how this error can occur:
GLSLstruct S { int x; }; bool b[2]; if (S) { // Causes the error because struct types are not allowed in selection IF expressions. return true; } else { return false; } if (b) { // Also causes the error because array types are not allowed in selection IF expressions. return true; } else { return false; }
- Divide or mod by zero in constant expression
-
Divide or mod by zero occurred in shader code. The following code demonstrates how this error can occur:
GLSLint a = 5 / 0; float a = 5.0 / 0.0; vec4 a; a[1 / 0] = 0.4;
- Invalid parameter count for macro
-
Invalid preprocessor parameter count on macro occurred in shader code. Ensure that the number of arguments passed to the macro matches the expected number of parameters for the macro. The following code demonstrates how this error can occur:
GLSL#define myMacro(x) (x < 0) myMacro(1,2)
- Maximum uniform vector count exceeded
-
Maximum uniform vector count exceeded in shader code. The following code demonstrates how this error can occur:
GLSLuniform vec4 v1[1000000];
- Maximum attribute vector count exceeded
-
Maximum attribute vector count exceeded in shader code. The following code demonstrates how this error can occur:
GLSLattribute vec4 v1[1000000];
- Maximum varying vector count exceeded
-
Maximum varying vector count exceeded in shader code. The following code demonstrates how this error can occur:
GLSLvarying vec4 v1[1000000];
- Maximum shader complexity exceeded
-
Shader code complexity error. Shader programs that encounter this can try to use a simpler version of the shader.
- Identifier already declared
-
Identifier already declared in the shader code. The following code demonstrates how this error can occur:
GLSLfloat a; float a[5]; int b; void b() {} struct { vec4 v; vec3 v[2]; } example2;
- Invalid character used outside of comment
-
Invalid character error within shader code. The following code demonstrates how this error can occur:
GLSLvoid exampleFunction() { int /@9$; }
- Invalid initializer in for loop, needs to be a single variable of type float or int and initialized to a constant
-
Invalid initializer in for loop within the shader code. The following code demonstrates how this error can occur:
GLSLvoid exampleFunction1() { int i; for (i = 0; i < 1; i++) { // Declaring i outside of the loop and assigning a value to it is an error. } } void exampleFunction2() { for (int i; i < 1; i++) { // i must be initialized. } } void exampleFunction3() { for (bool i = false; i; i = !i) { // i must be an int or float. } } void exampleFunction4() { struct S { int i; }; for (S s = S(2); s.i < 4; s.i++) { // i cannot be a struct. } } void exampleFunction5() { float x = 0.0; for (float i = x; i < 1.0; i++) { // i cannot be initialized via another variable. } }
- Invalid condition in for loop, needs to be in form loop_index { > | >= | < | <= | == | != } constant
-
Invalid condition in for loop within shader code. The following code demonstrates how this error can occur:
GLSLfor (int i = 0; ; i++) { } // The conditional statement is missing. for (int i = 0; 1 > i; i++) { } // The conditional must have the variable on the left. for (int i = 0; i * 2; i++) { } // The conditional cannot use operators outside of comparison and equality operators.
- Invalid iteration in for loop, needs to be in form { --loop_index | ++loop_index | loop_index++ | loop_index-- | loop_index+=constant | loop_index-=constant }
-
Invalid iteration in for loop within the shader code. The following code demonstrates how this error can occur:
GLSLvoid exampleFunction1() { for (int i = 0; i < 1; ) { // Missing increment/decrement statement. } } void exampleFunction2() { for (int i = 0; i < 10; i *= 2) { // The += and -= operators may be used but not *= or /= } } void exampleFunction3() { int x = 10; for (int i = 0; i < 10; i += x) { // The x variable must be a constant. } }
- Invalid modification to loop index inside loop body
-
Invalid write to loop variable within shader code. The following code demonstrates how this error can occur:
GLSLvoid exampleFunction1() { for (int i = 0; i < 1; i++) { i = 1; } } void exampleFunction2() { for (int i = 0; i < 1; i++) { i++; } } void exampleFunction3() { int x = 10; for (int i = 0; i < 1; i++) { int x; i = x = 1; } }
- Invalid identifier name - cannot start with 'gl_', 'webgl_', '_webgl_' or contain '__'
-
Invalid identifier name used in shader code. The following code demonstrates how this error can occur:
GLSLint webgl_baz; struct gl_faz { int bar; } svar; void __exampleFunction2() { } void webgl_exampleFunction3() { } void exampleFunction1(int a__rg) { } void exampleFunction1(int rg__) { }
- Token exceeds maximum length
-
A token exceeds its max length in shader code. Try shortening long identifier names.
- Invalid qualifier on array - cannot make arrays of attribute or const variables
-
Invalid qualifier on array in shader code, as demonstrated in the following:
GLSLattribute float foo[2]; const float bar[1]; // const array of structs not allowed: struct S1 { int i; }; const S1 s1[3]; const struct S2 { int i; } s2[3];
- Incompatible type used for return expression
-
Incompatible type used for return expression in shader code. The following code demonstrates how this error can occur:
GLSLvoid exampleFunction1() { float a; return (a + 1.0); } vec2 exampleFunction2() { float a; return (a + 1.0); } struct { bool b; } exampleFunction3() { // Note that anonymous structs are a valid return type for GLSL functions. return true; // Causes error in that this Boolean type does not match the expected return type. }
- Invalid qualifier on sampler variable declaration - must be uniform
-
Invalid qualifier on sampler variable declaration used in shader code, as demonstrated in the following:
GLSLvarying sampler2D sampler; varying samplerCube sampler; attribute sampler2D sampler; attribute samplerCube sampler; sampler2D sampler; sampler2D sampler[2]; samplerCube sampler;
- Invalid type passed to matrix constructor - arguments must be a matrix, or a scalar / vector of float / int / bool
-
Invalid type passed to matrix constructor in shader code. The following code demonstrates how this error can occur:
GLSLstruct S { int i; } s; mat2 v1 = mat2(s); int i[2]; mat2 v2 = mat2(i);
- Invalid type passed to componentwise vector or matrix constructor - arguments must be a scalar / vector of float / int / bool
-
Invalid type passed to component-wise vector or matrix constructor in shader code. The following code demonstrates how this error can occur:
GLSLuniform sampler2D s1; float f = float(s1); uniform samplerCube s2; int i = int(s2); bool b = int(s2);
GLSL// Structure and array types cannot be vector or tensor constructor arguments: struct S { int i; } s; vec2 v1 = vec2(1, s); int i[1]; ivec2 v2 = ivec2(1, i);
GLSL// Samplers are not allowed as vector constructor arguments: uniform sampler2D s1; vec4 v1 = vec4(0, 0, 0, s1); uniform samplerCube s2; vec4 v2 = vec4(0, 0, 0, s2);
GLSL// Samplers are not allowed as matrix constructor arguments: uniform sampler2D s1; mat2 v = mat2(0, 0, 0, s1); uniform samplerCube s2; mat2 v = mat2(0, 0, 0, s2);
GLSL// Cannot pass multiple matrix arguments: mat2 a; mat4 mat = mat4(a, a, a, a); // Structure and array types cannot be used in matrix constructors: struct S { int i; } s; mat2 v1 = mat2(1, s, 0, 1); int i[2]; mat2 v2 = mat2(1, i, 0, 1); // Cannot use matrix arguments to a matrix constructor if there are more than one arguments: mat3 m1 = mat3(vec3(0), vec2(0), mat2(1)); mat4 m2 = mat4(vec4(0), vec4(0), mat2(1), mat2(1));
- Invalid argument count in componentwise vector or matrix constructor - total components passed must equal vector or matrix size
-
Invalid count of components passed to matrix constructor in shader code. The following code demonstrates how this error can occur:
GLSLfloat f = float(1, 2); int i = int(1, 2); bool b = bool(1, 2); // Invalid component count using scalars: mat2 mat = mat2(1.0, 2.0, 3.0); mat3 mat = mat3(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0); mat4 mat = mat4(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0); // Invalid component count using vectors: vec3 a; vec3 b; vec3 c; mat2 m = mat2(a, b, c); // Invalid component count using vectors and scalars: vec2 a; mat2 mat = mat2(a, 3.0); vec4 a; mat3 mat = mat3(a, a, a, 3.0); //Invalid argument counts: vec2 a; mat2 m = mat2(a); vec2 a, b, c; mat2 m = mat2(a, b, c); vec3 a, b; mat3 m = mat3(a, b); vec3 a, b, c, d; mat3 m = mat3(a, b, c, d); vec4 a, b, c; mat4 m = mat4(a, b, c); vec4 a, b, c, d, e; mat4 m = mat4(a, b, c, d, e);
- Invalid expression on left of assignment expression
-
Invalid expression on left of assignment in shader code. There are many sources of this error including:
GLSL// Invalid constants and const variables: const float x = 0.0; x = 1.0; void exampleFunction(const float x) { x = 1.0; } // Invalid swizzle with repeats: vec4 x; x.xx = vec2(1.0, 1.0); vec4 x; x.ww -= vec2(1.0, 1.0); vec4 x; --x.xx; // Invalid function call: float test() { return 0.0; } void baz() { test() = 1.0; } // Invalid assignment expressions: float x, y; x *= 2.0 = y; float x; (x *= 2.0)++; // Writing to read-only built-in variables: gl_FrontFacing = false; gl_PointCoord = vec2(0.0, 0.0); gl_DepthRange.near = 1.0; // Writing to varying variables (which are read-only) within the fragment shader: varying vec3 baz1; void main() { baz1 = vec3(0.0) }; varying vec3 baz2; void main() { baz2.x = 1.0; } // Uniforms and attributes cannot be left-hand values: uniform bool abc; abc = true; attribute vec3 cba; cba.z = 1.0; // Constant objects cannot be left-hand values: void outfunc(inout float ret) { ret = 1.0; } void callingfunc() { const float x = 0.0; outfunc(x); } const struct S { vec4 v; } svar = S(vec4(0.0)); svar.v.x = 1.0;
- Invalid swizzle in field selection - swizzle component count must be equal or less than max vector size (4)
-
Too many components provided for swizzle in the shader code. The following code demonstrates how this error can occur:
GLSL// Cannot use more than four components: vec2 a; vec4 b; a = b.xxxxx;
- Invalid swizzle in field selection - swizzle components must be all from same set (xyzw, rgba or stpq)
-
For shader code, the provided swizzle components cannot be in different sets. The following code demonstrates how this error can occur:
GLSL// Cannot mix index types (like r and y): vec2 a; vec4 b; b = a.ry; b = a.xs; b = a.sg;
- Invalid swizzle component in field selection - must be from a valid GLSL set (xyzw, rgba or stpq)
-
An invalid swizzle component is used in the shader code. The following code demonstrates how this error can occur:
GLSL// Cannot use illegal characters in field selection of vectors: vec4 b; b = b.cdef;
- Swizzle component out of range - must select a component that exists in the vector
-
A swizzle component is out of range in the shader code. The following code demonstrates how this error can occur:
GLSL// Invalid index attempt (vec2 has no z component): vec2 a; vec4 b; b = a.yzzz; b = a.baaa; b = a.pqqq;
- This hardware is unable to support gl_FrontFacing
-
Shader code using gl_FrontFacing on FL 9 hardware. The following code demonstrates how this error can occur on FL9 hardware:
GLSLvoid main() { if (gl_FrontFacing) { gl_FragColor = vec4(1.0, 0, 0, 1); } }
- Const variable requires initialization
-
Shader code variables declared as const require initialization. The following code demonstrates how this error can occur:
GLSLconst float bar; const float a, b = 0.0, c; // Samplers can't be const variables: const sampler2D sampler; const samplerCube sampler; // const anonymous structures are impossible since they can't be initialized in GLSL: const struct { bool b; } svar; // const structures must be initialized: struct S { int i; }; const S s;
- Variables declared with uniform, attribute, or varying qualifier cannot be initialized
-
Shader code variables declared as uniform, attribute, or varying qualifier cannot be initialized. The following code demonstrates how this error can occur:
GLSLattribute vec3 attr1 = vec3(0.0); uniform float uniFloat = 0.0; varying vec2 varyVec = vec2(0.0); uniform float uniFloat = 0.0; varying vec2 varyVec = vec2(0.0);
- Varying variable cannot have bool, int, or struct type
-
Shader code variables declared as varying require an underlying component type of float. The following code demonstrates how this error can occur:
GLSLvarying int var; varying ivec2 var; varying ivec3 var[2]; varying bool var[3]; varying bvec4 var;
- Invalid argument passed to constructor - argument must be a basic GLSL type
-
Invalid constructor argument used in shader code. The following code demonstrates how this error can occur:
GLSLstruct Light { vec3 eyePosOrDir; bool isDirectional; vec3 intensity; float attenuation; } lightData; light = mat2(lightData);
- Invalid type qualifier for function parameter - only const on in parameters is allowed
-
Invalid type qualifier on parameter used in shader code. The following code demonstrates how this error can occur:
GLSLvoid exampleFunction1(const inout highp float x) {} void exampleFunction2(const inout highp float) {} void exampleFunction3(const inout float x[1]) {} void exampleFunction4(varying float x) {} void exampleFunction5(attribute float x) {}
- Array declarator requires a constant expression
-
For shader code, declarators declared as array types require a constant expression for the array size, as demonstrated as follows:
GLSL// Array expression must be constant: int i = (false) ? 1 : 2; int j[i]; // Array parameter declarators must have constant size: int bar = (true) ? 1 : 0; void exampleFunction1(float x[bar]) {} // Array declarators must be const in structs: uniform bool f; void exampleFunction2() { int i = (f) ? 1 : 2; struct { int j[i]; } svar; } // The following array must have a size specified, and the size specified must be an integral constant that's greater than zero: int arrraySize = 10; struct { int myArray[arrraySize + 1]; };
- Array was declared with size less than or equal to zero
-
For shader code, array size constants must be greater than or equal to zero. The following code demonstrates how this error can occur:
GLSLint j[0]; int j[-1]; void exampleFunction1(int bar[0]) {} void exampleFunction2(int bar[-1]) {} const int bar = 0; void exampleFunction3(float x[bar]) {} void exampleFunction4(float x[0]) {} struct { int z[0]; }; struct { int i, j[0]; } svar; struct { int j[-1]; } svar;
- Type qualifiers 'uniform' and 'attribute' are invalid for structs
-
Invalid type qualifier for struct used in shader code. The following code demonstrates how this error can occur:
GLSLattribute struct { vec4 v; } svar; varying struct { vec4 v; } svar;
- Invalid field name for struct type
-
Invalid type qualifier for struct used in shader code (can't be varying or attribute). The following code demonstrates how this error can occur:
GLSL// Cannot use a name that doesn't exist on the type for field selection: struct { int a; } svar; svar.b = 1; struct S { int x; }; void exampleFunction() { struct S { int y; } ss; S s; s.x = 1; }
- Invalid type for left hand side of field selection
-
Invalid type for left hand side of field selection used in shader code. The following code demonstrates how this error can occur:
GLSLvec4 b[2]; b.x = 1.0; // Invalid type for field selection (svar.v is an array): struct { vec4 v[10]; } svar; svar.v.x = 1.0;
- Samplers are not allowed in structs
-
For shader code, sampler types are not supported as struct fields. The following code demonstrates how this error can occur:
GLSLstruct { sampler2D samp; } svar; struct { samplerCube samp; } svar;
- Macros must be redefined the same as original definition
-
Macros must be redefined the same in shader code. The following code demonstrates how this error can occur:
GLSL#define A 7.0 A #define A(x) x A(1)
.
- Invalid loop index expression passed as out / inout parameter
-
Using loop index as out or inout parameter in shader code. The following code demonstrates how this error can occur:
GLSLvoid zar(out int x) { x = 1; } void bar() { for (int i = 0; i < 1; i++) { zar(i); } }
- Type cannot be used as a constructor
-
For shader code, types are not allowed to be constructed. The following code demonstrates how this error can occur:
GLSLvoid exampleFunction1() { return void(); } sampler2D s1 = sampler2D(0); samplerCube s2 = samplerCube(0);
- Undeclared type x
-
Type name has not been declared in shader code. The following code demonstrates how this error can occur:
GLSLstruct S { int x; }; void exampleFunction() { S S = S(10); S x; } // Member types must already be defined (forward references are not allowed): struct { svarB foo; } svarA; struct svarB { int bar; };
- Embedded struct declarations are not allowed
-
structs can't be nested in shader code. The following code demonstrates how this error can occur:
GLSLstruct { struct { int bar; } svarB; } svarA;
- Function x is declared and used but not defined
-
Invoked function not defined in shader code. The following code demonstrates how this error can occur:
GLSLvoid zar(); void bar() { zar(); }
- Function redefinition not allowed
-
Function illegally redefined in shader code. The following code demonstrates how this error can occur:
GLSLvoid bar(int) {} void bar(int) {} void zar1(inout int i) {} void zar1(inout int i) {} void zar2(in int i) {} void zar2(int i) {} void zar3(int i) {} void zar3(in int i) {}
- Function redeclaration not allowed
-
Function illegally re-declared in shader code. The following code demonstrates how this error can occur:
GLSL// Duplicate forward declarations are not allowed: void bar(int); void bar(int); // A definition counts as a declaration: void zar(int) {} void zar(int); void func1(out int i) {} void func1(out int i); void func2(in int i) {} void func2(int i); void func3(int i) {} void func3(in int i);
- Invalid single argument to vector constructor - must be a scalar type, or another vector, or a 2x2 matrix
-
Invalid argument passed to vector constructor in shader code. The following code demonstrates how this error can occur:
GLSL// Structure and array types cannot be vector or tensor constructor arguments: struct S { int i; } s; vec2 v1 = vec2(s); int i[2]; ivec2 v2 = ivec2(i);
- Struct constructor arguments' types do not match the struct's field types
-
For shader code, struct constructors require exactly matching types. The following code demonstrates how this error can occur:
GLSL// Structure constructor types must match exactly in count and type: // Types not matching: struct S { int x; }; S s = S(true); // Too few arguments: struct S { int x, y; }; S s = S(1); // Too many arguments: struct S { int x; }; S s = S(1, 2);
- Error: x
-
Custom preprocessor shader error code/message. For example, the #error directive can be used for detecting programmer inconsistencies and violation of constraints during preprocessing. When an #error directive is encountered, compilation terminates with a custom error code/message, if provided.
GLSL#if !defined(__cplusplus) #error C++ compiler required. #endif
Be aware that the error code/message is subject to macro expansion.
- Invalid location for continue statment - must be inside of a loop
-
Cannot execute a
continue
outside of a loop. The following code demonstrates how this error can occur:GLSLvoid main(void) { continue; }
- Cannot call main
-
main
is the designated entry point, and therefore cannot be called. The following code demonstrates how this error can occur:GLSLvoid exampleFunction { main(void); }
- Invalid qualifier on non-global variable - non-global variables can be const but cannot be varying, attribute or invariant
-
Invalid qualifier on non-global variable used in shader code. The following code demonstrates how this error can occur:
GLSLvoid main(void) { main(void); } void baz() { main(void); }
- Cannot redefine main or define main with incorrect signature
-
For shader code, you cannot redefine main or define main with an incorrect signature. The following code demonstrates how this error can occur:
GLSLvoid main(int x) { } void main(float x) { } void main(int x, float y) { } float main() { return 1.0; }
- Cannot use reserved operators such as '~', '%=', '>>=', '<<=', '&=', '|=', or '^='
-
Reserved operator used in shader code. The following code demonstrates how this error can occur:
GLSLint a; a >>= 1; int b; b <<= 1; int c; c %= 1; int d; d &= 1; int e; e |= 1; int f; f ^= 1; bool g; bool h = ~g;
- Ternary conditional operator must have boolean expression for test condition
-
For shader code, ternary conditional operators must have Boolean expression for the test condition. The following code demonstrates how this error can occur:
GLSLfloat a; int b; bool c; a = (c, a, b) ? (b = 1, 1.0) : (b = 2, 2.0); float a; float b; int c; a = b ? 1.0 : c; struct S { int x; }; bool baz1() { S s; return (s) ? true : false; } bool baz2() { bool b[2]; return (b) ? true : false; }
- Ternary conditional operator must have two expressions of equal types after test condition
-
For shader code, a ternary conditional operator must have two expressions of equal types after the test condition. The following code demonstrates how this error can occur:
GLSLfloat a; float b; int c; a = (b < 0.0) ? 1.0 : c;
- Invalid location for break statement - break statements must be inside a loop
-
Invalid location for break statement in shader code. The following code demonstrates how this error can occur:
GLSLvoid main(void) { break; }
- Invalid location for discard statement - discard statements must be inside a fragment shader
-
Invalid location for discard statement in shader code. The following code demonstrates how this error can occur:
GLSLvoid main(void) { discard; }
- Initializer for const variable must initialize to a constant value
-
Non-constant initializer used in shader code. The following code demonstrates how this error can occur:
GLSLint x = 0; const int y = x; bool x = false; const bool y = !x; int x[2]; const int y = x[0]; ivec2 x; const int y = x.x; struct structDef {int bar;}; structDef baz = structDef(1); const int y = baz.bar; bool f = true; const int y = (f) ? 1 : 0; // Function params with const are not const expressions: void baz(const int x) { const int y = x; } // Samplers also can't be const variables: uniform sampler2D a; const sampler2D sampler = a; uniform samplerCube b; const samplerCube sampler = b; // A const struct may not contain an array: int iArr[2]; struct S { int i[2]; }; const S s = S(iArr); S nonConstS; const S s = nonConstS; // const struct initialization requires const parameters: struct S { int i, j; }; int a, b; const S s = S(a, b);
- Functions cannot be overloaded on return type
-
Function overloaded on return type in shader code. The following code demonstrates how this error can occur:
GLSLvoid sin(float f) { } void sin(vec4 f); void pow(float f1, float f2) { } void pow(vec4 f1, vec4 f2); void clamp(float f1, float f2, float f3) { } void clamp(vec4 f1, vec4 f2, vec4 f3); void step(float f1, float f2) { } void step(float f, vec4 v); mat4 cross(vec3 a, vec3 b) { } mat4 cross(vec3 a, vec3 b); void equal(vec2 f1, vec2 f2) { } void equal(bvec4 f1, bvec4 f2); void any(bvec2 f) { } void any(bvec4 f); // Overloads on the return type are not allowed: int baz1(int); void baz1(int) {} struct S { int i; }; int baz2(S s) { return 1; } void baz2(S); struct S { int i; }; struct S2 { int i; }; S baz3(); S2 baz3();
- Known functions cannot be re-declared or re-defined
-
A known function was re-declared or re-defined in shader code. The following code demonstrates how this error can occur:
GLSLfloat sin(float f) { } vec4 sin(vec4 f); float pow(float f1, float f2) { } vec4 pow(vec4 f1, vec4 f2); float clamp(float f1, float f2, float f3) { } vec4 clamp(vec4 f1, vec4 f2, vec4 f3); float step(float f1, float f2) { } vec4 step(out float f, vec4 v); vec3 cross(vec3 a, vec3 b) { } vec3 cross(vec3 a, vec3 b); bvec2 equal(vec2 f1, vec2 f2) { } bvec4 equal(inout bvec4 f1, bvec4 f2); bool any(bvec2 f) { } bool any(bvec4 f);
- Function header definition parameter qualifiers must match declaration parameter qualifiers
-
A function was defined with mismatching qualifiers from its declaration in shader code. The following code demonstrates how this error can occur:
GLSLvoid baz1(int i); void baz1(out int i) {} void baz2(out int i); void baz2(inout int i) {} struct S { int i; }; void baz3(inout S i); void baz3(out S i) {} void baz3(S i); void baz3(out S i) {}
- Array size must be an integer constant expression
-
Array size must be an integer constant expression in shader code. The following code demonstrates how this error can occur:
GLSLfloat i = 0.0; int arr[2]; arr[i];
- Array size expression too complex
-
Array size unable to be calculated in shader code. The following code demonstrates how this error can occur:
GLSLconst bool x = false; const bool y = !x; int a[int(y)]; int a[ivec2(1, 1).x]; const ivec2 x = ivec2(1, 1); const int y = x.x; int a[y]; struct structDef {int bar;}; const structDef baz = structDef(1); const int y = baz.bar; int a[y]; int arr[2 > 1 ? 8 : 9];
- #version directive must specify 100 for version
-
Wrong #version directive used in shader code. The following code demonstrates how this error can occur:
GLSL#version 90 #version 110
- #version directive can only be preceded by whitespace or comments
-
#version directive in wrong place in shader code. The following code demonstrates how this error can occur:
GLSL#define BAZ #version 100
- Unary operator not defined for type
-
Unary operator not defined for this type in shader code. The following code demonstrates how this error can occur:
GLSLstruct S { int i; } s; +s; int a[2]; +a;
- Struct declarations are disallowed in function parameter declarators
-
struct type declaration in function parameter not allowed in shader code. The following code demonstrates how this error can occur:
GLSLbool exampleFunction(struct S { bool b; } svar) { return svar.b; }
- Struct type declaration exceeds maximum nesting level of 4
-
struct types exceeded maximum nesting level in shader code. The following code demonstrates how this error can occur:
GLSLstruct One { bool f; }; struct Two { One one[2]; }; struct Three { Two two[2]; }; struct Four { Three three[2]; }; struct Five { One one; Two two; Three three; Four four[2]; };
- Operator not defined for struct types
-
Illegal operator for struct type used in shader code. The following code demonstrates how this error can occur:
GLSLstruct S {int a;}; S a, b; a <= b; struct S {bool a;}; S a, b; a && b; struct S {int a;}; S a, b; a += b;
- Operator not defined for user-defined types that contain array types
-
Operator not defined for a type that contains an array type in shader code. The following code demonstrates how this error can occur:
GLSLstruct S {int a[2];}; S a, b; a = b;
- Unknown extension: x
-
Unknown extension used in shader code. For FL9 hardware, the following code demonstrates how this error can occur:
GLSL#extension GL_OES_standard_derivatives : enable\nvoid exampleFunction() { vec3 x; vec3 y = dFdx(x); }
- Invalid behavior specified for extension - behavior must be require, warn, enable or disable for regular extensions, or warn or disable for 'all'
-
Invalid behavior specified for extension in shader code. The following code demonstrates how this error can occur:
GLSL#extension all : enable #extension all : require #extension all : unknown
- Required extension x is not supported
-
A required extension is not supported for the shader code. For FL9 hardware, the following code demonstrates how this error can occur:
GLSL#extension GL_OES_standard_derivatives : require\nvoid exampleFunction() { vec3 x; vec3 y = dFdx(x); }
- Preprocessor directives can only be preceded by whitespace on a line
-
Directive not first thing on line in shader code. The following code demonstrates how this error can occur:
GLSLaaaa#define A a/**/aa #define B aaa#define C aa/**/a #define D
- Function declarations cannot be local
-
The following code demonstrates how this error can occur:
GLSL// Local function declarations are not allowed: void baz(int) { void bar(); }
- Variable declared as type void is not allowed
-
The following code demonstrates how this error can occur:
GLSLvoid v[3]; void baz(void vv); void baz(void vv) {} struct { void a; } svar; struct { void a[2]; } svar; struct { void a; } svar; struct { void a[2]; } svar;
- 'void' is an invalid parameter type unless used as '(void)'
-
The following code demonstrates how this error can occur:
GLSLvoid baz1(int, void) {} void baz2(int, vec3, mat2, void, mat4) {}
转自:http://msdn.microsoft.com/en-us/library/ie/dn611835(v=vs.85).aspx