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( ...@@ -172,63 +172,6 @@ static void writeCompoundAssignmentPrecisionEmulation(
"}\n"; "}\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) bool canRoundFloat(const TType &type)
{ {
return type.getBasicType() == EbtFloat && !type.isNonSquareMatrix() && !type.isArray() && return type.getBasicType() == EbtFloat && !type.isNonSquareMatrix() && !type.isArray() &&
...@@ -359,19 +302,25 @@ bool EmulatePrecision::visitBinary(Visit visit, TIntermBinary *node) ...@@ -359,19 +302,25 @@ bool EmulatePrecision::visitBinary(Visit visit, TIntermBinary *node)
// Compound assignment cases need to replace the operator with a function call. // Compound assignment cases need to replace the operator with a function call.
case EOpAddAssign: case EOpAddAssign:
{ {
mEmulateCompoundAdd.insert(TypePair(getFloatTypeStr(type), getFloatTypeStr(node->getRight()->getType()))); mEmulateCompoundAdd.insert(
TIntermNode *parent = getParentNode(); TypePair(type.getBuiltInTypeNameString(),
TIntermNode *replacement = createCompoundAssignmentFunctionCallNode(node->getLeft(), node->getRight(), "add"); node->getRight()->getType().getBuiltInTypeNameString()));
mReplacements.push_back(NodeUpdateEntry(parent, node, replacement, false)); TIntermNode *parent = getParentNode();
break; TIntermNode *replacement = createCompoundAssignmentFunctionCallNode(
node->getLeft(), node->getRight(), "add");
mReplacements.push_back(NodeUpdateEntry(parent, node, replacement, false));
break;
} }
case EOpSubAssign: case EOpSubAssign:
{ {
mEmulateCompoundSub.insert(TypePair(getFloatTypeStr(type), getFloatTypeStr(node->getRight()->getType()))); mEmulateCompoundSub.insert(
TIntermNode *parent = getParentNode(); TypePair(type.getBuiltInTypeNameString(),
TIntermNode *replacement = createCompoundAssignmentFunctionCallNode(node->getLeft(), node->getRight(), "sub"); node->getRight()->getType().getBuiltInTypeNameString()));
mReplacements.push_back(NodeUpdateEntry(parent, node, replacement, false)); TIntermNode *parent = getParentNode();
break; TIntermNode *replacement = createCompoundAssignmentFunctionCallNode(
node->getLeft(), node->getRight(), "sub");
mReplacements.push_back(NodeUpdateEntry(parent, node, replacement, false));
break;
} }
case EOpMulAssign: case EOpMulAssign:
case EOpVectorTimesMatrixAssign: case EOpVectorTimesMatrixAssign:
...@@ -379,19 +328,25 @@ bool EmulatePrecision::visitBinary(Visit visit, TIntermBinary *node) ...@@ -379,19 +328,25 @@ bool EmulatePrecision::visitBinary(Visit visit, TIntermBinary *node)
case EOpMatrixTimesScalarAssign: case EOpMatrixTimesScalarAssign:
case EOpMatrixTimesMatrixAssign: case EOpMatrixTimesMatrixAssign:
{ {
mEmulateCompoundMul.insert(TypePair(getFloatTypeStr(type), getFloatTypeStr(node->getRight()->getType()))); mEmulateCompoundMul.insert(
TIntermNode *parent = getParentNode(); TypePair(type.getBuiltInTypeNameString(),
TIntermNode *replacement = createCompoundAssignmentFunctionCallNode(node->getLeft(), node->getRight(), "mul"); node->getRight()->getType().getBuiltInTypeNameString()));
mReplacements.push_back(NodeUpdateEntry(parent, node, replacement, false)); TIntermNode *parent = getParentNode();
break; TIntermNode *replacement = createCompoundAssignmentFunctionCallNode(
node->getLeft(), node->getRight(), "mul");
mReplacements.push_back(NodeUpdateEntry(parent, node, replacement, false));
break;
} }
case EOpDivAssign: case EOpDivAssign:
{ {
mEmulateCompoundDiv.insert(TypePair(getFloatTypeStr(type), getFloatTypeStr(node->getRight()->getType()))); mEmulateCompoundDiv.insert(
TIntermNode *parent = getParentNode(); TypePair(type.getBuiltInTypeNameString(),
TIntermNode *replacement = createCompoundAssignmentFunctionCallNode(node->getLeft(), node->getRight(), "div"); node->getRight()->getType().getBuiltInTypeNameString()));
mReplacements.push_back(NodeUpdateEntry(parent, node, replacement, false)); TIntermNode *parent = getParentNode();
break; TIntermNode *replacement = createCompoundAssignmentFunctionCallNode(
node->getLeft(), node->getRight(), "div");
mReplacements.push_back(NodeUpdateEntry(parent, node, replacement, false));
break;
} }
default: default:
// The rest of the binary operations should not need precision emulation. // The rest of the binary operations should not need precision emulation.
......
...@@ -243,20 +243,20 @@ const TConstantUnion *TOutputGLSLBase::writeConstantUnion( ...@@ -243,20 +243,20 @@ const TConstantUnion *TOutputGLSLBase::writeConstantUnion(
return pConstUnion; return pConstUnion;
} }
void TOutputGLSLBase::writeConstructorTriplet(Visit visit, const TType &type, const char *constructorBaseType) void TOutputGLSLBase::writeConstructorTriplet(Visit visit, const TType &type)
{ {
TInfoSinkBase &out = objSink(); TInfoSinkBase &out = objSink();
if (visit == PreVisit) if (visit == PreVisit)
{ {
if (type.isArray()) if (type.isArray())
{ {
out << constructorBaseType; out << getTypeName(type);
out << arrayBrackets(type); out << arrayBrackets(type);
out << "("; out << "(";
} }
else else
{ {
out << constructorBaseType << "("; out << getTypeName(type) << "(";
} }
} }
else else
...@@ -917,88 +917,33 @@ bool TOutputGLSLBase::visitAggregate(Visit visit, TIntermAggregate *node) ...@@ -917,88 +917,33 @@ bool TOutputGLSLBase::visitAggregate(Visit visit, TIntermAggregate *node)
visitChildren = false; visitChildren = false;
break; break;
case EOpConstructFloat: case EOpConstructFloat:
writeConstructorTriplet(visit, node->getType(), "float");
break;
case EOpConstructVec2: case EOpConstructVec2:
writeConstructorTriplet(visit, node->getType(), "vec2");
break;
case EOpConstructVec3: case EOpConstructVec3:
writeConstructorTriplet(visit, node->getType(), "vec3");
break;
case EOpConstructVec4: case EOpConstructVec4:
writeConstructorTriplet(visit, node->getType(), "vec4");
break;
case EOpConstructBool: case EOpConstructBool:
writeConstructorTriplet(visit, node->getType(), "bool");
break;
case EOpConstructBVec2: case EOpConstructBVec2:
writeConstructorTriplet(visit, node->getType(), "bvec2");
break;
case EOpConstructBVec3: case EOpConstructBVec3:
writeConstructorTriplet(visit, node->getType(), "bvec3");
break;
case EOpConstructBVec4: case EOpConstructBVec4:
writeConstructorTriplet(visit, node->getType(), "bvec4");
break;
case EOpConstructInt: case EOpConstructInt:
writeConstructorTriplet(visit, node->getType(), "int");
break;
case EOpConstructIVec2: case EOpConstructIVec2:
writeConstructorTriplet(visit, node->getType(), "ivec2");
break;
case EOpConstructIVec3: case EOpConstructIVec3:
writeConstructorTriplet(visit, node->getType(), "ivec3");
break;
case EOpConstructIVec4: case EOpConstructIVec4:
writeConstructorTriplet(visit, node->getType(), "ivec4");
break;
case EOpConstructUInt: case EOpConstructUInt:
writeConstructorTriplet(visit, node->getType(), "uint");
break;
case EOpConstructUVec2: case EOpConstructUVec2:
writeConstructorTriplet(visit, node->getType(), "uvec2");
break;
case EOpConstructUVec3: case EOpConstructUVec3:
writeConstructorTriplet(visit, node->getType(), "uvec3");
break;
case EOpConstructUVec4: case EOpConstructUVec4:
writeConstructorTriplet(visit, node->getType(), "uvec4");
break;
case EOpConstructMat2: case EOpConstructMat2:
writeConstructorTriplet(visit, node->getType(), "mat2");
break;
case EOpConstructMat2x3: case EOpConstructMat2x3:
writeConstructorTriplet(visit, node->getType(), "mat2x3");
break;
case EOpConstructMat2x4: case EOpConstructMat2x4:
writeConstructorTriplet(visit, node->getType(), "mat2x4");
break;
case EOpConstructMat3x2: case EOpConstructMat3x2:
writeConstructorTriplet(visit, node->getType(), "mat3x2");
break;
case EOpConstructMat3: case EOpConstructMat3:
writeConstructorTriplet(visit, node->getType(), "mat3");
break;
case EOpConstructMat3x4: case EOpConstructMat3x4:
writeConstructorTriplet(visit, node->getType(), "mat3x4");
break;
case EOpConstructMat4x2: case EOpConstructMat4x2:
writeConstructorTriplet(visit, node->getType(), "mat4x2");
break;
case EOpConstructMat4x3: case EOpConstructMat4x3:
writeConstructorTriplet(visit, node->getType(), "mat4x3");
break;
case EOpConstructMat4: case EOpConstructMat4:
writeConstructorTriplet(visit, node->getType(), "mat4");
break;
case EOpConstructStruct: case EOpConstructStruct:
{ writeConstructorTriplet(visit, node->getType());
const TType &type = node->getType(); break;
ASSERT(type.getBasicType() == EbtStruct);
TString constructorName = hashName(type.getStruct()->name());
writeConstructorTriplet(visit, node->getType(), constructorName.c_str());
break;
}
case EOpOuterProduct: case EOpOuterProduct:
writeBuiltInFunctionTriplet(visit, "outerProduct(", useEmulatedFunction); writeBuiltInFunctionTriplet(visit, "outerProduct(", useEmulatedFunction);
...@@ -1208,45 +1153,10 @@ void TOutputGLSLBase::visitCodeBlock(TIntermNode *node) ...@@ -1208,45 +1153,10 @@ void TOutputGLSLBase::visitCodeBlock(TIntermNode *node)
TString TOutputGLSLBase::getTypeName(const TType &type) TString TOutputGLSLBase::getTypeName(const TType &type)
{ {
TInfoSinkBase out; if (type.getBasicType() == EbtStruct)
if (type.isMatrix()) return hashName(type.getStruct()->name());
{
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();
}
else else
{ return type.getBuiltInTypeNameString();
if (type.getBasicType() == EbtStruct)
out << hashName(type.getStruct()->name());
else
out << type.getBasicString();
}
return TString(out.c_str());
} }
TString TOutputGLSLBase::hashName(const TString &name) TString TOutputGLSLBase::hashName(const TString &name)
......
...@@ -37,7 +37,7 @@ class TOutputGLSLBase : public TIntermTraverser ...@@ -37,7 +37,7 @@ class TOutputGLSLBase : public TIntermTraverser
virtual bool writeVariablePrecision(TPrecision precision) = 0; virtual bool writeVariablePrecision(TPrecision precision) = 0;
void writeFunctionParameters(const TIntermSequence &args); void writeFunctionParameters(const TIntermSequence &args);
const TConstantUnion *writeConstantUnion(const TType &type, const TConstantUnion *pConstUnion); 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); TString getTypeName(const TType &type);
void visitSymbol(TIntermSymbol *node) override; void visitSymbol(TIntermSymbol *node) override;
......
...@@ -61,6 +61,122 @@ bool TStructure::equals(const TStructure &other) const ...@@ -61,6 +61,122 @@ bool TStructure::equals(const TStructure &other) const
return (uniqueId() == other.uniqueId()); 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 TString TType::getCompleteString() const
{ {
TStringStream stream; TStringStream stream;
......
...@@ -508,6 +508,7 @@ class TType ...@@ -508,6 +508,7 @@ class TType
{ {
return ::getBasicString(type); return ::getBasicString(type);
} }
const char *getPrecisionString() const const char *getPrecisionString() const
{ {
return ::getPrecisionString(precision); return ::getPrecisionString(precision);
...@@ -516,6 +517,9 @@ class TType ...@@ -516,6 +517,9 @@ class TType
{ {
return ::getQualifierString(qualifier); return ::getQualifierString(qualifier);
} }
const char *getBuiltInTypeNameString() const;
TString getCompleteString() const; TString getCompleteString() const;
// If this type is a struct, returns the deepest struct nesting of // 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