Commit bbd9d4c6 by Olli Etuaho Committed by Commit Bot

Use TVariable instead of TIntermSymbol for variables

This removes unnecessary indirection. It's easier to just create TVariables in createSamplerSymbols, and to track referenced variables using TVariable pointers instead of TIntermSymbol pointers. BUG=angleproject:2267 TEST=angle_unittests, angle_end2end_tests Change-Id: Id1e75e04da084eb9026f581f22070b27a45615ba Reviewed-on: https://chromium-review.googlesource.com/839442Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent 47c8ea3f
......@@ -408,8 +408,8 @@ void OutputHLSL::header(TInfoSinkBase &out,
for (const auto &varying : mReferencedVaryings)
{
const TType &type = varying.second->variable().getType();
const TString &name = varying.second->getName();
const TType &type = varying.second->getType();
const TString &name = varying.second->name();
// Program linking depends on this exact format
varyings += "static " + InterpolationString(type.getQualifier()) + " " + TypeString(type) +
......@@ -419,7 +419,7 @@ void OutputHLSL::header(TInfoSinkBase &out,
for (const auto &attribute : mReferencedAttributes)
{
const TType &type = attribute.second->getType();
const TString &name = attribute.second->getName();
const TString &name = attribute.second->name();
attributes += "static " + TypeString(type) + " " + Decorate(name) + ArrayString(type) +
" = " + initializer(type) + ";\n";
......@@ -491,7 +491,7 @@ void OutputHLSL::header(TInfoSinkBase &out,
{
for (const auto &outputVariable : mReferencedOutputVariables)
{
const TString &variableName = outputVariable.second->getName();
const TString &variableName = outputVariable.second->name();
const TType &variableType = outputVariable.second->getType();
out << "static " + TypeString(variableType) + " out_" + variableName +
......@@ -900,19 +900,19 @@ void OutputHLSL::visitSymbol(TIntermSymbol *node)
}
else
{
mReferencedUniforms[uniqueId.get()] = node;
mReferencedUniforms[uniqueId.get()] = &variable;
}
out << DecorateVariableIfNeeded(variable);
}
else if (qualifier == EvqAttribute || qualifier == EvqVertexIn)
{
mReferencedAttributes[uniqueId.get()] = node;
mReferencedAttributes[uniqueId.get()] = &variable;
out << Decorate(name);
}
else if (IsVarying(qualifier))
{
mReferencedVaryings[uniqueId.get()] = node;
mReferencedVaryings[uniqueId.get()] = &variable;
out << Decorate(name);
if (name == "ViewID_OVR")
{
......@@ -921,7 +921,7 @@ void OutputHLSL::visitSymbol(TIntermSymbol *node)
}
else if (qualifier == EvqFragmentOut)
{
mReferencedOutputVariables[uniqueId.get()] = node;
mReferencedOutputVariables[uniqueId.get()] = &variable;
out << "out_" << name;
}
else if (qualifier == EvqFragColor)
......@@ -1833,11 +1833,13 @@ bool OutputHLSL::visitDeclaration(Visit visit, TIntermDeclaration *node)
TIntermSymbol *symbol = declarator->getAsSymbolNode();
ASSERT(symbol); // Varying declarations can't have initializers.
if (symbol->variable().symbolType() != SymbolType::Empty)
const TVariable &variable = symbol->variable();
if (variable.symbolType() != SymbolType::Empty)
{
// Vertex outputs which are declared but not written to should still be declared to
// allow successful linking.
mReferencedVaryings[symbol->uniqueId().get()] = symbol;
mReferencedVaryings[symbol->uniqueId().get()] = &variable;
}
}
}
......@@ -1966,22 +1968,22 @@ bool OutputHLSL::visitAggregate(Visit visit, TIntermAggregate *node)
if (typedArg->getType().isStructureContainingSamplers())
{
const TType &argType = typedArg->getType();
TVector<TIntermSymbol *> samplerSymbols;
TVector<const TVariable *> samplerSymbols;
TString structName = samplerNamePrefixFromStruct(typedArg);
argType.createSamplerSymbols("angle_" + structName, "", &samplerSymbols,
nullptr, mSymbolTable);
for (const TIntermSymbol *sampler : samplerSymbols)
for (const TVariable *sampler : samplerSymbols)
{
if (mOutputType == SH_HLSL_4_0_FL9_3_OUTPUT)
{
out << ", texture_" << sampler->getName();
out << ", sampler_" << sampler->getName();
out << ", texture_" << sampler->name();
out << ", sampler_" << sampler->name();
}
else
{
// In case of HLSL 4.1+, this symbol is the sampler index, and in case
// of D3D9, it's the sampler variable.
out << ", " + sampler->getName();
out << ", " + sampler->name();
}
}
}
......@@ -2661,30 +2663,30 @@ TString OutputHLSL::argumentString(const TIntermSymbol *symbol)
if (type.isStructureContainingSamplers())
{
ASSERT(qualifier != EvqOut && qualifier != EvqInOut);
TVector<TIntermSymbol *> samplerSymbols;
TVector<const TVariable *> samplerSymbols;
type.createSamplerSymbols("angle" + nameStr, "", &samplerSymbols, nullptr, mSymbolTable);
for (const TIntermSymbol *sampler : samplerSymbols)
for (const TVariable *sampler : samplerSymbols)
{
const TType &samplerType = sampler->getType();
if (mOutputType == SH_HLSL_4_1_OUTPUT)
{
argString << ", const uint " << sampler->getName() << ArrayString(samplerType);
argString << ", const uint " << sampler->name() << ArrayString(samplerType);
}
else if (mOutputType == SH_HLSL_4_0_FL9_3_OUTPUT)
{
ASSERT(IsSampler(samplerType.getBasicType()));
argString << ", " << QualifierString(qualifier) << " "
<< TextureString(samplerType.getBasicType()) << " texture_"
<< sampler->getName() << ArrayString(samplerType) << ", "
<< sampler->name() << ArrayString(samplerType) << ", "
<< QualifierString(qualifier) << " "
<< SamplerString(samplerType.getBasicType()) << " sampler_"
<< sampler->getName() << ArrayString(samplerType);
<< sampler->name() << ArrayString(samplerType);
}
else
{
ASSERT(IsSampler(samplerType.getBasicType()));
argString << ", " << QualifierString(qualifier) << " " << TypeString(samplerType)
<< " " << sampler->getName() << ArrayString(samplerType);
<< " " << sampler->name() << ArrayString(samplerType);
}
}
}
......
......@@ -28,8 +28,9 @@ class ImageFunctionHLSL;
class UnfoldShortCircuit;
class UniformHLSL;
// Map from uniqueId to a symbol node.
// Maps from uniqueId to a symbol node or a variable.
typedef std::map<int, TIntermSymbol *> ReferencedSymbols;
typedef std::map<int, const TVariable *> ReferencedVariables;
class OutputHLSL : public TIntermTraverser
{
......@@ -155,7 +156,7 @@ class OutputHLSL : public TIntermTraverser
// TODO (jmadill): Just passing an InfoSink in function parameters would be simpler.
std::stack<TInfoSinkBase *> mInfoSinkStack;
ReferencedSymbols mReferencedUniforms;
ReferencedVariables mReferencedUniforms;
// Indexed by block id, not instance id. Stored nodes point to either the block instance in
// the case of an instanced block, or a member uniform in the case of a non-instanced block.
......@@ -163,9 +164,9 @@ class OutputHLSL : public TIntermTraverser
// blocks. It needs to know the instance name if any and link to the TInterfaceBlock object.
ReferencedSymbols mReferencedUniformBlocks;
ReferencedSymbols mReferencedAttributes;
ReferencedSymbols mReferencedVaryings;
ReferencedSymbols mReferencedOutputVariables;
ReferencedVariables mReferencedAttributes;
ReferencedVariables mReferencedVaryings;
ReferencedVariables mReferencedOutputVariables;
StructureHLSL *mStructureHLSL;
UniformHLSL *mUniformHLSL;
......
......@@ -76,8 +76,8 @@ TStructure::TStructure(TSymbolTable *symbolTable,
void TStructure::createSamplerSymbols(const TString &namePrefix,
const TString &apiNamePrefix,
TVector<TIntermSymbol *> *outputSymbols,
TMap<TIntermSymbol *, TString> *outputSymbolsToAPINames,
TVector<const TVariable *> *outputSymbols,
TMap<const TVariable *, TString> *outputSymbolsToAPINames,
TSymbolTable *symbolTable) const
{
ASSERT(containsSamplers());
......
......@@ -103,8 +103,8 @@ class TStructure : public TSymbol, public TFieldListCollection
void createSamplerSymbols(const TString &namePrefix,
const TString &apiNamePrefix,
TVector<TIntermSymbol *> *outputSymbols,
TMap<TIntermSymbol *, TString> *outputSymbolsToAPINames,
TVector<const TVariable *> *outputSymbols,
TMap<const TVariable *, TString> *outputSymbolsToAPINames,
TSymbolTable *symbolTable) const;
void setAtGlobalScope(bool atGlobalScope) { mAtGlobalScope = atGlobalScope; }
......
......@@ -776,8 +776,8 @@ void TType::invalidateMangledName()
void TType::createSamplerSymbols(const TString &namePrefix,
const TString &apiNamePrefix,
TVector<TIntermSymbol *> *outputSymbols,
TMap<TIntermSymbol *, TString> *outputSymbolsToAPINames,
TVector<const TVariable *> *outputSymbols,
TMap<const TVariable *, TString> *outputSymbolsToAPINames,
TSymbolTable *symbolTable) const
{
if (isStructureContainingSamplers())
......@@ -808,11 +808,10 @@ void TType::createSamplerSymbols(const TString &namePrefix,
ASSERT(IsSampler(type));
TVariable *variable = new TVariable(symbolTable, NewPoolTString(namePrefix.c_str()), *this,
SymbolType::AngleInternal);
TIntermSymbol *symbol = new TIntermSymbol(variable);
outputSymbols->push_back(symbol);
outputSymbols->push_back(variable);
if (outputSymbolsToAPINames)
{
(*outputSymbolsToAPINames)[symbol] = apiNamePrefix;
(*outputSymbolsToAPINames)[variable] = apiNamePrefix;
}
}
......
......@@ -22,6 +22,7 @@ class TType;
class TInterfaceBlock;
class TStructure;
class TSymbol;
class TVariable;
class TIntermSymbol;
class TSymbolTable;
......@@ -306,8 +307,8 @@ class TType
void createSamplerSymbols(const TString &namePrefix,
const TString &apiNamePrefix,
TVector<TIntermSymbol *> *outputSymbols,
TMap<TIntermSymbol *, TString> *outputSymbolsToAPINames,
TVector<const TVariable *> *outputSymbols,
TMap<const TVariable *, TString> *outputSymbolsToAPINames,
TSymbolTable *symbolTable) const;
// Initializes all lazily-initialized members.
......
......@@ -198,8 +198,8 @@ unsigned int UniformHLSL::assignSamplerInStructUniformRegister(const TType &type
void UniformHLSL::outputHLSLSamplerUniformGroup(
TInfoSinkBase &out,
const HLSLTextureGroup textureGroup,
const TVector<const TIntermSymbol *> &group,
const TMap<const TIntermSymbol *, TString> &samplerInStructSymbolsToAPINames,
const TVector<const TVariable *> &group,
const TMap<const TVariable *, TString> &samplerInStructSymbolsToAPINames,
unsigned int *groupTextureRegisterIndex)
{
if (group.empty())
......@@ -207,10 +207,10 @@ void UniformHLSL::outputHLSLSamplerUniformGroup(
return;
}
unsigned int groupRegisterCount = 0;
for (const TIntermSymbol *uniform : group)
for (const TVariable *uniform : group)
{
const TType &type = uniform->getType();
const TString &name = uniform->getName();
const TString &name = uniform->name();
unsigned int registerCount;
// The uniform might be just a regular sampler or one extracted from a struct.
......@@ -231,14 +231,14 @@ void UniformHLSL::outputHLSLSamplerUniformGroup(
if (type.isArray())
{
out << "static const uint " << DecorateVariableIfNeeded(uniform->variable())
<< ArrayString(type) << " = ";
out << "static const uint " << DecorateVariableIfNeeded(*uniform) << ArrayString(type)
<< " = ";
OutputSamplerIndexArrayInitializer(out, type, samplerArrayIndex);
out << ";\n";
}
else
{
out << "static const uint " << DecorateVariableIfNeeded(uniform->variable()) << " = "
out << "static const uint " << DecorateVariableIfNeeded(*uniform) << " = "
<< samplerArrayIndex << ";\n";
}
}
......@@ -340,7 +340,7 @@ void UniformHLSL::outputUniform(TInfoSinkBase &out,
void UniformHLSL::uniformsHeader(TInfoSinkBase &out,
ShShaderOutput outputType,
const ReferencedSymbols &referencedUniforms,
const ReferencedVariables &referencedUniforms,
TSymbolTable *symbolTable)
{
if (!referencedUniforms.empty())
......@@ -350,20 +350,19 @@ void UniformHLSL::uniformsHeader(TInfoSinkBase &out,
// In the case of HLSL 4, sampler uniforms need to be grouped by type before the code is
// written. They are grouped based on the combination of the HLSL texture type and
// HLSL sampler type, enumerated in HLSLTextureSamplerGroup.
TVector<TVector<const TIntermSymbol *>> groupedSamplerUniforms(HLSL_TEXTURE_MAX + 1);
TMap<const TIntermSymbol *, TString> samplerInStructSymbolsToAPINames;
TVector<const TIntermSymbol *> imageUniformsHLSL41Output;
TVector<TVector<const TVariable *>> groupedSamplerUniforms(HLSL_TEXTURE_MAX + 1);
TMap<const TVariable *, TString> samplerInStructSymbolsToAPINames;
TVector<const TVariable *> imageUniformsHLSL41Output;
for (auto &uniformIt : referencedUniforms)
{
// Output regular uniforms. Group sampler uniforms by type.
const TIntermSymbol &uniform = *uniformIt.second;
const TType &type = uniform.getType();
const TVariable &variable = uniform.variable();
const TVariable &variable = *uniformIt.second;
const TType &type = variable.getType();
if (outputType == SH_HLSL_4_1_OUTPUT && IsSampler(type.getBasicType()))
{
HLSLTextureGroup group = TextureGroup(type.getBasicType());
groupedSamplerUniforms[group].push_back(&uniform);
groupedSamplerUniforms[group].push_back(&variable);
}
else if (outputType == SH_HLSL_4_0_FL9_3_OUTPUT && IsSampler(type.getBasicType()))
{
......@@ -372,20 +371,19 @@ void UniformHLSL::uniformsHeader(TInfoSinkBase &out,
}
else if (outputType == SH_HLSL_4_1_OUTPUT && IsImage(type.getBasicType()))
{
imageUniformsHLSL41Output.push_back(&uniform);
imageUniformsHLSL41Output.push_back(&variable);
}
else
{
if (type.isStructureContainingSamplers())
{
TVector<TIntermSymbol *> samplerSymbols;
TMap<TIntermSymbol *, TString> symbolsToAPINames;
type.createSamplerSymbols("angle_" + uniform.getName(), uniform.getName(),
TVector<const TVariable *> samplerSymbols;
TMap<const TVariable *, TString> symbolsToAPINames;
type.createSamplerSymbols("angle_" + variable.name(), variable.name(),
&samplerSymbols, &symbolsToAPINames, symbolTable);
for (TIntermSymbol *sampler : samplerSymbols)
for (const TVariable *sampler : samplerSymbols)
{
const TType &samplerType = sampler->getType();
const TVariable &samplerVariable = sampler->variable();
if (outputType == SH_HLSL_4_1_OUTPUT)
{
......@@ -397,19 +395,18 @@ void UniformHLSL::uniformsHeader(TInfoSinkBase &out,
{
unsigned int registerIndex = assignSamplerInStructUniformRegister(
samplerType, symbolsToAPINames[sampler], nullptr);
outputHLSL4_0_FL9_3Sampler(out, samplerType, samplerVariable,
registerIndex);
outputHLSL4_0_FL9_3Sampler(out, samplerType, *sampler, registerIndex);
}
else
{
ASSERT(outputType == SH_HLSL_3_0_OUTPUT);
unsigned int registerIndex = assignSamplerInStructUniformRegister(
samplerType, symbolsToAPINames[sampler], nullptr);
outputUniform(out, samplerType, samplerVariable, registerIndex);
outputUniform(out, samplerType, *sampler, registerIndex);
}
}
}
unsigned int registerIndex = assignUniformRegister(type, uniform.getName(), nullptr);
unsigned int registerIndex = assignUniformRegister(type, variable.name(), nullptr);
outputUniform(out, type, variable, registerIndex);
}
}
......@@ -427,18 +424,17 @@ void UniformHLSL::uniformsHeader(TInfoSinkBase &out,
}
mSamplerCount = groupTextureRegisterIndex;
for (const TIntermSymbol *image : imageUniformsHLSL41Output)
for (const TVariable *image : imageUniformsHLSL41Output)
{
const TType &type = image->getType();
const TVariable &variable = image->variable();
unsigned int registerIndex = assignUniformRegister(type, image->getName(), nullptr);
unsigned int registerIndex = assignUniformRegister(type, image->name(), nullptr);
if (type.getMemoryQualifier().readonly)
{
outputHLSL4_1_FL11Texture(out, type, variable, registerIndex);
outputHLSL4_1_FL11Texture(out, type, *image, registerIndex);
}
else
{
outputHLSL4_1_FL11RWTexture(out, type, variable, registerIndex);
outputHLSL4_1_FL11RWTexture(out, type, *image, registerIndex);
}
}
}
......
......@@ -31,7 +31,7 @@ class UniformHLSL : angle::NonCopyable
void reserveUniformBlockRegisters(unsigned int registerCount);
void uniformsHeader(TInfoSinkBase &out,
ShShaderOutput outputType,
const ReferencedSymbols &referencedUniforms,
const ReferencedVariables &referencedUniforms,
TSymbolTable *symbolTable);
// Must be called after uniformsHeader
......@@ -89,8 +89,8 @@ class UniformHLSL : angle::NonCopyable
void outputHLSLSamplerUniformGroup(
TInfoSinkBase &out,
const HLSLTextureGroup textureGroup,
const TVector<const TIntermSymbol *> &group,
const TMap<const TIntermSymbol *, TString> &samplerInStructSymbolsToAPINames,
const TVector<const TVariable *> &group,
const TMap<const TVariable *, TString> &samplerInStructSymbolsToAPINames,
unsigned int *groupTextureRegisterIndex);
unsigned int mUniformRegister;
......
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