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 "GLSLANG/ShaderLang.h" 11 #include "common/angleutils.h" 12 #include "compiler/translator/Compiler.h" 13 #include "compiler/translator/InfoSink.h" 14 #include "compiler/translator/IntermTraverse.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 21 namespace sh 22 { 23 24 class EmulatePrecision : public TLValueTrackingTraverser 25 { 26 public: 27 EmulatePrecision(TSymbolTable *symbolTable, int shaderVersion); 28 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; 33 bool visitInvariantDeclaration(Visit visit, TIntermInvariantDeclaration *node) override; 34 bool visitDeclaration(Visit visit, TIntermDeclaration *node) override; 35 bool visitFunctionPrototype(Visit visit, TIntermFunctionPrototype *node) override; 36 37 void writeEmulationHelpers(TInfoSinkBase &sink, 38 const int shaderVersion, 39 const ShShaderOutput outputLanguage); 40 41 static bool SupportedInLanguage(const ShShaderOutput outputLanguage); 42 43 private: 44 struct TypePair 45 { TypePairTypePair46 TypePair(const char *l, const char *r) : lType(l), rType(r) {} 47 48 const char *lType; 49 const char *rType; 50 }; 51 52 struct TypePairComparator 53 { operatorTypePairComparator54 bool operator()(const TypePair &l, const TypePair &r) const 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 68 bool mDeclaringVariables; 69 }; 70 71 } // namespace sh 72 73 #endif // COMPILER_TRANSLATOR_EMULATE_PRECISION_H_ 74