blob: f1f560aa856b47ccac5c85c9a230ead7f996b780 [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:
Olli Etuaho853dc1a2014-11-06 17:25:48 +020033 struct TypePair
34 {
35 TypePair(const char *l, const char *r)
36 : lType(l), rType(r) { }
37
38 const char *lType;
39 const char *rType;
40 };
41
42 struct TypePairComparator
43 {
44 bool operator() (const TypePair& l, const TypePair& r) const
45 {
46 if (l.lType == r.lType)
47 return l.rType < r.rType;
48 return l.lType < r.lType;
49 }
50 };
51
52 typedef std::set<TypePair, TypePairComparator> EmulationSet;
53 EmulationSet mEmulateCompoundAdd;
54 EmulationSet mEmulateCompoundSub;
55 EmulationSet mEmulateCompoundMul;
56 EmulationSet mEmulateCompoundDiv;
57
58 // Stack of function call parameter iterators
59 std::vector<TIntermSequence::const_iterator> mSeqIterStack;
60
61 bool mDeclaringVariables;
62 bool mInLValue;
63 bool mInFunctionCallOutParameter;
64
65 struct TStringComparator
66 {
67 bool operator() (const TString& a, const TString& b) const { return a.compare(b) < 0; }
68 };
69
70 // Map from function names to their parameter sequences
71 std::map<TString, TIntermSequence*, TStringComparator> mFunctionMap;
72};
73
74#endif // COMPILER_TRANSLATOR_EMULATE_PRECISION_H_