blob: 4b4c5b98df02db3fc2b34b07a2f3ec52f55ed02b [file] [log] [blame]
Olli Etuaho853dc1a2014-11-06 17:25:48 +02001//
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"
11#include "compiler/translator/InfoSink.h"
12#include "compiler/translator/IntermNode.h"
13#include "GLSLANG/ShaderLang.h"
14
15// This class gathers all compound assignments from the AST and can then write
16// the functions required for their precision emulation. This way there is no
17// need to write a huge number of variations of the emulated compound assignment
18// to every translated shader with emulation enabled.
19
20class EmulatePrecision : public TIntermTraverser
21{
22 public:
23 EmulatePrecision();
24
25 virtual void visitSymbol(TIntermSymbol *node);
26 virtual bool visitBinary(Visit visit, TIntermBinary *node);
27 virtual bool visitUnary(Visit visit, TIntermUnary *node);
28 virtual bool visitAggregate(Visit visit, TIntermAggregate *node);
29
30 void writeEmulationHelpers(TInfoSinkBase& sink, ShShaderOutput outputLanguage);
31
32 private:
33 DISALLOW_COPY_AND_ASSIGN(EmulatePrecision);
34
35 struct TypePair
36 {
37 TypePair(const char *l, const char *r)
38 : lType(l), rType(r) { }
39
40 const char *lType;
41 const char *rType;
42 };
43
44 struct TypePairComparator
45 {
46 bool operator() (const TypePair& l, const TypePair& r) const
47 {
48 if (l.lType == r.lType)
49 return l.rType < r.rType;
50 return l.lType < r.lType;
51 }
52 };
53
54 typedef std::set<TypePair, TypePairComparator> EmulationSet;
55 EmulationSet mEmulateCompoundAdd;
56 EmulationSet mEmulateCompoundSub;
57 EmulationSet mEmulateCompoundMul;
58 EmulationSet mEmulateCompoundDiv;
59
60 // Stack of function call parameter iterators
61 std::vector<TIntermSequence::const_iterator> mSeqIterStack;
62
63 bool mDeclaringVariables;
64 bool mInLValue;
65 bool mInFunctionCallOutParameter;
66
67 struct TStringComparator
68 {
69 bool operator() (const TString& a, const TString& b) const { return a.compare(b) < 0; }
70 };
71
72 // Map from function names to their parameter sequences
73 std::map<TString, TIntermSequence*, TStringComparator> mFunctionMap;
74};
75
76#endif // COMPILER_TRANSLATOR_EMULATE_PRECISION_H_