Share a single TOperator enum among all constructor AST nodes
The code is a lot simpler when the type information is only carried
in the TType of the node, instead of being partially duplicated in the
enum value.
BUG=angleproject:1490
TEST=angle_unittests
Change-Id: I956376225ec01e469c7afb7378fa48cc097c0cea
Reviewed-on: https://chromium-review.googlesource.com/498768
Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/compiler/translator/EmulatePrecision.cpp b/src/compiler/translator/EmulatePrecision.cpp
index 80d5c1e..4b08309 100644
--- a/src/compiler/translator/EmulatePrecision.cpp
+++ b/src/compiler/translator/EmulatePrecision.cpp
@@ -640,12 +640,16 @@
bool visitChildren = true;
switch (node->getOp())
{
- case EOpConstructStruct:
case EOpCallInternalRawFunction:
case EOpCallFunctionInAST:
// User-defined function return values are not rounded. The calculations that produced
// the value inside the function definition should have been rounded.
break;
+ case EOpConstruct:
+ if (node->getBasicType() == EbtStruct)
+ {
+ break;
+ }
default:
TIntermNode *parent = getParentNode();
if (canRoundFloat(node->getType()) && visit == PreVisit &&
diff --git a/src/compiler/translator/IntermNode.cpp b/src/compiler/translator/IntermNode.cpp
index cbdca76..159958c 100644
--- a/src/compiler/translator/IntermNode.cpp
+++ b/src/compiler/translator/IntermNode.cpp
@@ -306,10 +306,7 @@
TIntermAggregate *TIntermAggregate::CreateConstructor(const TType &type,
TIntermSequence *arguments)
{
- TIntermAggregate *constructorNode =
- new TIntermAggregate(type, sh::TypeToConstructorOperator(type), arguments);
- ASSERT(constructorNode->isConstructor());
- return constructorNode;
+ return new TIntermAggregate(type, EOpConstruct, arguments);
}
TIntermAggregate *TIntermAggregate::Create(const TType &type,
@@ -343,7 +340,7 @@
{
// Structs should not be precision qualified, the individual members may be.
// Built-in types on the other hand should be precision qualified.
- if (mOp != EOpConstructStruct)
+ if (getBasicType() != EbtStruct)
{
setPrecisionFromChildren();
}
@@ -776,43 +773,9 @@
}
}
-// Returns true if the operator is for one of the constructors.
bool TIntermOperator::isConstructor() const
{
- switch (mOp)
- {
- case EOpConstructVec2:
- case EOpConstructVec3:
- case EOpConstructVec4:
- case EOpConstructMat2:
- case EOpConstructMat2x3:
- case EOpConstructMat2x4:
- case EOpConstructMat3x2:
- case EOpConstructMat3:
- case EOpConstructMat3x4:
- case EOpConstructMat4x2:
- case EOpConstructMat4x3:
- case EOpConstructMat4:
- case EOpConstructFloat:
- case EOpConstructIVec2:
- case EOpConstructIVec3:
- case EOpConstructIVec4:
- case EOpConstructInt:
- case EOpConstructUVec2:
- case EOpConstructUVec3:
- case EOpConstructUVec4:
- case EOpConstructUInt:
- case EOpConstructBVec2:
- case EOpConstructBVec3:
- case EOpConstructBVec4:
- case EOpConstructBool:
- case EOpConstructStruct:
- return true;
- default:
- // EOpConstruct is not supposed to be used in the AST.
- ASSERT(mOp != EOpConstruct);
- return false;
- }
+ return (mOp == EOpConstruct);
}
bool TIntermOperator::isFunctionCall() const
diff --git a/src/compiler/translator/Operator.cpp b/src/compiler/translator/Operator.cpp
index fc2a981..1858980 100644
--- a/src/compiler/translator/Operator.cpp
+++ b/src/compiler/translator/Operator.cpp
@@ -296,58 +296,6 @@
case EOpContinue:
return "continue";
- case EOpConstructInt:
- return "int";
- case EOpConstructUInt:
- return "uint";
- case EOpConstructBool:
- return "bool";
- case EOpConstructFloat:
- return "float";
- case EOpConstructVec2:
- return "vec2";
- case EOpConstructVec3:
- return "vec3";
- case EOpConstructVec4:
- return "vec4";
- case EOpConstructBVec2:
- return "bvec2";
- case EOpConstructBVec3:
- return "bvec3";
- case EOpConstructBVec4:
- return "bvec4";
- case EOpConstructIVec2:
- return "ivec2";
- case EOpConstructIVec3:
- return "ivec3";
- case EOpConstructIVec4:
- return "ivec4";
- case EOpConstructUVec2:
- return "uvec2";
- case EOpConstructUVec3:
- return "uvec3";
- case EOpConstructUVec4:
- return "uvec4";
- case EOpConstructMat2:
- return "mat2";
- case EOpConstructMat2x3:
- return "mat2x3";
- case EOpConstructMat2x4:
- return "mat2x4";
- case EOpConstructMat3x2:
- return "mat3x2";
- case EOpConstructMat3:
- return "mat3";
- case EOpConstructMat3x4:
- return "mat3x4";
- case EOpConstructMat4x2:
- return "mat4x2";
- case EOpConstructMat4x3:
- return "mat4x3";
- case EOpConstructMat4:
- return "mat4";
- // Note: EOpConstructStruct can't be handled here
-
case EOpAssign:
return "=";
case EOpInitialize:
diff --git a/src/compiler/translator/Operator.h b/src/compiler/translator/Operator.h
index 7ec29ed..5f028b9 100644
--- a/src/compiler/translator/Operator.h
+++ b/src/compiler/translator/Operator.h
@@ -202,40 +202,11 @@
EOpContinue,
//
- // Constructors
+ // Constructor
//
- // Used by ParseContext to denote any constructor.
EOpConstruct,
- // In the AST, constructors are stored using the below more specific op codes.
- EOpConstructInt,
- EOpConstructUInt,
- EOpConstructBool,
- EOpConstructFloat,
- EOpConstructVec2,
- EOpConstructVec3,
- EOpConstructVec4,
- EOpConstructBVec2,
- EOpConstructBVec3,
- EOpConstructBVec4,
- EOpConstructIVec2,
- EOpConstructIVec3,
- EOpConstructIVec4,
- EOpConstructUVec2,
- EOpConstructUVec3,
- EOpConstructUVec4,
- EOpConstructMat2,
- EOpConstructMat2x3,
- EOpConstructMat2x4,
- EOpConstructMat3x2,
- EOpConstructMat3,
- EOpConstructMat3x4,
- EOpConstructMat4x2,
- EOpConstructMat4x3,
- EOpConstructMat4,
- EOpConstructStruct,
-
//
// moves
//
diff --git a/src/compiler/translator/OutputGLSLBase.cpp b/src/compiler/translator/OutputGLSLBase.cpp
index aa7d8d5..94849ec 100644
--- a/src/compiler/translator/OutputGLSLBase.cpp
+++ b/src/compiler/translator/OutputGLSLBase.cpp
@@ -962,32 +962,7 @@
else
out << ")";
break;
- case EOpConstructFloat:
- case EOpConstructVec2:
- case EOpConstructVec3:
- case EOpConstructVec4:
- case EOpConstructBool:
- case EOpConstructBVec2:
- case EOpConstructBVec3:
- case EOpConstructBVec4:
- case EOpConstructInt:
- case EOpConstructIVec2:
- case EOpConstructIVec3:
- case EOpConstructIVec4:
- case EOpConstructUInt:
- case EOpConstructUVec2:
- case EOpConstructUVec3:
- case EOpConstructUVec4:
- case EOpConstructMat2:
- case EOpConstructMat2x3:
- case EOpConstructMat2x4:
- case EOpConstructMat3x2:
- case EOpConstructMat3:
- case EOpConstructMat3x4:
- case EOpConstructMat4x2:
- case EOpConstructMat4x3:
- case EOpConstructMat4:
- case EOpConstructStruct:
+ case EOpConstruct:
writeConstructorTriplet(visit, node->getType());
break;
diff --git a/src/compiler/translator/OutputHLSL.cpp b/src/compiler/translator/OutputHLSL.cpp
index 1a0fa96..695a4d0 100644
--- a/src/compiler/translator/OutputHLSL.cpp
+++ b/src/compiler/translator/OutputHLSL.cpp
@@ -1846,92 +1846,47 @@
return false;
}
- case EOpConstructFloat:
- outputConstructor(out, visit, node->getType(), "vec1", node->getSequence());
- break;
- case EOpConstructVec2:
- outputConstructor(out, visit, node->getType(), "vec2", node->getSequence());
- break;
- case EOpConstructVec3:
- outputConstructor(out, visit, node->getType(), "vec3", node->getSequence());
- break;
- case EOpConstructVec4:
- outputConstructor(out, visit, node->getType(), "vec4", node->getSequence());
- break;
- case EOpConstructBool:
- outputConstructor(out, visit, node->getType(), "bvec1", node->getSequence());
- break;
- case EOpConstructBVec2:
- outputConstructor(out, visit, node->getType(), "bvec2", node->getSequence());
- break;
- case EOpConstructBVec3:
- outputConstructor(out, visit, node->getType(), "bvec3", node->getSequence());
- break;
- case EOpConstructBVec4:
- outputConstructor(out, visit, node->getType(), "bvec4", node->getSequence());
- break;
- case EOpConstructInt:
- outputConstructor(out, visit, node->getType(), "ivec1", node->getSequence());
- break;
- case EOpConstructIVec2:
- outputConstructor(out, visit, node->getType(), "ivec2", node->getSequence());
- break;
- case EOpConstructIVec3:
- outputConstructor(out, visit, node->getType(), "ivec3", node->getSequence());
- break;
- case EOpConstructIVec4:
- outputConstructor(out, visit, node->getType(), "ivec4", node->getSequence());
- break;
- case EOpConstructUInt:
- outputConstructor(out, visit, node->getType(), "uvec1", node->getSequence());
- break;
- case EOpConstructUVec2:
- outputConstructor(out, visit, node->getType(), "uvec2", node->getSequence());
- break;
- case EOpConstructUVec3:
- outputConstructor(out, visit, node->getType(), "uvec3", node->getSequence());
- break;
- case EOpConstructUVec4:
- outputConstructor(out, visit, node->getType(), "uvec4", node->getSequence());
- break;
- case EOpConstructMat2:
- outputConstructor(out, visit, node->getType(), "mat2", node->getSequence());
- break;
- case EOpConstructMat2x3:
- outputConstructor(out, visit, node->getType(), "mat2x3", node->getSequence());
- break;
- case EOpConstructMat2x4:
- outputConstructor(out, visit, node->getType(), "mat2x4", node->getSequence());
- break;
- case EOpConstructMat3x2:
- outputConstructor(out, visit, node->getType(), "mat3x2", node->getSequence());
- break;
- case EOpConstructMat3:
- outputConstructor(out, visit, node->getType(), "mat3", node->getSequence());
- break;
- case EOpConstructMat3x4:
- outputConstructor(out, visit, node->getType(), "mat3x4", node->getSequence());
- break;
- case EOpConstructMat4x2:
- outputConstructor(out, visit, node->getType(), "mat4x2", node->getSequence());
- break;
- case EOpConstructMat4x3:
- outputConstructor(out, visit, node->getType(), "mat4x3", node->getSequence());
- break;
- case EOpConstructMat4:
- outputConstructor(out, visit, node->getType(), "mat4", node->getSequence());
- break;
- case EOpConstructStruct:
- {
- if (node->getType().isArray())
+ case EOpConstruct:
+ if (node->getBasicType() == EbtStruct)
{
- UNIMPLEMENTED();
+ if (node->getType().isArray())
+ {
+ UNIMPLEMENTED();
+ }
+ const TString &structName = StructNameString(*node->getType().getStruct());
+ mStructureHLSL->addConstructor(node->getType(), structName, node->getSequence());
+ outputTriplet(out, visit, (structName + "_ctor(").c_str(), ", ", ")");
}
- const TString &structName = StructNameString(*node->getType().getStruct());
- mStructureHLSL->addConstructor(node->getType(), structName, node->getSequence());
- outputTriplet(out, visit, (structName + "_ctor(").c_str(), ", ", ")");
- }
- break;
+ else
+ {
+ const char *name = "";
+ if (node->getType().getNominalSize() == 1)
+ {
+ switch (node->getBasicType())
+ {
+ case EbtFloat:
+ name = "vec1";
+ break;
+ case EbtInt:
+ name = "ivec1";
+ break;
+ case EbtUInt:
+ name = "uvec1";
+ break;
+ case EbtBool:
+ name = "bvec1";
+ break;
+ default:
+ UNREACHABLE();
+ }
+ }
+ else
+ {
+ name = node->getType().getBuiltInTypeNameString();
+ }
+ outputConstructor(out, visit, node->getType(), name, node->getSequence());
+ }
+ break;
case EOpEqualComponentWise:
outputTriplet(out, visit, "(", " == ", ")");
break;
diff --git a/src/compiler/translator/ScalarizeVecAndMatConstructorArgs.cpp b/src/compiler/translator/ScalarizeVecAndMatConstructorArgs.cpp
index 8a2929e..e09241a 100644
--- a/src/compiler/translator/ScalarizeVecAndMatConstructorArgs.cpp
+++ b/src/compiler/translator/ScalarizeVecAndMatConstructorArgs.cpp
@@ -97,37 +97,12 @@
bool ScalarizeArgsTraverser::visitAggregate(Visit visit, TIntermAggregate *node)
{
- if (visit == PreVisit)
+ if (visit == PreVisit && node->getOp() == EOpConstruct)
{
- switch (node->getOp())
- {
- case EOpConstructVec2:
- case EOpConstructVec3:
- case EOpConstructVec4:
- case EOpConstructBVec2:
- case EOpConstructBVec3:
- case EOpConstructBVec4:
- case EOpConstructIVec2:
- case EOpConstructIVec3:
- case EOpConstructIVec4:
- if (ContainsMatrixNode(*(node->getSequence())))
- scalarizeArgs(node, false, true);
- break;
- case EOpConstructMat2:
- case EOpConstructMat2x3:
- case EOpConstructMat2x4:
- case EOpConstructMat3x2:
- case EOpConstructMat3:
- case EOpConstructMat3x4:
- case EOpConstructMat4x2:
- case EOpConstructMat4x3:
- case EOpConstructMat4:
- if (ContainsVectorNode(*(node->getSequence())))
- scalarizeArgs(node, true, false);
- break;
- default:
- break;
- }
+ if (node->getType().isVector() && ContainsMatrixNode(*(node->getSequence())))
+ scalarizeArgs(node, false, true);
+ else if (node->getType().isMatrix() && ContainsVectorNode(*(node->getSequence())))
+ scalarizeArgs(node, true, false);
}
return true;
}
@@ -157,46 +132,8 @@
bool scalarizeMatrix)
{
ASSERT(aggregate);
- int size = 0;
- switch (aggregate->getOp())
- {
- case EOpConstructVec2:
- case EOpConstructBVec2:
- case EOpConstructIVec2:
- size = 2;
- break;
- case EOpConstructVec3:
- case EOpConstructBVec3:
- case EOpConstructIVec3:
- size = 3;
- break;
- case EOpConstructVec4:
- case EOpConstructBVec4:
- case EOpConstructIVec4:
- case EOpConstructMat2:
- size = 4;
- break;
- case EOpConstructMat2x3:
- case EOpConstructMat3x2:
- size = 6;
- break;
- case EOpConstructMat2x4:
- case EOpConstructMat4x2:
- size = 8;
- break;
- case EOpConstructMat3:
- size = 9;
- break;
- case EOpConstructMat3x4:
- case EOpConstructMat4x3:
- size = 12;
- break;
- case EOpConstructMat4:
- size = 16;
- break;
- default:
- break;
- }
+ ASSERT(!aggregate->isArray());
+ int size = static_cast<int>(aggregate->getType().getObjectSize());
TIntermSequence *sequence = aggregate->getSequence();
TIntermSequence original(*sequence);
sequence->clear();
diff --git a/src/compiler/translator/VersionGLSL.cpp b/src/compiler/translator/VersionGLSL.cpp
index 938325b..8168876 100644
--- a/src/compiler/translator/VersionGLSL.cpp
+++ b/src/compiler/translator/VersionGLSL.cpp
@@ -120,31 +120,17 @@
bool TVersionGLSL::visitAggregate(Visit, TIntermAggregate *node)
{
- switch (node->getOp())
+ if (node->getOp() == EOpConstruct && node->getType().isMatrix())
{
- case EOpConstructMat2:
- case EOpConstructMat2x3:
- case EOpConstructMat2x4:
- case EOpConstructMat3x2:
- case EOpConstructMat3:
- case EOpConstructMat3x4:
- case EOpConstructMat4x2:
- case EOpConstructMat4x3:
- case EOpConstructMat4:
+ const TIntermSequence &sequence = *(node->getSequence());
+ if (sequence.size() == 1)
{
- const TIntermSequence &sequence = *(node->getSequence());
- if (sequence.size() == 1)
+ TIntermTyped *typed = sequence.front()->getAsTyped();
+ if (typed && typed->isMatrix())
{
- TIntermTyped *typed = sequence.front()->getAsTyped();
- if (typed && typed->isMatrix())
- {
- ensureVersionIsAtLeast(GLSL_VERSION_120);
- }
+ ensureVersionIsAtLeast(GLSL_VERSION_120);
}
- break;
}
- default:
- break;
}
return true;
}
diff --git a/src/compiler/translator/intermOut.cpp b/src/compiler/translator/intermOut.cpp
index 2b71efa..38f8808 100644
--- a/src/compiler/translator/intermOut.cpp
+++ b/src/compiler/translator/intermOut.cpp
@@ -386,67 +386,58 @@
return true;
}
- if (node->isConstructor())
+ // Give verbose names for some built-in functions that are easy to confuse with others, but
+ // mostly use GLSL names for functions.
+ switch (node->getOp())
{
- if (node->getOp() == EOpConstructStruct)
- {
- out << "Construct structure";
- }
- else
- {
- out << "Construct " << GetOperatorString(node->getOp());
- }
- }
- else
- {
- // Give verbose names for some built-in functions that are easy to confuse with others, but
- // mostly use GLSL names for functions.
- switch (node->getOp())
- {
- case EOpCallFunctionInAST:
- OutputFunction(out, "Call an user-defined function", node->getFunctionSymbolInfo());
- break;
- case EOpCallInternalRawFunction:
- OutputFunction(out, "Call an internal function with raw implementation",
- node->getFunctionSymbolInfo());
- break;
- case EOpCallBuiltInFunction:
- OutputFunction(out, "Call a built-in function", node->getFunctionSymbolInfo());
- break;
+ case EOpCallFunctionInAST:
+ OutputFunction(out, "Call an user-defined function", node->getFunctionSymbolInfo());
+ break;
+ case EOpCallInternalRawFunction:
+ OutputFunction(out, "Call an internal function with raw implementation",
+ node->getFunctionSymbolInfo());
+ break;
+ case EOpCallBuiltInFunction:
+ OutputFunction(out, "Call a built-in function", node->getFunctionSymbolInfo());
+ break;
- case EOpEqualComponentWise:
- out << "component-wise equal";
- break;
- case EOpNotEqualComponentWise:
- out << "component-wise not equal";
- break;
- case EOpLessThanComponentWise:
- out << "component-wise less than";
- break;
- case EOpGreaterThanComponentWise:
- out << "component-wise greater than";
- break;
- case EOpLessThanEqualComponentWise:
- out << "component-wise less than or equal";
- break;
- case EOpGreaterThanEqualComponentWise:
- out << "component-wise greater than or equal";
- break;
+ case EOpConstruct:
+ // The type of the constructor will be printed below.
+ out << "Construct";
+ break;
- case EOpDot:
- out << "dot product";
- break;
- case EOpCross:
- out << "cross product";
- break;
- case EOpMulMatrixComponentWise:
- out << "component-wise multiply";
- break;
+ case EOpEqualComponentWise:
+ out << "component-wise equal";
+ break;
+ case EOpNotEqualComponentWise:
+ out << "component-wise not equal";
+ break;
+ case EOpLessThanComponentWise:
+ out << "component-wise less than";
+ break;
+ case EOpGreaterThanComponentWise:
+ out << "component-wise greater than";
+ break;
+ case EOpLessThanEqualComponentWise:
+ out << "component-wise less than or equal";
+ break;
+ case EOpGreaterThanEqualComponentWise:
+ out << "component-wise greater than or equal";
+ break;
- default:
- out << GetOperatorString(node->getOp());
- break;
- }
+ case EOpDot:
+ out << "dot product";
+ break;
+ case EOpCross:
+ out << "cross product";
+ break;
+ case EOpMulMatrixComponentWise:
+ out << "component-wise multiply";
+ break;
+
+ default:
+ out << GetOperatorString(node->getOp());
+ break;
}
out << " (" << node->getCompleteString() << ")";
diff --git a/src/compiler/translator/util.cpp b/src/compiler/translator/util.cpp
index 6a2f9fa..c87b725 100644
--- a/src/compiler/translator/util.cpp
+++ b/src/compiler/translator/util.cpp
@@ -575,134 +575,6 @@
}
}
-TOperator TypeToConstructorOperator(const TType &type)
-{
- switch (type.getBasicType())
- {
- case EbtFloat:
- if (type.isMatrix())
- {
- switch (type.getCols())
- {
- case 2:
- switch (type.getRows())
- {
- case 2:
- return EOpConstructMat2;
- case 3:
- return EOpConstructMat2x3;
- case 4:
- return EOpConstructMat2x4;
- default:
- break;
- }
- break;
-
- case 3:
- switch (type.getRows())
- {
- case 2:
- return EOpConstructMat3x2;
- case 3:
- return EOpConstructMat3;
- case 4:
- return EOpConstructMat3x4;
- default:
- break;
- }
- break;
-
- case 4:
- switch (type.getRows())
- {
- case 2:
- return EOpConstructMat4x2;
- case 3:
- return EOpConstructMat4x3;
- case 4:
- return EOpConstructMat4;
- default:
- break;
- }
- break;
- }
- }
- else
- {
- switch (type.getNominalSize())
- {
- case 1:
- return EOpConstructFloat;
- case 2:
- return EOpConstructVec2;
- case 3:
- return EOpConstructVec3;
- case 4:
- return EOpConstructVec4;
- default:
- break;
- }
- }
- break;
-
- case EbtInt:
- switch (type.getNominalSize())
- {
- case 1:
- return EOpConstructInt;
- case 2:
- return EOpConstructIVec2;
- case 3:
- return EOpConstructIVec3;
- case 4:
- return EOpConstructIVec4;
- default:
- break;
- }
- break;
-
- case EbtUInt:
- switch (type.getNominalSize())
- {
- case 1:
- return EOpConstructUInt;
- case 2:
- return EOpConstructUVec2;
- case 3:
- return EOpConstructUVec3;
- case 4:
- return EOpConstructUVec4;
- default:
- break;
- }
- break;
-
- case EbtBool:
- switch (type.getNominalSize())
- {
- case 1:
- return EOpConstructBool;
- case 2:
- return EOpConstructBVec2;
- case 3:
- return EOpConstructBVec3;
- case 4:
- return EOpConstructBVec4;
- default:
- break;
- }
- break;
-
- case EbtStruct:
- return EOpConstructStruct;
-
- default:
- break;
- }
-
- return EOpNull;
-}
-
// GLSL ES 1.0.17 4.6.1 The Invariant Qualifier
bool CanBeInvariantESSL1(TQualifier qualifier)
{
diff --git a/src/compiler/translator/util.h b/src/compiler/translator/util.h
index 35db88b..f27933c 100644
--- a/src/compiler/translator/util.h
+++ b/src/compiler/translator/util.h
@@ -43,8 +43,6 @@
TType GetShaderVariableBasicType(const sh::ShaderVariable &var);
-TOperator TypeToConstructorOperator(const TType &type);
-
bool IsBuiltinOutputVariable(TQualifier qualifier);
bool IsBuiltinFragmentInputVariable(TQualifier qualifier);
bool CanBeInvariantESSL1(TQualifier qualifier);