Consolidate shader variable storage in Compiler.
The Compiler base class now stores all the shader variables and
interface block information, instead of duplicating the information
in the HLSL translator.
BUG=angle:466
Change-Id: Ia69079fde64fbd6b0cbfc66defd5e37d99ee3e6e
Reviewed-on: https://chromium-review.googlesource.com/206020
Reviewed-by: Zhenyao Mo <zmo@chromium.org>
Reviewed-by: Nicolas Capens <capn@chromium.org>
Tested-by: Jamie Madill <jmadill@chromium.org>
diff --git a/src/compiler/translator/Compiler.cpp b/src/compiler/translator/Compiler.cpp
index 4402298..383beca 100644
--- a/src/compiler/translator/Compiler.cpp
+++ b/src/compiler/translator/Compiler.cpp
@@ -357,9 +357,11 @@
infoSink.obj.erase();
infoSink.debug.erase();
- attribs.clear();
+ attributes.clear();
+ outputVariables.clear();
uniforms.clear();
varyings.clear();
+ interfaceBlocks.clear();
builtInFunctionEmulator.Cleanup();
@@ -483,7 +485,7 @@
void TCompiler::collectVariables(TIntermNode* root)
{
- CollectVariables collect(&attribs, &uniforms, &varyings, hashFunction);
+ CollectVariables collect(&attributes, &uniforms, &varyings, hashFunction);
root->traverse(&collect);
}
diff --git a/src/compiler/translator/Compiler.h b/src/compiler/translator/Compiler.h
index 340714d..66c9563 100644
--- a/src/compiler/translator/Compiler.h
+++ b/src/compiler/translator/Compiler.h
@@ -67,9 +67,12 @@
// Get results of the last compilation.
int getShaderVersion() const { return shaderVersion; }
TInfoSink& getInfoSink() { return infoSink; }
- const std::vector<sh::Attribute> &getAttribs() const { return attribs; }
+
+ const std::vector<sh::Attribute> &getAttributes() const { return attributes; }
+ const std::vector<sh::Attribute> &getOutputVariables() const { return outputVariables; }
const std::vector<sh::Uniform> &getUniforms() const { return uniforms; }
const std::vector<sh::Varying> &getVaryings() const { return varyings; }
+ const std::vector<sh::InterfaceBlock> &getInterfaceBlocks() const { return interfaceBlocks; }
ShHashFunction64 getHashFunction() const { return hashFunction; }
NameMap& getNameMap() { return nameMap; }
@@ -130,6 +133,12 @@
ShArrayIndexClampingStrategy getArrayIndexClampingStrategy() const;
const BuiltInFunctionEmulator& getBuiltInFunctionEmulator() const;
+ std::vector<sh::Attribute> attributes;
+ std::vector<sh::Attribute> outputVariables;
+ std::vector<sh::Uniform> uniforms;
+ std::vector<sh::Varying> varyings;
+ std::vector<sh::InterfaceBlock> interfaceBlocks;
+
private:
sh::GLenum shaderType;
ShShaderSpec shaderSpec;
@@ -156,9 +165,6 @@
// Results of compilation.
int shaderVersion;
TInfoSink infoSink; // Output sink.
- std::vector<sh::Attribute> attribs; // Active attributes in the compiled shader.
- std::vector<sh::Uniform> uniforms; // Active uniforms in the compiled shader.
- std::vector<sh::Varying> varyings; // Varyings in the compiled shader.
// name hashing.
ShHashFunction64 hashFunction;
diff --git a/src/compiler/translator/ShaderLang.cpp b/src/compiler/translator/ShaderLang.cpp
index ecce06c..bc8d033 100644
--- a/src/compiler/translator/ShaderLang.cpp
+++ b/src/compiler/translator/ShaderLang.cpp
@@ -62,7 +62,7 @@
switch (varType)
{
case SH_ACTIVE_ATTRIBUTES:
- return ReturnVariable(compiler->getAttribs(), index);
+ return ReturnVariable(compiler->getAttributes(), index);
case SH_ACTIVE_UNIFORMS:
return ReturnVariable(compiler->getUniforms(), index);
case SH_VARYINGS:
@@ -257,7 +257,7 @@
*params = 1 + GetGlobalMaxTokenSize(compiler->getShaderSpec());
break;
case SH_ACTIVE_ATTRIBUTES:
- *params = compiler->getAttribs().size();
+ *params = compiler->getAttributes().size();
break;
case SH_ACTIVE_ATTRIBUTE_MAX_LENGTH:
*params = 1 + GetGlobalMaxTokenSize(compiler->getShaderSpec());
diff --git a/src/compiler/translator/TranslatorHLSL.cpp b/src/compiler/translator/TranslatorHLSL.cpp
index b75725b..8f9c753 100644
--- a/src/compiler/translator/TranslatorHLSL.cpp
+++ b/src/compiler/translator/TranslatorHLSL.cpp
@@ -10,7 +10,7 @@
#include "compiler/translator/OutputHLSL.h"
TranslatorHLSL::TranslatorHLSL(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output)
- : TCompiler(type, spec, output)
+ : TCompiler(type, spec, output)
{
}
@@ -21,9 +21,9 @@
outputHLSL.output();
- mActiveUniforms = outputHLSL.getUniforms();
- mActiveInterfaceBlocks = outputHLSL.getInterfaceBlocks();
- mActiveOutputVariables = outputHLSL.getOutputVariables();
- mActiveAttributes = outputHLSL.getAttributes();
- mActiveVaryings = outputHLSL.getVaryings();
+ attributes = outputHLSL.getAttributes();
+ outputVariables = outputHLSL.getOutputVariables();
+ uniforms = outputHLSL.getUniforms();
+ varyings = outputHLSL.getVaryings();
+ interfaceBlocks = outputHLSL.getInterfaceBlocks();
}
diff --git a/src/compiler/translator/TranslatorHLSL.h b/src/compiler/translator/TranslatorHLSL.h
index f9e771f..788aa59 100644
--- a/src/compiler/translator/TranslatorHLSL.h
+++ b/src/compiler/translator/TranslatorHLSL.h
@@ -10,25 +10,14 @@
#include "compiler/translator/Compiler.h"
#include "common/shadervars.h"
-class TranslatorHLSL : public TCompiler {
-public:
+class TranslatorHLSL : public TCompiler
+{
+ public:
TranslatorHLSL(sh::GLenum type, ShShaderSpec spec, ShShaderOutput output);
-
virtual TranslatorHLSL *getAsTranslatorHLSL() { return this; }
- const std::vector<sh::Uniform> &getUniforms() { return mActiveUniforms; }
- const std::vector<sh::InterfaceBlock> &getInterfaceBlocks() const { return mActiveInterfaceBlocks; }
- const std::vector<sh::Attribute> &getOutputVariables() { return mActiveOutputVariables; }
- const std::vector<sh::Attribute> &getAttributes() { return mActiveAttributes; }
- const std::vector<sh::Varying> &getVaryings() { return mActiveVaryings; }
-protected:
+ protected:
virtual void translate(TIntermNode* root);
-
- std::vector<sh::Uniform> mActiveUniforms;
- std::vector<sh::InterfaceBlock> mActiveInterfaceBlocks;
- std::vector<sh::Attribute> mActiveOutputVariables;
- std::vector<sh::Attribute> mActiveAttributes;
- std::vector<sh::Varying> mActiveVaryings;
};
#endif // COMPILER_TRANSLATORHLSL_H_