diff options
author | Brian Osman <brianosman@google.com> | 2017-10-19 12:54:52 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-10-23 15:27:12 +0000 |
commit | 1cb41717bc4a44272eab48bd47ca7579425dc22e (patch) | |
tree | b8aa968f554069942403ceaa4d3e7ba9c3eb736e /src/sksl | |
parent | e25d119709899d3cb101a6de5fc901baf04d46db (diff) |
Remove color space xform support from SkSL
Bug: skia:
Change-Id: Ia50c1f750e4626211f012ae7543db126b10134c3
Reviewed-on: https://skia-review.googlesource.com/61906
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Diffstat (limited to 'src/sksl')
-rw-r--r-- | src/sksl/README | 4 | ||||
-rw-r--r-- | src/sksl/SkSLCPPCodeGenerator.cpp | 63 | ||||
-rw-r--r-- | src/sksl/SkSLCPPCodeGenerator.h | 1 | ||||
-rw-r--r-- | src/sksl/SkSLCompiler.cpp | 1 | ||||
-rw-r--r-- | src/sksl/SkSLContext.h | 2 | ||||
-rw-r--r-- | src/sksl/SkSLHCodeGenerator.cpp | 5 | ||||
-rw-r--r-- | src/sksl/SkSLIRGenerator.cpp | 27 | ||||
-rw-r--r-- | src/sksl/SkSLIRGenerator.h | 6 | ||||
-rw-r--r-- | src/sksl/sksl_fp.include | 2 |
9 files changed, 6 insertions, 105 deletions
diff --git a/src/sksl/README b/src/sksl/README index d33217b7ee..1fdf09ffd3 100644 --- a/src/sksl/README +++ b/src/sksl/README @@ -110,10 +110,6 @@ Within an '.fp' fragment processor file: coordinates. sk_TransformedCoords2D[0] is equivalent to calling fragBuilder->ensureCoords2D(args.fTransformedCoords[0]) (and the result is cached, so you need not worry about using the value repeatedly). -* 'colorSpaceXform' is a supported type. It is reflected within SkSL as a mat4, - and on the C++ side as sk_sp<GrColorSpaceXform>. -* the texture() function can be passed a colorSpaceXform as an additional - parameter * Uniform variables support an additional 'when' layout key. 'layout(when=foo) uniform int x;' means that this uniform will only be emitted when the 'foo' expression is true. diff --git a/src/sksl/SkSLCPPCodeGenerator.cpp b/src/sksl/SkSLCPPCodeGenerator.cpp index 0b2ef78016..b5362bf2b7 100644 --- a/src/sksl/SkSLCPPCodeGenerator.cpp +++ b/src/sksl/SkSLCPPCodeGenerator.cpp @@ -13,8 +13,7 @@ namespace SkSL { static bool needs_uniform_var(const Variable& var) { - return (var.fModifiers.fFlags & Modifiers::kUniform_Flag) && - var.fType.fName != "colorSpaceXform"; + return (var.fModifiers.fFlags & Modifiers::kUniform_Flag); } CPPCodeGenerator::CPPCodeGenerator(const Context* context, const Program* program, @@ -116,9 +115,6 @@ void CPPCodeGenerator::writeIndexExpression(const IndexExpression& i) { } static String default_value(const Type& type) { - if (type.fName == "colorSpaceXform") { - return "float4x4(1.0)"; - } switch (type.kind()) { case Type::kScalar_Kind: return "0"; case Type::kVector_Kind: return type.name() + "(0)"; @@ -224,17 +220,8 @@ void CPPCodeGenerator::writeVariableReference(const VariableReference& ref) { if (ref.fVariable.fModifiers.fFlags & Modifiers::kUniform_Flag) { this->write("%s"); String name = ref.fVariable.fName; - String var; - if (ref.fVariable.fType == *fContext.fColorSpaceXform_Type) { - ASSERT(fNeedColorSpaceHelper); - var = String::printf("fColorSpaceHelper.isValid() ? " - "args.fUniformHandler->getUniformCStr(" - "fColorSpaceHelper.gamutXformUniform()) : \"%s\"", - default_value(ref.fVariable.fType).c_str()); - } else { - var = String::printf("args.fUniformHandler->getUniformCStr(%sVar)", - HCodeGenerator::FieldName(name.c_str()).c_str()); - } + String var = String::printf("args.fUniformHandler->getUniformCStr(%sVar)", + HCodeGenerator::FieldName(name.c_str()).c_str()); String code; if (ref.fVariable.fModifiers.fLayout.fWhen.size()) { code = String::printf("%sVar.isValid() ? %s : \"%s\"", @@ -300,21 +287,6 @@ void CPPCodeGenerator::writeFunctionCall(const FunctionCall& c) { fFormatArgs.push_back(childName + ".c_str()"); return; } - if (c.fFunction.fBuiltin && c.fFunction.fName == "COLORSPACE") { - String tmpVar = "_tmpVar" + to_string(++fVarCount); - fFunctionHeader += "half4 " + tmpVar + ";"; - ASSERT(c.fArguments.size() == 2); - this->write("%s"); - fFormatArgs.push_back("fColorSpaceHelper.isValid() ? \"(" + tmpVar + " = \" : \"\""); - this->writeExpression(*c.fArguments[0], kTopLevel_Precedence); - ASSERT(c.fArguments[1]->fKind == Expression::kVariableReference_Kind); - String xform("args.fUniformHandler->getUniformCStr(fColorSpaceHelper.gamutXformUniform())"); - this->write("%s"); - fFormatArgs.push_back("fColorSpaceHelper.isValid() ? SkStringPrintf(\", " - "half4(clamp((%s * half4(" + tmpVar + ".rgb, 1.0)).rgb, 0.0, " + - tmpVar + ".a), " + tmpVar + ".a))\", " + xform + ").c_str() : \"\""); - return; - } INHERITED::writeFunctionCall(c); if (c.fFunction.fBuiltin && c.fFunction.fName == "texture") { this->write(".%s"); @@ -409,8 +381,7 @@ void CPPCodeGenerator::addUniform(const Variable& var) { type = "kFloat4_GrSLType"; } else if (var.fType == *fContext.fHalf4_Type) { type = "kHalf4_GrSLType"; - } else if (var.fType == *fContext.fFloat4x4_Type || - var.fType == *fContext.fColorSpaceXform_Type) { + } else if (var.fType == *fContext.fFloat4x4_Type) { type = "kFloat4x4_GrSLType"; } else if (var.fType == *fContext.fHalf4x4_Type) { type = "kHalf4x4_GrSLType"; @@ -534,15 +505,6 @@ bool CPPCodeGenerator::writeEmitCode(std::vector<const Variable*>& uniforms) { this->writePrivateVarValues(); for (const auto u : uniforms) { this->addUniform(*u); - if (u->fType == *fContext.fColorSpaceXform_Type) { - if (fNeedColorSpaceHelper) { - fErrors.error(u->fOffset, "only a single ColorSpaceXform is supported"); - } - fNeedColorSpaceHelper = true; - this->writef(" fColorSpaceHelper.emitCode(args.fUniformHandler, " - "_outer.%s().get());\n", - String(u->fName).c_str()); - } } this->writeSection(EMIT_CODE_SECTION); OutputStream* old = fOut; @@ -584,12 +546,6 @@ void CPPCodeGenerator::writeSetData(std::vector<const Variable*>& uniforms) { " %s.setMatrix4f(%sVar, %sValue);\n", name, name, name, pdman, HCodeGenerator::FieldName(name).c_str(), name); - } else if (u->fType == *fContext.fColorSpaceXform_Type) { - ASSERT(fNeedColorSpaceHelper); - this->writef(" if (fColorSpaceHelper.isValid()) {\n" - " fColorSpaceHelper.setData(%s, _outer.%s().get());\n" - " }\n", - pdman, name); } else if (u->fType == *fContext.fFragmentProcessor_Type) { // do nothing } else { @@ -702,11 +658,6 @@ void CPPCodeGenerator::writeGetKey() { for (const auto& param : fSectionAndParameterHelper.getParameters()) { String nameString(param->fName); const char* name = nameString.c_str(); - if (param->fType == *fContext.fColorSpaceXform_Type) { - this->writef(" b->add32(GrColorSpaceXform::XformKey(%s.get()));\n", - HCodeGenerator::FieldName(name).c_str()); - continue; - } if (param->fModifiers.fLayout.fKey != Layout::kNo_Key && (param->fModifiers.fFlags & Modifiers::kUniform_Flag)) { fErrors.error(param->fOffset, @@ -770,8 +721,7 @@ bool CPPCodeGenerator::generateCode() { this->writef("#include \"%s.h\"\n" "#if SK_SUPPORT_GPU\n", fullName); this->writeSection(CPP_SECTION); - this->writef("#include \"glsl/GrGLSLColorSpaceXformHelper.h\"\n" - "#include \"glsl/GrGLSLFragmentProcessor.h\"\n" + this->writef("#include \"glsl/GrGLSLFragmentProcessor.h\"\n" "#include \"glsl/GrGLSLFragmentShaderBuilder.h\"\n" "#include \"glsl/GrGLSLProgramBuilder.h\"\n" "#include \"SkSLCPP.h\"\n" @@ -796,9 +746,6 @@ bool CPPCodeGenerator::generateCode() { HCodeGenerator::FieldName(String(param->fName).c_str()).c_str()); } } - if (fNeedColorSpaceHelper) { - this->write(" GrGLSLColorSpaceXformHelper fColorSpaceHelper;\n"); - } this->writef("};\n" "GrGLSLFragmentProcessor* %s::onCreateGLSLInstance() const {\n" " return new GrGLSL%s();\n" diff --git a/src/sksl/SkSLCPPCodeGenerator.h b/src/sksl/SkSLCPPCodeGenerator.h index a93b885a5c..2766522ef5 100644 --- a/src/sksl/SkSLCPPCodeGenerator.h +++ b/src/sksl/SkSLCPPCodeGenerator.h @@ -88,7 +88,6 @@ private: String fExtraEmitCodeCode; std::vector<String> fFormatArgs; std::set<int> fWrittenTransformedCoords; - bool fNeedColorSpaceHelper = false; // if true, we are writing a C++ expression instead of a GLSL expression bool fCPPMode = false; diff --git a/src/sksl/SkSLCompiler.cpp b/src/sksl/SkSLCompiler.cpp index 23c09ac1c1..06c43485f4 100644 --- a/src/sksl/SkSLCompiler.cpp +++ b/src/sksl/SkSLCompiler.cpp @@ -184,7 +184,6 @@ Compiler::Compiler(Flags flags) ADD_TYPE(SamplerCubeArrayShadow); ADD_TYPE(GSampler2DArrayShadow); ADD_TYPE(GSamplerCubeArrayShadow); - ADD_TYPE(ColorSpaceXform); ADD_TYPE(FragmentProcessor); StringFragment skCapsName("sk_Caps"); diff --git a/src/sksl/SkSLContext.h b/src/sksl/SkSLContext.h index a8158be4a0..407dbf8e82 100644 --- a/src/sksl/SkSLContext.h +++ b/src/sksl/SkSLContext.h @@ -184,7 +184,6 @@ public: fBool3_Type.get(), fBool4_Type.get() })) , fSkCaps_Type(new Type("$sk_Caps")) , fSkArgs_Type(new Type("$sk_Args")) - , fColorSpaceXform_Type(new Type("colorSpaceXform", *fFloat_Type, 4, 4)) , fFragmentProcessor_Type(new Type("fragmentProcessor")) , fDefined_Expression(new Defined(*fInvalid_Type)) {} @@ -333,7 +332,6 @@ public: const std::unique_ptr<Type> fSkCaps_Type; const std::unique_ptr<Type> fSkArgs_Type; - const std::unique_ptr<Type> fColorSpaceXform_Type; const std::unique_ptr<Type> fFragmentProcessor_Type; // dummy expression used to mark that a variable has a value during dataflow analysis (when it diff --git a/src/sksl/SkSLHCodeGenerator.cpp b/src/sksl/SkSLHCodeGenerator.cpp index a4a5c9a6ac..21f4f2842c 100644 --- a/src/sksl/SkSLHCodeGenerator.cpp +++ b/src/sksl/SkSLHCodeGenerator.cpp @@ -36,8 +36,6 @@ String HCodeGenerator::ParameterType(const Context& context, const Type& type) { return "SkMatrix44"; } else if (type.kind() == Type::kSampler_Kind) { return "sk_sp<GrTextureProxy>"; - } else if (type == *context.fColorSpaceXform_Type) { - return "sk_sp<GrColorSpaceXform>"; } else if (type == *context.fFragmentProcessor_Type) { return "std::unique_ptr<GrFragmentProcessor>"; } @@ -256,8 +254,7 @@ bool HCodeGenerator::generateCode() { "#if SK_SUPPORT_GPU\n"); this->writeSection(HEADER_SECTION); this->writef("#include \"GrFragmentProcessor.h\"\n" - "#include \"GrCoordTransform.h\"\n" - "#include \"GrColorSpaceXform.h\"\n"); + "#include \"GrCoordTransform.h\"\n"); this->writef("class %s : public GrFragmentProcessor {\n" "public:\n", fFullName.c_str()); diff --git a/src/sksl/SkSLIRGenerator.cpp b/src/sksl/SkSLIRGenerator.cpp index 0c872e4676..7608c420a2 100644 --- a/src/sksl/SkSLIRGenerator.cpp +++ b/src/sksl/SkSLIRGenerator.cpp @@ -922,9 +922,6 @@ std::unique_ptr<Expression> IRGenerator::coerce(std::unique_ptr<Expression> expr ASSERT(ctor); return this->call(-1, std::move(ctor), std::move(args)); } - if (type == *fContext.fColorSpaceXform_Type && expr->fType == *fContext.fFloat4x4_Type) { - return expr; - } std::vector<std::unique_ptr<Expression>> args; args.push_back(std::move(expr)); return std::unique_ptr<Expression>(new Constructor(-1, type, std::move(args))); @@ -1435,20 +1432,6 @@ int IRGenerator::callCost(const FunctionDeclaration& function, return total; } -std::unique_ptr<Expression> IRGenerator::applyColorSpace(std::unique_ptr<Expression> texture, - std::unique_ptr<Expression> xform) { - // Before: texture(img, coords, xform); - // After: COLORSPACE(texture(img, coords), xform) - int offset = texture->fOffset; - std::vector<std::unique_ptr<Expression>> args; - args.push_back(std::move(texture)); - args.push_back(std::move(xform)); - const Symbol* colorspaceSymbol = (*fSymbolTable)["COLORSPACE"]; - ASSERT(colorspaceSymbol->fKind == Symbol::kFunctionDeclaration_Kind); - const FunctionDeclaration& colorspaceFunction = (FunctionDeclaration&) *colorspaceSymbol; - return this->call(offset, colorspaceFunction, std::move(args)); -} - std::unique_ptr<Expression> IRGenerator::call(int offset, std::unique_ptr<Expression> functionValue, std::vector<std::unique_ptr<Expression>> arguments) { @@ -1462,16 +1445,6 @@ std::unique_ptr<Expression> IRGenerator::call(int offset, 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()); - arguments.pop_back(); - return this->applyColorSpace(this->call(offset, - std::move(functionValue), - std::move(arguments)), - std::move(colorspace)); - } - int bestCost = INT_MAX; const FunctionDeclaration* best = nullptr; if (ref->fFunctions.size() > 1) { diff --git a/src/sksl/SkSLIRGenerator.h b/src/sksl/SkSLIRGenerator.h index 0a2979dd73..a1d23eec4c 100644 --- a/src/sksl/SkSLIRGenerator.h +++ b/src/sksl/SkSLIRGenerator.h @@ -156,12 +156,6 @@ private: std::unique_ptr<Block> main, std::vector<std::unique_ptr<ProgramElement>>* out); - /** - * Wraps an expression in code that applies a colorspace transformation to it. This is used - * to implement texture(sampler, coord, colorSpaceXForm). - */ - std::unique_ptr<Expression> applyColorSpace(std::unique_ptr<Expression> texture, - std::unique_ptr<Expression> xform); void fixRectSampling(std::vector<std::unique_ptr<Expression>>& arguments); void checkValid(const Expression& expr); void markWrittenTo(const Expression& expr, bool readWrite); diff --git a/src/sksl/sksl_fp.include b/src/sksl/sksl_fp.include index eacc7e802e..d407fd08f6 100644 --- a/src/sksl/sksl_fp.include +++ b/src/sksl/sksl_fp.include @@ -21,7 +21,5 @@ layout(builtin=10004) out half4 sk_OutColor; layout(builtin=10005) float2[] sk_TransformedCoords2D; layout(builtin=10006) sampler2D[] sk_TextureSamplers; -half4 COLORSPACE(half4 color, colorSpaceXform colorSpace); - half4 process(fragmentProcessor fp); ) |