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 , fVarCount(0) | |
90 , fIndentation(0) | 84 , fIndentation(0) |
91 , fAtLineStart(true) {} | 85 , fAtLineStart(true) {} |
92 | 86 |
93 void generateCode(const Program& program, std::ostream& out) override; | 87 void generateCode(const Program& program, std::ostream& out) override; |
94 | 88 |
95 private: | 89 private: |
96 void write(const char* s); | 90 void write(const char* s); |
97 | 91 |
98 void writeLine(); | 92 void writeLine(); |
99 | 93 |
(...skipping 10 matching lines...) Expand all Loading... |
110 void writeInterfaceBlock(const InterfaceBlock& intf); | 104 void writeInterfaceBlock(const InterfaceBlock& intf); |
111 | 105 |
112 void writeFunctionStart(const FunctionDeclaration& f); | 106 void writeFunctionStart(const FunctionDeclaration& f); |
113 | 107 |
114 void writeFunctionDeclaration(const FunctionDeclaration& f); | 108 void writeFunctionDeclaration(const FunctionDeclaration& f); |
115 | 109 |
116 void writeFunction(const FunctionDefinition& f); | 110 void writeFunction(const FunctionDefinition& f); |
117 | 111 |
118 void writeLayout(const Layout& layout); | 112 void writeLayout(const Layout& layout); |
119 | 113 |
120 void writeModifiers(const Modifiers& modifiers, bool globalContext); | 114 void writeModifiers(const Modifiers& modifiers); |
121 | 115 |
122 void writeGlobalVars(const VarDeclaration& vs); | 116 void writeGlobalVars(const VarDeclaration& vs); |
123 | 117 |
124 void writeVarDeclarations(const VarDeclarations& decl, bool global); | 118 void writeVarDeclarations(const VarDeclarations& decl); |
125 | 119 |
126 void writeVariableReference(const VariableReference& ref); | 120 void writeVariableReference(const VariableReference& ref); |
127 | 121 |
128 void writeExpression(const Expression& expr, Precedence parentPrecedence); | 122 void writeExpression(const Expression& expr, Precedence parentPrecedence); |
129 | 123 |
130 void writeIntrinsicCall(const FunctionCall& c); | 124 void writeIntrinsicCall(const FunctionCall& c); |
131 | 125 |
132 void writeMinAbsHack(Expression& absExpr, Expression& otherExpr); | |
133 | |
134 void writeFunctionCall(const FunctionCall& c); | 126 void writeFunctionCall(const FunctionCall& c); |
135 | 127 |
136 void writeConstructor(const Constructor& c); | 128 void writeConstructor(const Constructor& c); |
137 | 129 |
138 void writeFieldAccess(const FieldAccess& f); | 130 void writeFieldAccess(const FieldAccess& f); |
139 | 131 |
140 void writeSwizzle(const Swizzle& swizzle); | 132 void writeSwizzle(const Swizzle& swizzle); |
141 | 133 |
142 void writeBinaryExpression(const BinaryExpression& b, Precedence parentPrece
dence); | 134 void writeBinaryExpression(const BinaryExpression& b, Precedence parentPrece
dence); |
143 | 135 |
(...skipping 21 matching lines...) Expand all Loading... |
165 | 157 |
166 void writeWhileStatement(const WhileStatement& w); | 158 void writeWhileStatement(const WhileStatement& w); |
167 | 159 |
168 void writeDoStatement(const DoStatement& d); | 160 void writeDoStatement(const DoStatement& d); |
169 | 161 |
170 void writeReturnStatement(const ReturnStatement& r); | 162 void writeReturnStatement(const ReturnStatement& r); |
171 | 163 |
172 const Context& fContext; | 164 const Context& fContext; |
173 const GLCaps fCaps; | 165 const GLCaps fCaps; |
174 std::ostream* fOut; | 166 std::ostream* fOut; |
175 std::string fFunctionHeader; | |
176 Program::Kind fProgramKind; | |
177 int fVarCount; | |
178 int fIndentation; | 167 int fIndentation; |
179 bool fAtLineStart; | 168 bool fAtLineStart; |
180 // 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 |
181 // 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 |
182 // fancier. | 171 // fancier. |
183 std::vector<const Type*> fWrittenStructs; | 172 std::vector<const Type*> fWrittenStructs; |
184 }; | 173 }; |
185 | 174 |
186 } | 175 } |
187 | 176 |
188 #endif | 177 #endif |
OLD | NEW |