OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef SKSL_GLSLCODEGENERATOR | 8 #ifndef SKSL_GLSLCODEGENERATOR |
9 #define SKSL_GLSLCODEGENERATOR | 9 #define SKSL_GLSLCODEGENERATOR |
10 | 10 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 namespace SkSL { | 43 namespace SkSL { |
44 | 44 |
45 #define kLast_Capability SpvCapabilityMultiViewport | 45 #define kLast_Capability SpvCapabilityMultiViewport |
46 | 46 |
47 struct GLCaps { | 47 struct GLCaps { |
48 int fVersion; | 48 int fVersion; |
49 enum { | 49 enum { |
50 kGL_Standard, | 50 kGL_Standard, |
51 kGLES_Standard | 51 kGLES_Standard |
52 } fStandard; | 52 } fStandard; |
53 bool fIsCoreProfile; | |
54 bool fUsesPrecisionModifiers; | |
55 bool fMustDeclareFragmentShaderOutput; | |
56 // The Tegra3 compiler will sometimes never return if we have min(abs(x), y) | |
57 bool fCanUseMinAndAbsTogether; | |
58 }; | 53 }; |
59 | 54 |
60 /** | 55 /** |
61 * Converts a Program into GLSL code. | 56 * Converts a Program into GLSL code. |
62 */ | 57 */ |
63 class GLSLCodeGenerator : public CodeGenerator { | 58 class GLSLCodeGenerator : public CodeGenerator { |
64 public: | 59 public: |
65 enum Precedence { | 60 enum Precedence { |
66 kParentheses_Precedence = 1, | 61 kParentheses_Precedence = 1, |
67 kPostfix_Precedence = 2, | 62 kPostfix_Precedence = 2, |
(...skipping 11 matching lines...) Expand all Loading... |
79 kLogicalOr_Precedence = 14, | 74 kLogicalOr_Precedence = 14, |
80 kTernary_Precedence = 15, | 75 kTernary_Precedence = 15, |
81 kAssignment_Precedence = 16, | 76 kAssignment_Precedence = 16, |
82 kSequence_Precedence = 17, | 77 kSequence_Precedence = 17, |
83 kTopLevel_Precedence = 18 | 78 kTopLevel_Precedence = 18 |
84 }; | 79 }; |
85 | 80 |
86 GLSLCodeGenerator(const Context* context, GLCaps caps) | 81 GLSLCodeGenerator(const Context* context, GLCaps caps) |
87 : fContext(*context) | 82 : fContext(*context) |
88 , fCaps(caps) | 83 , fCaps(caps) |
89 , fOut(nullptr) | |
90 , fVarCount(0) | |
91 , fIndentation(0) | 84 , fIndentation(0) |
92 , fAtLineStart(true) {} | 85 , fAtLineStart(true) {} |
93 | 86 |
94 void generateCode(const Program& program, std::ostream& out) override; | 87 void generateCode(const Program& program, std::ostream& out) override; |
95 | 88 |
96 private: | 89 private: |
97 void write(const char* s); | 90 void write(const char* s); |
98 | 91 |
99 void writeLine(); | 92 void writeLine(); |
100 | 93 |
(...skipping 10 matching lines...) Expand all Loading... |
111 void writeInterfaceBlock(const InterfaceBlock& intf); | 104 void writeInterfaceBlock(const InterfaceBlock& intf); |
112 | 105 |
113 void writeFunctionStart(const FunctionDeclaration& f); | 106 void writeFunctionStart(const FunctionDeclaration& f); |
114 | 107 |
115 void writeFunctionDeclaration(const FunctionDeclaration& f); | 108 void writeFunctionDeclaration(const FunctionDeclaration& f); |
116 | 109 |
117 void writeFunction(const FunctionDefinition& f); | 110 void writeFunction(const FunctionDefinition& f); |
118 | 111 |
119 void writeLayout(const Layout& layout); | 112 void writeLayout(const Layout& layout); |
120 | 113 |
121 void writeModifiers(const Modifiers& modifiers, bool globalContext); | 114 void writeModifiers(const Modifiers& modifiers); |
122 | 115 |
123 void writeGlobalVars(const VarDeclaration& vs); | 116 void writeGlobalVars(const VarDeclaration& vs); |
124 | 117 |
125 void writeVarDeclarations(const VarDeclarations& decl, bool global); | 118 void writeVarDeclarations(const VarDeclarations& decl); |
126 | 119 |
127 void writeVariableReference(const VariableReference& ref); | 120 void writeVariableReference(const VariableReference& ref); |
128 | 121 |
129 void writeExpression(const Expression& expr, Precedence parentPrecedence); | 122 void writeExpression(const Expression& expr, Precedence parentPrecedence); |
130 | 123 |
131 void writeIntrinsicCall(const FunctionCall& c); | 124 void writeIntrinsicCall(const FunctionCall& c); |
132 | 125 |
133 void writeMinAbsHack(Expression& absExpr, Expression& otherExpr); | |
134 | |
135 void writeFunctionCall(const FunctionCall& c); | 126 void writeFunctionCall(const FunctionCall& c); |
136 | 127 |
137 void writeConstructor(const Constructor& c); | 128 void writeConstructor(const Constructor& c); |
138 | 129 |
139 void writeFieldAccess(const FieldAccess& f); | 130 void writeFieldAccess(const FieldAccess& f); |
140 | 131 |
141 void writeSwizzle(const Swizzle& swizzle); | 132 void writeSwizzle(const Swizzle& swizzle); |
142 | 133 |
143 void writeBinaryExpression(const BinaryExpression& b, Precedence parentPrece
dence); | 134 void writeBinaryExpression(const BinaryExpression& b, Precedence parentPrece
dence); |
144 | 135 |
(...skipping 21 matching lines...) Expand all Loading... |
166 | 157 |
167 void writeWhileStatement(const WhileStatement& w); | 158 void writeWhileStatement(const WhileStatement& w); |
168 | 159 |
169 void writeDoStatement(const DoStatement& d); | 160 void writeDoStatement(const DoStatement& d); |
170 | 161 |
171 void writeReturnStatement(const ReturnStatement& r); | 162 void writeReturnStatement(const ReturnStatement& r); |
172 | 163 |
173 const Context& fContext; | 164 const Context& fContext; |
174 const GLCaps fCaps; | 165 const GLCaps fCaps; |
175 std::ostream* fOut; | 166 std::ostream* fOut; |
176 std::string fFunctionHeader; | |
177 Program::Kind fProgramKind; | |
178 int fVarCount; | |
179 int fIndentation; | 167 int fIndentation; |
180 bool fAtLineStart; | 168 bool fAtLineStart; |
181 // Keeps track of which struct types we have written. Given that we are unli
kely to ever write | 169 // Keeps track of which struct types we have written. Given that we are unli
kely to ever write |
182 // more than one or two structs per shader, a simple linear search will be f
aster than anything | 170 // more than one or two structs per shader, a simple linear search will be f
aster than anything |
183 // fancier. | 171 // fancier. |
184 std::vector<const Type*> fWrittenStructs; | 172 std::vector<const Type*> fWrittenStructs; |
185 }; | 173 }; |
186 | 174 |
187 } | 175 } |
188 | 176 |
189 #endif | 177 #endif |
OLD | NEW |