diff options
author | Ethan Nicholas <ethannicholas@google.com> | 2017-06-27 14:36:24 +0000 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-06-27 14:36:44 +0000 |
commit | ed50200682e0de72c3abecaa4d5324ebcd1ed9f9 (patch) | |
tree | f991fa9668072f9b87a9929c7834b55cd9175fff /src/sksl/SkSLIRGenerator.cpp | |
parent | ccf59917d3fe7aaf59de714acfbd0596503f324f (diff) |
Revert "sksl fragment processor support"
This reverts commit ccf59917d3fe7aaf59de714acfbd0596503f324f.
Reason for revert: breaking iOS bots
Original change's description:
> sksl fragment processor support
>
> Bug: skia:
> Change-Id: Ia3b0305c2b0c78074303831f628fb01852b90d34
> Reviewed-on: https://skia-review.googlesource.com/17843
> Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
> Reviewed-by: Ben Wagner <benjaminwagner@google.com>
> Reviewed-by: Mike Klein <mtklein@google.com>
TBR=mtklein@google.com,benjaminwagner@google.com,ethannicholas@google.com
Change-Id: I0a33060c7c42c7b44c5c13d443ac42958291c2f1
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/20962
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Diffstat (limited to 'src/sksl/SkSLIRGenerator.cpp')
-rw-r--r-- | src/sksl/SkSLIRGenerator.cpp | 164 |
1 files changed, 19 insertions, 145 deletions
diff --git a/src/sksl/SkSLIRGenerator.cpp b/src/sksl/SkSLIRGenerator.cpp index 78672cb52e..159ede46e2 100644 --- a/src/sksl/SkSLIRGenerator.cpp +++ b/src/sksl/SkSLIRGenerator.cpp @@ -42,7 +42,6 @@ #include "ir/SkSLPostfixExpression.h" #include "ir/SkSLPrefixExpression.h" #include "ir/SkSLReturnStatement.h" -#include "ir/SkSLSetting.h" #include "ir/SkSLSwitchCase.h" #include "ir/SkSLSwitchStatement.h" #include "ir/SkSLSwizzle.h" @@ -105,11 +104,9 @@ IRGenerator::IRGenerator(const Context* context, std::shared_ptr<SymbolTable> sy ErrorReporter& errorReporter) : fContext(*context) , fCurrentFunction(nullptr) -, fRootSymbolTable(symbolTable) -, fSymbolTable(symbolTable) +, fSymbolTable(std::move(symbolTable)) , fLoopLevel(0) , fSwitchLevel(0) -, fTmpCount(0) , fErrors(errorReporter) {} void IRGenerator::pushSymbolTable() { @@ -120,10 +117,8 @@ void IRGenerator::popSymbolTable() { fSymbolTable = fSymbolTable->fParent; } -static void fill_caps(const SKSL_CAPS_CLASS& caps, - std::unordered_map<String, Program::Settings::Value>* capsMap) { -#define CAP(name) capsMap->insert(std::make_pair(String(#name), \ - Program::Settings::Value(caps.name()))); +static void fill_caps(const SKSL_CAPS_CLASS& caps, std::unordered_map<String, CapValue>* capsMap) { +#define CAP(name) capsMap->insert(std::make_pair(String(#name), CapValue(caps.name()))); CAP(fbFetchSupport); CAP(fbFetchNeedsCustomOutput); CAP(bindlessTextureSupport); @@ -140,7 +135,6 @@ static void fill_caps(const SKSL_CAPS_CLASS& caps, CAP(mustEnableSpecificAdvBlendEqs); CAP(mustDeclareFragmentShaderOutput); CAP(canUseAnyFunctionInShader); - CAP(floatPrecisionVaries); #undef CAP } @@ -679,12 +673,7 @@ void IRGenerator::convertFunction(const ASTFunction& f, bool needInvocationIDWorkaround = fSettings->fCaps && fSettings->fCaps->mustImplementGSInvocationsWithLoop() && fInvocations != -1 && f.fName == "main"; - ASSERT(!fExtraVars.size()); std::unique_ptr<Block> body = this->convertBlock(*f.fBody); - for (auto& v : fExtraVars) { - body->fStatements.insert(body->fStatements.begin(), std::move(v)); - } - fExtraVars.clear(); fCurrentFunction = nullptr; if (!body) { return; @@ -856,7 +845,6 @@ std::unique_ptr<Expression> IRGenerator::convertIdentifier(const ASTIdentifier& } case Symbol::kVariable_Kind: { const Variable* var = (const Variable*) result; -#ifndef SKSL_STANDALONE if (var->fModifiers.fLayout.fBuiltin == SK_FRAGCOORD_BUILTIN) { fInputs.fFlipY = true; if (fSettings->fFlipY && @@ -865,7 +853,6 @@ std::unique_ptr<Expression> IRGenerator::convertIdentifier(const ASTIdentifier& fInputs.fRTHeight = true; } } -#endif // default to kRead_RefKind; this will be corrected later if the variable is written to return std::unique_ptr<VariableReference>(new VariableReference( identifier.fPosition, @@ -889,13 +876,9 @@ std::unique_ptr<Expression> IRGenerator::convertIdentifier(const ASTIdentifier& default: ABORT("unsupported symbol type %d\n", result->fKind); } -} -std::unique_ptr<Section> IRGenerator::convertSection(const ASTSection& s) { - return std::unique_ptr<Section>(new Section(s.fPosition, s.fName, s.fArgument, s.fText)); } - std::unique_ptr<Expression> IRGenerator::coerce(std::unique_ptr<Expression> expr, const Type& type) { if (!expr) { @@ -921,9 +904,6 @@ std::unique_ptr<Expression> IRGenerator::coerce(std::unique_ptr<Expression> expr ASSERT(ctor); return this->call(Position(), std::move(ctor), std::move(args)); } - if (type == *fContext.fColorSpaceXform_Type && expr->fType == *fContext.fMat4x4_Type) { - return expr; - } std::vector<std::unique_ptr<Expression>> args; args.push_back(std::move(expr)); return std::unique_ptr<Expression>(new Constructor(Position(), type, std::move(args))); @@ -1352,7 +1332,7 @@ std::unique_ptr<Expression> IRGenerator::call(Position position, return nullptr; } if (arguments[i] && (function.fParameters[i]->fModifiers.fFlags & Modifiers::kOut_Flag)) { - this->markWrittenTo(*arguments[i], + this->markWrittenTo(*arguments[i], function.fParameters[i]->fModifiers.fFlags & Modifiers::kIn_Flag); } } @@ -1393,87 +1373,6 @@ bool IRGenerator::determineCallCost(const FunctionDeclaration& function, return true; } -std::unique_ptr<Expression> IRGenerator::applyColorSpace(std::unique_ptr<Expression> texture, - const Variable* xform) { - // Before: - // vec4 color = texture(img, coords, xform); - // After: - // vec4 tmp; - // vec4 color = (tmp = texture(img, coords) , - // xform != mat4(1) ? - // vec4(clamp((xform * vec4(tmp.rgb, 1.0)).rgb, 0.0, tmp.a), tmp.a) : - // tmp); - - // a few macros to keep line lengths manageable - #define EXPR std::unique_ptr<Expression> - #define REF(v) EXPR(new VariableReference(p, *v)) - #define FLOAT(x) EXPR(new FloatLiteral(fContext, p, x)) - using std::move; - Position p = Position(); - // vec4 tmp; - Variable* tmp = new Variable(p, Modifiers(), "_tmp" + to_string(fTmpCount++), texture->fType, - Variable::kLocal_Storage); - fRootSymbolTable->takeOwnership(tmp); - std::vector<std::unique_ptr<VarDeclaration>> decls; - decls.emplace_back(new VarDeclaration(tmp, std::vector<std::unique_ptr<Expression>>(), - nullptr)); - const Type& type = texture->fType; - fExtraVars.emplace_back(new VarDeclarationsStatement(std::unique_ptr<VarDeclarations>( - new VarDeclarations(p, &type, move(decls))))); - // tmp = texture - EXPR assignment = EXPR(new BinaryExpression(p, - EXPR(new VariableReference(p, *tmp, - VariableReference::kWrite_RefKind)), - Token::EQ, - move(texture), type)); - // 1.0 - std::vector<EXPR> matArgs; - matArgs.push_back(FLOAT(1.0)); - // mat4(1.0) - EXPR mat = EXPR(new Constructor(p, *fContext.fMat4x4_Type, move(matArgs))); - // <xform> != mat4(1.0) - EXPR matNeq = EXPR(new BinaryExpression(p, REF(xform), Token::NEQ, move(mat), - *fContext.fBool_Type)); - // tmp.rgb - std::vector<int> rgb { 0, 1, 2 }; - EXPR tmpRgb = EXPR(new Swizzle(fContext, REF(tmp), rgb)); - // vec4(tmp.rgb, 1.0) - std::vector<EXPR> tmpVecArgs; - tmpVecArgs.push_back(move(tmpRgb)); - tmpVecArgs.push_back(FLOAT(1.0)); - EXPR tmpVec = EXPR(new Constructor(p, *fContext.fVec4_Type, move(tmpVecArgs))); - // xform * vec4(tmp.rgb, 1.0) - EXPR mul = EXPR(new BinaryExpression(p, REF(xform), Token::STAR, move(tmpVec), - *fContext.fVec4_Type)); - // (xform * vec4(tmp.rgb, 1.0)).rgb - EXPR mulRGB = EXPR(new Swizzle(fContext, std::move(mul), rgb)); - // tmp.a - std::vector<int> a { 3 }; - EXPR tmpA = EXPR(new Swizzle(fContext, REF(tmp), a)); - // clamp((xform * vec4(tmp.rgb, 1.0)).rgb, 0.0, tmp.a) - EXPR clamp = this->convertIdentifier(ASTIdentifier(p, "clamp")); - std::vector<EXPR> clampArgs; - clampArgs.push_back(move(mulRGB)); - clampArgs.push_back(FLOAT(0)); - clampArgs.push_back(move(tmpA)); - EXPR clampCall = this->call(p, move(clamp), move(clampArgs)); - // tmp.a - tmpA = EXPR(new Swizzle(fContext, REF(tmp), a)); - // vec4(clamp((xform * vec4(tmp.rgb, 1.0)).rgb, 0.0, tmp.a), tmp.a) - std::vector<EXPR> finalVecArgs; - finalVecArgs.push_back(move(clampCall)); - finalVecArgs.push_back(move(tmpA)); - EXPR finalVec = EXPR(new Constructor(p, *fContext.fVec4_Type, move(finalVecArgs))); - // xform != mat4(1) ? vec4(clamp((xform * vec4(tmp.rgb, 1.0)).rgb, 0.0, tmp.a), tmp.a) : tmp) - EXPR ternary = EXPR(new TernaryExpression(p, move(matNeq), move(finalVec), REF(tmp))); - // (tmp = texture , - // xform != mat4(1) ? vec4(clamp((xform * vec4(tmp.rgb, 1.0)).rgb, 0.0, tmp.a), tmp.a) : tmp)) - return EXPR(new BinaryExpression(p, move(assignment), Token::COMMA, move(ternary), type)); - #undef EXPR - #undef REF - #undef FLOAT -} - std::unique_ptr<Expression> IRGenerator::call(Position position, std::unique_ptr<Expression> functionValue, std::vector<std::unique_ptr<Expression>> arguments) { @@ -1487,17 +1386,6 @@ std::unique_ptr<Expression> IRGenerator::call(Position position, return nullptr; } FunctionReference* ref = (FunctionReference*) functionValue.get(); - if (ref->fFunctions[0]->fName == "texture" && - arguments.back()->fType == *fContext.fColorSpaceXform_Type) { - std::unique_ptr<Expression> colorspace = std::move(arguments.back()); - ASSERT(colorspace->fKind == Expression::kVariableReference_Kind); - arguments.pop_back(); - return this->applyColorSpace(this->call(position, - std::move(functionValue), - std::move(arguments)), - &((VariableReference&) *colorspace).fVariable); - } - int bestCost = INT_MAX; const FunctionDeclaration* best = nullptr; if (ref->fFunctions.size() > 1) { @@ -1563,7 +1451,7 @@ std::unique_ptr<Expression> IRGenerator::convertNumberConstructor( args[0]->fType.description() + "')"); return nullptr; } - return std::unique_ptr<Expression>(new Constructor(position, type, std::move(args))); + return std::unique_ptr<Expression>(new Constructor(position, std::move(type), std::move(args))); } int component_count(const Type& type) { @@ -1585,7 +1473,8 @@ std::unique_ptr<Expression> IRGenerator::convertCompoundConstructor( if (type.kind() == Type::kMatrix_Kind && args.size() == 1 && args[0]->fType.kind() == Type::kMatrix_Kind) { // matrix from matrix is always legal - return std::unique_ptr<Expression>(new Constructor(position, type, std::move(args))); + return std::unique_ptr<Expression>(new Constructor(position, std::move(type), + std::move(args))); } int actual = 0; int expected = type.rows() * type.columns(); @@ -1622,7 +1511,7 @@ std::unique_ptr<Expression> IRGenerator::convertCompoundConstructor( return nullptr; } } - return std::unique_ptr<Expression>(new Constructor(position, type, std::move(args))); + return std::unique_ptr<Expression>(new Constructor(position, std::move(type), std::move(args))); } std::unique_ptr<Expression> IRGenerator::convertConstructor( @@ -1645,7 +1534,8 @@ std::unique_ptr<Expression> IRGenerator::convertConstructor( return nullptr; } } - return std::unique_ptr<Expression>(new Constructor(position, type, std::move(args))); + return std::unique_ptr<Expression>(new Constructor(position, std::move(type), + std::move(args))); } else if (kind == Type::kVector_Kind || kind == Type::kMatrix_Kind) { return this->convertCompoundConstructor(position, type, std::move(args)); } else { @@ -1837,21 +1727,16 @@ std::unique_ptr<Expression> IRGenerator::getCap(Position position, String name) fErrors.error(position, "unknown capability flag '" + name + "'"); return nullptr; } - String fullName = "sk_Caps." + name; - return std::unique_ptr<Expression>(new Setting(position, fullName, - found->second.literal(fContext, position))); -} - -std::unique_ptr<Expression> IRGenerator::getArg(Position position, String name) { - auto found = fSettings->fArgs.find(name); - if (found == fSettings->fArgs.end()) { - fErrors.error(position, "unknown argument '" + name + "'"); - return nullptr; + switch (found->second.fKind) { + case CapValue::kBool_Kind: + return std::unique_ptr<Expression>(new BoolLiteral(fContext, position, + (bool) found->second.fValue)); + case CapValue::kInt_Kind: + return std::unique_ptr<Expression>(new IntLiteral(fContext, position, + found->second.fValue)); } - String fullName = "sk_Args." + name; - return std::unique_ptr<Expression>(new Setting(position, - fullName, - found->second.literal(fContext, position))); + ASSERT(false); + return nullptr; } std::unique_ptr<Expression> IRGenerator::convertSuffixExpression( @@ -1895,10 +1780,6 @@ std::unique_ptr<Expression> IRGenerator::convertSuffixExpression( return this->getCap(expression.fPosition, ((ASTFieldSuffix&) *expression.fSuffix).fField); } - if (base->fType == *fContext.fSkArgs_Type) { - return this->getArg(expression.fPosition, - ((ASTFieldSuffix&) *expression.fSuffix).fField); - } switch (base->fType.kind()) { case Type::kVector_Kind: return this->convertSwizzle(std::move(base), @@ -2043,13 +1924,6 @@ void IRGenerator::convertProgram(String text, } break; } - case ASTDeclaration::kSection_Kind: { - std::unique_ptr<Section> s = this->convertSection((ASTSection&) decl); - if (s) { - out->push_back(std::move(s)); - } - break; - } case ASTDeclaration::kPrecision_Kind: { *defaultPrecision = ((ASTPrecision&) decl).fPrecision; break; |