Add partial support for parsing layout qualifiers, added in the GLES SL 3.00 spec.

This allows us to run a lot of ES3 unit tests and sample apps. TRAC #23089 Signed-off-by: Nicolas Capens Signed-off-by: Shannon Woods Author: Jamie Madill git-svn-id: https://angleproject.googlecode.com/svn/branches/es3proto@2409 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent abf14cc3
...@@ -131,6 +131,26 @@ enum TQualifier ...@@ -131,6 +131,26 @@ enum TQualifier
EvqLast EvqLast
}; };
// Layout qualifiers
enum TLayoutQualifierType
{
ElqLocation,
ElqShared,
ElqPacked,
ElqStd140,
ElqRowMajor,
ElqColumnMajor,
ElqError
};
struct TLayoutQualifierId
{
TLayoutQualifierType type;
int location;
};
typedef std::vector<TLayoutQualifierId> TLayoutQualifier;
// //
// This is just for debug print out, carried along with the definitions above. // This is just for debug print out, carried along with the definitions above.
// //
......
...@@ -2081,6 +2081,87 @@ TIntermTyped* TParseContext::addFieldSelectionExpression(TIntermTyped *baseExpre ...@@ -2081,6 +2081,87 @@ TIntermTyped* TParseContext::addFieldSelectionExpression(TIntermTyped *baseExpre
return indexedExpression; return indexedExpression;
} }
TLayoutQualifierId TParseContext::addLayoutQualifierId(const TString &qualifierType, TSourceLoc qualifierTypeLine)
{
TLayoutQualifierId qualifierId;
qualifierId.type = ElqError;
qualifierId.location = -1;
if (qualifierType == "shared")
{
qualifierId.type = ElqShared;
}
else if (qualifierType == "packed")
{
qualifierId.type = ElqPacked;
}
else if (qualifierType == "std140")
{
qualifierId.type = ElqStd140;
}
else if (qualifierType == "row_major")
{
qualifierId.type = ElqRowMajor;
}
else if (qualifierType == "column_major")
{
qualifierId.type = ElqColumnMajor;
}
else if (qualifierType == "location")
{
error(qualifierTypeLine, "invalid layout qualifier", qualifierType.c_str(), "location requires an argument");
recover();
}
else
{
error(qualifierTypeLine, "invalid layout qualifier", qualifierType.c_str());
recover();
}
return qualifierId;
}
TLayoutQualifierId TParseContext::addLayoutQualifierId(const TString &qualifierType, TSourceLoc qualifierTypeLine, const TString &intValueString, int intValue, TSourceLoc intValueLine)
{
TLayoutQualifierId qualifierId;
qualifierId.type = ElqError;
qualifierId.location = -1;
if (qualifierType != "location")
{
error(qualifierTypeLine, "invalid layout qualifier", qualifierType.c_str(), "only location may have arguments");
recover();
}
else
{
if (intValue < 0)
{
error(intValueLine, "out of range", intValueString.c_str(), "value must be non-negative and < MAX_DRAW_BUFFERS");
recover();
}
else
{
qualifierId.location = intValue;
}
// TODO: must check that location is < MAX_DRAW_BUFFERS
}
return qualifierId;
}
TLayoutQualifier* TParseContext::makeLayoutQualifierFromId(TLayoutQualifierId layoutQualifierId)
{
return NULL;
}
TLayoutQualifier* TParseContext::extendLayoutQualifier(TLayoutQualifier *layoutQualifier, TLayoutQualifierId layoutQualifierId)
{
return NULL;
}
TTypeList *TParseContext::addStructDeclaratorList(const TPublicType& typeSpecifier, TTypeList *typeList) TTypeList *TParseContext::addStructDeclaratorList(const TPublicType& typeSpecifier, TTypeList *typeList)
{ {
if (voidErrorCheck(typeSpecifier.line, (*typeList)[0].type->getFieldName(), typeSpecifier)) { if (voidErrorCheck(typeSpecifier.line, (*typeList)[0].type->getFieldName(), typeSpecifier)) {
......
...@@ -139,6 +139,11 @@ struct TParseContext { ...@@ -139,6 +139,11 @@ struct TParseContext {
TIntermAggregate* addInterfaceBlock(const TPublicType& typeQualifier, TSourceLoc nameLine, const TString& blockName, TTypeList* typeList, TIntermAggregate* addInterfaceBlock(const TPublicType& typeQualifier, TSourceLoc nameLine, const TString& blockName, TTypeList* typeList,
const TString& instanceName, TSourceLoc instanceLine, TIntermTyped* arrayIndex, TSourceLoc arrayIndexLine); const TString& instanceName, TSourceLoc instanceLine, TIntermTyped* arrayIndex, TSourceLoc arrayIndexLine);
TLayoutQualifierId addLayoutQualifierId(const TString &qualifierType, TSourceLoc qualifierTypeLine);
TLayoutQualifierId addLayoutQualifierId(const TString &qualifierType, TSourceLoc qualifierTypeLine, const TString &intValueString, int intValue, TSourceLoc intValueLine);
TLayoutQualifier* makeLayoutQualifierFromId(TLayoutQualifierId layoutQualifierId);
TLayoutQualifier* extendLayoutQualifier(TLayoutQualifier *layoutQualifier, TLayoutQualifierId layoutQualifierId);
// Performs an error check for embedded struct declarations. // Performs an error check for embedded struct declarations.
// Returns true if an error was raised due to the declaration of // Returns true if an error was raised due to the declaration of
// this struct. // this struct.
......
...@@ -337,6 +337,7 @@ protected: ...@@ -337,6 +337,7 @@ protected:
struct TPublicType struct TPublicType
{ {
TBasicType type; TBasicType type;
TLayoutQualifier* layoutQualifier;
TQualifier qualifier; TQualifier qualifier;
TPrecision precision; TPrecision precision;
int primarySize; // size of vector or cols of matrix int primarySize; // size of vector or cols of matrix
...@@ -349,6 +350,7 @@ struct TPublicType ...@@ -349,6 +350,7 @@ struct TPublicType
void setBasic(TBasicType bt, TQualifier q, int ln = 0) void setBasic(TBasicType bt, TQualifier q, int ln = 0)
{ {
type = bt; type = bt;
layoutQualifier = NULL;
qualifier = q; qualifier = q;
precision = EbpUndefined; precision = EbpUndefined;
primarySize = 1; primarySize = 1;
......
...@@ -167,6 +167,8 @@ O [0-7] ...@@ -167,6 +167,8 @@ O [0-7]
"struct" { context->lexAfterType = true; return(STRUCT); } "struct" { context->lexAfterType = true; return(STRUCT); }
"layout" { return ES2_ident_ES3_keyword(context, LAYOUT); }
/* Reserved keywords for GLSL ES 3.00 that are not reserved for GLSL ES 1.00 */ /* Reserved keywords for GLSL ES 3.00 that are not reserved for GLSL ES 1.00 */
"coherent" | "coherent" |
"restrict" | "restrict" |
...@@ -233,6 +235,17 @@ O [0-7] ...@@ -233,6 +235,17 @@ O [0-7]
return reserved_word(yyscanner); return reserved_word(yyscanner);
} }
/* Reserved keywords in GLSL ES 1.00 that are not reserved in GLSL ES 3.00 */
"packed" {
if (context->shaderVersion >= 300)
{
yylval->lex.string = NewPoolTString(yytext);
return check_type(yyscanner);
}
return reserved_word(yyscanner);
}
/* Reserved keywords */ /* Reserved keywords */
"asm" | "asm" |
...@@ -242,7 +255,6 @@ O [0-7] ...@@ -242,7 +255,6 @@ O [0-7]
"typedef" | "typedef" |
"template" | "template" |
"this" | "this" |
"packed" |
"goto" | "goto" |
......
...@@ -72,6 +72,8 @@ WHICH GENERATES THE GLSL ES PARSER (glslang_tab.cpp AND glslang_tab.h). ...@@ -72,6 +72,8 @@ WHICH GENERATES THE GLSL ES PARSER (glslang_tab.cpp AND glslang_tab.h).
union { union {
TPublicType type; TPublicType type;
TPrecision precision; TPrecision precision;
TLayoutQualifierId layoutQualifierId;
TLayoutQualifier* layoutQualifier;
TQualifier qualifier; TQualifier qualifier;
TFunction* function; TFunction* function;
TParameter param; TParameter param;
...@@ -132,6 +134,7 @@ extern void yyerror(TParseContext* context, const char* reason); ...@@ -132,6 +134,7 @@ extern void yyerror(TParseContext* context, const char* reason);
%token <lex> STRUCT VOID_TYPE WHILE %token <lex> STRUCT VOID_TYPE WHILE
%token <lex> SAMPLER2D SAMPLERCUBE SAMPLER_EXTERNAL_OES SAMPLER2DRECT %token <lex> SAMPLER2D SAMPLERCUBE SAMPLER_EXTERNAL_OES SAMPLER2DRECT
%token <lex> SAMPLER3D SAMPLER3DRECT SAMPLER2DSHADOW %token <lex> SAMPLER3D SAMPLER3DRECT SAMPLER2DSHADOW
%token <lex> LAYOUT
%token <lex> IDENTIFIER TYPE_NAME FLOATCONSTANT INTCONSTANT UINTCONSTANT BOOLCONSTANT %token <lex> IDENTIFIER TYPE_NAME FLOATCONSTANT INTCONSTANT UINTCONSTANT BOOLCONSTANT
%token <lex> FIELD_SELECTION %token <lex> FIELD_SELECTION
...@@ -167,6 +170,8 @@ extern void yyerror(TParseContext* context, const char* reason); ...@@ -167,6 +170,8 @@ extern void yyerror(TParseContext* context, const char* reason);
%type <interm> parameter_declaration parameter_declarator parameter_type_specifier %type <interm> parameter_declaration parameter_declarator parameter_type_specifier
%type <interm.qualifier> parameter_qualifier parameter_type_qualifier %type <interm.qualifier> parameter_qualifier parameter_type_qualifier
%type <interm.layoutQualifier> layout_qualifier layout_qualifier_id_list
%type <interm.layoutQualifierId> layout_qualifier_id
%type <interm.precision> precision_qualifier %type <interm.precision> precision_qualifier
%type <interm.type> type_qualifier fully_specified_type type_specifier storage_qualifier interpolation_qualifier %type <interm.type> type_qualifier fully_specified_type type_specifier storage_qualifier interpolation_qualifier
...@@ -1369,6 +1374,14 @@ type_qualifier ...@@ -1369,6 +1374,14 @@ type_qualifier
TQualifier qual = context->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary; TQualifier qual = context->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;
$$.setBasic(EbtVoid, qual, $1.line); $$.setBasic(EbtVoid, qual, $1.line);
} }
| layout_qualifier {
$$.qualifier = context->symbolTable.atGlobalLevel() ? EvqGlobal : EvqTemporary;
$$.layoutQualifier = $1;
}
| layout_qualifier storage_qualifier {
$$.setBasic(EbtVoid, $2.qualifier, $2.line);
$$.layoutQualifier = $1;
}
; ;
storage_qualifier storage_qualifier
...@@ -1433,6 +1446,34 @@ precision_qualifier ...@@ -1433,6 +1446,34 @@ precision_qualifier
} }
; ;
layout_qualifier
: LAYOUT LEFT_PAREN layout_qualifier_id_list RIGHT_PAREN {
ES3_ONLY("layout", $1.line, "qualifier");
$$ = $3;
}
;
layout_qualifier_id_list
: layout_qualifier_id {
$$ = context->makeLayoutQualifierFromId($1);
}
| layout_qualifier_id_list COMMA layout_qualifier_id {
$$ = context->extendLayoutQualifier($1, $3);
}
;
layout_qualifier_id
: IDENTIFIER {
$$ = context->addLayoutQualifierId(*$1.string, $1.line);
}
| IDENTIFIER EQUAL INTCONSTANT {
$$ = context->addLayoutQualifierId(*$1.string, $1.line, *$3.string, $3.i, $3.line);
}
| IDENTIFIER EQUAL UINTCONSTANT {
$$ = context->addLayoutQualifierId(*$1.string, $1.line, *$3.string, $3.i, $3.line);
}
;
type_specifier_no_prec type_specifier_no_prec
: type_specifier_nonarray { : type_specifier_nonarray {
$$ = $1; $$ = $1;
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -107,58 +107,59 @@ extern int yydebug; ...@@ -107,58 +107,59 @@ extern int yydebug;
SAMPLER3D = 316, SAMPLER3D = 316,
SAMPLER3DRECT = 317, SAMPLER3DRECT = 317,
SAMPLER2DSHADOW = 318, SAMPLER2DSHADOW = 318,
IDENTIFIER = 319, LAYOUT = 319,
TYPE_NAME = 320, IDENTIFIER = 320,
FLOATCONSTANT = 321, TYPE_NAME = 321,
INTCONSTANT = 322, FLOATCONSTANT = 322,
UINTCONSTANT = 323, INTCONSTANT = 323,
BOOLCONSTANT = 324, UINTCONSTANT = 324,
FIELD_SELECTION = 325, BOOLCONSTANT = 325,
LEFT_OP = 326, FIELD_SELECTION = 326,
RIGHT_OP = 327, LEFT_OP = 327,
INC_OP = 328, RIGHT_OP = 328,
DEC_OP = 329, INC_OP = 329,
LE_OP = 330, DEC_OP = 330,
GE_OP = 331, LE_OP = 331,
EQ_OP = 332, GE_OP = 332,
NE_OP = 333, EQ_OP = 333,
AND_OP = 334, NE_OP = 334,
OR_OP = 335, AND_OP = 335,
XOR_OP = 336, OR_OP = 336,
MUL_ASSIGN = 337, XOR_OP = 337,
DIV_ASSIGN = 338, MUL_ASSIGN = 338,
ADD_ASSIGN = 339, DIV_ASSIGN = 339,
MOD_ASSIGN = 340, ADD_ASSIGN = 340,
LEFT_ASSIGN = 341, MOD_ASSIGN = 341,
RIGHT_ASSIGN = 342, LEFT_ASSIGN = 342,
AND_ASSIGN = 343, RIGHT_ASSIGN = 343,
XOR_ASSIGN = 344, AND_ASSIGN = 344,
OR_ASSIGN = 345, XOR_ASSIGN = 345,
SUB_ASSIGN = 346, OR_ASSIGN = 346,
LEFT_PAREN = 347, SUB_ASSIGN = 347,
RIGHT_PAREN = 348, LEFT_PAREN = 348,
LEFT_BRACKET = 349, RIGHT_PAREN = 349,
RIGHT_BRACKET = 350, LEFT_BRACKET = 350,
LEFT_BRACE = 351, RIGHT_BRACKET = 351,
RIGHT_BRACE = 352, LEFT_BRACE = 352,
DOT = 353, RIGHT_BRACE = 353,
COMMA = 354, DOT = 354,
COLON = 355, COMMA = 355,
EQUAL = 356, COLON = 356,
SEMICOLON = 357, EQUAL = 357,
BANG = 358, SEMICOLON = 358,
DASH = 359, BANG = 359,
TILDE = 360, DASH = 360,
PLUS = 361, TILDE = 361,
STAR = 362, PLUS = 362,
SLASH = 363, STAR = 363,
PERCENT = 364, SLASH = 364,
LEFT_ANGLE = 365, PERCENT = 365,
RIGHT_ANGLE = 366, LEFT_ANGLE = 366,
VERTICAL_BAR = 367, RIGHT_ANGLE = 367,
CARET = 368, VERTICAL_BAR = 368,
AMPERSAND = 369, CARET = 369,
QUESTION = 370 AMPERSAND = 370,
QUESTION = 371
}; };
#endif #endif
...@@ -191,6 +192,8 @@ typedef union YYSTYPE ...@@ -191,6 +192,8 @@ typedef union YYSTYPE
union { union {
TPublicType type; TPublicType type;
TPrecision precision; TPrecision precision;
TLayoutQualifierId layoutQualifierId;
TLayoutQualifier* layoutQualifier;
TQualifier qualifier; TQualifier qualifier;
TFunction* function; TFunction* function;
TParameter param; TParameter param;
......
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