Commit f5cfc8df by Olli Etuaho

Track whether a name is internal to ANGLE in a separate class

The AST contains identifiers in a few different places: besides symbols, there are also function names, which show up in function signatures and function calls. Any of these can be coming either from the original shader or from inside ANGLE. A class that encapsulates a string and its internalness will be useful for implementing a unified way of handling all names in shader translation. Start implementing this by splitting the functionality out of TSymbol. TEST=angle_unittests BUG=angleproject:1116 Change-Id: I0a1b5936dcccd0d5fc1c0c13c712102fbfff2a79 Reviewed-on: https://chromium-review.googlesource.com/291280Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Tested-by: 's avatarOlli Etuaho <oetuaho@nvidia.com>
parent ec17d54a
...@@ -44,6 +44,23 @@ class TIntermRaw; ...@@ -44,6 +44,23 @@ class TIntermRaw;
class TSymbolTable; class TSymbolTable;
// Encapsulate an identifier string and track whether it is coming from the original shader code
// (not internal) or from ANGLE (internal). Usually internal names shouldn't be decorated or hashed.
class TName
{
public:
POOL_ALLOCATOR_NEW_DELETE();
explicit TName(const TString &name) : mName(name), mIsInternal(false) {}
const TString &getString() const { return mName; }
bool isInternal() const { return mIsInternal; }
void setInternal(bool isInternal) { mIsInternal = isInternal; }
private:
TString mName;
bool mIsInternal;
};
// //
// Base class for the tree nodes // Base class for the tree nodes
// //
...@@ -212,22 +229,19 @@ class TIntermSymbol : public TIntermTyped ...@@ -212,22 +229,19 @@ class TIntermSymbol : public TIntermTyped
// If sym comes from per process globalpoolallocator, then it causes increased memory usage // If sym comes from per process globalpoolallocator, then it causes increased memory usage
// per compile it is essential to use "symbol = sym" to assign to symbol // per compile it is essential to use "symbol = sym" to assign to symbol
TIntermSymbol(int id, const TString &symbol, const TType &type) TIntermSymbol(int id, const TString &symbol, const TType &type)
: TIntermTyped(type), : TIntermTyped(type), mId(id), mSymbol(symbol)
mId(id),
mInternal(false)
{ {
mSymbol = symbol;
} }
bool hasSideEffects() const override { return false; } bool hasSideEffects() const override { return false; }
int getId() const { return mId; } int getId() const { return mId; }
const TString &getSymbol() const { return mSymbol; } const TString &getSymbol() const { return mSymbol.getString(); }
const TName &getName() const { return mSymbol; }
void setId(int newId) { mId = newId; } void setId(int newId) { mId = newId; }
bool isInternal() const { return mInternal; } void setInternal(bool internal) { mSymbol.setInternal(internal); }
void setInternal(bool isInternal) { mInternal = isInternal; }
void traverse(TIntermTraverser *it) override; void traverse(TIntermTraverser *it) override;
TIntermSymbol *getAsSymbolNode() override { return this; } TIntermSymbol *getAsSymbolNode() override { return this; }
...@@ -235,8 +249,7 @@ class TIntermSymbol : public TIntermTyped ...@@ -235,8 +249,7 @@ class TIntermSymbol : public TIntermTyped
protected: protected:
int mId; int mId;
bool mInternal; TName mSymbol;
TString mSymbol;
}; };
// A Raw node stores raw code, that the translator will insert verbatim // A Raw node stores raw code, that the translator will insert verbatim
......
...@@ -1391,13 +1391,9 @@ void OutputHLSL::visitSymbol(TIntermSymbol *node) ...@@ -1391,13 +1391,9 @@ void OutputHLSL::visitSymbol(TIntermSymbol *node)
mUsesFragDepth = true; mUsesFragDepth = true;
out << "gl_Depth"; out << "gl_Depth";
} }
else if (node->isInternal())
{
out << name;
}
else else
{ {
out << Decorate(name); out << DecorateIfNeeded(node->getName());
} }
} }
} }
...@@ -2849,25 +2845,27 @@ void OutputHLSL::outputLineDirective(int line) ...@@ -2849,25 +2845,27 @@ void OutputHLSL::outputLineDirective(int line)
TString OutputHLSL::argumentString(const TIntermSymbol *symbol) TString OutputHLSL::argumentString(const TIntermSymbol *symbol)
{ {
TQualifier qualifier = symbol->getQualifier(); TQualifier qualifier = symbol->getQualifier();
const TType &type = symbol->getType(); const TType &type = symbol->getType();
TString name = symbol->getSymbol(); const TName &name = symbol->getName();
TString nameStr;
if (name.empty()) // HLSL demands named arguments, also for prototypes if (name.getString().empty()) // HLSL demands named arguments, also for prototypes
{ {
name = "x" + str(mUniqueIndex++); nameStr = "x" + str(mUniqueIndex++);
} }
else if (!symbol->isInternal()) else
{ {
name = Decorate(name); nameStr = DecorateIfNeeded(name);
} }
if (mOutputType == SH_HLSL11_OUTPUT && IsSampler(type.getBasicType())) if (mOutputType == SH_HLSL11_OUTPUT && IsSampler(type.getBasicType()))
{ {
return QualifierString(qualifier) + " " + TextureString(type) + " texture_" + name + ArrayString(type) + ", " + return QualifierString(qualifier) + " " + TextureString(type) + " texture_" + nameStr +
QualifierString(qualifier) + " " + SamplerString(type) + " sampler_" + name + ArrayString(type); ArrayString(type) + ", " + QualifierString(qualifier) + " " + SamplerString(type) +
" sampler_" + nameStr + ArrayString(type);
} }
return QualifierString(qualifier) + " " + TypeString(type) + " " + name + ArrayString(type); return QualifierString(qualifier) + " " + TypeString(type) + " " + nameStr + ArrayString(type);
} }
TString OutputHLSL::initializer(const TType &type) TString OutputHLSL::initializer(const TType &type)
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
// //
#include "compiler/translator/UtilsHLSL.h" #include "compiler/translator/UtilsHLSL.h"
#include "compiler/translator/IntermNode.h"
#include "compiler/translator/StructureHLSL.h" #include "compiler/translator/StructureHLSL.h"
#include "compiler/translator/SymbolTable.h" #include "compiler/translator/SymbolTable.h"
...@@ -87,6 +88,18 @@ TString Decorate(const TString &string) ...@@ -87,6 +88,18 @@ TString Decorate(const TString &string)
return string; return string;
} }
TString DecorateIfNeeded(const TName &name)
{
if (name.isInternal())
{
return name.getString();
}
else
{
return Decorate(name.getString());
}
}
TString TypeString(const TType &type) TString TypeString(const TType &type)
{ {
const TStructure* structure = type.getStruct(); const TStructure* structure = type.getStruct();
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
#include "angle_gl.h" #include "angle_gl.h"
class TName;
namespace sh namespace sh
{ {
...@@ -22,6 +24,7 @@ TString TextureString(const TType &type); ...@@ -22,6 +24,7 @@ TString TextureString(const TType &type);
TString SamplerString(const TType &type); 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 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