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 | |
Olli Etuaho | 3fc9337 | 2015-08-11 14:50:59 +0300 | [diff] [blame] | 21 | class EmulatePrecision : public TLValueTrackingTraverser |
Olli Etuaho | 853dc1a | 2014-11-06 17:25:48 +0200 | [diff] [blame] | 22 | { |
| 23 | public: |
Olli Etuaho | 217fe6e | 2015-08-05 13:25:08 +0300 | [diff] [blame] | 24 | EmulatePrecision(const TSymbolTable &symbolTable, int shaderVersion); |
Olli Etuaho | 853dc1a | 2014-11-06 17:25:48 +0200 | [diff] [blame] | 25 | |
Corentin Wallez | e5a1f27 | 2015-08-21 02:58:25 +0200 | [diff] [blame] | 26 | void visitSymbol(TIntermSymbol *node) override; |
| 27 | bool visitBinary(Visit visit, TIntermBinary *node) override; |
| 28 | bool visitUnary(Visit visit, TIntermUnary *node) override; |
| 29 | bool visitAggregate(Visit visit, TIntermAggregate *node) override; |
Olli Etuaho | 853dc1a | 2014-11-06 17:25:48 +0200 | [diff] [blame] | 30 | |
Olli Etuaho | 61b81ac | 2016-06-28 14:15:20 +0300 | [diff] [blame^] | 31 | void writeEmulationHelpers(TInfoSinkBase &sink, |
| 32 | const int shaderVersion, |
| 33 | const ShShaderOutput outputLanguage); |
Olli Etuaho | 853dc1a | 2014-11-06 17:25:48 +0200 | [diff] [blame] | 34 | |
| 35 | private: |
Olli Etuaho | 853dc1a | 2014-11-06 17:25:48 +0200 | [diff] [blame] | 36 | struct TypePair |
| 37 | { |
| 38 | TypePair(const char *l, const char *r) |
| 39 | : lType(l), rType(r) { } |
| 40 | |
| 41 | const char *lType; |
| 42 | const char *rType; |
| 43 | }; |
| 44 | |
| 45 | struct TypePairComparator |
| 46 | { |
| 47 | bool operator() (const TypePair& l, const TypePair& r) const |
| 48 | { |
| 49 | if (l.lType == r.lType) |
| 50 | return l.rType < r.rType; |
| 51 | return l.lType < r.lType; |
| 52 | } |
| 53 | }; |
| 54 | |
| 55 | typedef std::set<TypePair, TypePairComparator> EmulationSet; |
| 56 | EmulationSet mEmulateCompoundAdd; |
| 57 | EmulationSet mEmulateCompoundSub; |
| 58 | EmulationSet mEmulateCompoundMul; |
| 59 | EmulationSet mEmulateCompoundDiv; |
| 60 | |
Olli Etuaho | 853dc1a | 2014-11-06 17:25:48 +0200 | [diff] [blame] | 61 | bool mDeclaringVariables; |
Olli Etuaho | 853dc1a | 2014-11-06 17:25:48 +0200 | [diff] [blame] | 62 | }; |
| 63 | |
| 64 | #endif // COMPILER_TRANSLATOR_EMULATE_PRECISION_H_ |