1 // 2 // Copyright 2002 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_TREEOPS_EMULATE_PRECISION_H_ 8 #define COMPILER_TRANSLATOR_TREEOPS_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/tree_util/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); 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 36 void writeEmulationHelpers(TInfoSinkBase &sink, 37 const int shaderVersion, 38 const ShShaderOutput outputLanguage); 39 40 static bool SupportedInLanguage(const ShShaderOutput outputLanguage); 41 42 private: 43 struct TypePair 44 { TypePairTypePair45 TypePair(const char *l, const char *r) : lType(l), rType(r) {} 46 47 const char *lType; 48 const char *rType; 49 }; 50 51 struct TypePairComparator 52 { operatorTypePairComparator53 bool operator()(const TypePair &l, const TypePair &r) const 54 { 55 if (l.lType == r.lType) 56 return l.rType < r.rType; 57 return l.lType < r.lType; 58 } 59 }; 60 61 const TFunction *getInternalFunction(const ImmutableString &functionName, 62 const TType &returnType, 63 TIntermSequence *arguments, 64 const TVector<const TVariable *> ¶meters, 65 bool knownToNotHaveSideEffects); 66 TIntermAggregate *createRoundingFunctionCallNode(TIntermTyped *roundedChild); 67 TIntermAggregate *createCompoundAssignmentFunctionCallNode(TIntermTyped *left, 68 TIntermTyped *right, 69 const char *opNameStr); 70 71 typedef std::set<TypePair, TypePairComparator> EmulationSet; 72 EmulationSet mEmulateCompoundAdd; 73 EmulationSet mEmulateCompoundSub; 74 EmulationSet mEmulateCompoundMul; 75 EmulationSet mEmulateCompoundDiv; 76 77 // Map from mangled name to function. 78 TMap<ImmutableString, const TFunction *> mInternalFunctions; 79 80 bool mDeclaringVariables; 81 }; 82 83 } // namespace sh 84 85 #endif // COMPILER_TRANSLATOR_TREEOPS_EMULATE_PRECISION_H_ 86