aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/ProcessorTest.cpp
diff options
context:
space:
mode:
authorGravatar Ethan Nicholas <ethannicholas@google.com>2017-01-27 15:34:34 +0000
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-01-27 15:34:43 +0000
commit052fd5158f7f85e478a9f87c45fecaacf7d0f5f3 (patch)
tree1dd49a45fbbaea5874cbc6d68fb8adf0994a1351 /tests/ProcessorTest.cpp
parent85eb4226a4cd8c10a0e3f3ba2f3a60efbb2dd61b (diff)
Revert "Start of rewrite of GrFragmentProcessor optimizations."
This reverts commit 85eb4226a4cd8c10a0e3f3ba2f3a60efbb2dd61b. Reason for revert: test failures on Windows, e.g. https://chromium-swarm.appspot.com/task?id=33f9527484414110&refresh=10 Original change's description: > Start of rewrite of GrFragmentProcessor optimizations. > > This adds a replacement for computeInvariantOutput buts does not use it yet. The replacement allows for three types of optimizations: > > * known input color -> known output color for GrFP elimination > * tracking of whether all color processors modulate their input for the "tweak alpha" optimziation > * opaqueness tracking > > This loses some of the generality of computInvariantOutput. It does not track the known output status of individual color components (other than opaque alpha). It does not track whether GrFragmentProcessors read their input color. It doesn't allow a processor that will receive non-constant output to advertise that it produces a constant output. These could probably be added back in the unlikely case that they prove valuable. > > Unlike computeInvariantOutput the optimizations are decided at instantiation time and constant colors are expressed as GrColor4f rather than GrColor. > > Change-Id: I684d3f9050693dde2d28154fa695e049ed8cf61a > Reviewed-on: https://skia-review.googlesource.com/7481 > Reviewed-by: Greg Daniel <egdaniel@google.com> > Commit-Queue: Brian Salomon <bsalomon@google.com> > TBR=egdaniel@google.com,bsalomon@google.com,brianosman@google.com NOPRESUBMIT=true NOTREECHECKS=true NOTRY=true Change-Id: I2390df257456013fa74137cb5d7b5a93820c291e Reviewed-on: https://skia-review.googlesource.com/7652 Commit-Queue: Ethan Nicholas <ethannicholas@google.com> Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Diffstat (limited to 'tests/ProcessorTest.cpp')
-rw-r--r--tests/ProcessorTest.cpp141
1 files changed, 2 insertions, 139 deletions
diff --git a/tests/ProcessorTest.cpp b/tests/ProcessorTest.cpp
index 0748e71337..398e702f7e 100644
--- a/tests/ProcessorTest.cpp
+++ b/tests/ProcessorTest.cpp
@@ -70,7 +70,7 @@ public:
private:
TestFP(const SkTArray<sk_sp<GrTexture>>& textures, const SkTArray<sk_sp<GrBuffer>>& buffers,
const SkTArray<Image>& images)
- : INHERITED(kNone_OptimizationFlags), fSamplers(4), fBuffers(4), fImages(4) {
+ : fSamplers(4), fBuffers(4), fImages(4) {
for (const auto& texture : textures) {
this->addTextureSampler(&fSamplers.emplace_back(texture.get()));
}
@@ -83,8 +83,7 @@ private:
}
}
- TestFP(sk_sp<GrFragmentProcessor> child)
- : INHERITED(kNone_OptimizationFlags), fSamplers(4), fBuffers(4), fImages(4) {
+ TestFP(sk_sp<GrFragmentProcessor> child) : fSamplers(4), fBuffers(4), fImages(4) {
this->registerChildProcessor(std::move(child));
}
@@ -107,7 +106,6 @@ private:
GrTAllocator<TextureSampler> fSamplers;
GrTAllocator<BufferAccess> fBuffers;
GrTAllocator<ImageStorageAccess> fImages;
- typedef GrFragmentProcessor INHERITED;
};
}
@@ -232,139 +230,4 @@ DEF_GPUTEST_FOR_ALL_CONTEXTS(ProcessorRefTest, reporter, ctxInfo) {
}
}
}
-
-// This test uses the random GrFragmentProcessor test factory, which relies on static initializers.
-#if SK_ALLOW_STATIC_GLOBAL_INITIALIZERS
-
-static GrColor texel_color(int i, int j) {
- SkASSERT((unsigned)i < 256 && (unsigned)j < 256);
- GrColor color = GrColorPackRGBA(j, (uint8_t)(i + j), (uint8_t)(2 * j - i), i);
- return GrPremulColor(color);
-}
-
-static GrColor4f texel_color4f(int i, int j) { return GrColor4f::FromGrColor(texel_color(i, j)); }
-
-DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ProcessorOptimizationValidationTest, reporter, ctxInfo) {
- GrContext* context = ctxInfo.grContext();
- using FPFactory = GrProcessorTestFactory<GrFragmentProcessor>;
- SkRandom random;
- sk_sp<GrRenderTargetContext> rtc = context->makeRenderTargetContext(
- SkBackingFit::kExact, 256, 256, kRGBA_8888_GrPixelConfig, nullptr);
- GrSurfaceDesc desc;
- desc.fWidth = 256;
- desc.fHeight = 256;
- desc.fFlags = kRenderTarget_GrSurfaceFlag;
- desc.fConfig = kRGBA_8888_GrPixelConfig;
- sk_sp<GrTexture> tex0(context->textureProvider()->createTexture(desc, SkBudgeted::kYes));
- desc.fConfig = kAlpha_8_GrPixelConfig;
- sk_sp<GrTexture> tex1(context->textureProvider()->createTexture(desc, SkBudgeted::kYes));
- GrTexture* textures[] = {tex0.get(), tex1.get()};
- GrProcessorTestData testData(&random, context, rtc.get(), textures);
-
- std::unique_ptr<GrColor> data(new GrColor[256 * 256]);
- for (int y = 0; y < 256; ++y) {
- for (int x = 0; x < 256; ++x) {
- data.get()[256 * y + x] = texel_color(x, y);
- }
- }
- desc.fConfig = kRGBA_8888_GrPixelConfig;
- sk_sp<GrTexture> dataTexture(context->textureProvider()->createTexture(
- desc, SkBudgeted::kYes, data.get(), 256 * sizeof(GrColor)));
-
- // Because processors factories configure themselves in random ways, this is not exhaustive.
- for (int i = 0; i < FPFactory::Count(); ++i) {
- int timesToInvokeFactory = 5;
- // Increase the number of attempts if the FP has child FPs since optimizations likely depend
- // on child optimizations being present.
- sk_sp<GrFragmentProcessor> fp = FPFactory::MakeIdx(i, &testData);
- for (int j = 0; j < fp->numChildProcessors(); ++j) {
- // This value made a reasonable trade off between time and coverage when this test was
- // written.
- timesToInvokeFactory *= FPFactory::Count() / 2;
- }
- for (int j = 0; j < timesToInvokeFactory; ++j) {
- fp = FPFactory::MakeIdx(i, &testData);
- if (!fp->hasConstantOutputForConstantInput() && !fp->preservesOpaqueInput() &&
- !fp->modulatesInput()) {
- continue;
- }
- GrPaint paint;
- paint.addColorTextureProcessor(dataTexture.get(), nullptr, SkMatrix::I());
- paint.addColorFragmentProcessor(fp);
- paint.setPorterDuffXPFactory(SkBlendMode::kSrc);
- rtc->drawRect(GrNoClip(), std::move(paint), GrAA::kNo, SkMatrix::I(),
- SkRect::MakeWH(256.f, 256.f));
- memset(data.get(), 0x0, sizeof(GrColor) * 256 * 256);
- rtc->readPixels(
- SkImageInfo::Make(256, 256, kRGBA_8888_SkColorType, kPremul_SkAlphaType),
- data.get(), 0, 0, 0);
- bool passing = true;
- if (0) { // Useful to see what FPs are being tested.
- SkString children;
- for (int c = 0; c < fp->numChildProcessors(); ++c) {
- if (!c) {
- children.append("(");
- }
- children.append(fp->childProcessor(c).name());
- children.append(c == fp->numChildProcessors() - 1 ? ")" : ", ");
- }
- SkDebugf("%s %s\n", fp->name(), children.c_str());
- }
- for (int y = 0; y < 256 && passing; ++y) {
- for (int x = 0; x < 256 && passing; ++x) {
- GrColor input = texel_color(x, y);
- GrColor output = data.get()[y * 256 + x];
- if (fp->modulatesInput()) {
- // A modulating processor is allowed to modulate either the input color or
- // just the input alpha.
- bool legalColorModulation =
- GrColorUnpackA(output) <= GrColorUnpackA(input) &&
- GrColorUnpackR(output) <= GrColorUnpackR(input) &&
- GrColorUnpackG(output) <= GrColorUnpackG(input) &&
- GrColorUnpackB(output) <= GrColorUnpackB(input);
- bool legalAlphaModulation =
- GrColorUnpackA(output) <= GrColorUnpackA(input) &&
- GrColorUnpackR(output) <= GrColorUnpackA(input) &&
- GrColorUnpackG(output) <= GrColorUnpackA(input) &&
- GrColorUnpackB(output) <= GrColorUnpackA(input);
- if (!legalColorModulation && !legalAlphaModulation) {
- ERRORF(reporter,
- "\"Modulating\" processor %s made color/alpha value larger. "
- "Input: 0x%0x8, Output: 0x%08x.",
- fp->name(), input, output);
- passing = false;
- }
- }
- GrColor4f input4f = texel_color4f(x, y);
- GrColor4f output4f = GrColor4f::FromGrColor(output);
- GrColor4f expected4f;
- if (fp->hasConstantOutputForConstantInput(input4f, &expected4f)) {
- float rDiff = fabsf(output4f.fRGBA[0] - expected4f.fRGBA[0]);
- float gDiff = fabsf(output4f.fRGBA[1] - expected4f.fRGBA[1]);
- float bDiff = fabsf(output4f.fRGBA[2] - expected4f.fRGBA[2]);
- float aDiff = fabsf(output4f.fRGBA[3] - expected4f.fRGBA[3]);
- static constexpr float kTol = 3 / 255.f;
- if (rDiff > kTol || gDiff > kTol || bDiff > kTol || aDiff > kTol) {
- ERRORF(reporter,
- "Processor %s claimed output for const input doesn't match "
- "actual output.",
- fp->name());
- passing = false;
- }
- }
- if (GrColorIsOpaque(input) && fp->preservesOpaqueInput() &&
- !GrColorIsOpaque(output)) {
- ERRORF(reporter,
- "Processor %s claimed opaqueness is preserved but it is not. Input: "
- "0x%0x8, Output: 0x%08x.",
- fp->name(), input, output);
- passing = false;
- }
- }
- }
- }
- }
-}
-#endif
-
#endif