Commit 59f9a641 by Olli Etuaho

Remove EOpInternalFunctionCall

It's cleaner to mark internal functions by using the TName class, similarly to TIntermSymbol. TEST=angle_unittests BUG=angleproject:1116 Change-Id: I12a03a3dea42b3fc571fa25a1b11d0161f24de72 Reviewed-on: https://chromium-review.googlesource.com/291621Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarOlli Etuaho <oetuaho@nvidia.com>
parent f5cfc8df
......@@ -238,8 +238,10 @@ bool canRoundFloat(const TType &type)
TIntermAggregate *createInternalFunctionCallNode(TString name, TIntermNode *child)
{
TIntermAggregate *callNode = new TIntermAggregate();
callNode->setOp(EOpInternalFunctionCall);
callNode->setName(name);
callNode->setOp(EOpFunctionCall);
TName nameObj(TFunction::mangleName(name));
nameObj.setInternal(true);
callNode->setNameObj(nameObj);
callNode->getSequence()->push_back(child);
return callNode;
}
......
......@@ -365,7 +365,7 @@ void TIntermAggregate::setBuiltInFunctionPrecision()
}
// ESSL 3.0 spec section 8: textureSize always gets highp precision.
// All other functions that take a sampler are assumed to be texture functions.
if (mName.find("textureSize") == 0)
if (mName.getString().find("textureSize") == 0)
mType.setPrecision(EbpHigh);
else
mType.setPrecision(precision);
......
......@@ -51,8 +51,10 @@ class TName
public:
POOL_ALLOCATOR_NEW_DELETE();
explicit TName(const TString &name) : mName(name), mIsInternal(false) {}
TName() : mName(), mIsInternal(false) {}
const TString &getString() const { return mName; }
void setString(const TString &string) { mName = string; }
bool isInternal() const { return mIsInternal; }
void setInternal(bool isInternal) { mIsInternal = isInternal; }
......@@ -469,8 +471,11 @@ class TIntermAggregate : public TIntermOperator
TIntermSequence *getSequence() { return &mSequence; }
void setName(const TString &name) { mName = name; }
const TString &getName() const { return mName; }
void setNameObj(const TName &name) { mName = name; }
const TName &getNameObj() const { return mName; }
void setName(const TString &name) { mName.setString(name); }
const TString &getName() const { return mName.getString(); }
void setUserDefined() { mUserDefined = true; }
bool isUserDefined() const { return mUserDefined; }
......@@ -496,7 +501,7 @@ class TIntermAggregate : public TIntermOperator
TIntermAggregate(const TIntermAggregate &); // disallow copy constructor
TIntermAggregate &operator=(const TIntermAggregate &); // disallow assignment operator
TIntermSequence mSequence;
TString mName;
TName mName;
bool mUserDefined; // used for user defined function names
int mFunctionId;
......
......@@ -159,7 +159,7 @@ void TLValueTrackingTraverser::addToFunctionMap(const TString &name, TIntermSequ
bool TLValueTrackingTraverser::isInFunctionMap(const TIntermAggregate *callNode) const
{
ASSERT(callNode->getOp() == EOpFunctionCall || callNode->getOp() == EOpInternalFunctionCall);
ASSERT(callNode->getOp() == EOpFunctionCall);
return (mFunctionMap.find(callNode->getName()) != mFunctionMap.end());
}
......
......@@ -15,7 +15,6 @@ enum TOperator
EOpNull, // if in a node, should only mean a node is still being built
EOpSequence, // denotes a list of statements, or parameters, etc.
EOpFunctionCall,
EOpInternalFunctionCall, // Call to an internal helper function
EOpFunction, // For function definition
EOpParameters, // an aggregate listing the parameters to a function
......
......@@ -783,7 +783,7 @@ bool TOutputGLSLBase::visitAggregate(Visit visit, TIntermAggregate *node)
out << arrayBrackets(type);
}
out << " " << hashFunctionName(node->getName());
out << " " << hashFunctionNameIfNeeded(node->getNameObj());
out << "(";
writeFunctionParameters(*(node->getSequence()));
......@@ -801,7 +801,7 @@ bool TOutputGLSLBase::visitAggregate(Visit visit, TIntermAggregate *node)
out << arrayBrackets(type);
}
out << " " << hashFunctionName(node->getName());
out << " " << hashFunctionNameIfNeeded(node->getNameObj());
incrementDepth(node);
// Function definition node contains one or two children nodes
......@@ -830,16 +830,7 @@ bool TOutputGLSLBase::visitAggregate(Visit visit, TIntermAggregate *node)
case EOpFunctionCall:
// Function call.
if (visit == PreVisit)
out << hashFunctionName(node->getName()) << "(";
else if (visit == InVisit)
out << ", ";
else
out << ")";
break;
case EOpInternalFunctionCall:
// Function call to an internal helper function.
if (visit == PreVisit)
out << node->getName() << "(";
out << hashFunctionNameIfNeeded(node->getNameObj()) << "(";
else if (visit == InVisit)
out << ", ";
else
......@@ -1234,12 +1225,16 @@ TString TOutputGLSLBase::hashVariableName(const TString &name)
return hashName(name);
}
TString TOutputGLSLBase::hashFunctionName(const TString &mangled_name)
TString TOutputGLSLBase::hashFunctionNameIfNeeded(const TName &mangledName)
{
TString name = TFunction::unmangleName(mangled_name);
if (mSymbolTable.findBuiltIn(mangled_name, mShaderVersion) != NULL || name == "main")
TString mangledStr = mangledName.getString();
TString name = TFunction::unmangleName(mangledStr);
if (mSymbolTable.findBuiltIn(mangledStr, mShaderVersion) != nullptr || name == "main")
return translateTextureFunction(name);
return hashName(name);
if (mangledName.isInternal())
return name;
else
return hashName(name);
}
bool TOutputGLSLBase::structDeclared(const TStructure *structure) const
......
......@@ -57,8 +57,8 @@ class TOutputGLSLBase : public TIntermTraverser
TString hashName(const TString &name);
// Same as hashName(), but without hashing built-in variables.
TString hashVariableName(const TString &name);
// Same as hashName(), but without hashing built-in functions.
TString hashFunctionName(const TString &mangled_name);
// Same as hashName(), but without hashing built-in functions and with unmangling.
TString hashFunctionNameIfNeeded(const TName &mangledName);
// Used to translate function names for differences between ESSL and GLSL
virtual TString translateTextureFunction(TString &name) { return name; }
......
......@@ -1939,7 +1939,9 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
return false;
}
out << TypeString(node->getType()) << " " << Decorate(TFunction::unmangleName(node->getName())) << (mOutputLod0Function ? "Lod0(" : "(");
TString name = DecorateFunctionIfNeeded(node->getNameObj());
out << TypeString(node->getType()) << " " << name
<< (mOutputLod0Function ? "Lod0(" : "(");
TIntermSequence *arguments = node->getSequence();
......@@ -1977,7 +1979,7 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
case EOpFunction:
{
ASSERT(mCurrentFunctionMetadata == nullptr);
TString name = TFunction::unmangleName(node->getName());
TString name = TFunction::unmangleName(node->getNameObj().getString());
size_t index = mCallDag.findIndex(node);
ASSERT(index != CallDAG::InvalidIndex);
......@@ -1991,7 +1993,8 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
}
else
{
out << Decorate(name) << (mOutputLod0Function ? "Lod0(" : "(");
out << DecorateFunctionIfNeeded(node->getNameObj())
<< (mOutputLod0Function ? "Lod0(" : "(");
}
TIntermSequence *sequence = node->getSequence();
......@@ -2047,7 +2050,6 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
break;
case EOpFunctionCall:
{
TString name = TFunction::unmangleName(node->getName());
TIntermSequence *arguments = node->getSequence();
bool lod0 = mInsideDiscontinuousLoop || mOutputLod0Function;
......@@ -2061,10 +2063,11 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
ASSERT(index != CallDAG::InvalidIndex);
lod0 &= mASTMetadataList[index].mNeedsLod0;
out << Decorate(name) << (lod0 ? "Lod0(" : "(");
out << DecorateFunctionIfNeeded(node->getNameObj()) << (lod0 ? "Lod0(" : "(");
}
else
{
TString name = TFunction::unmangleName(node->getNameObj().getString());
TBasicType samplerType = (*arguments)[0]->getAsTyped()->getType().getBasicType();
TextureFunction textureFunction;
......
......@@ -100,6 +100,18 @@ TString DecorateIfNeeded(const TName &name)
}
}
TString DecorateFunctionIfNeeded(const TName &name)
{
if (name.isInternal())
{
return TFunction::unmangleName(name.getString());
}
else
{
return Decorate(TFunction::unmangleName(name.getString()));
}
}
TString TypeString(const TType &type)
{
const TStructure* structure = type.getStruct();
......
......@@ -25,6 +25,8 @@ TString SamplerString(const TType &type);
// Prepends an underscore to avoid naming clashes
TString Decorate(const TString &string);
TString DecorateIfNeeded(const TName &name);
// Decorates and also unmangles the function name
TString DecorateFunctionIfNeeded(const TName &name);
TString DecorateUniform(const TString &string, const TType &type);
TString DecorateField(const TString &string, const TStructure &structure);
TString DecoratePrivate(const TString &privateText);
......
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