Commit 7d626796 by Nicolas Capens

Implement support for layout qualifier locations.

Bug 19331817 Change-Id: I98c650311c6226bf769bc9f3c2eed8dac788a396 Reviewed-on: https://swiftshader-review.googlesource.com/2320Reviewed-by: 's avatarNicolas Capens <capn@google.com> Tested-by: 's avatarNicolas Capens <capn@google.com>
parent 2c1239f5
...@@ -119,6 +119,25 @@ enum TQualifier ...@@ -119,6 +119,25 @@ enum TQualifier
EvqLast EvqLast
}; };
struct TLayoutQualifier
{
static TLayoutQualifier create()
{
TLayoutQualifier layoutQualifier;
layoutQualifier.location = -1;
return layoutQualifier;
}
bool isEmpty() const
{
return location == -1;
}
int location;
};
// //
// 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.
// //
......
...@@ -1321,6 +1321,66 @@ TIntermTyped* TParseContext::addConstStruct(TString& identifier, TIntermTyped* n ...@@ -1321,6 +1321,66 @@ TIntermTyped* TParseContext::addConstStruct(TString& identifier, TIntermTyped* n
return typedNode; return typedNode;
} }
TLayoutQualifier TParseContext::parseLayoutQualifier(const TString &qualifierType, const TSourceLoc& qualifierTypeLine)
{
TLayoutQualifier qualifier;
qualifier.location = -1;
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 qualifier;
}
TLayoutQualifier TParseContext::parseLayoutQualifier(const TString &qualifierType, const TSourceLoc& qualifierTypeLine, const TString &intValueString, int intValue, const TSourceLoc& intValueLine)
{
TLayoutQualifier qualifier;
qualifier.location = -1;
if (qualifierType != "location")
{
error(qualifierTypeLine, "invalid layout qualifier", qualifierType.c_str(), "only location may have arguments");
recover();
}
else
{
// must check that location is non-negative
if (intValue < 0)
{
error(intValueLine, "out of range:", intValueString.c_str(), "location must be non-negative");
recover();
}
else
{
qualifier.location = intValue;
}
}
return qualifier;
}
TLayoutQualifier TParseContext::joinLayoutQualifiers(TLayoutQualifier leftQualifier, TLayoutQualifier rightQualifier)
{
TLayoutQualifier joinedQualifier = leftQualifier;
if (rightQualifier.location != -1)
{
joinedQualifier.location = rightQualifier.location;
}
return joinedQualifier;
}
bool TParseContext::enterStructDeclaration(int line, const TString& identifier) bool TParseContext::enterStructDeclaration(int line, const TString& identifier)
{ {
++structNestingLevel; ++structNestingLevel;
......
...@@ -40,7 +40,7 @@ struct TParseContext { ...@@ -40,7 +40,7 @@ struct TParseContext {
functionReturnsValue(false), functionReturnsValue(false),
checksPrecisionErrors(checksPrecErrors), checksPrecisionErrors(checksPrecErrors),
diagnostics(is), diagnostics(is),
shaderVersion(100), shaderVersion(100),
directiveHandler(ext, diagnostics, shaderVersion), directiveHandler(ext, diagnostics, shaderVersion),
preprocessor(&diagnostics, &directiveHandler), preprocessor(&diagnostics, &directiveHandler),
scanner(NULL) { } scanner(NULL) { }
...@@ -124,6 +124,10 @@ struct TParseContext { ...@@ -124,6 +124,10 @@ struct TParseContext {
TIntermTyped* addConstArrayNode(int index, TIntermTyped* node, TSourceLoc line); TIntermTyped* addConstArrayNode(int index, TIntermTyped* node, TSourceLoc line);
TIntermTyped* addConstStruct(TString& , TIntermTyped*, TSourceLoc); TIntermTyped* addConstStruct(TString& , TIntermTyped*, TSourceLoc);
TLayoutQualifier parseLayoutQualifier(const TString &qualifierType, const TSourceLoc& qualifierTypeLine);
TLayoutQualifier parseLayoutQualifier(const TString &qualifierType, const TSourceLoc& qualifierTypeLine, const TString &intValueString, int intValue, const TSourceLoc& intValueLine);
TLayoutQualifier joinLayoutQualifiers(TLayoutQualifier leftQualifier, TLayoutQualifier rightQualifier);
// 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.
......
...@@ -267,6 +267,7 @@ protected: ...@@ -267,6 +267,7 @@ protected:
struct TPublicType struct TPublicType
{ {
TBasicType type; TBasicType type;
TLayoutQualifier layoutQualifier;
TQualifier qualifier; TQualifier qualifier;
TPrecision precision; TPrecision precision;
int size; // size of vector or matrix, not size of array int size; // size of vector or matrix, not size of array
...@@ -279,6 +280,7 @@ struct TPublicType ...@@ -279,6 +280,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 = TLayoutQualifier::create();
qualifier = q; qualifier = q;
precision = EbpUndefined; precision = EbpUndefined;
size = 1; size = 1;
......
...@@ -155,6 +155,8 @@ O [0-7] ...@@ -155,6 +155,8 @@ O [0-7]
"struct" { context->lexAfterType = true; return(STRUCT); } "struct" { context->lexAfterType = true; return(STRUCT); }
"layout" { return ES2_identifier_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" |
...@@ -221,6 +223,17 @@ O [0-7] ...@@ -221,6 +223,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" |
...@@ -230,7 +243,6 @@ O [0-7] ...@@ -230,7 +243,6 @@ O [0-7]
"typedef" | "typedef" |
"template" | "template" |
"this" | "this" |
"packed" |
"goto" | "goto" |
......
...@@ -71,6 +71,7 @@ WHICH GENERATES THE GLSL ES PARSER (glslang_tab.cpp AND glslang_tab.h). ...@@ -71,6 +71,7 @@ WHICH GENERATES THE GLSL ES PARSER (glslang_tab.cpp AND glslang_tab.h).
union { union {
TPublicType type; TPublicType type;
TPrecision precision; TPrecision precision;
TLayoutQualifier layoutQualifier;
TQualifier qualifier; TQualifier qualifier;
TFunction* function; TFunction* function;
TParameter param; TParameter param;
...@@ -130,6 +131,7 @@ extern void yyerror(TParseContext* context, const char* reason); ...@@ -130,6 +131,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
...@@ -165,6 +167,7 @@ extern void yyerror(TParseContext* context, const char* reason); ...@@ -165,6 +167,7 @@ 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 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 %type <interm.type> type_qualifier fully_specified_type type_specifier storage_qualifier
...@@ -1529,6 +1532,14 @@ type_qualifier ...@@ -1529,6 +1532,14 @@ type_qualifier
| storage_qualifier { | storage_qualifier {
$$.setBasic(EbtVoid, $1.qualifier, $1.line); $$.setBasic(EbtVoid, $1.qualifier, $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
...@@ -1595,6 +1606,34 @@ precision_qualifier ...@@ -1595,6 +1606,34 @@ precision_qualifier
} }
; ;
layout_qualifier
: LAYOUT LEFT_PAREN layout_qualifier_id_list RIGHT_PAREN {
ES3_ONLY("layout", $1.line);
$$ = $3;
}
;
layout_qualifier_id_list
: layout_qualifier_id {
$$ = $1;
}
| layout_qualifier_id_list COMMA layout_qualifier_id {
$$ = context->joinLayoutQualifiers($1, $3);
}
;
layout_qualifier_id
: IDENTIFIER {
$$ = context->parseLayoutQualifier(*$1.string, $1.line);
}
| IDENTIFIER EQUAL INTCONSTANT {
$$ = context->parseLayoutQualifier(*$1.string, $1.line, *$3.string, $3.i, $3.line);
}
| IDENTIFIER EQUAL UINTCONSTANT {
$$ = context->parseLayoutQualifier(*$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;
......
...@@ -94,58 +94,59 @@ ...@@ -94,58 +94,59 @@
SAMPLER3D = 310, SAMPLER3D = 310,
SAMPLER3DRECT = 311, SAMPLER3DRECT = 311,
SAMPLER2DSHADOW = 312, SAMPLER2DSHADOW = 312,
IDENTIFIER = 313, LAYOUT = 313,
TYPE_NAME = 314, IDENTIFIER = 314,
FLOATCONSTANT = 315, TYPE_NAME = 315,
INTCONSTANT = 316, FLOATCONSTANT = 316,
UINTCONSTANT = 317, INTCONSTANT = 317,
BOOLCONSTANT = 318, UINTCONSTANT = 318,
FIELD_SELECTION = 319, BOOLCONSTANT = 319,
LEFT_OP = 320, FIELD_SELECTION = 320,
RIGHT_OP = 321, LEFT_OP = 321,
INC_OP = 322, RIGHT_OP = 322,
DEC_OP = 323, INC_OP = 323,
LE_OP = 324, DEC_OP = 324,
GE_OP = 325, LE_OP = 325,
EQ_OP = 326, GE_OP = 326,
NE_OP = 327, EQ_OP = 327,
AND_OP = 328, NE_OP = 328,
OR_OP = 329, AND_OP = 329,
XOR_OP = 330, OR_OP = 330,
MUL_ASSIGN = 331, XOR_OP = 331,
DIV_ASSIGN = 332, MUL_ASSIGN = 332,
ADD_ASSIGN = 333, DIV_ASSIGN = 333,
MOD_ASSIGN = 334, ADD_ASSIGN = 334,
LEFT_ASSIGN = 335, MOD_ASSIGN = 335,
RIGHT_ASSIGN = 336, LEFT_ASSIGN = 336,
AND_ASSIGN = 337, RIGHT_ASSIGN = 337,
XOR_ASSIGN = 338, AND_ASSIGN = 338,
OR_ASSIGN = 339, XOR_ASSIGN = 339,
SUB_ASSIGN = 340, OR_ASSIGN = 340,
LEFT_PAREN = 341, SUB_ASSIGN = 341,
RIGHT_PAREN = 342, LEFT_PAREN = 342,
LEFT_BRACKET = 343, RIGHT_PAREN = 343,
RIGHT_BRACKET = 344, LEFT_BRACKET = 344,
LEFT_BRACE = 345, RIGHT_BRACKET = 345,
RIGHT_BRACE = 346, LEFT_BRACE = 346,
DOT = 347, RIGHT_BRACE = 347,
COMMA = 348, DOT = 348,
COLON = 349, COMMA = 349,
EQUAL = 350, COLON = 350,
SEMICOLON = 351, EQUAL = 351,
BANG = 352, SEMICOLON = 352,
DASH = 353, BANG = 353,
TILDE = 354, DASH = 354,
PLUS = 355, TILDE = 355,
STAR = 356, PLUS = 356,
SLASH = 357, STAR = 357,
PERCENT = 358, SLASH = 358,
LEFT_ANGLE = 359, PERCENT = 359,
RIGHT_ANGLE = 360, LEFT_ANGLE = 360,
VERTICAL_BAR = 361, RIGHT_ANGLE = 361,
CARET = 362, VERTICAL_BAR = 362,
AMPERSAND = 363, CARET = 363,
QUESTION = 364 AMPERSAND = 364,
QUESTION = 365
}; };
#endif #endif
...@@ -179,6 +180,7 @@ typedef union YYSTYPE ...@@ -179,6 +180,7 @@ typedef union YYSTYPE
union { union {
TPublicType type; TPublicType type;
TPrecision precision; TPrecision precision;
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