Use the CollectVariables path on the HLSL translator.
This approach consolidates our two methods, and lets us reuse the
same code for both methods of variable collection.
BUG=angle:466
Change-Id: Ie92f76ff0b6d0d0dbfd211a234d0ab86290fa798
Reviewed-on: https://chromium-review.googlesource.com/213504
Tested-by: Jamie Madill <jmadill@chromium.org>
Reviewed-by: Nicolas Capens <capn@chromium.org>
diff --git a/src/compiler/translator/OutputHLSL.cpp b/src/compiler/translator/OutputHLSL.cpp
index defb34a..a5ea715 100644
--- a/src/compiler/translator/OutputHLSL.cpp
+++ b/src/compiler/translator/OutputHLSL.cpp
@@ -21,6 +21,7 @@
#include "compiler/translator/util.h"
#include "compiler/translator/UniformHLSL.h"
#include "compiler/translator/StructureHLSL.h"
+#include "compiler/translator/TranslatorHLSL.h"
#include <algorithm>
#include <cfloat>
@@ -29,18 +30,6 @@
namespace sh
{
-static sh::Attribute MakeAttributeFromType(const TType &type, const TString &name)
-{
- sh::Attribute attributeVar;
- attributeVar.type = GLVariableType(type);
- attributeVar.precision = GLVariablePrecision(type);
- attributeVar.name = name.c_str();
- attributeVar.arraySize = static_cast<unsigned int>(type.getArraySize());
- attributeVar.location = type.getLayoutQualifier().location;
-
- return attributeVar;
-}
-
TString OutputHLSL::TextureFunction::name() const
{
TString name = "gl_texture";
@@ -105,8 +94,10 @@
return false;
}
-OutputHLSL::OutputHLSL(TParseContext &context, const ShBuiltInResources& resources, ShShaderOutput outputType)
- : TIntermTraverser(true, true, true), mContext(context), mOutputType(outputType)
+OutputHLSL::OutputHLSL(TParseContext &context, TranslatorHLSL *parentTranslator)
+ : TIntermTraverser(true, true, true),
+ mContext(context),
+ mOutputType(parentTranslator->getOutputType())
{
mUnfoldShortCircuit = new UnfoldShortCircuit(context, this);
mInsideFunction = false;
@@ -138,6 +129,7 @@
mUsesDiscardRewriting = false;
mUsesNestedBreak = false;
+ const ShBuiltInResources &resources = parentTranslator->getResources();
mNumRenderTargets = resources.EXT_draw_buffers ? resources.MaxDrawBuffers : 1;
mUniqueIndex = 0;
@@ -150,7 +142,7 @@
mExcessiveLoopIndex = NULL;
mStructureHLSL = new StructureHLSL;
- mUniformHLSL = new UniformHLSL(mStructureHLSL, mOutputType);
+ mUniformHLSL = new UniformHLSL(mStructureHLSL, parentTranslator);
if (mOutputType == SH_HLSL9_OUTPUT)
{
@@ -224,31 +216,6 @@
return mBody;
}
-const std::vector<sh::Uniform> &OutputHLSL::getUniforms()
-{
- return mUniformHLSL->getUniforms();
-}
-
-const std::vector<sh::InterfaceBlock> &OutputHLSL::getInterfaceBlocks() const
-{
- return mUniformHLSL->getInterfaceBlocks();
-}
-
-const std::vector<sh::Attribute> &OutputHLSL::getOutputVariables() const
-{
- return mActiveOutputVariables;
-}
-
-const std::vector<sh::Attribute> &OutputHLSL::getAttributes() const
-{
- return mActiveAttributes;
-}
-
-const std::vector<sh::Varying> &OutputHLSL::getVaryings() const
-{
- return mActiveVaryings;
-}
-
const std::map<std::string, unsigned int> &OutputHLSL::getInterfaceBlockRegisterMap() const
{
return mUniformHLSL->getInterfaceBlockRegisterMap();
@@ -336,8 +303,6 @@
// Program linking depends on this exact format
varyings += "static " + InterpolationString(type.getQualifier()) + " " + TypeString(type) + " " +
Decorate(name) + ArrayString(type) + " = " + initializer(type) + ";\n";
-
- declareVaryingToList(type, type.getQualifier(), name, mActiveVaryings);
}
for (ReferencedSymbols::const_iterator attribute = mReferencedAttributes.begin(); attribute != mReferencedAttributes.end(); attribute++)
@@ -346,9 +311,6 @@
const TString &name = attribute->second->getSymbol();
attributes += "static " + TypeString(type) + " " + Decorate(name) + ArrayString(type) + " = " + initializer(type) + ";\n";
-
- sh::Attribute attributeVar = MakeAttributeFromType(type, name);
- mActiveAttributes.push_back(attributeVar);
}
out << mStructureHLSL->structsHeader();
@@ -384,9 +346,6 @@
out << "static " + TypeString(variableType) + " out_" + variableName + ArrayString(variableType) +
" = " + initializer(variableType) + ";\n";
-
- sh::Attribute outputVar = MakeAttributeFromType(variableType, variableName);
- mActiveOutputVariables.push_back(outputVar);
}
}
else
@@ -2922,12 +2881,4 @@
return constUnion;
}
-void OutputHLSL::declareVaryingToList(const TType &type, TQualifier baseTypeQualifier,
- const TString &name, std::vector<Varying> &fieldsOut)
-{
- GetVariableTraverser traverser;
- traverser.traverse(type, name, &fieldsOut);
- fieldsOut.back().interpolation = GetInterpolationType(baseTypeQualifier);
-}
-
}