1 //
2 // Copyright (c) 2002-2011 The ANGLE Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5 //
6 
7 #ifndef COMPILER_TRANSLATOR_VARIABLEINFO_H_
8 #define COMPILER_TRANSLATOR_VARIABLEINFO_H_
9 
10 #include <GLSLANG/ShaderLang.h>
11 
12 #include "compiler/translator/ExtensionBehavior.h"
13 #include "compiler/translator/IntermNode.h"
14 
15 class TSymbolTable;
16 
17 namespace sh
18 {
19 
20 // Traverses intermediate tree to collect all attributes, uniforms, varyings.
21 class CollectVariables : public TIntermTraverser
22 {
23   public:
24     CollectVariables(std::vector<Attribute> *attribs,
25                      std::vector<OutputVariable> *outputVariables,
26                      std::vector<Uniform> *uniforms,
27                      std::vector<Varying> *varyings,
28                      std::vector<InterfaceBlock> *interfaceBlocks,
29                      ShHashFunction64 hashFunction,
30                      const TSymbolTable &symbolTable,
31                      const TExtensionBehavior &extensionBehavior);
32 
33     void visitSymbol(TIntermSymbol *symbol) override;
34     bool visitDeclaration(Visit, TIntermDeclaration *node) override;
35     bool visitBinary(Visit visit, TIntermBinary *binaryNode) override;
36 
37   private:
38     template <typename VarT>
39     void visitVariable(const TIntermSymbol *variable, std::vector<VarT> *infoList) const;
40 
41     template <typename VarT>
42     void visitInfoList(const TIntermSequence &sequence, std::vector<VarT> *infoList) const;
43 
44     std::vector<Attribute> *mAttribs;
45     std::vector<OutputVariable> *mOutputVariables;
46     std::vector<Uniform> *mUniforms;
47     std::vector<Varying> *mVaryings;
48     std::vector<InterfaceBlock> *mInterfaceBlocks;
49 
50     std::map<std::string, InterfaceBlockField *> mInterfaceBlockFields;
51 
52     bool mDepthRangeAdded;
53     bool mPointCoordAdded;
54     bool mFrontFacingAdded;
55     bool mFragCoordAdded;
56 
57     bool mInstanceIDAdded;
58     bool mVertexIDAdded;
59     bool mPositionAdded;
60     bool mPointSizeAdded;
61     bool mLastFragDataAdded;
62     bool mFragColorAdded;
63     bool mFragDataAdded;
64     bool mFragDepthEXTAdded;
65     bool mFragDepthAdded;
66     bool mSecondaryFragColorEXTAdded;
67     bool mSecondaryFragDataEXTAdded;
68 
69     ShHashFunction64 mHashFunction;
70 
71     const TSymbolTable &mSymbolTable;
72     const TExtensionBehavior &mExtensionBehavior;
73 };
74 
75 void ExpandVariable(const ShaderVariable &variable,
76                     const std::string &name,
77                     const std::string &mappedName,
78                     bool markStaticUse,
79                     std::vector<ShaderVariable> *expanded);
80 
81 // Expand struct uniforms to flattened lists of split variables
82 void ExpandUniforms(const std::vector<Uniform> &compact,
83                     std::vector<ShaderVariable> *expanded);
84 
85 }
86 
87 #endif  // COMPILER_TRANSLATOR_VARIABLEINFO_H_
88