Commit e92507bc by Olli Etuaho Committed by Commit Bot

Reuse code for determining built-in type name string

Add TType::getBuiltInTypeNameString() that returns an unique char pointer for each built-in type. They can be easily stored in an std::set as required by EmulatePrecision, and the function can also be used in TOutputGLSLBase. BUG=angleproject:1437 TEST=angle_unittests Change-Id: I9acfe1b149546dedeae058841cbabf0d9829cdc9 Reviewed-on: https://chromium-review.googlesource.com/358471Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent 701b19bf
......@@ -172,63 +172,6 @@ static void writeCompoundAssignmentPrecisionEmulation(
"}\n";
}
const char *getFloatTypeStr(const TType& type)
{
switch (type.getNominalSize())
{
case 1:
return "float";
case 2:
switch(type.getSecondarySize())
{
case 1:
return "vec2";
case 2:
return "mat2";
case 3:
return "mat2x3";
case 4:
return "mat2x4";
default:
UNREACHABLE();
return NULL;
}
case 3:
switch(type.getSecondarySize())
{
case 1:
return "vec3";
case 2:
return "mat3x2";
case 3:
return "mat3";
case 4:
return "mat3x4";
default:
UNREACHABLE();
return NULL;
}
case 4:
switch(type.getSecondarySize())
{
case 1:
return "vec4";
case 2:
return "mat4x2";
case 3:
return "mat4x3";
case 4:
return "mat4";
default:
UNREACHABLE();
return NULL;
}
default:
UNREACHABLE();
return NULL;
}
}
bool canRoundFloat(const TType &type)
{
return type.getBasicType() == EbtFloat && !type.isNonSquareMatrix() && !type.isArray() &&
......@@ -359,19 +302,25 @@ bool EmulatePrecision::visitBinary(Visit visit, TIntermBinary *node)
// Compound assignment cases need to replace the operator with a function call.
case EOpAddAssign:
{
mEmulateCompoundAdd.insert(TypePair(getFloatTypeStr(type), getFloatTypeStr(node->getRight()->getType())));
TIntermNode *parent = getParentNode();
TIntermNode *replacement = createCompoundAssignmentFunctionCallNode(node->getLeft(), node->getRight(), "add");
mReplacements.push_back(NodeUpdateEntry(parent, node, replacement, false));
break;
mEmulateCompoundAdd.insert(
TypePair(type.getBuiltInTypeNameString(),
node->getRight()->getType().getBuiltInTypeNameString()));
TIntermNode *parent = getParentNode();
TIntermNode *replacement = createCompoundAssignmentFunctionCallNode(
node->getLeft(), node->getRight(), "add");
mReplacements.push_back(NodeUpdateEntry(parent, node, replacement, false));
break;
}
case EOpSubAssign:
{
mEmulateCompoundSub.insert(TypePair(getFloatTypeStr(type), getFloatTypeStr(node->getRight()->getType())));
TIntermNode *parent = getParentNode();
TIntermNode *replacement = createCompoundAssignmentFunctionCallNode(node->getLeft(), node->getRight(), "sub");
mReplacements.push_back(NodeUpdateEntry(parent, node, replacement, false));
break;
mEmulateCompoundSub.insert(
TypePair(type.getBuiltInTypeNameString(),
node->getRight()->getType().getBuiltInTypeNameString()));
TIntermNode *parent = getParentNode();
TIntermNode *replacement = createCompoundAssignmentFunctionCallNode(
node->getLeft(), node->getRight(), "sub");
mReplacements.push_back(NodeUpdateEntry(parent, node, replacement, false));
break;
}
case EOpMulAssign:
case EOpVectorTimesMatrixAssign:
......@@ -379,19 +328,25 @@ bool EmulatePrecision::visitBinary(Visit visit, TIntermBinary *node)
case EOpMatrixTimesScalarAssign:
case EOpMatrixTimesMatrixAssign:
{
mEmulateCompoundMul.insert(TypePair(getFloatTypeStr(type), getFloatTypeStr(node->getRight()->getType())));
TIntermNode *parent = getParentNode();
TIntermNode *replacement = createCompoundAssignmentFunctionCallNode(node->getLeft(), node->getRight(), "mul");
mReplacements.push_back(NodeUpdateEntry(parent, node, replacement, false));
break;
mEmulateCompoundMul.insert(
TypePair(type.getBuiltInTypeNameString(),
node->getRight()->getType().getBuiltInTypeNameString()));
TIntermNode *parent = getParentNode();
TIntermNode *replacement = createCompoundAssignmentFunctionCallNode(
node->getLeft(), node->getRight(), "mul");
mReplacements.push_back(NodeUpdateEntry(parent, node, replacement, false));
break;
}
case EOpDivAssign:
{
mEmulateCompoundDiv.insert(TypePair(getFloatTypeStr(type), getFloatTypeStr(node->getRight()->getType())));
TIntermNode *parent = getParentNode();
TIntermNode *replacement = createCompoundAssignmentFunctionCallNode(node->getLeft(), node->getRight(), "div");
mReplacements.push_back(NodeUpdateEntry(parent, node, replacement, false));
break;
mEmulateCompoundDiv.insert(
TypePair(type.getBuiltInTypeNameString(),
node->getRight()->getType().getBuiltInTypeNameString()));
TIntermNode *parent = getParentNode();
TIntermNode *replacement = createCompoundAssignmentFunctionCallNode(
node->getLeft(), node->getRight(), "div");
mReplacements.push_back(NodeUpdateEntry(parent, node, replacement, false));
break;
}
default:
// The rest of the binary operations should not need precision emulation.
......
......@@ -243,20 +243,20 @@ const TConstantUnion *TOutputGLSLBase::writeConstantUnion(
return pConstUnion;
}
void TOutputGLSLBase::writeConstructorTriplet(Visit visit, const TType &type, const char *constructorBaseType)
void TOutputGLSLBase::writeConstructorTriplet(Visit visit, const TType &type)
{
TInfoSinkBase &out = objSink();
if (visit == PreVisit)
{
if (type.isArray())
{
out << constructorBaseType;
out << getTypeName(type);
out << arrayBrackets(type);
out << "(";
}
else
{
out << constructorBaseType << "(";
out << getTypeName(type) << "(";
}
}
else
......@@ -917,88 +917,33 @@ bool TOutputGLSLBase::visitAggregate(Visit visit, TIntermAggregate *node)
visitChildren = false;
break;
case EOpConstructFloat:
writeConstructorTriplet(visit, node->getType(), "float");
break;
case EOpConstructVec2:
writeConstructorTriplet(visit, node->getType(), "vec2");
break;
case EOpConstructVec3:
writeConstructorTriplet(visit, node->getType(), "vec3");
break;
case EOpConstructVec4:
writeConstructorTriplet(visit, node->getType(), "vec4");
break;
case EOpConstructBool:
writeConstructorTriplet(visit, node->getType(), "bool");
break;
case EOpConstructBVec2:
writeConstructorTriplet(visit, node->getType(), "bvec2");
break;
case EOpConstructBVec3:
writeConstructorTriplet(visit, node->getType(), "bvec3");
break;
case EOpConstructBVec4:
writeConstructorTriplet(visit, node->getType(), "bvec4");
break;
case EOpConstructInt:
writeConstructorTriplet(visit, node->getType(), "int");
break;
case EOpConstructIVec2:
writeConstructorTriplet(visit, node->getType(), "ivec2");
break;
case EOpConstructIVec3:
writeConstructorTriplet(visit, node->getType(), "ivec3");
break;
case EOpConstructIVec4:
writeConstructorTriplet(visit, node->getType(), "ivec4");
break;
case EOpConstructUInt:
writeConstructorTriplet(visit, node->getType(), "uint");
break;
case EOpConstructUVec2:
writeConstructorTriplet(visit, node->getType(), "uvec2");
break;
case EOpConstructUVec3:
writeConstructorTriplet(visit, node->getType(), "uvec3");
break;
case EOpConstructUVec4:
writeConstructorTriplet(visit, node->getType(), "uvec4");
break;
case EOpConstructMat2:
writeConstructorTriplet(visit, node->getType(), "mat2");
break;
case EOpConstructMat2x3:
writeConstructorTriplet(visit, node->getType(), "mat2x3");
break;
case EOpConstructMat2x4:
writeConstructorTriplet(visit, node->getType(), "mat2x4");
break;
case EOpConstructMat3x2:
writeConstructorTriplet(visit, node->getType(), "mat3x2");
break;
case EOpConstructMat3:
writeConstructorTriplet(visit, node->getType(), "mat3");
break;
case EOpConstructMat3x4:
writeConstructorTriplet(visit, node->getType(), "mat3x4");
break;
case EOpConstructMat4x2:
writeConstructorTriplet(visit, node->getType(), "mat4x2");
break;
case EOpConstructMat4x3:
writeConstructorTriplet(visit, node->getType(), "mat4x3");
break;
case EOpConstructMat4:
writeConstructorTriplet(visit, node->getType(), "mat4");
break;
case EOpConstructStruct:
{
const TType &type = node->getType();
ASSERT(type.getBasicType() == EbtStruct);
TString constructorName = hashName(type.getStruct()->name());
writeConstructorTriplet(visit, node->getType(), constructorName.c_str());
break;
}
writeConstructorTriplet(visit, node->getType());
break;
case EOpOuterProduct:
writeBuiltInFunctionTriplet(visit, "outerProduct(", useEmulatedFunction);
......@@ -1208,45 +1153,10 @@ void TOutputGLSLBase::visitCodeBlock(TIntermNode *node)
TString TOutputGLSLBase::getTypeName(const TType &type)
{
TInfoSinkBase out;
if (type.isMatrix())
{
out << "mat";
out << type.getNominalSize();
if (type.getSecondarySize() != type.getNominalSize())
{
out << "x" << type.getSecondarySize();
}
}
else if (type.isVector())
{
switch (type.getBasicType())
{
case EbtFloat:
out << "vec";
break;
case EbtInt:
out << "ivec";
break;
case EbtBool:
out << "bvec";
break;
case EbtUInt:
out << "uvec";
break;
default:
UNREACHABLE();
}
out << type.getNominalSize();
}
if (type.getBasicType() == EbtStruct)
return hashName(type.getStruct()->name());
else
{
if (type.getBasicType() == EbtStruct)
out << hashName(type.getStruct()->name());
else
out << type.getBasicString();
}
return TString(out.c_str());
return type.getBuiltInTypeNameString();
}
TString TOutputGLSLBase::hashName(const TString &name)
......
......@@ -37,7 +37,7 @@ class TOutputGLSLBase : public TIntermTraverser
virtual bool writeVariablePrecision(TPrecision precision) = 0;
void writeFunctionParameters(const TIntermSequence &args);
const TConstantUnion *writeConstantUnion(const TType &type, const TConstantUnion *pConstUnion);
void writeConstructorTriplet(Visit visit, const TType &type, const char *constructorBaseType);
void writeConstructorTriplet(Visit visit, const TType &type);
TString getTypeName(const TType &type);
void visitSymbol(TIntermSymbol *node) override;
......
......@@ -61,6 +61,122 @@ bool TStructure::equals(const TStructure &other) const
return (uniqueId() == other.uniqueId());
}
const char *TType::getBuiltInTypeNameString() const
{
if (isMatrix())
{
switch (getCols())
{
case 2:
switch (getRows())
{
case 2:
return "mat2";
case 3:
return "mat2x3";
case 4:
return "mat2x4";
default:
UNREACHABLE();
return nullptr;
}
case 3:
switch (getRows())
{
case 2:
return "mat3x2";
case 3:
return "mat3";
case 4:
return "mat3x4";
default:
UNREACHABLE();
return nullptr;
}
case 4:
switch (getRows())
{
case 2:
return "mat4x2";
case 3:
return "mat4x3";
case 4:
return "mat4";
default:
UNREACHABLE();
return nullptr;
}
default:
UNREACHABLE();
return nullptr;
}
}
if (isVector())
{
switch (getBasicType())
{
case EbtFloat:
switch (getNominalSize())
{
case 2:
return "vec2";
case 3:
return "vec3";
case 4:
return "vec4";
default:
UNREACHABLE();
return nullptr;
}
case EbtInt:
switch (getNominalSize())
{
case 2:
return "ivec2";
case 3:
return "ivec3";
case 4:
return "ivec4";
default:
UNREACHABLE();
return nullptr;
}
case EbtBool:
switch (getNominalSize())
{
case 2:
return "bvec2";
case 3:
return "bvec3";
case 4:
return "bvec4";
default:
UNREACHABLE();
return nullptr;
}
case EbtUInt:
switch (getNominalSize())
{
case 2:
return "uvec2";
case 3:
return "uvec3";
case 4:
return "uvec4";
default:
UNREACHABLE();
return nullptr;
}
default:
UNREACHABLE();
return nullptr;
}
}
ASSERT(getBasicType() != EbtStruct);
ASSERT(getBasicType() != EbtInterfaceBlock);
return getBasicString();
}
TString TType::getCompleteString() const
{
TStringStream stream;
......
......@@ -508,6 +508,7 @@ class TType
{
return ::getBasicString(type);
}
const char *getPrecisionString() const
{
return ::getPrecisionString(precision);
......@@ -516,6 +517,9 @@ class TType
{
return ::getQualifierString(qualifier);
}
const char *getBuiltInTypeNameString() const;
TString getCompleteString() const;
// If this type is a struct, returns the deepest struct nesting of
......
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