| 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 #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 "ast/SkSLASTPrecision.h" |
| 14 #include "SkSLCFGGenerator.h" | 14 #include "SkSLCFGGenerator.h" |
| 15 #include "SkSLIRGenerator.h" | 15 #include "SkSLIRGenerator.h" |
| 16 #include "SkSLParser.h" | 16 #include "SkSLParser.h" |
| 17 #include "SkSLSPIRVCodeGenerator.h" | 17 #include "SkSLSPIRVCodeGenerator.h" |
| 18 #include "ir/SkSLExpression.h" | 18 #include "ir/SkSLExpression.h" |
| 19 #include "ir/SkSLIntLiteral.h" | 19 #include "ir/SkSLIntLiteral.h" |
| 20 #include "ir/SkSLModifiersDeclaration.h" | 20 #include "ir/SkSLModifiersDeclaration.h" |
| 21 #include "ir/SkSLSymbolTable.h" | 21 #include "ir/SkSLSymbolTable.h" |
| 22 #include "ir/SkSLUnresolvedFunction.h" |
| 22 #include "ir/SkSLVarDeclarations.h" | 23 #include "ir/SkSLVarDeclarations.h" |
| 23 #include "SkMutex.h" | 24 #include "SkMutex.h" |
| 24 | 25 |
| 25 #define STRINGIFY(x) #x | 26 #define STRINGIFY(x) #x |
| 26 | 27 |
| 27 // include the built-in shader symbols as static strings | 28 // include the built-in shader symbols as static strings |
| 28 | 29 |
| 29 static const char* SKSL_INCLUDE = | 30 static const char* SKSL_INCLUDE = |
| 30 #include "sksl.include" | 31 #include "sksl.include" |
| 31 ; | 32 ; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 ADD_TYPE(Sampler2DRectShadow); | 129 ADD_TYPE(Sampler2DRectShadow); |
| 129 ADD_TYPE(Sampler1DArrayShadow); | 130 ADD_TYPE(Sampler1DArrayShadow); |
| 130 ADD_TYPE(Sampler2DArrayShadow); | 131 ADD_TYPE(Sampler2DArrayShadow); |
| 131 ADD_TYPE(SamplerCubeArrayShadow); | 132 ADD_TYPE(SamplerCubeArrayShadow); |
| 132 ADD_TYPE(GSampler2DArrayShadow); | 133 ADD_TYPE(GSampler2DArrayShadow); |
| 133 ADD_TYPE(GSamplerCubeArrayShadow); | 134 ADD_TYPE(GSamplerCubeArrayShadow); |
| 134 | 135 |
| 135 Modifiers::Flag ignored1; | 136 Modifiers::Flag ignored1; |
| 136 std::vector<std::unique_ptr<ProgramElement>> ignored2; | 137 std::vector<std::unique_ptr<ProgramElement>> ignored2; |
| 137 this->internalConvertProgram(SKSL_INCLUDE, &ignored1, &ignored2); | 138 this->internalConvertProgram(SKSL_INCLUDE, &ignored1, &ignored2); |
| 139 fIRGenerator->fSymbolTable->markAllFunctionsBuiltin(); |
| 138 ASSERT(!fErrorCount); | 140 ASSERT(!fErrorCount); |
| 139 } | 141 } |
| 140 | 142 |
| 141 Compiler::~Compiler() { | 143 Compiler::~Compiler() { |
| 142 delete fIRGenerator; | 144 delete fIRGenerator; |
| 143 } | 145 } |
| 144 | 146 |
| 145 // add the definition created by assigning to the lvalue to the definition set | 147 // add the definition created by assigning to the lvalue to the definition set |
| 146 void Compiler::addDefinition(const Expression* lvalue, const Expression* expr, | 148 void Compiler::addDefinition(const Expression* lvalue, const Expression* expr, |
| 147 std::unordered_map<const Variable*, const Expression*
>* definitions) { | 149 std::unordered_map<const Variable*, const Expression*
>* definitions) { |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 std::vector<std::unique_ptr<ProgramElement>> elements; | 388 std::vector<std::unique_ptr<ProgramElement>> elements; |
| 387 Modifiers::Flag ignored; | 389 Modifiers::Flag ignored; |
| 388 switch (kind) { | 390 switch (kind) { |
| 389 case Program::kVertex_Kind: | 391 case Program::kVertex_Kind: |
| 390 this->internalConvertProgram(SKSL_VERT_INCLUDE, &ignored, &elements)
; | 392 this->internalConvertProgram(SKSL_VERT_INCLUDE, &ignored, &elements)
; |
| 391 break; | 393 break; |
| 392 case Program::kFragment_Kind: | 394 case Program::kFragment_Kind: |
| 393 this->internalConvertProgram(SKSL_FRAG_INCLUDE, &ignored, &elements)
; | 395 this->internalConvertProgram(SKSL_FRAG_INCLUDE, &ignored, &elements)
; |
| 394 break; | 396 break; |
| 395 } | 397 } |
| 398 fIRGenerator->fSymbolTable->markAllFunctionsBuiltin(); |
| 396 Modifiers::Flag defaultPrecision; | 399 Modifiers::Flag defaultPrecision; |
| 397 this->internalConvertProgram(text, &defaultPrecision, &elements); | 400 this->internalConvertProgram(text, &defaultPrecision, &elements); |
| 398 auto result = std::unique_ptr<Program>(new Program(kind, defaultPrecision, s
td::move(elements), | 401 auto result = std::unique_ptr<Program>(new Program(kind, defaultPrecision, s
td::move(elements), |
| 399 fIRGenerator->fSymbolTabl
e));; | 402 fIRGenerator->fSymbolTabl
e)); |
| 400 fIRGenerator->popSymbolTable(); | 403 fIRGenerator->popSymbolTable(); |
| 401 this->writeErrorCount(); | 404 this->writeErrorCount(); |
| 402 return result; | 405 return result; |
| 403 } | 406 } |
| 404 | 407 |
| 405 void Compiler::error(Position position, std::string msg) { | 408 void Compiler::error(Position position, std::string msg) { |
| 406 fErrorCount++; | 409 fErrorCount++; |
| 407 fErrorText += "error: " + position.description() + ": " + msg.c_str() + "\n"
; | 410 fErrorText += "error: " + position.description() + ": " + msg.c_str() + "\n"
; |
| 408 } | 411 } |
| 409 | 412 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 456 std::string* out) { | 459 std::string* out) { |
| 457 std::stringstream buffer; | 460 std::stringstream buffer; |
| 458 bool result = this->toGLSL(kind, text, caps, buffer); | 461 bool result = this->toGLSL(kind, text, caps, buffer); |
| 459 if (result) { | 462 if (result) { |
| 460 *out = buffer.str(); | 463 *out = buffer.str(); |
| 461 } | 464 } |
| 462 return result; | 465 return result; |
| 463 } | 466 } |
| 464 | 467 |
| 465 } // namespace | 468 } // namespace |
| OLD | NEW |