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 visitGlobalQualifierDeclaration(Visit visit, 34 TIntermGlobalQualifierDeclaration *node) override; 35 bool visitDeclaration(Visit visit, TIntermDeclaration *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 const TFunction *getInternalFunction(const ImmutableString &functionName, 63 const TType &returnType, 64 TIntermSequence *arguments, 65 const TVector<const TVariable *> ¶meters, 66 bool knownToNotHaveSideEffects); 67 TIntermAggregate *createRoundingFunctionCallNode(TIntermTyped *roundedChild); 68 TIntermAggregate *createCompoundAssignmentFunctionCallNode(TIntermTyped *left, 69 TIntermTyped *right, 70 const char *opNameStr); 71 72 typedef std::set<TypePair, TypePairComparator> EmulationSet; 73 EmulationSet mEmulateCompoundAdd; 74 EmulationSet mEmulateCompoundSub; 75 EmulationSet mEmulateCompoundMul; 76 EmulationSet mEmulateCompoundDiv; 77 78 // Map from mangled name to function. 79 TMap<ImmutableString, const TFunction *> mInternalFunctions; 80 81 bool mDeclaringVariables; 82 }; 83 84 } // namespace sh 85 86 #endif // COMPILER_TRANSLATOR_TREEOPS_EMULATE_PRECISION_H_ 87