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 | |
Olli Etuaho | cccf2b0 | 2017-07-05 14:50:54 +0300 | [diff] [blame] | 12 | #include "compiler/translator/HashNames.h" |
| 13 | #include "compiler/translator/InfoSink.h" |
| 14 | #include "compiler/translator/IntermTraverse.h" |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 15 | |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame] | 16 | namespace sh |
| 17 | { |
| 18 | |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 19 | class TOutputGLSLBase : public TIntermTraverser |
| 20 | { |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 21 | public: |
| 22 | TOutputGLSLBase(TInfoSinkBase &objSink, |
shannon.woods@transgaming.com | 1d432bb | 2013-01-25 21:57:28 +0000 | [diff] [blame] | 23 | ShArrayIndexClampingStrategy clampingStrategy, |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 24 | ShHashFunction64 hashFunction, |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 25 | NameMap &nameMap, |
Olli Etuaho | a5e693a | 2017-07-13 16:07:26 +0300 | [diff] [blame] | 26 | TSymbolTable *symbolTable, |
Qiankun Miao | 89dd8f3 | 2016-11-09 12:59:30 +0000 | [diff] [blame] | 27 | sh::GLenum shaderType, |
Zhenyao Mo | 05b6b7f | 2015-03-02 17:08:09 -0800 | [diff] [blame] | 28 | int shaderVersion, |
Qiankun Miao | 705a919 | 2016-08-29 10:05:27 +0800 | [diff] [blame] | 29 | ShShaderOutput output, |
| 30 | ShCompileOptions compileOptions); |
Zhenyao Mo | 05b6b7f | 2015-03-02 17:08:09 -0800 | [diff] [blame] | 31 | |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 32 | ShShaderOutput getShaderOutput() const { return mOutput; } |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 33 | |
Olli Etuaho | 09b04a2 | 2016-12-15 13:30:26 +0000 | [diff] [blame] | 34 | // Return the original name if hash function pointer is NULL; |
| 35 | // otherwise return the hashed name. Has special handling for internal names, which are not |
| 36 | // hashed. |
| 37 | TString hashName(const TName &name); |
| 38 | |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 39 | protected: |
| 40 | TInfoSinkBase &objSink() { return mObjSink; } |
Olli Etuaho | 56a2f95 | 2016-12-08 12:16:27 +0000 | [diff] [blame] | 41 | void writeFloat(TInfoSinkBase &out, float f); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 42 | void writeTriplet(Visit visit, const char *preStr, const char *inStr, const char *postStr); |
Jamie Madill | 2a9e107 | 2017-09-22 11:31:57 -0400 | [diff] [blame] | 43 | virtual void writeLayoutQualifier(TIntermTyped *variable); |
Zhenyao Mo | b7bf742 | 2016-11-08 14:44:05 -0800 | [diff] [blame] | 44 | void writeInvariantQualifier(const TType &type); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 45 | void writeVariableType(const TType &type); |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 46 | virtual bool writeVariablePrecision(TPrecision precision) = 0; |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 47 | void writeFunctionParameters(const TIntermSequence &args); |
Jamie Madill | 6ba6ead | 2015-05-04 14:21:21 -0400 | [diff] [blame] | 48 | const TConstantUnion *writeConstantUnion(const TType &type, const TConstantUnion *pConstUnion); |
Olli Etuaho | e92507b | 2016-07-04 11:20:10 +0300 | [diff] [blame] | 49 | void writeConstructorTriplet(Visit visit, const TType &type); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 50 | TString getTypeName(const TType &type); |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 51 | |
Corentin Wallez | e5a1f27 | 2015-08-21 02:58:25 +0200 | [diff] [blame] | 52 | void visitSymbol(TIntermSymbol *node) override; |
| 53 | void visitConstantUnion(TIntermConstantUnion *node) override; |
Olli Etuaho | b6fa043 | 2016-09-28 16:28:05 +0100 | [diff] [blame] | 54 | bool visitSwizzle(Visit visit, TIntermSwizzle *node) override; |
Corentin Wallez | e5a1f27 | 2015-08-21 02:58:25 +0200 | [diff] [blame] | 55 | bool visitBinary(Visit visit, TIntermBinary *node) override; |
| 56 | bool visitUnary(Visit visit, TIntermUnary *node) override; |
Olli Etuaho | d0bad2c | 2016-09-09 18:01:16 +0300 | [diff] [blame] | 57 | bool visitTernary(Visit visit, TIntermTernary *node) override; |
Olli Etuaho | 5796127 | 2016-09-14 13:57:46 +0300 | [diff] [blame] | 58 | bool visitIfElse(Visit visit, TIntermIfElse *node) override; |
Corentin Wallez | e5a1f27 | 2015-08-21 02:58:25 +0200 | [diff] [blame] | 59 | bool visitSwitch(Visit visit, TIntermSwitch *node) override; |
| 60 | bool visitCase(Visit visit, TIntermCase *node) override; |
Olli Etuaho | 16c745a | 2017-01-16 17:02:27 +0000 | [diff] [blame] | 61 | bool visitFunctionPrototype(Visit visit, TIntermFunctionPrototype *node) override; |
Olli Etuaho | 336b147 | 2016-10-05 16:37:55 +0100 | [diff] [blame] | 62 | bool visitFunctionDefinition(Visit visit, TIntermFunctionDefinition *node) override; |
Corentin Wallez | e5a1f27 | 2015-08-21 02:58:25 +0200 | [diff] [blame] | 63 | bool visitAggregate(Visit visit, TIntermAggregate *node) override; |
Olli Etuaho | 6d40bbd | 2016-09-30 13:49:38 +0100 | [diff] [blame] | 64 | bool visitBlock(Visit visit, TIntermBlock *node) override; |
Olli Etuaho | bf4e1b7 | 2016-12-09 11:30:15 +0000 | [diff] [blame] | 65 | bool visitInvariantDeclaration(Visit visit, TIntermInvariantDeclaration *node) override; |
Olli Etuaho | 13389b6 | 2016-10-16 11:48:18 +0100 | [diff] [blame] | 66 | bool visitDeclaration(Visit visit, TIntermDeclaration *node) override; |
Corentin Wallez | e5a1f27 | 2015-08-21 02:58:25 +0200 | [diff] [blame] | 67 | bool visitLoop(Visit visit, TIntermLoop *node) override; |
| 68 | bool visitBranch(Visit visit, TIntermBranch *node) override; |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 69 | |
Olli Etuaho | 6d40bbd | 2016-09-30 13:49:38 +0100 | [diff] [blame] | 70 | void visitCodeBlock(TIntermBlock *node); |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 71 | |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 72 | // Same as hashName(), but without hashing built-in variables. |
Olli Etuaho | 0982a2b | 2016-11-01 15:13:46 +0000 | [diff] [blame] | 73 | TString hashVariableName(const TName &name); |
Olli Etuaho | ec9232b | 2017-03-27 17:01:37 +0300 | [diff] [blame] | 74 | // Same as hashName(), but without hashing internal functions or "main". |
| 75 | TString hashFunctionNameIfNeeded(const TFunctionSymbolInfo &info); |
Nicolas Capens | 4648508 | 2014-04-15 13:12:50 -0400 | [diff] [blame] | 76 | // Used to translate function names for differences between ESSL and GLSL |
Olli Etuaho | ec9232b | 2017-03-27 17:01:37 +0300 | [diff] [blame] | 77 | virtual TString translateTextureFunction(const TString &name) { return name; } |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 78 | |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 79 | private: |
| 80 | bool structDeclared(const TStructure *structure) const; |
| 81 | void declareStruct(const TStructure *structure); |
Jamie Madill | 98493dd | 2013-07-08 14:39:03 -0400 | [diff] [blame] | 82 | |
Geoff Lang | bdcc54a | 2015-09-02 13:09:48 -0400 | [diff] [blame] | 83 | void declareInterfaceBlockLayout(const TInterfaceBlock *interfaceBlock); |
| 84 | void declareInterfaceBlock(const TInterfaceBlock *interfaceBlock); |
| 85 | |
Olli Etuaho | e180559 | 2017-01-02 16:41:20 +0000 | [diff] [blame] | 86 | void writeBuiltInFunctionTriplet(Visit visit, TOperator op, bool useEmulatedFunction); |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 87 | |
Zhenyao Mo | b7bf742 | 2016-11-08 14:44:05 -0800 | [diff] [blame] | 88 | const char *mapQualifierToString(TQualifier qialifier); |
| 89 | |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 90 | TInfoSinkBase &mObjSink; |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 91 | bool mDeclaringVariables; |
| 92 | |
Jamie Madill | 01f85ac | 2014-06-06 11:55:04 -0400 | [diff] [blame] | 93 | // This set contains all the ids of the structs from every scope. |
| 94 | std::set<int> mDeclaredStructs; |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 95 | |
shannon.woods@transgaming.com | 1d432bb | 2013-01-25 21:57:28 +0000 | [diff] [blame] | 96 | ShArrayIndexClampingStrategy mClampingStrategy; |
| 97 | |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 98 | // name hashing. |
| 99 | ShHashFunction64 mHashFunction; |
shannon.woods@transgaming.com | 1d432bb | 2013-01-25 21:57:28 +0000 | [diff] [blame] | 100 | |
Zhenyao Mo | 9eedea0 | 2014-05-12 16:02:35 -0700 | [diff] [blame] | 101 | NameMap &mNameMap; |
daniel@transgaming.com | 0aa3b5a | 2012-11-28 19:43:24 +0000 | [diff] [blame] | 102 | |
Qiankun Miao | 89dd8f3 | 2016-11-09 12:59:30 +0000 | [diff] [blame] | 103 | sh::GLenum mShaderType; |
| 104 | |
Jamie Madill | 02f20dd | 2013-09-12 12:07:42 -0400 | [diff] [blame] | 105 | const int mShaderVersion; |
Zhenyao Mo | 05b6b7f | 2015-03-02 17:08:09 -0800 | [diff] [blame] | 106 | |
| 107 | ShShaderOutput mOutput; |
Qiankun Miao | 705a919 | 2016-08-29 10:05:27 +0800 | [diff] [blame] | 108 | |
| 109 | ShCompileOptions mCompileOptions; |
zmo@google.com | 5601ea0 | 2011-06-10 18:23:25 +0000 | [diff] [blame] | 110 | }; |
| 111 | |
Shao | b5cc119 | 2017-07-06 10:47:20 +0800 | [diff] [blame] | 112 | void WriteGeometryShaderLayoutQualifiers(TInfoSinkBase &out, |
| 113 | sh::TLayoutPrimitiveType inputPrimitive, |
| 114 | int invocations, |
| 115 | sh::TLayoutPrimitiveType outputPrimitive, |
| 116 | int maxVertices); |
| 117 | |
Jamie Madill | 2a9e107 | 2017-09-22 11:31:57 -0400 | [diff] [blame] | 118 | bool NeedsToWriteLayoutQualifier(const TType &type); |
| 119 | |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame] | 120 | } // namespace sh |
| 121 | |
Geoff Lang | 0a73dd8 | 2014-11-19 16:18:08 -0500 | [diff] [blame] | 122 | #endif // COMPILER_TRANSLATOR_OUTPUTGLSLBASE_H_ |