Commit c6841851 by Nicolas Capens

Add support for new ESSL 3.00 keywords.

Bug 19331817 Change-Id: I3315de44d1976219fada3013af13146433aa6eaa Reviewed-on: https://swiftshader-review.googlesource.com/2100Reviewed-by: 's avatarAlexis Hétu <sugoi@google.com> Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent 996314b4
......@@ -120,7 +120,7 @@ bool TCompiler::compile(const char* const shaderStrings[],
(PaParseStrings(numStrings - firstSource, &shaderStrings[firstSource], NULL, &parseContext) == 0) &&
(parseContext.treeRoot != NULL);
shaderVersion = parseContext.shaderVersion();
shaderVersion = parseContext.getShaderVersion();
if (success) {
TIntermNode* root = parseContext.treeRoot;
......
......@@ -297,6 +297,9 @@
<ClInclude Include="ConstantUnion.h" />
<ClInclude Include="debug.h" />
<ClInclude Include="Diagnostics.h" />
<ClInclude Include="DirectiveHandler.h" />
<ClInclude Include="ExtensionBehavior.h" />
<ClInclude Include="glslang.h" />
<ClInclude Include="InfoSink.h" />
<ClInclude Include="Initialize.h" />
<ClInclude Include="InitializeGlobals.h" />
......
......@@ -160,6 +160,15 @@
<ClInclude Include="Compiler.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="DirectiveHandler.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ExtensionBehavior.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="glslang.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<CustomBuild Include="glslang.l">
......
......@@ -26,9 +26,11 @@ static TBehavior getBehavior(const std::string& str)
}
TDirectiveHandler::TDirectiveHandler(TExtensionBehavior& extBehavior,
TDiagnostics& diagnostics)
TDiagnostics& diagnostics,
int& shaderVersion)
: mExtensionBehavior(extBehavior),
mDiagnostics(diagnostics)
mDiagnostics(diagnostics),
mShaderVersion(shaderVersion)
{
}
......@@ -151,7 +153,7 @@ void TDirectiveHandler::handleVersion(const pp::SourceLocation& loc,
if (version == 100 ||
version == 300)
{
mDiagnostics.setShaderVersion(version);
mShaderVersion = version;
}
else
{
......
......@@ -15,9 +15,10 @@ class TDiagnostics;
class TDirectiveHandler : public pp::DirectiveHandler
{
public:
public:
TDirectiveHandler(TExtensionBehavior& extBehavior,
TDiagnostics& diagnostics);
TDiagnostics& diagnostics,
int& shaderVersion);
virtual ~TDirectiveHandler();
const TPragma& pragma() const { return mPragma; }
......@@ -37,10 +38,11 @@ class TDirectiveHandler : public pp::DirectiveHandler
virtual void handleVersion(const pp::SourceLocation& loc,
int version);
private:
private:
TPragma mPragma;
TExtensionBehavior& mExtensionBehavior;
TDiagnostics& mDiagnostics;
int& mShaderVersion;
};
#endif // COMPILER_DIRECTIVE_HANDLER_H_
......@@ -40,12 +40,14 @@ struct TParseContext {
functionReturnsValue(false),
checksPrecisionErrors(checksPrecErrors),
diagnostics(is),
directiveHandler(ext, diagnostics),
shaderVersion(100),
directiveHandler(ext, diagnostics, shaderVersion),
preprocessor(&diagnostics, &directiveHandler),
scanner(NULL) { }
TIntermediate& intermediate; // to hold and build a parse tree
TSymbolTable& symbolTable; // symbol table that goes with the language currently being parsed
GLenum shaderType; // vertex or fragment language (future: pack or unpack)
int shaderVersion;
int compileOptions;
const char* sourcePath; // Path of source file or NULL.
TIntermNode* treeRoot; // root of parse tree being created
......@@ -63,7 +65,7 @@ struct TParseContext {
pp::Preprocessor preprocessor;
void* scanner;
int shaderVersion() const { return diagnostics.shaderVersion(); }
int getShaderVersion() const { return shaderVersion; }
int numErrors() const { return diagnostics.numErrors(); }
TInfoSink& infoSink() { return diagnostics.infoSink(); }
void error(TSourceLoc loc, const char *reason, const char* token,
......
......@@ -15,7 +15,7 @@ WHICH GENERATES THE GLSL ES LEXER (glslang_lex.cpp).
%top{
//
// Copyright (c) 2012 The ANGLE Project Authors. All rights reserved.
// Copyright (c) 2012-2013 The ANGLE Project Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
......@@ -89,10 +89,10 @@ O [0-7]
"lowp" { return(LOW_PRECISION); }
"precision" { return(PRECISION); }
"attribute" { return(ATTRIBUTE); }
"attribute" { if (context->shaderVersion < 300) return(ATTRIBUTE); return reserved_word(yyscanner); }
"const" { return(CONST_QUAL); }
"uniform" { return(UNIFORM); }
"varying" { return(VARYING); }
"varying" { if (context->shaderVersion < 300) return(VARYING); return reserved_word(yyscanner); }
"break" { return(BREAK); }
"continue" { return(CONTINUE); }
......@@ -102,6 +102,13 @@ O [0-7]
"if" { return(IF); }
"else" { return(ELSE); }
"switch" { if (context->shaderVersion < 300) return reserved_word(yyscanner); return(SWITCH); }
"case" { if (context->shaderVersion < 300) return reserved_word(yyscanner); return(CASE); }
"default" { if (context->shaderVersion < 300) return reserved_word(yyscanner); return(DEFAULT); }
"centroid" { if (context->shaderVersion < 300) return reserved_word(yyscanner); return(CENTROID); }
"flat" { if (context->shaderVersion < 300) return reserved_word(yyscanner); return(FLAT); }
"smooth" { if (context->shaderVersion < 300) return reserved_word(yyscanner); return(SMOOTH); }
"in" { return(IN_QUAL); }
"out" { return(OUT_QUAL); }
......@@ -131,71 +138,133 @@ O [0-7]
"bvec3" { context->lexAfterType = true; return (BVEC3); }
"bvec4" { context->lexAfterType = true; return (BVEC4); }
"sampler2D" { context->lexAfterType = true; return SAMPLER2D; }
"samplerCube" { context->lexAfterType = true; return SAMPLERCUBE; }
"sampler2D" { context->lexAfterType = true; return SAMPLER2D; }
"samplerCube" { context->lexAfterType = true; return SAMPLERCUBE; }
"samplerExternalOES" { context->lexAfterType = true; return SAMPLER_EXTERNAL_OES; }
"sampler3D" { context->lexAfterType = true; return SAMPLER3D; }
"sampler3D" { context->lexAfterType = true; return SAMPLER3D; }
"sampler3DRect" { if (context->shaderVersion < 300) return reserved_word(yyscanner); context->lexAfterType = true; return SAMPLER3DRECT; }
"sampler2DShadow" { if (context->shaderVersion < 300) return reserved_word(yyscanner); context->lexAfterType = true; return SAMPLER2DSHADOW; }
"struct" { context->lexAfterType = true; return(STRUCT); }
"asm" { return reserved_word(yyscanner); }
"class" { return reserved_word(yyscanner); }
"union" { return reserved_word(yyscanner); }
"enum" { return reserved_word(yyscanner); }
"typedef" { return reserved_word(yyscanner); }
"template" { return reserved_word(yyscanner); }
"this" { return reserved_word(yyscanner); }
"packed" { return reserved_word(yyscanner); }
"goto" { return reserved_word(yyscanner); }
"switch" { return reserved_word(yyscanner); }
"default" { return reserved_word(yyscanner); }
"inline" { return reserved_word(yyscanner); }
"noinline" { return reserved_word(yyscanner); }
"volatile" { return reserved_word(yyscanner); }
"public" { return reserved_word(yyscanner); }
"static" { return reserved_word(yyscanner); }
"extern" { return reserved_word(yyscanner); }
"external" { return reserved_word(yyscanner); }
"interface" { return reserved_word(yyscanner); }
"flat" { return reserved_word(yyscanner); }
"long" { return reserved_word(yyscanner); }
"short" { return reserved_word(yyscanner); }
"double" { return reserved_word(yyscanner); }
"half" { return reserved_word(yyscanner); }
"fixed" { return reserved_word(yyscanner); }
"unsigned" { return reserved_word(yyscanner); }
"superp" { return reserved_word(yyscanner); }
"input" { return reserved_word(yyscanner); }
"output" { return reserved_word(yyscanner); }
"hvec2" { return reserved_word(yyscanner); }
"hvec3" { return reserved_word(yyscanner); }
"hvec4" { return reserved_word(yyscanner); }
"dvec2" { return reserved_word(yyscanner); }
"dvec3" { return reserved_word(yyscanner); }
"dvec4" { return reserved_word(yyscanner); }
"fvec2" { return reserved_word(yyscanner); }
"fvec3" { return reserved_word(yyscanner); }
"fvec4" { return reserved_word(yyscanner); }
"sampler1D" { return reserved_word(yyscanner); }
"sampler1DShadow" { return reserved_word(yyscanner); }
"sampler2DShadow" { return reserved_word(yyscanner); }
"sampler2DRect" { return reserved_word(yyscanner); }
"sampler3DRect" { return reserved_word(yyscanner); }
"sampler2DRectShadow" { return reserved_word(yyscanner); }
"sizeof" { return reserved_word(yyscanner); }
"cast" { return reserved_word(yyscanner); }
"namespace" { return reserved_word(yyscanner); }
/* Reserved keywords for GLSL ES 3.00 that are not reserved for GLSL ES 1.00 */
"coherent" |
"restrict" |
"readonly" |
"writeonly" |
"resource" |
"atomic_uint" |
"noperspective" |
"patch" |
"sample" |
"subroutine" |
"common" |
"partition" |
"active" |
"filter" |
"image1D" |
"image2D" |
"image3D" |
"imageCube" |
"iimage1D" |
"iimage2D" |
"iimage3D" |
"iimageCube" |
"uimage1D" |
"uimage2D" |
"uimage3D" |
"uimageCube" |
"image1DArray" |
"image2DArray" |
"iimage1DArray" |
"iimage2DArray" |
"uimage1DArray" |
"uimage2DArray" |
"image1DShadow" |
"image2DShadow" |
"image1DArrayShadow" |
"image2DArrayShadow" |
"imageBuffer" |
"iimageBuffer" |
"uimageBuffer" |
"sampler1DArray" |
"sampler1DArrayShadow" |
"isampler1D" |
"isampler1DArray" |
"usampler1D" |
"usampler1DArray" |
"isampler2DRect" |
"usampler2DRect" |
"samplerBuffer" |
"isamplerBuffer" |
"usamplerBuffer" |
"sampler2DMS" |
"isampler2DMS" |
"usampler2DMS" |
"sampler2DMSArray" |
"isampler2DMSArray" |
"usampler2DMSArray" {
if (context->shaderVersion < 300) {
yylval->lex.string = NewPoolTString(yytext);
return check_type(yyscanner);
}
return reserved_word(yyscanner);
}
/* Reserved keywords */
"asm" |
"class" |
"union" |
"enum" |
"typedef" |
"template" |
"this" |
"packed" |
"goto" |
"inline" |
"noinline" |
"volatile" |
"public" |
"static" |
"extern" |
"external" |
"interface" |
"long" |
"short" |
"double" |
"half" |
"fixed" |
"unsigned" |
"superp" |
"input" |
"output" |
"hvec2" |
"hvec3" |
"hvec4" |
"dvec2" |
"dvec3" |
"dvec4" |
"fvec2" |
"fvec3" |
"fvec4" |
"sampler1D" |
"sampler1DShadow" |
"sampler2DRect" |
"sampler2DRectShadow" |
"sizeof" |
"cast" |
"namespace" |
"using" { return reserved_word(yyscanner); }
{L}({L}|{D})* {
......@@ -237,27 +306,27 @@ O [0-7]
";" { context->lexAfterType = false; return(SEMICOLON); }
("{"|"<%") { context->lexAfterType = false; return(LEFT_BRACE); }
("}"|"%>") { return(RIGHT_BRACE); }
"," { if (context->inTypeParen) context->lexAfterType = false; return(COMMA); }
":" { return(COLON); }
"=" { context->lexAfterType = false; return(EQUAL); }
"(" { context->lexAfterType = false; context->inTypeParen = true; return(LEFT_PAREN); }
")" { context->inTypeParen = false; return(RIGHT_PAREN); }
"," { if (context->inTypeParen) context->lexAfterType = false; return(COMMA); }
":" { return(COLON); }
"=" { context->lexAfterType = false; return(EQUAL); }
"(" { context->lexAfterType = false; context->inTypeParen = true; return(LEFT_PAREN); }
")" { context->inTypeParen = false; return(RIGHT_PAREN); }
("["|"<:") { return(LEFT_BRACKET); }
("]"|":>") { return(RIGHT_BRACKET); }
"." { BEGIN(FIELDS); return(DOT); }
"!" { return(BANG); }
"-" { return(DASH); }
"~" { return(TILDE); }
"+" { return(PLUS); }
"*" { return(STAR); }
"/" { return(SLASH); }
"%" { return(PERCENT); }
"<" { return(LEFT_ANGLE); }
">" { return(RIGHT_ANGLE); }
"|" { return(VERTICAL_BAR); }
"^" { return(CARET); }
"&" { return(AMPERSAND); }
"?" { return(QUESTION); }
"." { BEGIN(FIELDS); return(DOT); }
"!" { return(BANG); }
"-" { return(DASH); }
"~" { return(TILDE); }
"+" { return(PLUS); }
"*" { return(STAR); }
"/" { return(SLASH); }
"%" { return(PERCENT); }
"<" { return(LEFT_ANGLE); }
">" { return(RIGHT_ANGLE); }
"|" { return(VERTICAL_BAR); }
"^" { return(CARET); }
"&" { return(AMPERSAND); }
"?" { return(QUESTION); }
<FIELDS>{L}({L}|{D})* {
BEGIN(INITIAL);
......
......@@ -104,15 +104,31 @@ extern void yyerror(TParseContext* context, const char* reason);
context->recover(); \
} \
}
#define ES2_ONLY(S, L) { \
if (context->shaderVersion != 100) { \
context->error(L, " supported in GLSL ES 1.00 only ", S); \
context->recover(); \
} \
}
#define ES3_ONLY(S, L) { \
if (context->shaderVersion != 300) { \
context->error(L, " supported in GLSL ES 3.00 only ", S); \
context->recover(); \
} \
}
%}
%token <lex> INVARIANT HIGH_PRECISION MEDIUM_PRECISION LOW_PRECISION PRECISION
%token <lex> ATTRIBUTE CONST_QUAL BOOL_TYPE FLOAT_TYPE INT_TYPE
%token <lex> BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN
%token <lex> BREAK CONTINUE DO ELSE FOR IF DISCARD RETURN SWITCH CASE DEFAULT
%token <lex> BVEC2 BVEC3 BVEC4 IVEC2 IVEC3 IVEC4 VEC2 VEC3 VEC4
%token <lex> MATRIX2 MATRIX3 MATRIX4 IN_QUAL OUT_QUAL INOUT_QUAL UNIFORM VARYING
%token <lex> CENTROID FLAT SMOOTH
%token <lex> STRUCT VOID_TYPE WHILE
%token <lex> SAMPLER2D SAMPLERCUBE SAMPLER_EXTERNAL_OES SAMPLER3D
%token <lex> SAMPLER2D SAMPLERCUBE SAMPLER_EXTERNAL_OES SAMPLER2DRECT
%token <lex> SAMPLER3D SAMPLER3DRECT SAMPLER2DSHADOW
%token <lex> IDENTIFIER TYPE_NAME FLOATCONSTANT INTCONSTANT BOOLCONSTANT
%token <lex> FIELD_SELECTION
......@@ -1486,11 +1502,13 @@ type_qualifier
}
| ATTRIBUTE {
VERTEX_ONLY("attribute", $1.line);
ES2_ONLY("attribute", $1.line);
if (context->globalErrorCheck($1.line, context->symbolTable.atGlobalLevel(), "attribute"))
context->recover();
$$.setBasic(EbtVoid, EvqAttribute, $1.line);
}
| VARYING {
ES2_ONLY("varying", $1.line);
if (context->globalErrorCheck($1.line, context->symbolTable.atGlobalLevel(), "varying"))
context->recover();
if (context->shaderType == GL_VERTEX_SHADER)
......@@ -1499,6 +1517,7 @@ type_qualifier
$$.setBasic(EbtVoid, EvqVaryingIn, $1.line);
}
| INVARIANT VARYING {
ES2_ONLY("varying", $1.line);
if (context->globalErrorCheck($1.line, context->symbolTable.atGlobalLevel(), "invariant varying"))
context->recover();
if (context->shaderType == GL_VERTEX_SHADER)
......
......@@ -57,81 +57,90 @@
IF = 273,
DISCARD = 274,
RETURN = 275,
BVEC2 = 276,
BVEC3 = 277,
BVEC4 = 278,
IVEC2 = 279,
IVEC3 = 280,
IVEC4 = 281,
VEC2 = 282,
VEC3 = 283,
VEC4 = 284,
MATRIX2 = 285,
MATRIX3 = 286,
MATRIX4 = 287,
IN_QUAL = 288,
OUT_QUAL = 289,
INOUT_QUAL = 290,
UNIFORM = 291,
VARYING = 292,
STRUCT = 293,
VOID_TYPE = 294,
WHILE = 295,
SAMPLER2D = 296,
SAMPLERCUBE = 297,
SAMPLER_EXTERNAL_OES = 298,
SAMPLER3D = 299,
IDENTIFIER = 300,
TYPE_NAME = 301,
FLOATCONSTANT = 302,
INTCONSTANT = 303,
BOOLCONSTANT = 304,
FIELD_SELECTION = 305,
LEFT_OP = 306,
RIGHT_OP = 307,
INC_OP = 308,
DEC_OP = 309,
LE_OP = 310,
GE_OP = 311,
EQ_OP = 312,
NE_OP = 313,
AND_OP = 314,
OR_OP = 315,
XOR_OP = 316,
MUL_ASSIGN = 317,
DIV_ASSIGN = 318,
ADD_ASSIGN = 319,
MOD_ASSIGN = 320,
LEFT_ASSIGN = 321,
RIGHT_ASSIGN = 322,
AND_ASSIGN = 323,
XOR_ASSIGN = 324,
OR_ASSIGN = 325,
SUB_ASSIGN = 326,
LEFT_PAREN = 327,
RIGHT_PAREN = 328,
LEFT_BRACKET = 329,
RIGHT_BRACKET = 330,
LEFT_BRACE = 331,
RIGHT_BRACE = 332,
DOT = 333,
COMMA = 334,
COLON = 335,
EQUAL = 336,
SEMICOLON = 337,
BANG = 338,
DASH = 339,
TILDE = 340,
PLUS = 341,
STAR = 342,
SLASH = 343,
PERCENT = 344,
LEFT_ANGLE = 345,
RIGHT_ANGLE = 346,
VERTICAL_BAR = 347,
CARET = 348,
AMPERSAND = 349,
QUESTION = 350
SWITCH = 276,
CASE = 277,
DEFAULT = 278,
BVEC2 = 279,
BVEC3 = 280,
BVEC4 = 281,
IVEC2 = 282,
IVEC3 = 283,
IVEC4 = 284,
VEC2 = 285,
VEC3 = 286,
VEC4 = 287,
MATRIX2 = 288,
MATRIX3 = 289,
MATRIX4 = 290,
IN_QUAL = 291,
OUT_QUAL = 292,
INOUT_QUAL = 293,
UNIFORM = 294,
VARYING = 295,
CENTROID = 296,
FLAT = 297,
SMOOTH = 298,
STRUCT = 299,
VOID_TYPE = 300,
WHILE = 301,
SAMPLER2D = 302,
SAMPLERCUBE = 303,
SAMPLER_EXTERNAL_OES = 304,
SAMPLER2DRECT = 305,
SAMPLER3D = 306,
SAMPLER3DRECT = 307,
SAMPLER2DSHADOW = 308,
IDENTIFIER = 309,
TYPE_NAME = 310,
FLOATCONSTANT = 311,
INTCONSTANT = 312,
BOOLCONSTANT = 313,
FIELD_SELECTION = 314,
LEFT_OP = 315,
RIGHT_OP = 316,
INC_OP = 317,
DEC_OP = 318,
LE_OP = 319,
GE_OP = 320,
EQ_OP = 321,
NE_OP = 322,
AND_OP = 323,
OR_OP = 324,
XOR_OP = 325,
MUL_ASSIGN = 326,
DIV_ASSIGN = 327,
ADD_ASSIGN = 328,
MOD_ASSIGN = 329,
LEFT_ASSIGN = 330,
RIGHT_ASSIGN = 331,
AND_ASSIGN = 332,
XOR_ASSIGN = 333,
OR_ASSIGN = 334,
SUB_ASSIGN = 335,
LEFT_PAREN = 336,
RIGHT_PAREN = 337,
LEFT_BRACKET = 338,
RIGHT_BRACKET = 339,
LEFT_BRACE = 340,
RIGHT_BRACE = 341,
DOT = 342,
COMMA = 343,
COLON = 344,
EQUAL = 345,
SEMICOLON = 346,
BANG = 347,
DASH = 348,
TILDE = 349,
PLUS = 350,
STAR = 351,
SLASH = 352,
PERCENT = 353,
LEFT_ANGLE = 354,
RIGHT_ANGLE = 355,
VERTICAL_BAR = 356,
CARET = 357,
AMPERSAND = 358,
QUESTION = 359
};
#endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment