Commit 3b5c2dae by Jamie Madill

Add a new invariant declaration operator.

BUG=angle:711 Change-Id: I54a48b636a68c317b8d44ee2d578847b80095289 Reviewed-on: https://chromium-review.googlesource.com/213500Reviewed-by: 's avatarZhenyao Mo <zmo@chromium.org> Tested-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 268b6bcd
...@@ -69,7 +69,6 @@ enum TBasicType ...@@ -69,7 +69,6 @@ enum TBasicType
EbtStruct, EbtStruct,
EbtInterfaceBlock, EbtInterfaceBlock,
EbtAddress, // should be deprecated?? EbtAddress, // should be deprecated??
EbtInvariant // used as a type when qualifying a previously declared variable as being invariant
}; };
const char* getBasicString(TBasicType t); const char* getBasicString(TBasicType t);
......
...@@ -37,6 +37,7 @@ enum TOperator ...@@ -37,6 +37,7 @@ enum TOperator
EOpParameters, // an aggregate listing the parameters to a function EOpParameters, // an aggregate listing the parameters to a function
EOpDeclaration, EOpDeclaration,
EOpInvariantDeclaration, // Specialized declarations for attributing invariance
EOpPrototype, EOpPrototype,
// //
......
...@@ -81,8 +81,7 @@ void TOutputGLSLBase::writeVariableType(const TType &type) ...@@ -81,8 +81,7 @@ void TOutputGLSLBase::writeVariableType(const TType &type)
{ {
TInfoSinkBase &out = objSink(); TInfoSinkBase &out = objSink();
TQualifier qualifier = type.getQualifier(); TQualifier qualifier = type.getQualifier();
if (qualifier != EvqTemporary && qualifier != EvqGlobal && if (qualifier != EvqTemporary && qualifier != EvqGlobal)
type.getBasicType() != EbtInvariant)
{ {
out << type.getQualifierString() << " "; out << type.getQualifierString() << " ";
} }
...@@ -650,6 +649,17 @@ bool TOutputGLSLBase::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -650,6 +649,17 @@ bool TOutputGLSLBase::visitAggregate(Visit visit, TIntermAggregate *node)
mDeclaringVariables = false; mDeclaringVariables = false;
} }
break; break;
case EOpInvariantDeclaration: {
// Invariant declaration.
ASSERT(visit == PreVisit);
const TIntermSequence *sequence = node->getSequence();
ASSERT(sequence && sequence->size() == 1);
const TIntermSymbol *symbol = sequence->front()->getAsSymbolNode();
ASSERT(symbol);
out << "invariant " << symbol->getSymbol() << ";";
visitChildren = false;
break;
}
case EOpConstructFloat: case EOpConstructFloat:
writeTriplet(visit, "float(", NULL, ")"); writeTriplet(visit, "float(", NULL, ")");
break; break;
......
...@@ -1937,12 +1937,6 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -1937,12 +1937,6 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
} }
else if (variable && IsVaryingOut(variable->getQualifier())) else if (variable && IsVaryingOut(variable->getQualifier()))
{ {
// Skip translation of invariant declarations
if (variable->getBasicType() == EbtInvariant)
{
return false;
}
for (TIntermSequence::iterator sit = sequence->begin(); sit != sequence->end(); sit++) for (TIntermSequence::iterator sit = sequence->begin(); sit != sequence->end(); sit++)
{ {
TIntermSymbol *symbol = (*sit)->getAsSymbolNode(); TIntermSymbol *symbol = (*sit)->getAsSymbolNode();
...@@ -1966,6 +1960,9 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -1966,6 +1960,9 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
out << ", "; out << ", ";
} }
break; break;
case EOpInvariantDeclaration:
// Do not do any translation
return false;
case EOpPrototype: case EOpPrototype:
if (visit == PreVisit) if (visit == PreVisit)
{ {
......
...@@ -1089,6 +1089,8 @@ const TFunction* TParseContext::findFunction(const TSourceLoc& line, TFunction* ...@@ -1089,6 +1089,8 @@ const TFunction* TParseContext::findFunction(const TSourceLoc& line, TFunction*
// Initializers show up in several places in the grammar. Have one set of // Initializers show up in several places in the grammar. Have one set of
// code to handle them here. // code to handle them here.
// //
// Returns true on error, false if no error
//
bool TParseContext::executeInitializer(const TSourceLoc& line, const TString& identifier, TPublicType& pType, bool TParseContext::executeInitializer(const TSourceLoc& line, const TString& identifier, TPublicType& pType,
TIntermTyped* initializer, TIntermNode*& intermNode, TVariable* variable) TIntermTyped* initializer, TIntermNode*& intermNode, TVariable* variable)
{ {
...@@ -1352,6 +1354,7 @@ TIntermAggregate* TParseContext::parseInvariantDeclaration(const TSourceLoc &inv ...@@ -1352,6 +1354,7 @@ TIntermAggregate* TParseContext::parseInvariantDeclaration(const TSourceLoc &inv
const TString *identifier, const TString *identifier,
const TSymbol *symbol) const TSymbol *symbol)
{ {
// invariant declaration
if (globalErrorCheck(invariantLoc, symbolTable.atGlobalLevel(), "invariant varying")) if (globalErrorCheck(invariantLoc, symbolTable.atGlobalLevel(), "invariant varying"))
{ {
recover(); recover();
...@@ -1366,21 +1369,20 @@ TIntermAggregate* TParseContext::parseInvariantDeclaration(const TSourceLoc &inv ...@@ -1366,21 +1369,20 @@ TIntermAggregate* TParseContext::parseInvariantDeclaration(const TSourceLoc &inv
} }
else else
{ {
TType type(EbtInvariant); const TVariable *variable = getNamedVariable(identifierLoc, identifier, symbol);
type.setQualifier(EvqInvariantVaryingOut); ASSERT(variable);
TIntermSymbol *symbol = intermediate.addSymbol(0, *identifier, type, identifierLoc); const TType &type = variable->getType();
return intermediate.makeAggregate(symbol, identifierLoc); TIntermSymbol *intermSymbol = intermediate.addSymbol(variable->getUniqueId(),
*identifier, type, identifierLoc);
TIntermAggregate *aggregate = intermediate.makeAggregate(intermSymbol, identifierLoc);
aggregate->setOp(EOpInvariantDeclaration);
return aggregate;
} }
} }
TIntermAggregate* TParseContext::parseDeclarator(TPublicType &publicType, TIntermAggregate *aggregateDeclaration, TSymbol *identifierSymbol, const TSourceLoc& identifierLocation, const TString &identifier) TIntermAggregate* TParseContext::parseDeclarator(TPublicType &publicType, TIntermAggregate *aggregateDeclaration, TSymbol *identifierSymbol, const TSourceLoc& identifierLocation, const TString &identifier)
{ {
if (publicType.type == EbtInvariant && !identifierSymbol)
{
error(identifierLocation, "undeclared identifier declared as invariant", identifier.c_str());
recover();
}
TIntermSymbol* symbol = intermediate.addSymbol(0, identifier, TType(publicType), identifierLocation); TIntermSymbol* symbol = intermediate.addSymbol(0, identifier, TType(publicType), identifierLocation);
TIntermAggregate* intermAggregate = intermediate.growAggregate(aggregateDeclaration, symbol, identifierLocation); TIntermAggregate* intermAggregate = intermediate.growAggregate(aggregateDeclaration, symbol, identifierLocation);
......
...@@ -41,7 +41,6 @@ const char* getBasicString(TBasicType t) ...@@ -41,7 +41,6 @@ const char* getBasicString(TBasicType t)
case EbtSampler2DArrayShadow: return "sampler2DArrayShadow"; break; case EbtSampler2DArrayShadow: return "sampler2DArrayShadow"; break;
case EbtStruct: return "structure"; break; case EbtStruct: return "structure"; break;
case EbtInterfaceBlock: return "interface block"; break; case EbtInterfaceBlock: return "interface block"; break;
case EbtInvariant: return "invariant"; break;
default: UNREACHABLE(); return "unknown type"; default: UNREACHABLE(); return "unknown type";
} }
} }
......
...@@ -346,12 +346,7 @@ bool CollectVariables::visitAggregate(Visit, TIntermAggregate *node) ...@@ -346,12 +346,7 @@ bool CollectVariables::visitAggregate(Visit, TIntermAggregate *node)
visitInfoList(sequence, mUniforms); visitInfoList(sequence, mUniforms);
break; break;
default: default:
// do not traverse invariant declarations such as visitInfoList(sequence, mVaryings);
// "invariant gl_Position;"
if (typedNode.getBasicType() != EbtInvariant)
{
visitInfoList(sequence, mVaryings);
}
break; break;
} }
......
...@@ -67,6 +67,9 @@ bool TVersionGLSL::visitAggregate(Visit, TIntermAggregate *node) ...@@ -67,6 +67,9 @@ bool TVersionGLSL::visitAggregate(Visit, TIntermAggregate *node)
} }
break; break;
} }
case EOpInvariantDeclaration:
updateVersion(GLSL_VERSION_120);
break;
case EOpParameters: case EOpParameters:
{ {
const TIntermSequence &params = *(node->getSequence()); const TIntermSequence &params = *(node->getSequence());
......
...@@ -1072,8 +1072,7 @@ single_declaration ...@@ -1072,8 +1072,7 @@ single_declaration
$$.intermAggregate = context->parseSingleInitDeclaration($$.type, @2, *$2.string, @3, $4); $$.intermAggregate = context->parseSingleInitDeclaration($$.type, @2, *$2.string, @3, $4);
} }
| INVARIANT IDENTIFIER { | INVARIANT IDENTIFIER {
VERTEX_ONLY("invariant declaration", @1); // $$.type is not used in invariant declarations.
$$.type.setBasic(EbtInvariant, EvqInvariantVaryingOut, @2);
$$.intermAggregate = context->parseInvariantDeclaration(@1, @2, $2.string, $2.symbol); $$.intermAggregate = context->parseInvariantDeclaration(@1, @2, $2.string, $2.symbol);
} }
; ;
......
...@@ -805,22 +805,22 @@ static const yytype_uint16 yyrline[] = ...@@ -805,22 +805,22 @@ static const yytype_uint16 yyrline[] =
730, 733, 744, 752, 760, 787, 793, 804, 808, 812, 730, 733, 744, 752, 760, 787, 793, 804, 808, 812,
816, 823, 879, 882, 889, 897, 918, 939, 949, 977, 816, 823, 879, 882, 889, 897, 918, 939, 949, 977,
982, 992, 997, 1007, 1010, 1013, 1016, 1022, 1029, 1032, 982, 992, 997, 1007, 1010, 1013, 1016, 1022, 1029, 1032,
1036, 1040, 1044, 1051, 1055, 1059, 1066, 1070, 1074, 1082, 1036, 1040, 1044, 1051, 1055, 1059, 1066, 1070, 1074, 1081,
1091, 1097, 1100, 1106, 1112, 1119, 1128, 1137, 1145, 1148, 1090, 1096, 1099, 1105, 1111, 1118, 1127, 1136, 1144, 1147,
1155, 1159, 1166, 1169, 1173, 1177, 1186, 1195, 1203, 1213, 1154, 1158, 1165, 1168, 1172, 1176, 1185, 1194, 1202, 1212,
1225, 1228, 1231, 1237, 1244, 1247, 1253, 1256, 1259, 1265, 1224, 1227, 1230, 1236, 1243, 1246, 1252, 1255, 1258, 1264,
1268, 1283, 1287, 1291, 1295, 1299, 1303, 1308, 1313, 1318, 1267, 1282, 1286, 1290, 1294, 1298, 1302, 1307, 1312, 1317,
1323, 1328, 1333, 1338, 1343, 1348, 1353, 1358, 1363, 1368, 1322, 1327, 1332, 1337, 1342, 1347, 1352, 1357, 1362, 1367,
1373, 1378, 1383, 1388, 1393, 1398, 1403, 1408, 1412, 1416, 1372, 1377, 1382, 1387, 1392, 1397, 1402, 1407, 1411, 1415,
1420, 1424, 1428, 1432, 1436, 1440, 1444, 1448, 1452, 1456, 1419, 1423, 1427, 1431, 1435, 1439, 1443, 1447, 1451, 1455,
1460, 1464, 1468, 1476, 1484, 1488, 1501, 1501, 1504, 1504, 1459, 1463, 1467, 1475, 1483, 1487, 1500, 1500, 1503, 1503,
1510, 1513, 1529, 1532, 1541, 1545, 1551, 1558, 1573, 1577, 1509, 1512, 1528, 1531, 1540, 1544, 1550, 1557, 1572, 1576,
1581, 1582, 1588, 1589, 1590, 1591, 1592, 1596, 1597, 1597, 1580, 1581, 1587, 1588, 1589, 1590, 1591, 1595, 1596, 1596,
1597, 1607, 1608, 1612, 1612, 1613, 1613, 1618, 1621, 1631, 1596, 1606, 1607, 1611, 1611, 1612, 1612, 1617, 1620, 1630,
1634, 1640, 1641, 1645, 1653, 1657, 1667, 1672, 1689, 1689, 1633, 1639, 1640, 1644, 1652, 1656, 1666, 1671, 1688, 1688,
1694, 1694, 1701, 1701, 1709, 1712, 1718, 1721, 1727, 1731, 1693, 1693, 1700, 1700, 1708, 1711, 1717, 1720, 1726, 1730,
1738, 1745, 1752, 1759, 1770, 1779, 1783, 1790, 1793, 1799, 1737, 1744, 1751, 1758, 1769, 1778, 1782, 1789, 1792, 1798,
1799 1798
}; };
#endif #endif
...@@ -3689,8 +3689,7 @@ yyreduce: ...@@ -3689,8 +3689,7 @@ yyreduce:
case 108: case 108:
{ {
VERTEX_ONLY("invariant declaration", (yylsp[(1) - (2)])); // $$.type is not used in invariant declarations.
(yyval.interm).type.setBasic(EbtInvariant, EvqInvariantVaryingOut, (yylsp[(2) - (2)]));
(yyval.interm).intermAggregate = context->parseInvariantDeclaration((yylsp[(1) - (2)]), (yylsp[(2) - (2)]), (yyvsp[(2) - (2)].lex).string, (yyvsp[(2) - (2)].lex).symbol); (yyval.interm).intermAggregate = context->parseInvariantDeclaration((yylsp[(1) - (2)]), (yylsp[(2) - (2)]), (yyvsp[(2) - (2)].lex).string, (yyvsp[(2) - (2)].lex).symbol);
} }
break; break;
......
...@@ -342,6 +342,7 @@ bool TOutputTraverser::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -342,6 +342,7 @@ bool TOutputTraverser::visitAggregate(Visit visit, TIntermAggregate *node)
case EOpMul: out << "component-wise multiply"; break; case EOpMul: out << "component-wise multiply"; break;
case EOpDeclaration: out << "Declaration: "; break; case EOpDeclaration: out << "Declaration: "; break;
case EOpInvariantDeclaration: out << "Invariant Declaration: "; break;
default: default:
out.prefix(EPrefixError); out.prefix(EPrefixError);
......
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