diff options
author | Ethan Nicholas <ethannicholas@google.com> | 2018-06-18 14:14:13 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2018-06-18 18:40:58 +0000 |
commit | dfbfc738a9edfff7a9804253175e380c230f3d21 (patch) | |
tree | 974f1093a905e07601ffff34d04d2e8ed70e6fc4 /src/sksl/SkSLIRGenerator.cpp | |
parent | b831ea22960c684b65f8ead76efe24059d119086 (diff) |
added GrSkSLFP and converted DitherEffect to use it
Bug: skia:
Change-Id: I84b71165eab1712355f3c7669cee2d33d259f3df
Reviewed-on: https://skia-review.googlesource.com/124504
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/sksl/SkSLIRGenerator.cpp')
-rw-r--r-- | src/sksl/SkSLIRGenerator.cpp | 46 |
1 files changed, 35 insertions, 11 deletions
diff --git a/src/sksl/SkSLIRGenerator.cpp b/src/sksl/SkSLIRGenerator.cpp index 5a54b07333..144708bbae 100644 --- a/src/sksl/SkSLIRGenerator.cpp +++ b/src/sksl/SkSLIRGenerator.cpp @@ -144,10 +144,16 @@ static void fill_caps(const SKSL_CAPS_CLASS& caps, void IRGenerator::start(const Program::Settings* settings, std::vector<std::unique_ptr<ProgramElement>>* inherited) { + if (fStarted) { + this->popSymbolTable(); + } fSettings = settings; fCapsMap.clear(); if (settings->fCaps) { fill_caps(*settings->fCaps, &fCapsMap); + } else { + fCapsMap.insert(std::make_pair(String("integerSupport"), + Program::Settings::Value(true))); } this->pushSymbolTable(); fInvocations = -1; @@ -168,11 +174,6 @@ void IRGenerator::start(const Program::Settings* settings, } } -void IRGenerator::finish() { - this->popSymbolTable(); - fSettings = nullptr; -} - std::unique_ptr<Extension> IRGenerator::convertExtension(const ASTExtension& extension) { return std::unique_ptr<Extension>(new Extension(extension.fOffset, extension.fName)); } @@ -682,6 +683,26 @@ void IRGenerator::convertFunction(const ASTFunction& f) { parameters.push_back(var); } + if (f.fName == "main") { + if (fKind == Program::kPipelineStage_Kind) { + bool valid = parameters.size() == 3 && + parameters[0]->fType == *fContext.fInt_Type && + parameters[0]->fModifiers.fFlags == 0 && + parameters[1]->fType == *fContext.fInt_Type && + parameters[1]->fModifiers.fFlags == 0 && + parameters[2]->fType == *fContext.fHalf4_Type && + parameters[2]->fModifiers.fFlags == (Modifiers::kIn_Flag | + Modifiers::kOut_Flag); + if (!valid) { + fErrors.error(f.fOffset, "pipeline stage 'main' must be declared main(int, " + "int, inout half4)"); + return; + } + } else if (parameters.size()) { + fErrors.error(f.fOffset, "shader 'main' must have zero parameters"); + } + } + // find existing declaration const FunctionDeclaration* decl = nullptr; auto entry = (*fSymbolTable)[f.fName]; @@ -752,6 +773,11 @@ void IRGenerator::convertFunction(const ASTFunction& f) { decl->fDefined = true; std::shared_ptr<SymbolTable> old = fSymbolTable; AutoSymbolTable table(this); + if (f.fName == "main" && fKind == Program::kPipelineStage_Kind) { + parameters[0]->fModifiers.fLayout.fBuiltin = SK_MAIN_X_BUILTIN; + parameters[1]->fModifiers.fLayout.fBuiltin = SK_MAIN_Y_BUILTIN; + parameters[2]->fModifiers.fLayout.fBuiltin = SK_OUTCOLOR_BUILTIN; + } for (size_t i = 0; i < parameters.size(); i++) { fSymbolTable->addWithoutOwnership(parameters[i]->fName, decl->fParameters[i]); } @@ -1644,17 +1670,15 @@ std::unique_ptr<Expression> IRGenerator::convertNumberConstructor( } if (type.isFloat() && args.size() == 1 && args[0]->fKind == Expression::kFloatLiteral_Kind) { double value = ((FloatLiteral&) *args[0]).fValue; - return std::unique_ptr<Expression>(new FloatLiteral(fContext, offset, value, &type)); + return std::unique_ptr<Expression>(new FloatLiteral(offset, value, &type)); } if (type.isFloat() && args.size() == 1 && args[0]->fKind == Expression::kIntLiteral_Kind) { int64_t value = ((IntLiteral&) *args[0]).fValue; - return std::unique_ptr<Expression>(new FloatLiteral(fContext, offset, (double) value, - &type)); + return std::unique_ptr<Expression>(new FloatLiteral(offset, (double) value, &type)); } if (args[0]->fKind == Expression::kIntLiteral_Kind && (type == *fContext.fInt_Type || type == *fContext.fUInt_Type)) { - return std::unique_ptr<Expression>(new IntLiteral(fContext, - offset, + return std::unique_ptr<Expression>(new IntLiteral(offset, ((IntLiteral&) *args[0]).fValue, &type)); } @@ -1952,7 +1976,7 @@ std::unique_ptr<Expression> IRGenerator::getCap(int offset, String name) { found->second.literal(fContext, offset))); } -std::unique_ptr<Expression> IRGenerator::getArg(int offset, String name) { +std::unique_ptr<Expression> IRGenerator::getArg(int offset, String name) const { auto found = fSettings->fArgs.find(name); if (found == fSettings->fArgs.end()) { fErrors.error(offset, "unknown argument '" + name + "'"); |