Commit 19515019 by Olli Etuaho Committed by Commit Bot

Refactor CollectVariables

New helper functions are added for collecting built-in variables, and the traverser is encapsulated inside VariableInfo.cpp. The helper functions get data for built-in variables from the symbol table, so a duplicate copy of the data doesn't need to be maintained in CollectVariables any more. BUG=angleproject:2068 TEST=angle_unittests Change-Id: I42595d0da0e5d4fb634a3d92f38db1dd6dd9efab Reviewed-on: https://chromium-review.googlesource.com/549323Reviewed-by: 's avatarCorentin Wallez <cwallez@chromium.org> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Olli Etuaho <oetuaho@nvidia.com>
parent 0dc97810
...@@ -433,14 +433,24 @@ TIntermBlock *TCompiler::compileTreeImpl(const char *const shaderStrings[], ...@@ -433,14 +433,24 @@ TIntermBlock *TCompiler::compileTreeImpl(const char *const shaderStrings[],
if (success && shouldCollectVariables(compileOptions)) if (success && shouldCollectVariables(compileOptions))
{ {
collectVariables(root); ASSERT(!variablesCollected);
CollectVariables(root, &attributes, &outputVariables, &uniforms, &varyings,
&interfaceBlocks, hashFunction, symbolTable, shaderVersion,
extensionBehavior);
variablesCollected = true;
if (compileOptions & SH_USE_UNUSED_STANDARD_SHARED_BLOCKS) if (compileOptions & SH_USE_UNUSED_STANDARD_SHARED_BLOCKS)
{ {
useAllMembersInUnusedStandardAndSharedBlocks(root); useAllMembersInUnusedStandardAndSharedBlocks(root);
} }
if (compileOptions & SH_ENFORCE_PACKING_RESTRICTIONS) if (compileOptions & SH_ENFORCE_PACKING_RESTRICTIONS)
{ {
success = enforcePackingRestrictions(); std::vector<sh::ShaderVariable> expandedUniforms;
sh::ExpandUniforms(uniforms, &expandedUniforms);
VariablePacker packer;
// Returns true if, after applying the packing rules in the GLSL ES 1.00.17 spec
// Appendix A, section 7, the shader does not use too many uniforms.
success =
packer.CheckVariablesWithinPackingLimits(maxUniformVectors, expandedUniforms);
if (!success) if (!success)
{ {
mDiagnostics.globalError("too many uniforms"); mDiagnostics.globalError("too many uniforms");
...@@ -689,7 +699,6 @@ void TCompiler::clearResults() ...@@ -689,7 +699,6 @@ void TCompiler::clearResults()
attributes.clear(); attributes.clear();
outputVariables.clear(); outputVariables.clear();
uniforms.clear(); uniforms.clear();
expandedUniforms.clear();
varyings.clear(); varyings.clear();
interfaceBlocks.clear(); interfaceBlocks.clear();
variablesCollected = false; variablesCollected = false;
...@@ -887,21 +896,6 @@ bool TCompiler::limitExpressionComplexity(TIntermBlock *root) ...@@ -887,21 +896,6 @@ bool TCompiler::limitExpressionComplexity(TIntermBlock *root)
return true; return true;
} }
void TCompiler::collectVariables(TIntermNode *root)
{
if (!variablesCollected)
{
sh::CollectVariables collect(&attributes, &outputVariables, &uniforms, &varyings,
&interfaceBlocks, hashFunction, symbolTable,
extensionBehavior);
root->traverse(&collect);
// This is for enforcePackingRestriction().
sh::ExpandUniforms(uniforms, &expandedUniforms);
variablesCollected = true;
}
}
bool TCompiler::shouldCollectVariables(ShCompileOptions compileOptions) bool TCompiler::shouldCollectVariables(ShCompileOptions compileOptions)
{ {
return (compileOptions & SH_VARIABLES) != 0; return (compileOptions & SH_VARIABLES) != 0;
...@@ -912,12 +906,6 @@ bool TCompiler::wereVariablesCollected() const ...@@ -912,12 +906,6 @@ bool TCompiler::wereVariablesCollected() const
return variablesCollected; return variablesCollected;
} }
bool TCompiler::enforcePackingRestrictions()
{
VariablePacker packer;
return packer.CheckVariablesWithinPackingLimits(maxUniformVectors, expandedUniforms);
}
void TCompiler::initializeGLPosition(TIntermBlock *root) void TCompiler::initializeGLPosition(TIntermBlock *root)
{ {
InitVariableList list; InitVariableList list;
......
...@@ -138,9 +138,6 @@ class TCompiler : public TShHandleBase ...@@ -138,9 +138,6 @@ class TCompiler : public TShHandleBase
ShCompileOptions compileOptions){}; ShCompileOptions compileOptions){};
// Translate to object code. // Translate to object code.
virtual void translate(TIntermBlock *root, ShCompileOptions compileOptions) = 0; virtual void translate(TIntermBlock *root, ShCompileOptions compileOptions) = 0;
// Returns true if, after applying the packing rules in the GLSL 1.017 spec
// Appendix A, section 7, the shader does not use too many uniforms.
bool enforcePackingRestrictions();
// Insert statements to reference all members in unused uniform blocks with standard and shared // Insert statements to reference all members in unused uniform blocks with standard and shared
// layout. This is to work around a Mac driver that treats unused standard/shared // layout. This is to work around a Mac driver that treats unused standard/shared
// uniform blocks as inactive. // uniform blocks as inactive.
...@@ -176,7 +173,6 @@ class TCompiler : public TShHandleBase ...@@ -176,7 +173,6 @@ class TCompiler : public TShHandleBase
std::vector<sh::Attribute> attributes; std::vector<sh::Attribute> attributes;
std::vector<sh::OutputVariable> outputVariables; std::vector<sh::OutputVariable> outputVariables;
std::vector<sh::Uniform> uniforms; std::vector<sh::Uniform> uniforms;
std::vector<sh::ShaderVariable> expandedUniforms;
std::vector<sh::Varying> varyings; std::vector<sh::Varying> varyings;
std::vector<sh::InterfaceBlock> interfaceBlocks; std::vector<sh::InterfaceBlock> interfaceBlocks;
...@@ -189,9 +185,6 @@ class TCompiler : public TShHandleBase ...@@ -189,9 +185,6 @@ class TCompiler : public TShHandleBase
void initSamplerDefaultPrecision(TBasicType samplerType); void initSamplerDefaultPrecision(TBasicType samplerType);
// Collect info for all attribs, uniforms, varyings.
void collectVariables(TIntermNode *root);
bool variablesCollected; bool variablesCollected;
// Removes unused function declarations and prototypes from the AST // Removes unused function declarations and prototypes from the AST
......
...@@ -10,71 +10,23 @@ ...@@ -10,71 +10,23 @@
#include <GLSLANG/ShaderLang.h> #include <GLSLANG/ShaderLang.h>
#include "compiler/translator/ExtensionBehavior.h" #include "compiler/translator/ExtensionBehavior.h"
#include "compiler/translator/IntermNode.h"
class TSymbolTable;
namespace sh namespace sh
{ {
// Traverses intermediate tree to collect all attributes, uniforms, varyings. class TIntermBlock;
class CollectVariables : public TIntermTraverser class TSymbolTable;
{
public:
CollectVariables(std::vector<Attribute> *attribs,
std::vector<OutputVariable> *outputVariables,
std::vector<Uniform> *uniforms,
std::vector<Varying> *varyings,
std::vector<InterfaceBlock> *interfaceBlocks,
ShHashFunction64 hashFunction,
const TSymbolTable &symbolTable,
const TExtensionBehavior &extensionBehavior);
void visitSymbol(TIntermSymbol *symbol) override;
bool visitDeclaration(Visit, TIntermDeclaration *node) override;
bool visitBinary(Visit visit, TIntermBinary *binaryNode) override;
private:
void setCommonVariableProperties(const TType &type,
const TString &name,
ShaderVariable *variableOut) const;
Attribute recordAttribute(const TIntermSymbol &variable) const;
OutputVariable recordOutputVariable(const TIntermSymbol &variable) const;
Varying recordVarying(const TIntermSymbol &variable) const;
InterfaceBlock recordInterfaceBlock(const TIntermSymbol &variable) const;
Uniform recordUniform(const TIntermSymbol &variable) const;
std::vector<Attribute> *mAttribs;
std::vector<OutputVariable> *mOutputVariables;
std::vector<Uniform> *mUniforms;
std::vector<Varying> *mVaryings;
std::vector<InterfaceBlock> *mInterfaceBlocks;
std::map<std::string, InterfaceBlockField *> mInterfaceBlockFields;
bool mDepthRangeAdded;
bool mPointCoordAdded;
bool mFrontFacingAdded;
bool mFragCoordAdded;
bool mInstanceIDAdded;
bool mVertexIDAdded;
bool mPositionAdded;
bool mPointSizeAdded;
bool mLastFragDataAdded;
bool mFragColorAdded;
bool mFragDataAdded;
bool mFragDepthEXTAdded;
bool mFragDepthAdded;
bool mSecondaryFragColorEXTAdded;
bool mSecondaryFragDataEXTAdded;
ShHashFunction64 mHashFunction;
const TSymbolTable &mSymbolTable; void CollectVariables(TIntermBlock *root,
const TExtensionBehavior &mExtensionBehavior; std::vector<Attribute> *attributes,
}; std::vector<OutputVariable> *outputVariables,
std::vector<Uniform> *uniforms,
std::vector<Varying> *varyings,
std::vector<InterfaceBlock> *interfaceBlocks,
ShHashFunction64 hashFunction,
const TSymbolTable &symbolTable,
int shaderVersion,
const TExtensionBehavior &extensionBehavior);
void ExpandVariable(const ShaderVariable &variable, void ExpandVariable(const ShaderVariable &variable,
const std::string &name, const std::string &name,
......
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