blob: e41dd935a53190f807829ff504706b5a57660e27 [file] [log] [blame]
zmo@google.com5601ea02011-06-10 18:23:25 +00001//
Jamie Madill02f20dd2013-09-12 12:07:42 -04002// Copyright (c) 2002-2013 The ANGLE Project Authors. All rights reserved.
zmo@google.com5601ea02011-06-10 18:23:25 +00003// Use of this source code is governed by a BSD-style license that can be
4// found in the LICENSE file.
5//
6
Geoff Lang0a73dd82014-11-19 16:18:08 -05007#ifndef COMPILER_TRANSLATOR_OUTPUTGLSLBASE_H_
8#define COMPILER_TRANSLATOR_OUTPUTGLSLBASE_H_
zmo@google.com5601ea02011-06-10 18:23:25 +00009
Jamie Madill01f85ac2014-06-06 11:55:04 -040010#include <set>
zmo@google.com5601ea02011-06-10 18:23:25 +000011
Olli Etuahocccf2b02017-07-05 14:50:54 +030012#include "compiler/translator/HashNames.h"
13#include "compiler/translator/InfoSink.h"
14#include "compiler/translator/IntermTraverse.h"
zmo@google.com5601ea02011-06-10 18:23:25 +000015
Jamie Madill45bcc782016-11-07 13:58:48 -050016namespace sh
17{
18
zmo@google.com5601ea02011-06-10 18:23:25 +000019class TOutputGLSLBase : public TIntermTraverser
20{
Zhenyao Mo9eedea02014-05-12 16:02:35 -070021 public:
22 TOutputGLSLBase(TInfoSinkBase &objSink,
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +000023 ShArrayIndexClampingStrategy clampingStrategy,
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000024 ShHashFunction64 hashFunction,
Zhenyao Mo9eedea02014-05-12 16:02:35 -070025 NameMap &nameMap,
Olli Etuahoa5e693a2017-07-13 16:07:26 +030026 TSymbolTable *symbolTable,
Qiankun Miao89dd8f32016-11-09 12:59:30 +000027 sh::GLenum shaderType,
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080028 int shaderVersion,
Qiankun Miao705a9192016-08-29 10:05:27 +080029 ShShaderOutput output,
30 ShCompileOptions compileOptions);
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -080031
Jamie Madilld7b1ab52016-12-12 14:42:19 -050032 ShShaderOutput getShaderOutput() const { return mOutput; }
zmo@google.com5601ea02011-06-10 18:23:25 +000033
Olli Etuaho09b04a22016-12-15 13:30:26 +000034 // Return the original name if hash function pointer is NULL;
35 // otherwise return the hashed name. Has special handling for internal names, which are not
36 // hashed.
37 TString hashName(const TName &name);
38
Zhenyao Mo9eedea02014-05-12 16:02:35 -070039 protected:
40 TInfoSinkBase &objSink() { return mObjSink; }
Olli Etuaho56a2f952016-12-08 12:16:27 +000041 void writeFloat(TInfoSinkBase &out, float f);
Zhenyao Mo9eedea02014-05-12 16:02:35 -070042 void writeTriplet(Visit visit, const char *preStr, const char *inStr, const char *postStr);
Jamie Madill2a9e1072017-09-22 11:31:57 -040043 virtual void writeLayoutQualifier(TIntermTyped *variable);
Zhenyao Mob7bf7422016-11-08 14:44:05 -080044 void writeInvariantQualifier(const TType &type);
Zhenyao Mo9eedea02014-05-12 16:02:35 -070045 void writeVariableType(const TType &type);
zmo@google.com5601ea02011-06-10 18:23:25 +000046 virtual bool writeVariablePrecision(TPrecision precision) = 0;
Zhenyao Mo9eedea02014-05-12 16:02:35 -070047 void writeFunctionParameters(const TIntermSequence &args);
Jamie Madill6ba6ead2015-05-04 14:21:21 -040048 const TConstantUnion *writeConstantUnion(const TType &type, const TConstantUnion *pConstUnion);
Olli Etuahoe92507b2016-07-04 11:20:10 +030049 void writeConstructorTriplet(Visit visit, const TType &type);
Zhenyao Mo9eedea02014-05-12 16:02:35 -070050 TString getTypeName(const TType &type);
zmo@google.com5601ea02011-06-10 18:23:25 +000051
Corentin Walleze5a1f272015-08-21 02:58:25 +020052 void visitSymbol(TIntermSymbol *node) override;
53 void visitConstantUnion(TIntermConstantUnion *node) override;
Olli Etuahob6fa0432016-09-28 16:28:05 +010054 bool visitSwizzle(Visit visit, TIntermSwizzle *node) override;
Corentin Walleze5a1f272015-08-21 02:58:25 +020055 bool visitBinary(Visit visit, TIntermBinary *node) override;
56 bool visitUnary(Visit visit, TIntermUnary *node) override;
Olli Etuahod0bad2c2016-09-09 18:01:16 +030057 bool visitTernary(Visit visit, TIntermTernary *node) override;
Olli Etuaho57961272016-09-14 13:57:46 +030058 bool visitIfElse(Visit visit, TIntermIfElse *node) override;
Corentin Walleze5a1f272015-08-21 02:58:25 +020059 bool visitSwitch(Visit visit, TIntermSwitch *node) override;
60 bool visitCase(Visit visit, TIntermCase *node) override;
Olli Etuaho16c745a2017-01-16 17:02:27 +000061 bool visitFunctionPrototype(Visit visit, TIntermFunctionPrototype *node) override;
Olli Etuaho336b1472016-10-05 16:37:55 +010062 bool visitFunctionDefinition(Visit visit, TIntermFunctionDefinition *node) override;
Corentin Walleze5a1f272015-08-21 02:58:25 +020063 bool visitAggregate(Visit visit, TIntermAggregate *node) override;
Olli Etuaho6d40bbd2016-09-30 13:49:38 +010064 bool visitBlock(Visit visit, TIntermBlock *node) override;
Olli Etuahobf4e1b72016-12-09 11:30:15 +000065 bool visitInvariantDeclaration(Visit visit, TIntermInvariantDeclaration *node) override;
Olli Etuaho13389b62016-10-16 11:48:18 +010066 bool visitDeclaration(Visit visit, TIntermDeclaration *node) override;
Corentin Walleze5a1f272015-08-21 02:58:25 +020067 bool visitLoop(Visit visit, TIntermLoop *node) override;
68 bool visitBranch(Visit visit, TIntermBranch *node) override;
zmo@google.com5601ea02011-06-10 18:23:25 +000069
Olli Etuaho6d40bbd2016-09-30 13:49:38 +010070 void visitCodeBlock(TIntermBlock *node);
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000071
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000072 // Same as hashName(), but without hashing built-in variables.
Olli Etuaho0982a2b2016-11-01 15:13:46 +000073 TString hashVariableName(const TName &name);
Olli Etuahoec9232b2017-03-27 17:01:37 +030074 // Same as hashName(), but without hashing internal functions or "main".
75 TString hashFunctionNameIfNeeded(const TFunctionSymbolInfo &info);
Nicolas Capens46485082014-04-15 13:12:50 -040076 // Used to translate function names for differences between ESSL and GLSL
Olli Etuahoec9232b2017-03-27 17:01:37 +030077 virtual TString translateTextureFunction(const TString &name) { return name; }
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000078
Zhenyao Mo9eedea02014-05-12 16:02:35 -070079 private:
80 bool structDeclared(const TStructure *structure) const;
81 void declareStruct(const TStructure *structure);
Jamie Madill98493dd2013-07-08 14:39:03 -040082
Geoff Langbdcc54a2015-09-02 13:09:48 -040083 void declareInterfaceBlockLayout(const TInterfaceBlock *interfaceBlock);
84 void declareInterfaceBlock(const TInterfaceBlock *interfaceBlock);
85
Olli Etuahoe1805592017-01-02 16:41:20 +000086 void writeBuiltInFunctionTriplet(Visit visit, TOperator op, bool useEmulatedFunction);
Zhenyao Mo9eedea02014-05-12 16:02:35 -070087
Zhenyao Mob7bf7422016-11-08 14:44:05 -080088 const char *mapQualifierToString(TQualifier qialifier);
89
Zhenyao Mo9eedea02014-05-12 16:02:35 -070090 TInfoSinkBase &mObjSink;
zmo@google.com5601ea02011-06-10 18:23:25 +000091 bool mDeclaringVariables;
92
Jamie Madill01f85ac2014-06-06 11:55:04 -040093 // This set contains all the ids of the structs from every scope.
94 std::set<int> mDeclaredStructs;
zmo@google.com5601ea02011-06-10 18:23:25 +000095
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +000096 ShArrayIndexClampingStrategy mClampingStrategy;
97
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +000098 // name hashing.
99 ShHashFunction64 mHashFunction;
shannon.woods@transgaming.com1d432bb2013-01-25 21:57:28 +0000100
Zhenyao Mo9eedea02014-05-12 16:02:35 -0700101 NameMap &mNameMap;
daniel@transgaming.com0aa3b5a2012-11-28 19:43:24 +0000102
Qiankun Miao89dd8f32016-11-09 12:59:30 +0000103 sh::GLenum mShaderType;
104
Jamie Madill02f20dd2013-09-12 12:07:42 -0400105 const int mShaderVersion;
Zhenyao Mo05b6b7f2015-03-02 17:08:09 -0800106
107 ShShaderOutput mOutput;
Qiankun Miao705a9192016-08-29 10:05:27 +0800108
109 ShCompileOptions mCompileOptions;
zmo@google.com5601ea02011-06-10 18:23:25 +0000110};
111
Shaob5cc1192017-07-06 10:47:20 +0800112void WriteGeometryShaderLayoutQualifiers(TInfoSinkBase &out,
113 sh::TLayoutPrimitiveType inputPrimitive,
114 int invocations,
115 sh::TLayoutPrimitiveType outputPrimitive,
116 int maxVertices);
117
Jamie Madill2a9e1072017-09-22 11:31:57 -0400118bool NeedsToWriteLayoutQualifier(const TType &type);
119
Jamie Madill45bcc782016-11-07 13:58:48 -0500120} // namespace sh
121
Geoff Lang0a73dd82014-11-19 16:18:08 -0500122#endif // COMPILER_TRANSLATOR_OUTPUTGLSLBASE_H_