blob: 4d30dbe608700b517beebde14db393ea79d3f5bf [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"
Qingqing Dengad0d0792015-04-08 14:25:06 -070011#include "compiler/translator/Compiler.h"
Olli Etuaho853dc1a2014-11-06 17:25:48 +020012#include "compiler/translator/InfoSink.h"
13#include "compiler/translator/IntermNode.h"
14#include "GLSLANG/ShaderLang.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
Jamie Madill45bcc782016-11-07 13:58:48 -050021namespace sh
22{
23
Olli Etuaho3fc93372015-08-11 14:50:59 +030024class EmulatePrecision : public TLValueTrackingTraverser
Olli Etuaho853dc1a2014-11-06 17:25:48 +020025{
26 public:
Olli Etuaho217fe6e2015-08-05 13:25:08 +030027 EmulatePrecision(const TSymbolTable &symbolTable, int shaderVersion);
Olli Etuaho853dc1a2014-11-06 17:25:48 +020028
Corentin Walleze5a1f272015-08-21 02:58:25 +020029 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;
Olli Etuaho13389b62016-10-16 11:48:18 +010033 bool visitDeclaration(Visit visit, TIntermDeclaration *node) override;
Olli Etuaho853dc1a2014-11-06 17:25:48 +020034
Olli Etuaho61b81ac2016-06-28 14:15:20 +030035 void writeEmulationHelpers(TInfoSinkBase &sink,
36 const int shaderVersion,
37 const ShShaderOutput outputLanguage);
Olli Etuaho853dc1a2014-11-06 17:25:48 +020038
Jamie Madilld5696192016-10-06 11:09:24 -040039 static bool SupportedInLanguage(const ShShaderOutput outputLanguage);
40
Olli Etuaho853dc1a2014-11-06 17:25:48 +020041 private:
Olli Etuaho853dc1a2014-11-06 17:25:48 +020042 struct TypePair
43 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -050044 TypePair(const char *l, const char *r) : lType(l), rType(r) {}
Olli Etuaho853dc1a2014-11-06 17:25:48 +020045
46 const char *lType;
47 const char *rType;
48 };
49
50 struct TypePairComparator
51 {
Jamie Madilld7b1ab52016-12-12 14:42:19 -050052 bool operator()(const TypePair &l, const TypePair &r) const
Olli Etuaho853dc1a2014-11-06 17:25:48 +020053 {
54 if (l.lType == r.lType)
55 return l.rType < r.rType;
56 return l.lType < r.lType;
57 }
58 };
59
60 typedef std::set<TypePair, TypePairComparator> EmulationSet;
61 EmulationSet mEmulateCompoundAdd;
62 EmulationSet mEmulateCompoundSub;
63 EmulationSet mEmulateCompoundMul;
64 EmulationSet mEmulateCompoundDiv;
65
Olli Etuaho853dc1a2014-11-06 17:25:48 +020066 bool mDeclaringVariables;
Olli Etuaho853dc1a2014-11-06 17:25:48 +020067};
68
Jamie Madill45bcc782016-11-07 13:58:48 -050069} // namespace sh
70
Olli Etuaho853dc1a2014-11-06 17:25:48 +020071#endif // COMPILER_TRANSLATOR_EMULATE_PRECISION_H_