daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 1 | // |
Nicolas Capens | b1f45b7 | 2013-12-19 17:37:19 -0500 | [diff] [blame] | 2 | // Copyright (c) 2002-2014 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 | |
Geoff Lang | 0a73dd8 | 2014-11-19 16:18:08 -0500 | [diff] [blame] | 7 | #ifndef COMPILER_TRANSLATOR_OUTPUTHLSL_H_ |
| 8 | #define COMPILER_TRANSLATOR_OUTPUTHLSL_H_ |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 9 | |
alokp@chromium.org | 4e89d23 | 2010-05-14 19:37:21 +0000 | [diff] [blame] | 10 | #include <list> |
| 11 | #include <set> |
daniel@transgaming.com | 652468c | 2012-12-20 21:11:57 +0000 | [diff] [blame] | 12 | #include <map> |
Jamie Madill | 32aab01 | 2015-01-27 14:12:26 -0500 | [diff] [blame^] | 13 | #include <stack> |
daniel@transgaming.com | 652468c | 2012-12-20 21:11:57 +0000 | [diff] [blame] | 14 | |
Jamie Madill | f51639a | 2014-06-25 16:04:57 -0400 | [diff] [blame] | 15 | #include "angle_gl.h" |
Jamie Madill | b1a85f4 | 2014-08-19 15:23:24 -0400 | [diff] [blame] | 16 | #include "compiler/translator/IntermNode.h" |
Jamie Madill | 6b9cb25 | 2013-10-17 10:45:47 -0400 | [diff] [blame] | 17 | #include "compiler/translator/ParseContext.h" |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 18 | |
Olli Etuaho | e17e319 | 2015-01-02 12:47:59 +0200 | [diff] [blame] | 19 | class BuiltInFunctionEmulatorHLSL; |
| 20 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 21 | namespace sh |
| 22 | { |
daniel@transgaming.com | f8f8f36 | 2012-04-28 00:35:00 +0000 | [diff] [blame] | 23 | class UnfoldShortCircuit; |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 24 | class StructureHLSL; |
Jamie Madill | f91ce81 | 2014-06-13 10:04:34 -0400 | [diff] [blame] | 25 | class UniformHLSL; |
| 26 | |
| 27 | typedef std::map<TString, TIntermSymbol*> ReferencedSymbols; |
daniel@transgaming.com | b587598 | 2010-04-15 20:44:53 +0000 | [diff] [blame] | 28 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 29 | class OutputHLSL : public TIntermTraverser |
| 30 | { |
| 31 | public: |
Jamie Madill | 54ad4f8 | 2014-09-03 09:40:46 -0400 | [diff] [blame] | 32 | OutputHLSL(TParseContext &context, TranslatorHLSL *parentTranslator); |
daniel@transgaming.com | b587598 | 2010-04-15 20:44:53 +0000 | [diff] [blame] | 33 | ~OutputHLSL(); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 34 | |
daniel@transgaming.com | 950f993 | 2010-04-13 03:26:14 +0000 | [diff] [blame] | 35 | void output(); |
| 36 | |
Jamie Madill | 4e1fd41 | 2014-07-10 17:50:10 -0400 | [diff] [blame] | 37 | const std::map<std::string, unsigned int> &getInterfaceBlockRegisterMap() const; |
Jamie Madill | 9fe25e9 | 2014-07-18 10:33:08 -0400 | [diff] [blame] | 38 | const std::map<std::string, unsigned int> &getUniformRegisterMap() const; |
Jamie Madill | 4e1fd41 | 2014-07-10 17:50:10 -0400 | [diff] [blame] | 39 | |
daniel@transgaming.com | b587598 | 2010-04-15 20:44:53 +0000 | [diff] [blame] | 40 | static TString initializer(const TType &type); |
daniel@transgaming.com | b587598 | 2010-04-15 20:44:53 +0000 | [diff] [blame] | 41 | |
Jamie Madill | 32aab01 | 2015-01-27 14:12:26 -0500 | [diff] [blame^] | 42 | TInfoSinkBase &getInfoSink() { ASSERT(!mInfoSinkStack.empty()); return *mInfoSinkStack.top(); } |
| 43 | |
daniel@transgaming.com | 950f993 | 2010-04-13 03:26:14 +0000 | [diff] [blame] | 44 | protected: |
Olli Etuaho | e17e319 | 2015-01-02 12:47:59 +0200 | [diff] [blame] | 45 | void header(const BuiltInFunctionEmulatorHLSL *builtInFunctionEmulator); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 46 | |
daniel@transgaming.com | 950f993 | 2010-04-13 03:26:14 +0000 | [diff] [blame] | 47 | // Visit AST nodes and output their code to the body stream |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 48 | void visitSymbol(TIntermSymbol*); |
Jamie Madill | 4cfb1e8 | 2014-07-07 12:49:23 -0400 | [diff] [blame] | 49 | void visitRaw(TIntermRaw*); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 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 | |
daniel@transgaming.com | 44fffee | 2012-04-28 00:34:20 +0000 | [diff] [blame] | 58 | void traverseStatements(TIntermNode *node); |
daniel@transgaming.com | b587598 | 2010-04-15 20:44:53 +0000 | [diff] [blame] | 59 | bool isSingleStatement(TIntermNode *node); |
daniel@transgaming.com | 4a35ef2 | 2010-04-08 03:51:06 +0000 | [diff] [blame] | 60 | bool handleExcessiveLoop(TIntermLoop *node); |
daniel@transgaming.com | 67de6d6 | 2010-04-29 03:35:30 +0000 | [diff] [blame] | 61 | 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] | 62 | void outputLineDirective(int line); |
daniel@transgaming.com | 005c739 | 2010-04-15 20:45:27 +0000 | [diff] [blame] | 63 | TString argumentString(const TIntermSymbol *symbol); |
daniel@transgaming.com | 0b6b834 | 2010-04-26 15:33:45 +0000 | [diff] [blame] | 64 | int vectorSize(const TType &type) const; |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 65 | |
Nicolas Capens | 1af18dc | 2014-06-11 11:07:32 -0400 | [diff] [blame] | 66 | void outputConstructor(Visit visit, const TType &type, const TString &name, const TIntermSequence *parameters); |
daniel@transgaming.com | a54da4e | 2010-05-07 13:03:28 +0000 | [diff] [blame] | 67 | const ConstantUnion *writeConstantUnion(const TType &type, const ConstantUnion *constUnion); |
daniel@transgaming.com | 6369186 | 2010-04-29 03:32:42 +0000 | [diff] [blame] | 68 | |
Olli Etuaho | 5c9cd3d | 2014-12-18 13:04:25 +0200 | [diff] [blame] | 69 | void writeEmulatedFunctionTriplet(Visit visit, const char *preStr); |
| 70 | |
daniel@transgaming.com | 950f993 | 2010-04-13 03:26:14 +0000 | [diff] [blame] | 71 | TParseContext &mContext; |
shannon.woods@transgaming.com | b73964e | 2013-01-25 21:49:14 +0000 | [diff] [blame] | 72 | const ShShaderOutput mOutputType; |
daniel@transgaming.com | f8f8f36 | 2012-04-28 00:35:00 +0000 | [diff] [blame] | 73 | UnfoldShortCircuit *mUnfoldShortCircuit; |
daniel@transgaming.com | f9ef107 | 2010-04-22 13:35:16 +0000 | [diff] [blame] | 74 | bool mInsideFunction; |
daniel@transgaming.com | 950f993 | 2010-04-13 03:26:14 +0000 | [diff] [blame] | 75 | |
| 76 | // Output streams |
| 77 | TInfoSinkBase mHeader; |
| 78 | TInfoSinkBase mBody; |
| 79 | TInfoSinkBase mFooter; |
daniel@transgaming.com | d91cfe7 | 2010-04-13 03:26:17 +0000 | [diff] [blame] | 80 | |
Jamie Madill | 32aab01 | 2015-01-27 14:12:26 -0500 | [diff] [blame^] | 81 | // A stack is useful when we want to traverse in the header, or in helper functions, but not always |
| 82 | // write to the body. Instead use an InfoSink stack to keep our current state intact. |
| 83 | std::stack<TInfoSinkBase *> mInfoSinkStack; |
| 84 | |
daniel@transgaming.com | 8803b85 | 2012-12-20 21:11:47 +0000 | [diff] [blame] | 85 | ReferencedSymbols mReferencedUniforms; |
shannonwoods@chromium.org | 4a643ae | 2013-05-30 00:12:27 +0000 | [diff] [blame] | 86 | ReferencedSymbols mReferencedInterfaceBlocks; |
daniel@transgaming.com | 8803b85 | 2012-12-20 21:11:47 +0000 | [diff] [blame] | 87 | ReferencedSymbols mReferencedAttributes; |
| 88 | ReferencedSymbols mReferencedVaryings; |
Jamie Madill | 46131a3 | 2013-06-20 11:55:50 -0400 | [diff] [blame] | 89 | ReferencedSymbols mReferencedOutputVariables; |
daniel@transgaming.com | 86f7c9d | 2010-04-20 18:52:06 +0000 | [diff] [blame] | 90 | |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 91 | StructureHLSL *mStructureHLSL; |
Jamie Madill | f91ce81 | 2014-06-13 10:04:34 -0400 | [diff] [blame] | 92 | UniformHLSL *mUniformHLSL; |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 93 | |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 94 | struct TextureFunction |
| 95 | { |
Nicolas Capens | 75fb475 | 2013-07-10 15:14:47 -0400 | [diff] [blame] | 96 | enum Method |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 97 | { |
Nicolas Capens | 75fb475 | 2013-07-10 15:14:47 -0400 | [diff] [blame] | 98 | IMPLICIT, // Mipmap LOD determined implicitly (standard lookup) |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 99 | BIAS, |
| 100 | LOD, |
Nicolas Capens | 75fb475 | 2013-07-10 15:14:47 -0400 | [diff] [blame] | 101 | LOD0, |
Nicolas Capens | 84cfa12 | 2014-04-14 13:48:45 -0400 | [diff] [blame] | 102 | LOD0BIAS, |
Nicolas Capens | fc01454 | 2014-02-18 14:47:13 -0500 | [diff] [blame] | 103 | SIZE, // textureSize() |
Nicolas Capens | d11d549 | 2014-02-19 17:06:10 -0500 | [diff] [blame] | 104 | FETCH, |
| 105 | GRAD |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 106 | }; |
| 107 | |
| 108 | TBasicType sampler; |
| 109 | int coords; |
| 110 | bool proj; |
Nicolas Capens | b1f45b7 | 2013-12-19 17:37:19 -0500 | [diff] [blame] | 111 | bool offset; |
Nicolas Capens | 75fb475 | 2013-07-10 15:14:47 -0400 | [diff] [blame] | 112 | Method method; |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 113 | |
| 114 | TString name() const; |
| 115 | |
| 116 | bool operator<(const TextureFunction &rhs) const; |
| 117 | }; |
| 118 | |
| 119 | typedef std::set<TextureFunction> TextureFunctionSet; |
| 120 | |
daniel@transgaming.com | d91cfe7 | 2010-04-13 03:26:17 +0000 | [diff] [blame] | 121 | // Parameters determining what goes in the header output |
Nicolas Capens | e0ba27a | 2013-06-24 16:10:52 -0400 | [diff] [blame] | 122 | TextureFunctionSet mUsesTexture; |
shannon.woods%transgaming.com@gtempaccount.com | aa8b5cf | 2013-04-13 03:31:55 +0000 | [diff] [blame] | 123 | bool mUsesFragColor; |
| 124 | bool mUsesFragData; |
daniel@transgaming.com | d7c9810 | 2010-05-14 17:30:48 +0000 | [diff] [blame] | 125 | bool mUsesDepthRange; |
daniel@transgaming.com | 4af7acc | 2010-05-14 17:30:53 +0000 | [diff] [blame] | 126 | bool mUsesFragCoord; |
| 127 | bool mUsesPointCoord; |
| 128 | bool mUsesFrontFacing; |
| 129 | bool mUsesPointSize; |
Jamie Madill | 2aeb26a | 2013-07-08 14:02:55 -0400 | [diff] [blame] | 130 | bool mUsesFragDepth; |
daniel@transgaming.com | d7c9810 | 2010-05-14 17:30:48 +0000 | [diff] [blame] | 131 | bool mUsesXor; |
Jamie Madill | 3c9eeb9 | 2013-11-04 11:09:26 -0500 | [diff] [blame] | 132 | bool mUsesDiscardRewriting; |
Nicolas Capens | 655fe36 | 2014-04-11 13:12:34 -0400 | [diff] [blame] | 133 | bool mUsesNestedBreak; |
daniel@transgaming.com | 005c739 | 2010-04-15 20:45:27 +0000 | [diff] [blame] | 134 | |
shannon.woods%transgaming.com@gtempaccount.com | aa8b5cf | 2013-04-13 03:31:55 +0000 | [diff] [blame] | 135 | int mNumRenderTargets; |
| 136 | |
daniel@transgaming.com | b6ef8f1 | 2010-11-15 16:41:14 +0000 | [diff] [blame] | 137 | int mUniqueIndex; // For creating unique names |
daniel@transgaming.com | 89431aa | 2012-05-31 01:20:29 +0000 | [diff] [blame] | 138 | |
| 139 | bool mContainsLoopDiscontinuity; |
Corentin Wallez | 80bacde | 2014-11-10 12:07:37 -0800 | [diff] [blame] | 140 | bool mContainsAnyLoop; |
daniel@transgaming.com | 89431aa | 2012-05-31 01:20:29 +0000 | [diff] [blame] | 141 | bool mOutputLod0Function; |
daniel@transgaming.com | e11100c | 2012-05-31 01:20:32 +0000 | [diff] [blame] | 142 | bool mInsideDiscontinuousLoop; |
Nicolas Capens | 655fe36 | 2014-04-11 13:12:34 -0400 | [diff] [blame] | 143 | int mNestedLoopDepth; |
daniel@transgaming.com | e9b3f60 | 2012-07-11 20:37:31 +0000 | [diff] [blame] | 144 | |
| 145 | TIntermSymbol *mExcessiveLoopIndex; |
daniel@transgaming.com | 652468c | 2012-12-20 21:11:57 +0000 | [diff] [blame] | 146 | |
Jamie Madill | 98493dd | 2013-07-08 14:39:03 -0400 | [diff] [blame] | 147 | TString structInitializerString(int indent, const TStructure &structure, const TString &rhsStructName); |
daniel@transgaming.com | f4d9fef | 2012-12-20 21:12:13 +0000 | [diff] [blame] | 148 | |
Jamie Madill | 570e04d | 2013-06-21 09:15:33 -0400 | [diff] [blame] | 149 | std::map<TIntermTyped*, TString> mFlaggedStructMappedNames; |
| 150 | std::map<TIntermTyped*, TString> mFlaggedStructOriginalNames; |
| 151 | |
| 152 | void makeFlaggedStructMaps(const std::vector<TIntermTyped *> &flaggedStructs); |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 153 | }; |
Jamie Madill | 8daaba1 | 2014-06-13 10:04:33 -0400 | [diff] [blame] | 154 | |
daniel@transgaming.com | 4f39fd9 | 2010-03-08 20:26:45 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Geoff Lang | 0a73dd8 | 2014-11-19 16:18:08 -0500 | [diff] [blame] | 157 | #endif // COMPILER_TRANSLATOR_OUTPUTHLSL_H_ |