| |
1 // |
| |
2 // Copyright (c) 2002-2013 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_OUTPUTHLSL_H_ |
| |
8 #define COMPILER_OUTPUTHLSL_H_ |
| |
9 |
| |
10 #include <list> |
| |
11 #include <set> |
| |
12 #include <map> |
| |
13 |
| |
14 #define GL_APICALL |
| |
15 #include <GLES2/gl2.h> |
| |
16 |
| |
17 #include "compiler/intermediate.h" |
| |
18 #include "compiler/ParseHelper.h" |
| |
19 #include "compiler/CompilerUniform.h" |
| |
20 |
| |
21 namespace sh |
| |
22 { |
| |
23 class UnfoldShortCircuit; |
| |
24 |
| |
25 class OutputHLSL : public TIntermTraverser |
| |
26 { |
| |
27 public: |
| |
28 OutputHLSL(TParseContext &context, const ShBuiltInResources& resources, ShShaderOutput outputType); |
| |
29 ~OutputHLSL(); |
| |
30 |
| |
31 void output(); |
| |
32 |
| |
33 TInfoSinkBase &getBodyStream(); |
| |
34 const ActiveUniforms &getUniforms(); |
| |
35 |
| |
36 TString typeString(const TType &type); |
| |
37 TString textureString(const TType &type); |
| |
38 static TString qualifierString(TQualifier qualifier); |
| |
39 static TString arrayString(const TType &type); |
| |
40 static TString initializer(const TType &type); |
| |
41 static TString decorate(const TString &string); // Prepends an underscore to avoid naming clashes |
| |
42 static TString decorateUniform(const TString &string, const TType &type); |
| |
43 static TString decorateField(const TString &string, const TType &structure); |
| |
44 |
| |
45 protected: |
| |
46 void header(); |
| |
47 |
| |
48 // Visit AST nodes and output their code to the body stream |
| |
49 void visitSymbol(TIntermSymbol*); |
| |
50 void visitConstantUnion(TIntermConstantUnion*); |
| |
51 bool visitBinary(Visit visit, TIntermBinary*); |
| |
52 bool visitUnary(Visit visit, TIntermUnary*); |
| |
53 bool visitSelection(Visit visit, TIntermSelection*); |
| |
54 bool visitAggregate(Visit visit, TIntermAggregate*); |
| |
55 bool visitLoop(Visit visit, TIntermLoop*); |
| |
56 bool visitBranch(Visit visit, TIntermBranch*); |
| |
57 |
| |
58 void traverseStatements(TIntermNode *node); |
| |
59 bool isSingleStatement(TIntermNode *node); |
| |
60 bool handleExcessiveLoop(TIntermLoop *node); |
| |
61 void outputTriplet(Visit visit, const TString &preString, const TString &inString, const TString &postString); |
| |
62 void outputLineDirective(int line); |
| |
63 TString argumentString(const TIntermSymbol *symbol); |
| |
64 int vectorSize(const TType &type) const; |
| |
65 |
| |
66 void addConstructor(const TType &type, const TString &name, const TIntermSequence *parameters); |
| |
67 const ConstantUnion *writeConstantUnion(const TType &type, const ConstantUnion *constUnion); |
| |
68 |
| |
69 TString scopeString(unsigned int depthLimit); |
| |
70 TString scopedStruct(const TString &typeName); |
| |
71 TString structLookup(const TString &typeName); |
| |
72 |
| |
73 TParseContext &mContext; |
| |
74 const ShShaderOutput mOutputType; |
| |
75 UnfoldShortCircuit *mUnfoldShortCircuit; |
| |
76 bool mInsideFunction; |
| |
77 |
| |
78 // Output streams |
| |
79 TInfoSinkBase mHeader; |
| |
80 TInfoSinkBase mBody; |
| |
81 TInfoSinkBase mFooter; |
| |
82 |
| |
83 typedef std::map<TString, TIntermSymbol*> ReferencedSymbols; |
| |
84 ReferencedSymbols mReferencedUniforms; |
| |
85 ReferencedSymbols mReferencedAttributes; |
| |
86 ReferencedSymbols mReferencedVaryings; |
| |
87 |
| |
88 // Parameters determining what goes in the header output |
| |
89 bool mUsesTexture2D; |
| |
90 bool mUsesTexture2D_bias; |
| |
91 bool mUsesTexture2DLod; |
| |
92 bool mUsesTexture2DProj; |
| |
93 bool mUsesTexture2DProj_bias; |
| |
94 bool mUsesTexture2DProjLod; |
| |
95 bool mUsesTextureCube; |
| |
96 bool mUsesTextureCube_bias; |
| |
97 bool mUsesTextureCubeLod; |
| |
98 bool mUsesTexture2DLod0; |
| |
99 bool mUsesTexture2DLod0_bias; |
| |
100 bool mUsesTexture2DProjLod0; |
| |
101 bool mUsesTexture2DProjLod0_bias; |
| |
102 bool mUsesTextureCubeLod0; |
| |
103 bool mUsesTextureCubeLod0_bias; |
| |
104 bool mUsesFragColor; |
| |
105 bool mUsesFragData; |
| |
106 bool mUsesDepthRange; |
| |
107 bool mUsesFragCoord; |
| |
108 bool mUsesPointCoord; |
| |
109 bool mUsesFrontFacing; |
| |
110 bool mUsesPointSize; |
| |
111 bool mUsesFragDepth; |
| |
112 bool mUsesXor; |
| |
113 bool mUsesMod1; |
| |
114 bool mUsesMod2v; |
| |
115 bool mUsesMod2f; |
| |
116 bool mUsesMod3v; |
| |
117 bool mUsesMod3f; |
| |
118 bool mUsesMod4v; |
| |
119 bool mUsesMod4f; |
| |
120 bool mUsesFaceforward1; |
| |
121 bool mUsesFaceforward2; |
| |
122 bool mUsesFaceforward3; |
| |
123 bool mUsesFaceforward4; |
| |
124 bool mUsesAtan2_1; |
| |
125 bool mUsesAtan2_2; |
| |
126 bool mUsesAtan2_3; |
| |
127 bool mUsesAtan2_4; |
| |
128 |
| |
129 int mNumRenderTargets; |
| |
130 |
| |
131 typedef std::set<TString> Constructors; |
| |
132 Constructors mConstructors; |
| |
133 |
| |
134 typedef std::set<TString> StructNames; |
| |
135 StructNames mStructNames; |
| |
136 |
| |
137 typedef std::list<TString> StructDeclarations; |
| |
138 StructDeclarations mStructDeclarations; |
| |
139 |
| |
140 typedef std::vector<int> ScopeBracket; |
| |
141 ScopeBracket mScopeBracket; |
| |
142 unsigned int mScopeDepth; |
| |
143 |
| |
144 int mUniqueIndex; // For creating unique names |
| |
145 |
| |
146 bool mContainsLoopDiscontinuity; |
| |
147 bool mOutputLod0Function; |
| |
148 bool mInsideDiscontinuousLoop; |
| |
149 |
| |
150 TIntermSymbol *mExcessiveLoopIndex; |
| |
151 |
| |
152 int mUniformRegister; |
| |
153 int mSamplerRegister; |
| |
154 |
| |
155 TString registerString(TIntermSymbol *operand); |
| |
156 int samplerRegister(TIntermSymbol *sampler); |
| |
157 int uniformRegister(TIntermSymbol *uniform); |
| |
158 void declareUniform(const TType &type, const TString &name, int index); |
| |
159 static GLenum glVariableType(const TType &type); |
| |
160 static GLenum glVariablePrecision(const TType &type); |
| |
161 |
| |
162 ActiveUniforms mActiveUniforms; |
| |
163 }; |
| |
164 } |
| |
165 |
| |
166 #endif // COMPILER_OUTPUTHLSL_H_ |