Simplified uniform/varying/attribute output.

TRAC #22293 Signed-off-by: Daniel Koch Signed-off-by: Shannon Woods Author: Nicolas Capens git-svn-id: https://angleproject.googlecode.com/svn/branches/dx11proto@1620 736b8ea6-26fd-11df-bfd4-992fa37f6226
parent d0f82bc4
...@@ -135,54 +135,37 @@ void OutputHLSL::header() ...@@ -135,54 +135,37 @@ void OutputHLSL::header()
out << *constructor; out << *constructor;
} }
if (shaderType == SH_FRAGMENT_SHADER)
{
TString uniforms; TString uniforms;
TString varyings; TString varyings;
TString attributes;
TSymbolTableLevel *symbols = mContext.symbolTable.getGlobalLevel(); for (ReferencedSymbols::const_iterator uniform = mReferencedUniforms.begin(); uniform != mReferencedUniforms.end(); uniform++)
int semanticIndex = 0;
for (TSymbolTableLevel::const_iterator namedSymbol = symbols->begin(); namedSymbol != symbols->end(); namedSymbol++)
{
const TSymbol *symbol = (*namedSymbol).second;
const TString &name = symbol->getName();
if (symbol->isVariable())
{ {
const TVariable *variable = static_cast<const TVariable*>(symbol); const TType &type = uniform->second->getType();
const TType &type = variable->getType(); const TString &name = uniform->second->getSymbol();
TQualifier qualifier = type.getQualifier();
if (qualifier == EvqUniform)
{
if (mReferencedUniforms.find(name.c_str()) != mReferencedUniforms.end())
{
uniforms += "uniform " + typeString(type) + " " + decorateUniform(name, type) + arrayString(type) + ";\n"; uniforms += "uniform " + typeString(type) + " " + decorateUniform(name, type) + arrayString(type) + ";\n";
} }
}
else if (qualifier == EvqVaryingIn || qualifier == EvqInvariantVaryingIn) for (ReferencedSymbols::const_iterator varying = mReferencedVaryings.begin(); varying != mReferencedVaryings.end(); varying++)
{
if (mReferencedVaryings.find(name.c_str()) != mReferencedVaryings.end())
{ {
const TType &type = varying->second->getType();
const TString &name = varying->second->getSymbol();
// Program linking depends on this exact format // Program linking depends on this exact format
varyings += "static " + typeString(type) + " " + decorate(name) + arrayString(type) + " = " + initializer(type) + ";\n"; varyings += "static " + typeString(type) + " " + decorate(name) + arrayString(type) + " = " + initializer(type) + ";\n";
semanticIndex += type.isArray() ? type.getArraySize() : 1;
}
} }
else if (qualifier == EvqGlobal || qualifier == EvqTemporary)
{ for (ReferencedSymbols::const_iterator attribute = mReferencedAttributes.begin(); attribute != mReferencedAttributes.end(); attribute++)
// Globals are declared and intialized as an aggregate node
}
else if (qualifier == EvqConst)
{ {
// Constants are repeated as literals where used const TType &type = attribute->second->getType();
} const TString &name = attribute->second->getSymbol();
else UNREACHABLE();
} attributes += "static " + typeString(type) + " " + decorate(name) + arrayString(type) + " = " + initializer(type) + ";\n";
} }
if (shaderType == SH_FRAGMENT_SHADER)
{
out << "// Varyings\n"; out << "// Varyings\n";
out << varyings; out << varyings;
out << "\n" out << "\n"
...@@ -351,57 +334,6 @@ void OutputHLSL::header() ...@@ -351,57 +334,6 @@ void OutputHLSL::header()
} }
else // Vertex shader else // Vertex shader
{ {
TString uniforms;
TString attributes;
TString varyings;
TSymbolTableLevel *symbols = mContext.symbolTable.getGlobalLevel();
for (TSymbolTableLevel::const_iterator namedSymbol = symbols->begin(); namedSymbol != symbols->end(); namedSymbol++)
{
const TSymbol *symbol = (*namedSymbol).second;
const TString &name = symbol->getName();
if (symbol->isVariable())
{
const TVariable *variable = static_cast<const TVariable*>(symbol);
const TType &type = variable->getType();
TQualifier qualifier = type.getQualifier();
if (qualifier == EvqUniform)
{
if (mReferencedUniforms.find(name.c_str()) != mReferencedUniforms.end())
{
uniforms += "uniform " + typeString(type) + " " + decorateUniform(name, type) + arrayString(type) + ";\n";
}
}
else if (qualifier == EvqAttribute)
{
if (mReferencedAttributes.find(name.c_str()) != mReferencedAttributes.end())
{
attributes += "static " + typeString(type) + " " + decorate(name) + arrayString(type) + " = " + initializer(type) + ";\n";
}
}
else if (qualifier == EvqVaryingOut || qualifier == EvqInvariantVaryingOut)
{
if (mReferencedVaryings.find(name.c_str()) != mReferencedVaryings.end())
{
// Program linking depends on this exact format
varyings += "static " + typeString(type) + " " + decorate(name) + arrayString(type) + " = " + initializer(type) + ";\n";
}
}
else if (qualifier == EvqGlobal || qualifier == EvqTemporary)
{
// Globals are declared and intialized as an aggregate node
}
else if (qualifier == EvqConst)
{
// Constants are repeated as literals where used
}
else UNREACHABLE();
}
}
out << "// Attributes\n"; out << "// Attributes\n";
out << attributes; out << attributes;
out << "\n" out << "\n"
...@@ -846,17 +778,17 @@ void OutputHLSL::visitSymbol(TIntermSymbol *node) ...@@ -846,17 +778,17 @@ void OutputHLSL::visitSymbol(TIntermSymbol *node)
if (qualifier == EvqUniform) if (qualifier == EvqUniform)
{ {
mReferencedUniforms.insert(name.c_str()); mReferencedUniforms[name] = node;
out << decorateUniform(name, node->getType()); out << decorateUniform(name, node->getType());
} }
else if (qualifier == EvqAttribute) else if (qualifier == EvqAttribute)
{ {
mReferencedAttributes.insert(name.c_str()); mReferencedAttributes[name] = node;
out << decorate(name); out << decorate(name);
} }
else if (qualifier == EvqVaryingOut || qualifier == EvqInvariantVaryingOut || qualifier == EvqVaryingIn || qualifier == EvqInvariantVaryingIn) else if (qualifier == EvqVaryingOut || qualifier == EvqInvariantVaryingOut || qualifier == EvqVaryingIn || qualifier == EvqInvariantVaryingIn)
{ {
mReferencedVaryings.insert(name.c_str()); mReferencedVaryings[name] = node;
out << decorate(name); out << decorate(name);
} }
else else
......
...@@ -72,9 +72,10 @@ class OutputHLSL : public TIntermTraverser ...@@ -72,9 +72,10 @@ class OutputHLSL : public TIntermTraverser
TInfoSinkBase mBody; TInfoSinkBase mBody;
TInfoSinkBase mFooter; TInfoSinkBase mFooter;
std::set<std::string> mReferencedUniforms; typedef std::map<TString, TIntermSymbol*> ReferencedSymbols;
std::set<std::string> mReferencedAttributes; ReferencedSymbols mReferencedUniforms;
std::set<std::string> mReferencedVaryings; ReferencedSymbols mReferencedAttributes;
ReferencedSymbols mReferencedVaryings;
// Parameters determining what goes in the header output // Parameters determining what goes in the header output
bool mUsesTexture2D; bool mUsesTexture2D;
......
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