Replace GrOverrideInputFragmentProcessor with a runtime FP
Change-Id: Ife4dcd5627851b2dac1ed05b38c551d5d258e39c
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/419797
Reviewed-by: Brian Salomon <bsalomon@google.com>
Reviewed-by: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/gn/gpu.gni b/gn/gpu.gni
index 0a404e0..3f7bc45 100644
--- a/gn/gpu.gni
+++ b/gn/gpu.gni
@@ -322,8 +322,6 @@
"$_src/gpu/effects/generated/GrDitherEffect.h",
"$_src/gpu/effects/generated/GrEllipseEffect.cpp",
"$_src/gpu/effects/generated/GrEllipseEffect.h",
- "$_src/gpu/effects/generated/GrOverrideInputFragmentProcessor.cpp",
- "$_src/gpu/effects/generated/GrOverrideInputFragmentProcessor.h",
"$_src/gpu/effects/generated/GrRRectBlurEffect.cpp",
"$_src/gpu/effects/generated/GrRRectBlurEffect.h",
"$_src/gpu/effects/generated/GrRectBlurEffect.cpp",
diff --git a/gn/sksl.gni b/gn/sksl.gni
index 3e18115..da040ad 100644
--- a/gn/sksl.gni
+++ b/gn/sksl.gni
@@ -214,7 +214,6 @@
"$_src/gpu/effects/GrConfigConversionEffect.fp",
"$_src/gpu/effects/GrDitherEffect.fp",
"$_src/gpu/effects/GrEllipseEffect.fp",
- "$_src/gpu/effects/GrOverrideInputFragmentProcessor.fp",
"$_src/gpu/effects/GrRRectBlurEffect.fp",
"$_src/gpu/effects/GrRectBlurEffect.fp",
"$_src/gpu/gradients/GrClampedGradientEffect.fp",
diff --git a/src/gpu/GrFragmentProcessor.cpp b/src/gpu/GrFragmentProcessor.cpp
index d6344a6..d87eb5e 100644
--- a/src/gpu/GrFragmentProcessor.cpp
+++ b/src/gpu/GrFragmentProcessor.cpp
@@ -11,7 +11,6 @@
#include "src/gpu/GrProcessorAnalysis.h"
#include "src/gpu/effects/GrBlendFragmentProcessor.h"
#include "src/gpu/effects/GrSkSLFP.h"
-#include "src/gpu/effects/generated/GrOverrideInputFragmentProcessor.h"
#include "src/gpu/glsl/GrGLSLFragmentProcessor.h"
#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
#include "src/gpu/glsl/GrGLSLProgramDataManager.h"
@@ -420,7 +419,19 @@
if (!fp) {
return nullptr;
}
- return GrOverrideInputFragmentProcessor::Make(std::move(fp), color, useUniform);
+ static auto effect = SkMakeRuntimeEffect(SkRuntimeEffect::MakeForColorFilter, R"(
+ uniform colorFilter fp; // Declared as colorFilter so we can use sample(..., color)
+ uniform half4 color;
+ half4 main(half4 inColor) {
+ return sample(fp, color);
+ }
+ )");
+ SkASSERT(SkRuntimeEffectPriv::SupportsConstantOutputForConstantInput(effect));
+ return GrSkSLFP::Make(effect, "OverrideInput", /*inputFP=*/nullptr,
+ color.isOpaque() ? GrSkSLFP::OptFlags::kPreservesOpaqueInput
+ : GrSkSLFP::OptFlags::kNone,
+ "fp", std::move(fp),
+ "color", GrSkSLFP::SpecializeIf(!useUniform, color));
}
//////////////////////////////////////////////////////////////////////////////
diff --git a/src/gpu/GrProcessor.h b/src/gpu/GrProcessor.h
index d863925..452060f 100644
--- a/src/gpu/GrProcessor.h
+++ b/src/gpu/GrProcessor.h
@@ -90,7 +90,6 @@
kGrMatrixEffect_ClassID,
kGrMeshTestProcessor_ClassID,
kGrMorphologyEffect_ClassID,
- kGrOverrideInputFragmentProcessor_ClassID,
kGrPathProcessor_ClassID,
kGrPerlinNoise2Effect_ClassID,
kGrPipelineDynamicStateTestProcessor_ClassID,
diff --git a/src/gpu/effects/GrOverrideInputFragmentProcessor.fp b/src/gpu/effects/GrOverrideInputFragmentProcessor.fp
deleted file mode 100644
index 73e0143..0000000
--- a/src/gpu/effects/GrOverrideInputFragmentProcessor.fp
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * Copyright 2019 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-// Ignores its own input color and invokes 'fp' with a constant color
-// The constant color can either be specified as a literal or as a
-// uniform, controlled by useUniform.
-
-in fragmentProcessor fp;
-layout(key) in bool useUniform;
-layout(when=useUniform, ctype=SkPMColor4f) in uniform half4 uniformColor;
-layout(when=!useUniform, key, ctype=SkPMColor4f) in half4 literalColor;
-
-@make {
- static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> fp,
- const SkPMColor4f& color,
- bool useUniform = true) {
- return std::unique_ptr<GrFragmentProcessor>(
- new GrOverrideInputFragmentProcessor(std::move(fp), useUniform, color, color));
- }
-}
-
-@class {
- static OptimizationFlags OptFlags(const std::unique_ptr<GrFragmentProcessor>& fp,
- const SkPMColor4f& color) {
- auto childFlags = ProcessorOptimizationFlags(fp.get());
- auto flags = kNone_OptimizationFlags;
- if (childFlags & kConstantOutputForConstantInput_OptimizationFlag) {
- flags |= kConstantOutputForConstantInput_OptimizationFlag;
- }
- if ((childFlags & kPreservesOpaqueInput_OptimizationFlag) && color.isOpaque()) {
- flags |= kPreservesOpaqueInput_OptimizationFlag;
- }
- return flags;
- }
-
- SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& input) const override {
- return ConstantOutputForConstantInput(this->childProcessor(0), uniformColor);
- }
-}
-
-@optimizationFlags { OptFlags(fp, useUniform ? uniformColor : literalColor) }
-
-half4 main() {
- return sample(fp, useUniform ? uniformColor : literalColor);
-}
diff --git a/src/gpu/effects/generated/GrOverrideInputFragmentProcessor.cpp b/src/gpu/effects/generated/GrOverrideInputFragmentProcessor.cpp
deleted file mode 100644
index 488ef7c..0000000
--- a/src/gpu/effects/generated/GrOverrideInputFragmentProcessor.cpp
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Copyright 2019 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-/**************************************************************************************************
- *** This file was autogenerated from GrOverrideInputFragmentProcessor.fp; do not modify.
- **************************************************************************************************/
-#include "GrOverrideInputFragmentProcessor.h"
-
-#include "src/core/SkUtils.h"
-#include "src/gpu/GrTexture.h"
-#include "src/gpu/glsl/GrGLSLFragmentProcessor.h"
-#include "src/gpu/glsl/GrGLSLFragmentShaderBuilder.h"
-#include "src/gpu/glsl/GrGLSLProgramBuilder.h"
-#include "src/sksl/SkSLCPP.h"
-#include "src/sksl/SkSLUtil.h"
-class GrGLSLOverrideInputFragmentProcessor : public GrGLSLFragmentProcessor {
-public:
- GrGLSLOverrideInputFragmentProcessor() {}
- void emitCode(EmitArgs& args) override {
- GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
- const GrOverrideInputFragmentProcessor& _outer =
- args.fFp.cast<GrOverrideInputFragmentProcessor>();
- (void)_outer;
- auto useUniform = _outer.useUniform;
- (void)useUniform;
- auto uniformColor = _outer.uniformColor;
- (void)uniformColor;
- auto literalColor = _outer.literalColor;
- (void)literalColor;
- if (useUniform) {
- uniformColorVar = args.fUniformHandler->addUniform(
- &_outer, kFragment_GrShaderFlag, kHalf4_GrSLType, "uniformColor");
- }
- SkString _input0 = SkStringPrintf(
- "%s ? %s : half4(%f, %f, %f, %f)",
- (_outer.useUniform ? "true" : "false"),
- uniformColorVar.isValid() ? args.fUniformHandler->getUniformCStr(uniformColorVar)
- : "half4(0)",
- _outer.literalColor.fR,
- _outer.literalColor.fG,
- _outer.literalColor.fB,
- _outer.literalColor.fA);
- SkString _sample0 = this->invokeChild(0, _input0.c_str(), args);
- fragBuilder->codeAppendf(
- R"SkSL(return %s;
-)SkSL",
- _sample0.c_str());
- }
-
-private:
- void onSetData(const GrGLSLProgramDataManager& pdman,
- const GrFragmentProcessor& _proc) override {
- const GrOverrideInputFragmentProcessor& _outer =
- _proc.cast<GrOverrideInputFragmentProcessor>();
- {
- if (uniformColorVar.isValid()) {
- pdman.set4fv(uniformColorVar, 1, _outer.uniformColor.vec());
- }
- }
- }
- UniformHandle uniformColorVar;
-};
-std::unique_ptr<GrGLSLFragmentProcessor> GrOverrideInputFragmentProcessor::onMakeProgramImpl()
- const {
- return std::make_unique<GrGLSLOverrideInputFragmentProcessor>();
-}
-void GrOverrideInputFragmentProcessor::onGetGLSLProcessorKey(const GrShaderCaps& caps,
- GrProcessorKeyBuilder* b) const {
- b->addBool(useUniform, "useUniform");
- if (!useUniform) {
- uint16_t red = SkFloatToHalf(literalColor.fR);
- uint16_t green = SkFloatToHalf(literalColor.fG);
- uint16_t blue = SkFloatToHalf(literalColor.fB);
- uint16_t alpha = SkFloatToHalf(literalColor.fA);
- b->add32(((uint32_t)red << 16) | green, "literalColor.rg");
- b->add32(((uint32_t)blue << 16) | alpha, "literalColor.ba");
- }
-}
-bool GrOverrideInputFragmentProcessor::onIsEqual(const GrFragmentProcessor& other) const {
- const GrOverrideInputFragmentProcessor& that = other.cast<GrOverrideInputFragmentProcessor>();
- (void)that;
- if (useUniform != that.useUniform) return false;
- if (uniformColor != that.uniformColor) return false;
- if (literalColor != that.literalColor) return false;
- return true;
-}
-GrOverrideInputFragmentProcessor::GrOverrideInputFragmentProcessor(
- const GrOverrideInputFragmentProcessor& src)
- : INHERITED(kGrOverrideInputFragmentProcessor_ClassID, src.optimizationFlags())
- , useUniform(src.useUniform)
- , uniformColor(src.uniformColor)
- , literalColor(src.literalColor) {
- this->cloneAndRegisterAllChildProcessors(src);
-}
-std::unique_ptr<GrFragmentProcessor> GrOverrideInputFragmentProcessor::clone() const {
- return std::make_unique<GrOverrideInputFragmentProcessor>(*this);
-}
-#if GR_TEST_UTILS
-SkString GrOverrideInputFragmentProcessor::onDumpInfo() const {
- return SkStringPrintf(
- "(useUniform=%s, uniformColor=half4(%f, %f, %f, %f), literalColor=half4(%f, %f, %f, "
- "%f))",
- (useUniform ? "true" : "false"),
- uniformColor.fR,
- uniformColor.fG,
- uniformColor.fB,
- uniformColor.fA,
- literalColor.fR,
- literalColor.fG,
- literalColor.fB,
- literalColor.fA);
-}
-#endif
diff --git a/src/gpu/effects/generated/GrOverrideInputFragmentProcessor.h b/src/gpu/effects/generated/GrOverrideInputFragmentProcessor.h
deleted file mode 100644
index 5d73a2a..0000000
--- a/src/gpu/effects/generated/GrOverrideInputFragmentProcessor.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Copyright 2019 Google Inc.
- *
- * Use of this source code is governed by a BSD-style license that can be
- * found in the LICENSE file.
- */
-
-/**************************************************************************************************
- *** This file was autogenerated from GrOverrideInputFragmentProcessor.fp; do not modify.
- **************************************************************************************************/
-#ifndef GrOverrideInputFragmentProcessor_DEFINED
-#define GrOverrideInputFragmentProcessor_DEFINED
-
-#include "include/core/SkM44.h"
-#include "include/core/SkTypes.h"
-
-#include "src/gpu/GrFragmentProcessor.h"
-
-class GrOverrideInputFragmentProcessor : public GrFragmentProcessor {
-public:
- static OptimizationFlags OptFlags(const std::unique_ptr<GrFragmentProcessor>& fp,
- const SkPMColor4f& color) {
- auto childFlags = ProcessorOptimizationFlags(fp.get());
- auto flags = kNone_OptimizationFlags;
- if (childFlags & kConstantOutputForConstantInput_OptimizationFlag) {
- flags |= kConstantOutputForConstantInput_OptimizationFlag;
- }
- if ((childFlags & kPreservesOpaqueInput_OptimizationFlag) && color.isOpaque()) {
- flags |= kPreservesOpaqueInput_OptimizationFlag;
- }
- return flags;
- }
-
- SkPMColor4f constantOutputForConstantInput(const SkPMColor4f& input) const override {
- return ConstantOutputForConstantInput(this->childProcessor(0), uniformColor);
- }
-
- static std::unique_ptr<GrFragmentProcessor> Make(std::unique_ptr<GrFragmentProcessor> fp,
- const SkPMColor4f& color,
- bool useUniform = true) {
- return std::unique_ptr<GrFragmentProcessor>(
- new GrOverrideInputFragmentProcessor(std::move(fp), useUniform, color, color));
- }
- GrOverrideInputFragmentProcessor(const GrOverrideInputFragmentProcessor& src);
- std::unique_ptr<GrFragmentProcessor> clone() const override;
- const char* name() const override { return "OverrideInputFragmentProcessor"; }
- bool useUniform;
- SkPMColor4f uniformColor;
- SkPMColor4f literalColor;
-
-private:
- GrOverrideInputFragmentProcessor(std::unique_ptr<GrFragmentProcessor> fp,
- bool useUniform,
- SkPMColor4f uniformColor,
- SkPMColor4f literalColor)
- : INHERITED(kGrOverrideInputFragmentProcessor_ClassID,
- (OptimizationFlags)OptFlags(fp, useUniform ? uniformColor : literalColor))
- , useUniform(useUniform)
- , uniformColor(uniformColor)
- , literalColor(literalColor) {
- this->registerChild(std::move(fp), SkSL::SampleUsage::PassThrough());
- }
- std::unique_ptr<GrGLSLFragmentProcessor> onMakeProgramImpl() const override;
- void onGetGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override;
- bool onIsEqual(const GrFragmentProcessor&) const override;
-#if GR_TEST_UTILS
- SkString onDumpInfo() const override;
-#endif
- GR_DECLARE_FRAGMENT_PROCESSOR_TEST
- using INHERITED = GrFragmentProcessor;
-};
-#endif
diff --git a/tests/SkRuntimeEffectTest.cpp b/tests/SkRuntimeEffectTest.cpp
index 278bbde..9c29383 100644
--- a/tests/SkRuntimeEffectTest.cpp
+++ b/tests/SkRuntimeEffectTest.cpp
@@ -831,7 +831,7 @@
SkTArray<uint32_t, true> key;
};
- // Constant color, but with a similar option to GrOverrideInputFragmentProcessor
+ // Constant color, but with a similar option to GrFragmentProcessor::OverrideInput
// specialize decides if the color is inserted in the SkSL as a literal, or left as a uniform
auto make_color_fp = [&](SkPMColor4f color, bool specialize) {
auto effect = SkMakeRuntimeEffect(SkRuntimeEffect::MakeForShader, R"(