Commit 8fab320c by Olli Etuaho Committed by Commit Bot

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: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent 9405005f
......@@ -640,12 +640,16 @@ bool EmulatePrecision::visitAggregate(Visit visit, TIntermAggregate *node)
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 &&
......
......@@ -306,10 +306,7 @@ TIntermAggregate *TIntermAggregate::CreateBuiltInFunctionCall(const TFunction &f
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 @@ void TIntermAggregate::setTypePrecisionAndQualifier(const TType &type)
{
// 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 @@ bool TIntermOperator::isMultiplication() const
}
}
// 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
......
......@@ -296,58 +296,6 @@ const char *GetOperatorString(TOperator op)
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:
......
......@@ -202,40 +202,11 @@ enum TOperator
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
//
......
......@@ -962,32 +962,7 @@ bool TOutputGLSLBase::visitAggregate(Visit visit, TIntermAggregate *node)
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;
......
......@@ -1846,92 +1846,47 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
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;
......
......@@ -97,37 +97,12 @@ class ScalarizeArgsTraverser : public TIntermTraverser
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 @@ void ScalarizeArgsTraverser::scalarizeArgs(TIntermAggregate *aggregate,
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();
......
......@@ -120,31 +120,17 @@ bool TVersionGLSL::visitFunctionPrototype(Visit, TIntermFunctionPrototype *node)
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;
}
......
......@@ -386,67 +386,58 @@ bool TOutputTraverser::visitAggregate(Visit visit, TIntermAggregate *node)
return true;
}
if (node->isConstructor())
{
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())
{
// 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() << ")";
......
......@@ -575,134 +575,6 @@ TType GetShaderVariableBasicType(const sh::ShaderVariable &var)
}
}
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)
{
......
......@@ -43,8 +43,6 @@ TString ArrayString(const TType &type);
TType GetShaderVariableBasicType(const sh::ShaderVariable &var);
TOperator TypeToConstructorOperator(const TType &type);
bool IsBuiltinOutputVariable(TQualifier qualifier);
bool IsBuiltinFragmentInputVariable(TQualifier qualifier);
bool CanBeInvariantESSL1(TQualifier qualifier);
......
......@@ -157,12 +157,12 @@ TEST_F(TypeTrackingTest, BuiltInMatFunctionResultTypeAndPrecision)
"}\n";
compile(shaderString);
ASSERT_FALSE(foundErrorInIntermediateTree());
ASSERT_TRUE(foundInIntermediateTree("Construct mat2x3 (mediump 2X3 matrix of float)"));
ASSERT_TRUE(foundInIntermediateTree("Construct mat3x2 (mediump 3X2 matrix of float)"));
ASSERT_TRUE(foundInIntermediateTree("Construct mat2x4 (mediump 2X4 matrix of float)"));
ASSERT_TRUE(foundInIntermediateTree("Construct mat4x2 (mediump 4X2 matrix of float)"));
ASSERT_TRUE(foundInIntermediateTree("Construct mat3x4 (mediump 3X4 matrix of float)"));
ASSERT_TRUE(foundInIntermediateTree("Construct mat4x3 (mediump 4X3 matrix of float)"));
ASSERT_TRUE(foundInIntermediateTree("Construct (mediump 2X3 matrix of float)"));
ASSERT_TRUE(foundInIntermediateTree("Construct (mediump 3X2 matrix of float)"));
ASSERT_TRUE(foundInIntermediateTree("Construct (mediump 2X4 matrix of float)"));
ASSERT_TRUE(foundInIntermediateTree("Construct (mediump 4X2 matrix of float)"));
ASSERT_TRUE(foundInIntermediateTree("Construct (mediump 3X4 matrix of float)"));
ASSERT_TRUE(foundInIntermediateTree("Construct (mediump 4X3 matrix of float)"));
}
TEST_F(TypeTrackingTest, BuiltInFunctionChoosesHigherPrecision)
......@@ -288,7 +288,7 @@ TEST_F(TypeTrackingTest, BuiltInConstructorResultTypeAndPrecision)
"}\n";
compile(shaderString);
ASSERT_FALSE(foundErrorInIntermediateTree());
ASSERT_TRUE(foundInIntermediateTree("Construct vec4 (mediump 4-component vector of float)"));
ASSERT_TRUE(foundInIntermediateTree("Construct (mediump 4-component vector of float)"));
}
TEST_F(TypeTrackingTest, StructConstructorResultNoPrecision)
......@@ -304,7 +304,7 @@ TEST_F(TypeTrackingTest, StructConstructorResultNoPrecision)
"}\n";
compile(shaderString);
ASSERT_FALSE(foundErrorInIntermediateTree());
ASSERT_TRUE(foundInIntermediateTree("Construct structure (structure)"));
ASSERT_TRUE(foundInIntermediateTree("Construct (structure)"));
}
TEST_F(TypeTrackingTest, PackResultTypeAndPrecision)
......
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