Olli Etuaho | 853dc1a | 2014-11-06 17:25:48 +0200 | [diff] [blame] | 1 | // |
| 2 | // Copyright (c) 2002-2014 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_TRANSLATOR_EMULATE_PRECISION_H_ |
| 8 | #define COMPILER_TRANSLATOR_EMULATE_PRECISION_H_ |
| 9 | |
| 10 | #include "common/angleutils.h" |
Qingqing Deng | ad0d079 | 2015-04-08 14:25:06 -0700 | [diff] [blame] | 11 | #include "compiler/translator/Compiler.h" |
Olli Etuaho | 853dc1a | 2014-11-06 17:25:48 +0200 | [diff] [blame] | 12 | #include "compiler/translator/InfoSink.h" |
| 13 | #include "compiler/translator/IntermNode.h" |
| 14 | #include "GLSLANG/ShaderLang.h" |
| 15 | |
| 16 | // This class gathers all compound assignments from the AST and can then write |
| 17 | // the functions required for their precision emulation. This way there is no |
| 18 | // need to write a huge number of variations of the emulated compound assignment |
| 19 | // to every translated shader with emulation enabled. |
| 20 | |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame] | 21 | namespace sh |
| 22 | { |
| 23 | |
Olli Etuaho | 3fc9337 | 2015-08-11 14:50:59 +0300 | [diff] [blame] | 24 | class EmulatePrecision : public TLValueTrackingTraverser |
Olli Etuaho | 853dc1a | 2014-11-06 17:25:48 +0200 | [diff] [blame] | 25 | { |
| 26 | public: |
Olli Etuaho | 217fe6e | 2015-08-05 13:25:08 +0300 | [diff] [blame] | 27 | EmulatePrecision(const TSymbolTable &symbolTable, int shaderVersion); |
Olli Etuaho | 853dc1a | 2014-11-06 17:25:48 +0200 | [diff] [blame] | 28 | |
Corentin Wallez | e5a1f27 | 2015-08-21 02:58:25 +0200 | [diff] [blame] | 29 | void visitSymbol(TIntermSymbol *node) override; |
| 30 | bool visitBinary(Visit visit, TIntermBinary *node) override; |
| 31 | bool visitUnary(Visit visit, TIntermUnary *node) override; |
| 32 | bool visitAggregate(Visit visit, TIntermAggregate *node) override; |
Olli Etuaho | bf4e1b7 | 2016-12-09 11:30:15 +0000 | [diff] [blame] | 33 | bool visitInvariantDeclaration(Visit visit, TIntermInvariantDeclaration *node) override; |
Olli Etuaho | 13389b6 | 2016-10-16 11:48:18 +0100 | [diff] [blame] | 34 | bool visitDeclaration(Visit visit, TIntermDeclaration *node) override; |
Olli Etuaho | 16c745a | 2017-01-16 17:02:27 +0000 | [diff] [blame] | 35 | bool visitFunctionPrototype(Visit visit, TIntermFunctionPrototype *node) override; |
Olli Etuaho | 853dc1a | 2014-11-06 17:25:48 +0200 | [diff] [blame] | 36 | |
Olli Etuaho | 61b81ac | 2016-06-28 14:15:20 +0300 | [diff] [blame] | 37 | void writeEmulationHelpers(TInfoSinkBase &sink, |
| 38 | const int shaderVersion, |
| 39 | const ShShaderOutput outputLanguage); |
Olli Etuaho | 853dc1a | 2014-11-06 17:25:48 +0200 | [diff] [blame] | 40 | |
Jamie Madill | d569619 | 2016-10-06 11:09:24 -0400 | [diff] [blame] | 41 | static bool SupportedInLanguage(const ShShaderOutput outputLanguage); |
| 42 | |
Olli Etuaho | 853dc1a | 2014-11-06 17:25:48 +0200 | [diff] [blame] | 43 | private: |
Olli Etuaho | 853dc1a | 2014-11-06 17:25:48 +0200 | [diff] [blame] | 44 | struct TypePair |
| 45 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 46 | TypePair(const char *l, const char *r) : lType(l), rType(r) {} |
Olli Etuaho | 853dc1a | 2014-11-06 17:25:48 +0200 | [diff] [blame] | 47 | |
| 48 | const char *lType; |
| 49 | const char *rType; |
| 50 | }; |
| 51 | |
| 52 | struct TypePairComparator |
| 53 | { |
Jamie Madill | d7b1ab5 | 2016-12-12 14:42:19 -0500 | [diff] [blame] | 54 | bool operator()(const TypePair &l, const TypePair &r) const |
Olli Etuaho | 853dc1a | 2014-11-06 17:25:48 +0200 | [diff] [blame] | 55 | { |
| 56 | if (l.lType == r.lType) |
| 57 | return l.rType < r.rType; |
| 58 | return l.lType < r.lType; |
| 59 | } |
| 60 | }; |
| 61 | |
| 62 | typedef std::set<TypePair, TypePairComparator> EmulationSet; |
| 63 | EmulationSet mEmulateCompoundAdd; |
| 64 | EmulationSet mEmulateCompoundSub; |
| 65 | EmulationSet mEmulateCompoundMul; |
| 66 | EmulationSet mEmulateCompoundDiv; |
| 67 | |
Olli Etuaho | 853dc1a | 2014-11-06 17:25:48 +0200 | [diff] [blame] | 68 | bool mDeclaringVariables; |
Olli Etuaho | 853dc1a | 2014-11-06 17:25:48 +0200 | [diff] [blame] | 69 | }; |
| 70 | |
Jamie Madill | 45bcc78 | 2016-11-07 13:58:48 -0500 | [diff] [blame] | 71 | } // namespace sh |
| 72 | |
Olli Etuaho | 853dc1a | 2014-11-06 17:25:48 +0200 | [diff] [blame] | 73 | #endif // COMPILER_TRANSLATOR_EMULATE_PRECISION_H_ |