1 // 2 // Copyright (c) 2002-2010 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 13 #include "compiler/intermediate.h" 14 #include "compiler/ParseHelper.h" 15 16 namespace sh 17 { 18 class UnfoldSelect; 19 20 class OutputHLSL : public TIntermTraverser 21 { 22 public: 23 explicit OutputHLSL(TParseContext &context); 24 ~OutputHLSL(); 25 26 void output(); 27 28 TInfoSinkBase &getBodyStream(); 29 30 TString typeString(const TType &type); 31 static TString qualifierString(TQualifier qualifier); 32 static TString arrayString(const TType &type); 33 static TString initializer(const TType &type); 34 static TString decorate(const TString &string); // Prepend an underscore to avoid naming clashes 35 36 protected: 37 void header(); 38 39 // Visit AST nodes and output their code to the body stream 40 void visitSymbol(TIntermSymbol*); 41 void visitConstantUnion(TIntermConstantUnion*); 42 bool visitBinary(Visit visit, TIntermBinary*); 43 bool visitUnary(Visit visit, TIntermUnary*); 44 bool visitSelection(Visit visit, TIntermSelection*); 45 bool visitAggregate(Visit visit, TIntermAggregate*); 46 bool visitLoop(Visit visit, TIntermLoop*); 47 bool visitBranch(Visit visit, TIntermBranch*); 48 49 bool isSingleStatement(TIntermNode *node); 50 bool handleExcessiveLoop(TIntermLoop *node); 51 void outputTriplet(Visit visit, const TString &preString, const TString &inString, const TString &postString); 52 TString argumentString(const TIntermSymbol *symbol); 53 int vectorSize(const TType &type) const; 54 55 void addConstructor(const TType &type, const TString &name, const TIntermSequence *parameters); 56 const ConstantUnion *writeConstantUnion(const TType &type, const ConstantUnion *constUnion); 57 58 TString scopeString(unsigned int depthLimit); 59 TString scopedStruct(const TString &typeName); 60 TString structLookup(const TString &typeName); 61 62 TParseContext &mContext; 63 UnfoldSelect *mUnfoldSelect; 64 bool mInsideFunction; 65 66 // Output streams 67 TInfoSinkBase mHeader; 68 TInfoSinkBase mBody; 69 TInfoSinkBase mFooter; 70 71 std::set<std::string> mReferencedUniforms; 72 std::set<std::string> mReferencedAttributes; 73 std::set<std::string> mReferencedVaryings; 74 75 // Parameters determining what goes in the header output 76 bool mUsesTexture2D; 77 bool mUsesTexture2D_bias; 78 bool mUsesTexture2DProj; 79 bool mUsesTexture2DProj_bias; 80 bool mUsesTextureCube; 81 bool mUsesTextureCube_bias; 82 bool mUsesDepthRange; 83 bool mUsesFragCoord; 84 bool mUsesPointCoord; 85 bool mUsesFrontFacing; 86 bool mUsesPointSize; 87 bool mUsesXor; 88 bool mUsesMod1; 89 bool mUsesMod2; 90 bool mUsesMod3; 91 bool mUsesMod4; 92 bool mUsesFaceforward1; 93 bool mUsesFaceforward2; 94 bool mUsesFaceforward3; 95 bool mUsesFaceforward4; 96 bool mUsesEqualMat2; 97 bool mUsesEqualMat3; 98 bool mUsesEqualMat4; 99 bool mUsesEqualVec2; 100 bool mUsesEqualVec3; 101 bool mUsesEqualVec4; 102 bool mUsesEqualIVec2; 103 bool mUsesEqualIVec3; 104 bool mUsesEqualIVec4; 105 bool mUsesEqualBVec2; 106 bool mUsesEqualBVec3; 107 bool mUsesEqualBVec4; 108 bool mUsesAtan2; 109 110 typedef std::set<TString> Constructors; 111 Constructors mConstructors; 112 113 typedef std::set<TString> StructNames; 114 StructNames mStructNames; 115 116 typedef std::list<TString> StructDeclarations; 117 StructDeclarations mStructDeclarations; 118 119 typedef std::vector<int> ScopeBracket; 120 ScopeBracket mScopeBracket; 121 unsigned int mScopeDepth; 122 123 int mUniqueIndex; // For creating unique names 124 }; 125 } 126 127 #endif // COMPILER_OUTPUTHLSL_H_ 128