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