Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(508)

Side by Side Diff: src/sksl/SkSLGLSLCodeGenerator.h

Issue 2288033003: Turned on SkSL->GLSL compiler (Closed)
Patch Set: changed <iostream> to <ostream> Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/sksl/SkSLContext.h ('k') | src/sksl/SkSLGLSLCodeGenerator.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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;
53 }; 58 };
54 59
55 /** 60 /**
56 * Converts a Program into GLSL code. 61 * Converts a Program into GLSL code.
57 */ 62 */
58 class GLSLCodeGenerator : public CodeGenerator { 63 class GLSLCodeGenerator : public CodeGenerator {
59 public: 64 public:
60 enum Precedence { 65 enum Precedence {
61 kParentheses_Precedence = 1, 66 kParentheses_Precedence = 1,
62 kPostfix_Precedence = 2, 67 kPostfix_Precedence = 2,
(...skipping 11 matching lines...) Expand all
74 kLogicalOr_Precedence = 14, 79 kLogicalOr_Precedence = 14,
75 kTernary_Precedence = 15, 80 kTernary_Precedence = 15,
76 kAssignment_Precedence = 16, 81 kAssignment_Precedence = 16,
77 kSequence_Precedence = 17, 82 kSequence_Precedence = 17,
78 kTopLevel_Precedence = 18 83 kTopLevel_Precedence = 18
79 }; 84 };
80 85
81 GLSLCodeGenerator(const Context* context, GLCaps caps) 86 GLSLCodeGenerator(const Context* context, GLCaps caps)
82 : fContext(*context) 87 : fContext(*context)
83 , fCaps(caps) 88 , fCaps(caps)
89 , fOut(nullptr)
90 , fVarCount(0)
84 , fIndentation(0) 91 , fIndentation(0)
85 , fAtLineStart(true) {} 92 , fAtLineStart(true) {}
86 93
87 void generateCode(const Program& program, std::ostream& out) override; 94 void generateCode(const Program& program, std::ostream& out) override;
88 95
89 private: 96 private:
90 void write(const char* s); 97 void write(const char* s);
91 98
92 void writeLine(); 99 void writeLine();
93 100
(...skipping 10 matching lines...) Expand all
104 void writeInterfaceBlock(const InterfaceBlock& intf); 111 void writeInterfaceBlock(const InterfaceBlock& intf);
105 112
106 void writeFunctionStart(const FunctionDeclaration& f); 113 void writeFunctionStart(const FunctionDeclaration& f);
107 114
108 void writeFunctionDeclaration(const FunctionDeclaration& f); 115 void writeFunctionDeclaration(const FunctionDeclaration& f);
109 116
110 void writeFunction(const FunctionDefinition& f); 117 void writeFunction(const FunctionDefinition& f);
111 118
112 void writeLayout(const Layout& layout); 119 void writeLayout(const Layout& layout);
113 120
114 void writeModifiers(const Modifiers& modifiers); 121 void writeModifiers(const Modifiers& modifiers, bool globalContext);
115 122
116 void writeGlobalVars(const VarDeclaration& vs); 123 void writeGlobalVars(const VarDeclaration& vs);
117 124
118 void writeVarDeclarations(const VarDeclarations& decl); 125 void writeVarDeclarations(const VarDeclarations& decl, bool global);
119 126
120 void writeVariableReference(const VariableReference& ref); 127 void writeVariableReference(const VariableReference& ref);
121 128
122 void writeExpression(const Expression& expr, Precedence parentPrecedence); 129 void writeExpression(const Expression& expr, Precedence parentPrecedence);
123 130
124 void writeIntrinsicCall(const FunctionCall& c); 131 void writeIntrinsicCall(const FunctionCall& c);
125 132
133 void writeMinAbsHack(Expression& absExpr, Expression& otherExpr);
134
126 void writeFunctionCall(const FunctionCall& c); 135 void writeFunctionCall(const FunctionCall& c);
127 136
128 void writeConstructor(const Constructor& c); 137 void writeConstructor(const Constructor& c);
129 138
130 void writeFieldAccess(const FieldAccess& f); 139 void writeFieldAccess(const FieldAccess& f);
131 140
132 void writeSwizzle(const Swizzle& swizzle); 141 void writeSwizzle(const Swizzle& swizzle);
133 142
134 void writeBinaryExpression(const BinaryExpression& b, Precedence parentPrece dence); 143 void writeBinaryExpression(const BinaryExpression& b, Precedence parentPrece dence);
135 144
(...skipping 21 matching lines...) Expand all
157 166
158 void writeWhileStatement(const WhileStatement& w); 167 void writeWhileStatement(const WhileStatement& w);
159 168
160 void writeDoStatement(const DoStatement& d); 169 void writeDoStatement(const DoStatement& d);
161 170
162 void writeReturnStatement(const ReturnStatement& r); 171 void writeReturnStatement(const ReturnStatement& r);
163 172
164 const Context& fContext; 173 const Context& fContext;
165 const GLCaps fCaps; 174 const GLCaps fCaps;
166 std::ostream* fOut; 175 std::ostream* fOut;
176 std::string fFunctionHeader;
177 Program::Kind fProgramKind;
178 int fVarCount;
167 int fIndentation; 179 int fIndentation;
168 bool fAtLineStart; 180 bool fAtLineStart;
169 // Keeps track of which struct types we have written. Given that we are unli kely to ever write 181 // Keeps track of which struct types we have written. Given that we are unli kely to ever write
170 // more than one or two structs per shader, a simple linear search will be f aster than anything 182 // more than one or two structs per shader, a simple linear search will be f aster than anything
171 // fancier. 183 // fancier.
172 std::vector<const Type*> fWrittenStructs; 184 std::vector<const Type*> fWrittenStructs;
173 }; 185 };
174 186
175 } 187 }
176 188
177 #endif 189 #endif
OLDNEW
« no previous file with comments | « src/sksl/SkSLContext.h ('k') | src/sksl/SkSLGLSLCodeGenerator.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698