daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
daniel@transgaming.com | 35342dc | 2012-02-28 02:01:22 +0000 | [diff] [blame] | 2 | // Copyright (c) 2002-2012 The ANGLE Project Authors. All rights reserved. |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 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 | |
alokp@chromium.org | 4e89d23 | 2010-05-14 19:37:21 +0000 | [diff] [blame] | 10 | #include <list> |
| 11 | #include <set> |
| 12 | |
daniel@transgaming.com | bbf56f7 | 2010-04-20 18:52:13 +0000 | [diff] [blame] | 13 | #include "compiler/intermediate.h" |
| 14 | #include "compiler/ParseHelper.h" |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 15 | |
| 16 | namespace sh |
| 17 | { |
daniel@transgaming.com | f8f8f36 | 2012-04-28 00:35:00 +0000 | [diff] [blame] | 18 | class UnfoldShortCircuit; |
daniel@transgaming.com | b587598 | 2010-04-15 20:44:53 +0000 | [diff] [blame] | 19 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 20 | class OutputHLSL : public TIntermTraverser |
| 21 | { |
| 22 | public: |
daniel@transgaming.com | b587598 | 2010-04-15 20:44:53 +0000 | [diff] [blame] | 23 | explicit OutputHLSL(TParseContext &context); |
| 24 | ~OutputHLSL(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 25 | |
daniel@transgaming.com | 950f993 | 2010-04-13 03:26:14 +0000 | [diff] [blame] | 26 | void output(); |
| 27 | |
daniel@transgaming.com | b587598 | 2010-04-15 20:44:53 +0000 | [diff] [blame] | 28 | TInfoSinkBase &getBodyStream(); |
| 29 | |
daniel@transgaming.com | a2a95e7 | 2010-05-20 19:17:55 +0000 | [diff] [blame] | 30 | TString typeString(const TType &type); |
daniel@transgaming.com | b587598 | 2010-04-15 20:44:53 +0000 | [diff] [blame] | 31 | static TString qualifierString(TQualifier qualifier); |
daniel@transgaming.com | b587598 | 2010-04-15 20:44:53 +0000 | [diff] [blame] | 32 | static TString arrayString(const TType &type); |
| 33 | static TString initializer(const TType &type); |
daniel@transgaming.com | c72c641 | 2011-09-20 16:09:17 +0000 | [diff] [blame] | 34 | static TString decorate(const TString &string); // Prepends an underscore to avoid naming clashes |
apatrick@chromium.org | 6575602 | 2012-01-17 21:45:38 +0000 | [diff] [blame] | 35 | static TString decorateUniform(const TString &string, const TType &type); |
daniel@transgaming.com | 2e793f0 | 2012-04-11 19:41:35 +0000 | [diff] [blame] | 36 | static TString decorateField(const TString &string, const TType &structure); |
daniel@transgaming.com | b587598 | 2010-04-15 20:44:53 +0000 | [diff] [blame] | 37 | |
daniel@transgaming.com | 950f993 | 2010-04-13 03:26:14 +0000 | [diff] [blame] | 38 | protected: |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 39 | void header(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 40 | |
daniel@transgaming.com | 950f993 | 2010-04-13 03:26:14 +0000 | [diff] [blame] | 41 | // Visit AST nodes and output their code to the body stream |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 42 | void visitSymbol(TIntermSymbol*); |
| 43 | void visitConstantUnion(TIntermConstantUnion*); |
| 44 | bool visitBinary(Visit visit, TIntermBinary*); |
| 45 | bool visitUnary(Visit visit, TIntermUnary*); |
| 46 | bool visitSelection(Visit visit, TIntermSelection*); |
| 47 | bool visitAggregate(Visit visit, TIntermAggregate*); |
| 48 | bool visitLoop(Visit visit, TIntermLoop*); |
| 49 | bool visitBranch(Visit visit, TIntermBranch*); |
| 50 | |
daniel@transgaming.com | 44fffee | 2012-04-28 00:34:20 +0000 | [diff] [blame] | 51 | void traverseStatements(TIntermNode *node); |
daniel@transgaming.com | b587598 | 2010-04-15 20:44:53 +0000 | [diff] [blame] | 52 | bool isSingleStatement(TIntermNode *node); |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 53 | bool handleExcessiveLoop(TIntermLoop *node); |
daniel@transgaming.com | 67de6d6 | 2010-04-29 03:35:30 +0000 | [diff] [blame] | 54 | void outputTriplet(Visit visit, const TString &preString, const TString &inString, const TString &postString); |
apatrick@chromium.org | 0f4cefe | 2011-01-26 19:30:57 +0000 | [diff] [blame] | 55 | void outputLineDirective(int line); |
daniel@transgaming.com | 005c739 | 2010-04-15 20:45:27 +0000 | [diff] [blame] | 56 | TString argumentString(const TIntermSymbol *symbol); |
daniel@transgaming.com | 0b6b834 | 2010-04-26 15:33:45 +0000 | [diff] [blame] | 57 | int vectorSize(const TType &type) const; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 58 | |
daniel@transgaming.com | 67de6d6 | 2010-04-29 03:35:30 +0000 | [diff] [blame] | 59 | void addConstructor(const TType &type, const TString &name, const TIntermSequence *parameters); |
daniel@transgaming.com | a54da4e | 2010-05-07 13:03:28 +0000 | [diff] [blame] | 60 | const ConstantUnion *writeConstantUnion(const TType &type, const ConstantUnion *constUnion); |
daniel@transgaming.com | 6369186 | 2010-04-29 03:32:42 +0000 | [diff] [blame] | 61 | |
daniel@transgaming.com | a2a95e7 | 2010-05-20 19:17:55 +0000 | [diff] [blame] | 62 | TString scopeString(unsigned int depthLimit); |
| 63 | TString scopedStruct(const TString &typeName); |
| 64 | TString structLookup(const TString &typeName); |
| 65 | |
daniel@transgaming.com | 950f993 | 2010-04-13 03:26:14 +0000 | [diff] [blame] | 66 | TParseContext &mContext; |
daniel@transgaming.com | f8f8f36 | 2012-04-28 00:35:00 +0000 | [diff] [blame] | 67 | UnfoldShortCircuit *mUnfoldShortCircuit; |
daniel@transgaming.com | f9ef107 | 2010-04-22 13:35:16 +0000 | [diff] [blame] | 68 | bool mInsideFunction; |
daniel@transgaming.com | 950f993 | 2010-04-13 03:26:14 +0000 | [diff] [blame] | 69 | |
| 70 | // Output streams |
| 71 | TInfoSinkBase mHeader; |
| 72 | TInfoSinkBase mBody; |
| 73 | TInfoSinkBase mFooter; |
daniel@transgaming.com | d91cfe7 | 2010-04-13 03:26:17 +0000 | [diff] [blame] | 74 | |
daniel@transgaming.com | 86f7c9d | 2010-04-20 18:52:06 +0000 | [diff] [blame] | 75 | std::set<std::string> mReferencedUniforms; |
| 76 | std::set<std::string> mReferencedAttributes; |
| 77 | std::set<std::string> mReferencedVaryings; |
| 78 | |
daniel@transgaming.com | d91cfe7 | 2010-04-13 03:26:17 +0000 | [diff] [blame] | 79 | // Parameters determining what goes in the header output |
daniel@transgaming.com | 5024cc4 | 2010-04-20 18:52:04 +0000 | [diff] [blame] | 80 | bool mUsesTexture2D; |
| 81 | bool mUsesTexture2D_bias; |
daniel@transgaming.com | 1579519 | 2011-05-11 15:36:20 +0000 | [diff] [blame] | 82 | bool mUsesTexture2DLod; |
daniel@transgaming.com | 5024cc4 | 2010-04-20 18:52:04 +0000 | [diff] [blame] | 83 | bool mUsesTexture2DProj; |
| 84 | bool mUsesTexture2DProj_bias; |
daniel@transgaming.com | 1579519 | 2011-05-11 15:36:20 +0000 | [diff] [blame] | 85 | bool mUsesTexture2DProjLod; |
daniel@transgaming.com | 5024cc4 | 2010-04-20 18:52:04 +0000 | [diff] [blame] | 86 | bool mUsesTextureCube; |
| 87 | bool mUsesTextureCube_bias; |
daniel@transgaming.com | 1579519 | 2011-05-11 15:36:20 +0000 | [diff] [blame] | 88 | bool mUsesTextureCubeLod; |
daniel@transgaming.com | a54f518 | 2012-05-31 01:20:16 +0000 | [diff] [blame] | 89 | bool mUsesTexture2DLod0; |
| 90 | bool mUsesTexture2DLod0_bias; |
| 91 | bool mUsesTexture2DProjLod0; |
| 92 | bool mUsesTexture2DProjLod0_bias; |
| 93 | bool mUsesTextureCubeLod0; |
| 94 | bool mUsesTextureCubeLod0_bias; |
daniel@transgaming.com | d7c9810 | 2010-05-14 17:30:48 +0000 | [diff] [blame] | 95 | bool mUsesDepthRange; |
daniel@transgaming.com | 4af7acc | 2010-05-14 17:30:53 +0000 | [diff] [blame] | 96 | bool mUsesFragCoord; |
| 97 | bool mUsesPointCoord; |
| 98 | bool mUsesFrontFacing; |
| 99 | bool mUsesPointSize; |
daniel@transgaming.com | d7c9810 | 2010-05-14 17:30:48 +0000 | [diff] [blame] | 100 | bool mUsesXor; |
| 101 | bool mUsesMod1; |
daniel@transgaming.com | 4229f59 | 2011-11-24 22:34:04 +0000 | [diff] [blame] | 102 | bool mUsesMod2v; |
| 103 | bool mUsesMod2f; |
| 104 | bool mUsesMod3v; |
| 105 | bool mUsesMod3f; |
| 106 | bool mUsesMod4v; |
| 107 | bool mUsesMod4f; |
daniel@transgaming.com | 0bbb031 | 2010-04-26 15:33:39 +0000 | [diff] [blame] | 108 | bool mUsesFaceforward1; |
| 109 | bool mUsesFaceforward2; |
| 110 | bool mUsesFaceforward3; |
| 111 | bool mUsesFaceforward4; |
daniel@transgaming.com | d91cfe7 | 2010-04-13 03:26:17 +0000 | [diff] [blame] | 112 | bool mUsesEqualMat2; |
| 113 | bool mUsesEqualMat3; |
| 114 | bool mUsesEqualMat4; |
| 115 | bool mUsesEqualVec2; |
| 116 | bool mUsesEqualVec3; |
| 117 | bool mUsesEqualVec4; |
| 118 | bool mUsesEqualIVec2; |
| 119 | bool mUsesEqualIVec3; |
| 120 | bool mUsesEqualIVec4; |
| 121 | bool mUsesEqualBVec2; |
| 122 | bool mUsesEqualBVec3; |
| 123 | bool mUsesEqualBVec4; |
daniel@transgaming.com | 35342dc | 2012-02-28 02:01:22 +0000 | [diff] [blame] | 124 | bool mUsesAtan2_1; |
| 125 | bool mUsesAtan2_2; |
| 126 | bool mUsesAtan2_3; |
| 127 | bool mUsesAtan2_4; |
daniel@transgaming.com | 005c739 | 2010-04-15 20:45:27 +0000 | [diff] [blame] | 128 | |
daniel@transgaming.com | a2a95e7 | 2010-05-20 19:17:55 +0000 | [diff] [blame] | 129 | typedef std::set<TString> Constructors; |
| 130 | Constructors mConstructors; |
daniel@transgaming.com | 6369186 | 2010-04-29 03:32:42 +0000 | [diff] [blame] | 131 | |
daniel@transgaming.com | a2a95e7 | 2010-05-20 19:17:55 +0000 | [diff] [blame] | 132 | typedef std::set<TString> StructNames; |
| 133 | StructNames mStructNames; |
daniel@transgaming.com | 6369186 | 2010-04-29 03:32:42 +0000 | [diff] [blame] | 134 | |
daniel@transgaming.com | a2a95e7 | 2010-05-20 19:17:55 +0000 | [diff] [blame] | 135 | typedef std::list<TString> StructDeclarations; |
| 136 | StructDeclarations mStructDeclarations; |
daniel@transgaming.com | 6369186 | 2010-04-29 03:32:42 +0000 | [diff] [blame] | 137 | |
daniel@transgaming.com | a2a95e7 | 2010-05-20 19:17:55 +0000 | [diff] [blame] | 138 | typedef std::vector<int> ScopeBracket; |
| 139 | ScopeBracket mScopeBracket; |
| 140 | unsigned int mScopeDepth; |
daniel@transgaming.com | 7a7003c | 2010-04-29 03:35:33 +0000 | [diff] [blame] | 141 | |
daniel@transgaming.com | b6ef8f1 | 2010-11-15 16:41:14 +0000 | [diff] [blame] | 142 | int mUniqueIndex; // For creating unique names |
daniel@transgaming.com | 89431aa | 2012-05-31 01:20:29 +0000 | [diff] [blame^] | 143 | |
| 144 | bool mContainsLoopDiscontinuity; |
| 145 | bool mOutputLod0Function; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 146 | }; |
| 147 | } |
| 148 | |
| 149 | #endif // COMPILER_OUTPUTHLSL_H_ |