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

Side by Side Diff: src/sksl/SkSLCompiler.cpp

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/SkSLCompiler.h ('k') | src/sksl/SkSLContext.h » ('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 #include "SkSLCompiler.h" 8 #include "SkSLCompiler.h"
9 9
10 #include <fstream> 10 #include <fstream>
11 #include <streambuf> 11 #include <streambuf>
12 12
13 #include "ast/SkSLASTPrecision.h"
13 #include "SkSLIRGenerator.h" 14 #include "SkSLIRGenerator.h"
14 #include "SkSLParser.h" 15 #include "SkSLParser.h"
15 #include "SkSLSPIRVCodeGenerator.h" 16 #include "SkSLSPIRVCodeGenerator.h"
16 #include "ir/SkSLExpression.h" 17 #include "ir/SkSLExpression.h"
17 #include "ir/SkSLIntLiteral.h" 18 #include "ir/SkSLIntLiteral.h"
19 #include "ir/SkSLModifiersDeclaration.h"
18 #include "ir/SkSLSymbolTable.h" 20 #include "ir/SkSLSymbolTable.h"
19 #include "ir/SkSLVarDeclaration.h" 21 #include "ir/SkSLVarDeclaration.h"
20 #include "SkMutex.h" 22 #include "SkMutex.h"
21 23
22 #define STRINGIFY(x) #x 24 #define STRINGIFY(x) #x
23 25
24 // include the built-in shader symbols as static strings 26 // include the built-in shader symbols as static strings
25 27
26 static std::string SKSL_INCLUDE = 28 static const char* SKSL_INCLUDE =
27 #include "sksl.include" 29 #include "sksl.include"
28 ; 30 ;
29 31
30 static std::string SKSL_VERT_INCLUDE = 32 static const char* SKSL_VERT_INCLUDE =
31 #include "sksl_vert.include" 33 #include "sksl_vert.include"
32 ; 34 ;
33 35
34 static std::string SKSL_FRAG_INCLUDE = 36 static const char* SKSL_FRAG_INCLUDE =
35 #include "sksl_frag.include" 37 #include "sksl_frag.include"
36 ; 38 ;
37 39
38 namespace SkSL { 40 namespace SkSL {
39 41
40 Compiler::Compiler() 42 Compiler::Compiler()
41 : fErrorCount(0) { 43 : fErrorCount(0) {
42 auto types = std::shared_ptr<SymbolTable>(new SymbolTable(*this)); 44 auto types = std::shared_ptr<SymbolTable>(new SymbolTable(*this));
43 auto symbols = std::shared_ptr<SymbolTable>(new SymbolTable(types, *this)); 45 auto symbols = std::shared_ptr<SymbolTable>(new SymbolTable(types, *this));
44 fIRGenerator = new IRGenerator(&fContext, symbols, *this); 46 fIRGenerator = new IRGenerator(&fContext, symbols, *this);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
90 ADD_TYPE(GVec3); 92 ADD_TYPE(GVec3);
91 ADD_TYPE(GVec4); 93 ADD_TYPE(GVec4);
92 ADD_TYPE(DVec); 94 ADD_TYPE(DVec);
93 ADD_TYPE(IVec); 95 ADD_TYPE(IVec);
94 ADD_TYPE(UVec); 96 ADD_TYPE(UVec);
95 ADD_TYPE(BVec); 97 ADD_TYPE(BVec);
96 98
97 ADD_TYPE(Sampler1D); 99 ADD_TYPE(Sampler1D);
98 ADD_TYPE(Sampler2D); 100 ADD_TYPE(Sampler2D);
99 ADD_TYPE(Sampler3D); 101 ADD_TYPE(Sampler3D);
102 ADD_TYPE(SamplerExternalOES);
100 ADD_TYPE(SamplerCube); 103 ADD_TYPE(SamplerCube);
101 ADD_TYPE(Sampler2DRect); 104 ADD_TYPE(Sampler2DRect);
102 ADD_TYPE(Sampler1DArray); 105 ADD_TYPE(Sampler1DArray);
103 ADD_TYPE(Sampler2DArray); 106 ADD_TYPE(Sampler2DArray);
104 ADD_TYPE(SamplerCubeArray); 107 ADD_TYPE(SamplerCubeArray);
105 ADD_TYPE(SamplerBuffer); 108 ADD_TYPE(SamplerBuffer);
106 ADD_TYPE(Sampler2DMS); 109 ADD_TYPE(Sampler2DMS);
107 ADD_TYPE(Sampler2DMSArray); 110 ADD_TYPE(Sampler2DMSArray);
108 111
109 ADD_TYPE(GSampler1D); 112 ADD_TYPE(GSampler1D);
(...skipping 11 matching lines...) Expand all
121 ADD_TYPE(Sampler1DShadow); 124 ADD_TYPE(Sampler1DShadow);
122 ADD_TYPE(Sampler2DShadow); 125 ADD_TYPE(Sampler2DShadow);
123 ADD_TYPE(SamplerCubeShadow); 126 ADD_TYPE(SamplerCubeShadow);
124 ADD_TYPE(Sampler2DRectShadow); 127 ADD_TYPE(Sampler2DRectShadow);
125 ADD_TYPE(Sampler1DArrayShadow); 128 ADD_TYPE(Sampler1DArrayShadow);
126 ADD_TYPE(Sampler2DArrayShadow); 129 ADD_TYPE(Sampler2DArrayShadow);
127 ADD_TYPE(SamplerCubeArrayShadow); 130 ADD_TYPE(SamplerCubeArrayShadow);
128 ADD_TYPE(GSampler2DArrayShadow); 131 ADD_TYPE(GSampler2DArrayShadow);
129 ADD_TYPE(GSamplerCubeArrayShadow); 132 ADD_TYPE(GSamplerCubeArrayShadow);
130 133
131 std::vector<std::unique_ptr<ProgramElement>> ignored; 134 Modifiers::Flag ignored1;
132 this->internalConvertProgram(SKSL_INCLUDE, &ignored); 135 std::vector<std::unique_ptr<ProgramElement>> ignored2;
136 this->internalConvertProgram(SKSL_INCLUDE, &ignored1, &ignored2);
133 ASSERT(!fErrorCount); 137 ASSERT(!fErrorCount);
134 } 138 }
135 139
136 Compiler::~Compiler() { 140 Compiler::~Compiler() {
137 delete fIRGenerator; 141 delete fIRGenerator;
138 } 142 }
139 143
140 void Compiler::internalConvertProgram(std::string text, 144 void Compiler::internalConvertProgram(std::string text,
145 Modifiers::Flag* defaultPrecision,
141 std::vector<std::unique_ptr<ProgramElement >>* result) { 146 std::vector<std::unique_ptr<ProgramElement >>* result) {
142 Parser parser(text, *fTypes, *this); 147 Parser parser(text, *fTypes, *this);
143 std::vector<std::unique_ptr<ASTDeclaration>> parsed = parser.file(); 148 std::vector<std::unique_ptr<ASTDeclaration>> parsed = parser.file();
144 if (fErrorCount) { 149 if (fErrorCount) {
145 return; 150 return;
146 } 151 }
152 *defaultPrecision = Modifiers::kHighp_Flag;
147 for (size_t i = 0; i < parsed.size(); i++) { 153 for (size_t i = 0; i < parsed.size(); i++) {
148 ASTDeclaration& decl = *parsed[i]; 154 ASTDeclaration& decl = *parsed[i];
149 switch (decl.fKind) { 155 switch (decl.fKind) {
150 case ASTDeclaration::kVar_Kind: { 156 case ASTDeclaration::kVar_Kind: {
151 std::unique_ptr<VarDeclarations> s = fIRGenerator->convertVarDec larations( 157 std::unique_ptr<VarDeclarations> s = fIRGenerator->convertVarDec larations(
152 (ASTVar Declarations&) decl, 158 (ASTVar Declarations&) decl,
153 Variabl e::kGlobal_Storage); 159 Variabl e::kGlobal_Storage);
154 if (s) { 160 if (s) {
155 result->push_back(std::move(s)); 161 result->push_back(std::move(s));
156 } 162 }
157 break; 163 break;
158 } 164 }
159 case ASTDeclaration::kFunction_Kind: { 165 case ASTDeclaration::kFunction_Kind: {
160 std::unique_ptr<FunctionDefinition> f = fIRGenerator->convertFun ction( 166 std::unique_ptr<FunctionDefinition> f = fIRGenerator->convertFun ction(
161 ( ASTFunction&) decl); 167 ( ASTFunction&) decl);
162 if (f) { 168 if (f) {
163 result->push_back(std::move(f)); 169 result->push_back(std::move(f));
164 } 170 }
165 break; 171 break;
166 } 172 }
173 case ASTDeclaration::kModifiers_Kind: {
174 std::unique_ptr<ModifiersDeclaration> f = fIRGenerator->convertM odifiersDeclaration(
175 (ASTModifiers Declaration&) decl);
176 if (f) {
177 result->push_back(std::move(f));
178 }
179 break;
180 }
167 case ASTDeclaration::kInterfaceBlock_Kind: { 181 case ASTDeclaration::kInterfaceBlock_Kind: {
168 std::unique_ptr<InterfaceBlock> i = fIRGenerator->convertInterfa ceBlock( 182 std::unique_ptr<InterfaceBlock> i = fIRGenerator->convertInterfa ceBlock(
169 (ASTInt erfaceBlock&) decl); 183 (ASTInt erfaceBlock&) decl);
170 if (i) { 184 if (i) {
171 result->push_back(std::move(i)); 185 result->push_back(std::move(i));
172 } 186 }
173 break; 187 break;
174 } 188 }
175 case ASTDeclaration::kExtension_Kind: { 189 case ASTDeclaration::kExtension_Kind: {
176 std::unique_ptr<Extension> e = fIRGenerator->convertExtension((A STExtension&) decl); 190 std::unique_ptr<Extension> e = fIRGenerator->convertExtension((A STExtension&) decl);
177 if (e) { 191 if (e) {
178 result->push_back(std::move(e)); 192 result->push_back(std::move(e));
179 } 193 }
180 break; 194 break;
181 } 195 }
196 case ASTDeclaration::kPrecision_Kind: {
197 *defaultPrecision = ((ASTPrecision&) decl).fPrecision;
198 break;
199 }
182 default: 200 default:
183 ABORT("unsupported declaration: %s\n", decl.description().c_str( )); 201 ABORT("unsupported declaration: %s\n", decl.description().c_str( ));
184 } 202 }
185 } 203 }
186 } 204 }
187 205
188 std::unique_ptr<Program> Compiler::convertProgram(Program::Kind kind, std::strin g text) { 206 std::unique_ptr<Program> Compiler::convertProgram(Program::Kind kind, std::strin g text) {
189 fErrorText = ""; 207 fErrorText = "";
190 fErrorCount = 0; 208 fErrorCount = 0;
191 fIRGenerator->pushSymbolTable(); 209 fIRGenerator->pushSymbolTable();
192 std::vector<std::unique_ptr<ProgramElement>> elements; 210 std::vector<std::unique_ptr<ProgramElement>> elements;
211 Modifiers::Flag ignored;
193 switch (kind) { 212 switch (kind) {
194 case Program::kVertex_Kind: 213 case Program::kVertex_Kind:
195 this->internalConvertProgram(SKSL_VERT_INCLUDE, &elements); 214 this->internalConvertProgram(SKSL_VERT_INCLUDE, &ignored, &elements) ;
196 break; 215 break;
197 case Program::kFragment_Kind: 216 case Program::kFragment_Kind:
198 this->internalConvertProgram(SKSL_FRAG_INCLUDE, &elements); 217 this->internalConvertProgram(SKSL_FRAG_INCLUDE, &ignored, &elements) ;
199 break; 218 break;
200 } 219 }
201 this->internalConvertProgram(text, &elements); 220 Modifiers::Flag defaultPrecision;
202 auto result = std::unique_ptr<Program>(new Program(kind, std::move(elements) , 221 this->internalConvertProgram(text, &defaultPrecision, &elements);
222 auto result = std::unique_ptr<Program>(new Program(kind, defaultPrecision, s td::move(elements),
203 fIRGenerator->fSymbolTabl e));; 223 fIRGenerator->fSymbolTabl e));;
204 fIRGenerator->popSymbolTable(); 224 fIRGenerator->popSymbolTable();
205 this->writeErrorCount(); 225 this->writeErrorCount();
206 return result; 226 return result;
207 } 227 }
208 228
209 void Compiler::error(Position position, std::string msg) { 229 void Compiler::error(Position position, std::string msg) {
210 fErrorCount++; 230 fErrorCount++;
211 fErrorText += "error: " + position.description() + ": " + msg.c_str() + "\n" ; 231 fErrorText += "error: " + position.description() + ": " + msg.c_str() + "\n" ;
212 } 232 }
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 std::string* out) { 280 std::string* out) {
261 std::stringstream buffer; 281 std::stringstream buffer;
262 bool result = this->toGLSL(kind, text, caps, buffer); 282 bool result = this->toGLSL(kind, text, caps, buffer);
263 if (result) { 283 if (result) {
264 *out = buffer.str(); 284 *out = buffer.str();
265 } 285 }
266 return result; 286 return result;
267 } 287 }
268 288
269 } // namespace 289 } // namespace
OLDNEW
« no previous file with comments | « src/sksl/SkSLCompiler.h ('k') | src/sksl/SkSLContext.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698