zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 1 | // |
Jamie Madill | 02f20dd | 2013-09-12 12:07:42 -0400 | [diff] [blame] | 2 | // Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved. |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +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_OUTPUTGLSLBASE_H_ |
| 8 | #define COMPILER_TRANSLATOR_OUTPUTGLSLBASE_H_ |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 9 | |
Jamie Madill | 01f85ac | 2014-06-06 11:55:04 -0400 | [diff] [blame] | 10 | #include <set> |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 11 | |
Jamie Madill | b1a85f4 | 2014-08-19 15:23:24 -0400 | [diff] [blame] | 12 | #include "compiler/translator/IntermNode.h" |
Zhenyao Mo | 550c600 | 2014-02-26 15:40:48 -0800 | [diff] [blame] | 13 | #include "compiler/translator/LoopInfo.h" |
Jamie Madill | 6b9cb25 | 2013-10-17 10:45:47 -0400 | [diff] [blame] | 14 | #include "compiler/translator/ParseContext.h" |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 15 | |
| 16 | class TOutputGLSLBase : public TIntermTraverser |
| 17 | { |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 18 | public: |
| 19 | TOutputGLSLBase(TInfoSinkBase &objSink, |
shannon.woods@transgaming.com | 1d432bb | 2013-01-25 21:57:28 +0000 | [diff] [blame] | 20 | ShArrayIndexClampingStrategy clampingStrategy, |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 21 | ShHashFunction64 hashFunction, |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 22 | NameMap &nameMap, |
Jamie Madill | 02f20dd | 2013-09-12 12:07:42 -0400 | [diff] [blame] | 23 | TSymbolTable& symbolTable, |
Zhenyao Mo | 05b6b7f | 2015-03-02 17:08:09 -0800 | [diff] [blame] | 24 | int shaderVersion, |
| 25 | ShShaderOutput output); |
| 26 | |
| 27 | ShShaderOutput getShaderOutput() const |
| 28 | { |
| 29 | return mOutput; |
| 30 | } |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 31 | |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 32 | protected: |
| 33 | TInfoSinkBase &objSink() { return mObjSink; } |
| 34 | void writeTriplet(Visit visit, const char *preStr, const char *inStr, const char *postStr); |
Olli Etuaho | ae69d7e | 2015-10-07 17:19:50 +0300 | [diff] [blame] | 35 | void writeLayoutQualifier(const TType &type); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 36 | void writeVariableType(const TType &type); |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 37 | virtual bool writeVariablePrecision(TPrecision precision) = 0; |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 38 | void writeFunctionParameters(const TIntermSequence &args); |
Jamie Madill | 6ba6ead | 2015-05-04 14:21:21 -0400 | [diff] [blame] | 39 | const TConstantUnion *writeConstantUnion(const TType &type, const TConstantUnion *pConstUnion); |
Olli Etuaho | e92507b | 2016-07-04 11:20:10 +0300 | [diff] [blame] | 40 | void writeConstructorTriplet(Visit visit, const TType &type); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 41 | TString getTypeName(const TType &type); |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 42 | |
Corentin Wallez | e5a1f27 | 2015-08-21 02:58:25 +0200 | [diff] [blame] | 43 | void visitSymbol(TIntermSymbol *node) override; |
| 44 | void visitConstantUnion(TIntermConstantUnion *node) override; |
Olli Etuaho | b6fa043 | 2016-09-28 16:28:05 +0100 | [diff] [blame] | 45 | bool visitSwizzle(Visit visit, TIntermSwizzle *node) override; |
Corentin Wallez | e5a1f27 | 2015-08-21 02:58:25 +0200 | [diff] [blame] | 46 | bool visitBinary(Visit visit, TIntermBinary *node) override; |
| 47 | bool visitUnary(Visit visit, TIntermUnary *node) override; |
Olli Etuaho | d0bad2c | 2016-09-09 18:01:16 +0300 | [diff] [blame] | 48 | bool visitTernary(Visit visit, TIntermTernary *node) override; |
Olli Etuaho | 5796127 | 2016-09-14 13:57:46 +0300 | [diff] [blame] | 49 | bool visitIfElse(Visit visit, TIntermIfElse *node) override; |
Corentin Wallez | e5a1f27 | 2015-08-21 02:58:25 +0200 | [diff] [blame] | 50 | bool visitSwitch(Visit visit, TIntermSwitch *node) override; |
| 51 | bool visitCase(Visit visit, TIntermCase *node) override; |
Olli Etuaho | 336b147 | 2016-10-05 16:37:55 +0100 | [diff] [blame^] | 52 | bool visitFunctionDefinition(Visit visit, TIntermFunctionDefinition *node) override; |
Corentin Wallez | e5a1f27 | 2015-08-21 02:58:25 +0200 | [diff] [blame] | 53 | bool visitAggregate(Visit visit, TIntermAggregate *node) override; |
Olli Etuaho | 6d40bbd | 2016-09-30 13:49:38 +0100 | [diff] [blame] | 54 | bool visitBlock(Visit visit, TIntermBlock *node) override; |
Corentin Wallez | e5a1f27 | 2015-08-21 02:58:25 +0200 | [diff] [blame] | 55 | bool visitLoop(Visit visit, TIntermLoop *node) override; |
| 56 | bool visitBranch(Visit visit, TIntermBranch *node) override; |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 57 | |
Olli Etuaho | 6d40bbd | 2016-09-30 13:49:38 +0100 | [diff] [blame] | 58 | void visitCodeBlock(TIntermBlock *node); |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 59 | |
| 60 | // Return the original name if hash function pointer is NULL; |
| 61 | // otherwise return the hashed name. |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 62 | TString hashName(const TString &name); |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 63 | // Same as hashName(), but without hashing built-in variables. |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 64 | TString hashVariableName(const TString &name); |
Olli Etuaho | 59f9a64 | 2015-08-06 20:38:26 +0300 | [diff] [blame] | 65 | // Same as hashName(), but without hashing built-in functions and with unmangling. |
| 66 | TString hashFunctionNameIfNeeded(const TName &mangledName); |
Nicolas Capens | 4648508 | 2014-04-15 13:12:50 -0400 | [diff] [blame] | 67 | // Used to translate function names for differences between ESSL and GLSL |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 68 | virtual TString translateTextureFunction(TString &name) { return name; } |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 69 | |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 70 | private: |
| 71 | bool structDeclared(const TStructure *structure) const; |
| 72 | void declareStruct(const TStructure *structure); |
Jamie Madill | 98493dd | 2013-07-08 14:39:03 -0400 | [diff] [blame] | 73 | |
Geoff Lang | bdcc54a | 2015-09-02 13:09:48 -0400 | [diff] [blame] | 74 | void declareInterfaceBlockLayout(const TInterfaceBlock *interfaceBlock); |
| 75 | void declareInterfaceBlock(const TInterfaceBlock *interfaceBlock); |
| 76 | |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 77 | void writeBuiltInFunctionTriplet(Visit visit, const char *preStr, bool useEmulatedFunction); |
| 78 | |
| 79 | TInfoSinkBase &mObjSink; |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 80 | bool mDeclaringVariables; |
| 81 | |
Jamie Madill | 01f85ac | 2014-06-06 11:55:04 -0400 | [diff] [blame] | 82 | // This set contains all the ids of the structs from every scope. |
| 83 | std::set<int> mDeclaredStructs; |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 84 | |
Zhenyao Mo | 550c600 | 2014-02-26 15:40:48 -0800 | [diff] [blame] | 85 | // Stack of loops that need to be unrolled. |
| 86 | TLoopStack mLoopUnrollStack; |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 87 | |
shannon.woods@transgaming.com | 1d432bb | 2013-01-25 21:57:28 +0000 | [diff] [blame] | 88 | ShArrayIndexClampingStrategy mClampingStrategy; |
| 89 | |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 90 | // name hashing. |
| 91 | ShHashFunction64 mHashFunction; |
shannon.woods@transgaming.com | 1d432bb | 2013-01-25 21:57:28 +0000 | [diff] [blame] | 92 | |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 93 | NameMap &mNameMap; |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 94 | |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 95 | TSymbolTable &mSymbolTable; |
Jamie Madill | 02f20dd | 2013-09-12 12:07:42 -0400 | [diff] [blame] | 96 | |
| 97 | const int mShaderVersion; |
Zhenyao Mo | 05b6b7f | 2015-03-02 17:08:09 -0800 | [diff] [blame] | 98 | |
| 99 | ShShaderOutput mOutput; |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 100 | }; |
| 101 | |
Geoff Lang | 0a73dd8 | 2014-11-19 16:18:08 -0500 | [diff] [blame] | 102 | #endif // COMPILER_TRANSLATOR_OUTPUTGLSLBASE_H_ |