Add a bench for various single color xforms

PipeA is where we want to be, and probably by filling in something
like the TODO I left in SkColorSpaceXformSteps.h?

    curr/maxrss	loops	min	median	mean	max	stddev	samples   	config	bench
      13/13  MB	49	82.8ns	83.2ns	83.2ns	84.1ns	0%	█▂▅▄▂▁▃▄▃▃	nonrendering	ColorSpaceXformBench_pipeB
      13/13  MB	1259	29.6ns	29.7ns	30.4ns	37.2ns	8%	▁▁▁▁▁▁▁▁▁█	nonrendering	ColorSpaceXformBench_pipeA
      13/13  MB	661	110ns	119ns	119ns	128ns	4%	▅▅▅▅▅▅▅▅█▁	nonrendering	ColorSpaceXformBench_steps
      13/13  MB	26	239ns	247ns	283ns	609ns	40%	▁▁█▁▁▁▁▁▁▁	nonrendering	ColorSpaceXformBench_xform

Change-Id: I98af634ab0a7a1522a5bcfde9ce3fc934d82ecf8
Reviewed-on: https://skia-review.googlesource.com/145643
Commit-Queue: Mike Klein <mtklein@google.com>
Auto-Submit: Mike Klein <mtklein@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
Mike Klein 2018-08-06 17:03:33 -04:00 committed by Skia Commit-Bot
parent 929a681e68
commit 4ed73e09d3
3 changed files with 130 additions and 0 deletions

View File

@ -0,0 +1,113 @@
/*
* Copyright 2017 Google Inc.
*
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*/
#include "../src/jumper/SkJumper.h"
#include "Benchmark.h"
#include "SkColor.h"
#include "SkColorSpaceXform.h"
#include "SkColorSpaceXformSteps.h"
#include "SkMakeUnique.h"
#include "SkPM4fPriv.h"
#include "SkRandom.h"
#include "SkRasterPipeline.h"
enum class Mode { xform, steps, pipeA, pipeB };
struct ColorSpaceXformBench : public Benchmark {
ColorSpaceXformBench(Mode mode) : fMode(mode) {}
const Mode fMode;
std::unique_ptr<SkColorSpaceXform> fXform;
std::unique_ptr<SkColorSpaceXformSteps> fSteps;
std::function<void(size_t, size_t, size_t, size_t)> fPipeA;
SkJumper_MemoryCtx fPipeSrc = {nullptr,0},
fPipeDst = {nullptr,0};
SkSTArenaAlloc<1024> fAlloc;
const char* onGetName() override {
switch (fMode) {
case Mode::xform: return "ColorSpaceXformBench_xform";
case Mode::steps: return "ColorSpaceXformBench_steps";
case Mode::pipeA: return "ColorSpaceXformBench_pipeA";
case Mode::pipeB: return "ColorSpaceXformBench_pipeB";
}
return "";
}
bool isSuitableFor(Backend backend) override { return kNonRendering_Backend == backend; }
void onDelayedSetup() override {
sk_sp<SkColorSpace> src = SkColorSpace::MakeSRGB(),
dst = SkColorSpace::MakeRGB(SkColorSpace::kSRGB_RenderTargetGamma,
SkColorSpace::kDCIP3_D65_Gamut);
fXform = SkColorSpaceXform::New(src.get(), dst.get());
fSteps = skstd::make_unique<SkColorSpaceXformSteps>(src.get(),
kOpaque_SkAlphaType,
dst.get());
SkRasterPipeline p(&fAlloc);
p.append(SkRasterPipeline::load_bgra, &fPipeSrc);
fSteps->apply(&p);
p.append(SkRasterPipeline::store_bgra, &fPipeDst);
fPipeA = p.compile();
}
void onDraw(int n, SkCanvas* canvas) override {
volatile SkColor junk = 0;
SkRandom rand;
for (int i = 0; i < n; i++) {
SkColor src = rand.nextU(),
dst;
fPipeSrc.pixels = &src;
fPipeDst.pixels = &dst;
switch (fMode) {
case Mode::xform: {
fXform->apply(SkColorSpaceXform::kBGRA_8888_ColorFormat, &dst,
SkColorSpaceXform::kBGRA_8888_ColorFormat, &src,
1, kUnpremul_SkAlphaType);
} break;
case Mode::steps: {
float rgba[4];
swizzle_rb(Sk4f_fromL32(src)).store(rgba);
fSteps->apply(rgba);
dst = Sk4f_toL32(swizzle_rb(Sk4f::Load(rgba)));
} break;
case Mode::pipeA: {
fPipeA(0,0,1,1);
} break;
case Mode::pipeB: {
SkSTArenaAlloc<1024> alloc;
SkRasterPipeline p(&alloc);
p.append(SkRasterPipeline::load_bgra, &fPipeSrc);
fSteps->apply(&p);
p.append(SkRasterPipeline::store_bgra, &fPipeDst);
p.run(0,0,1,1);
} break;
}
if (false && i == 0) {
SkDebugf("%x ~~> %x\n", src, dst);
}
junk ^= dst;
}
}
};
DEF_BENCH(return new ColorSpaceXformBench{Mode::xform};)
DEF_BENCH(return new ColorSpaceXformBench{Mode::steps};)
DEF_BENCH(return new ColorSpaceXformBench{Mode::pipeA};)
DEF_BENCH(return new ColorSpaceXformBench{Mode::pipeB};)

View File

@ -34,6 +34,7 @@ bench_sources = [
"$_bench/ColorCanvasDrawBitmapBench.cpp",
"$_bench/ColorFilterBench.cpp",
"$_bench/ColorPrivBench.cpp",
"$_bench/ColorSpaceXformBench.cpp",
"$_bench/CompositingImagesBench.cpp",
"$_bench/ControlBench.cpp",
"$_bench/CoverageBench.cpp",

View File

@ -52,4 +52,20 @@ struct SkColorSpaceXformSteps {
float src_to_dst_matrix[9]; // Apply this 3x3 column-major matrix for gamut_transform.
};
/* TODO?
struct BakedXformSteps {
SkColorSpaceXformSteps fSteps;
SkSTArenaAlloc<exactly_the_right_size> fAlloc;
std::function<void(size_t, size_t, size_t, size_t)> fXform8888,
fXformFFFF;
SkJumper_MemoryCtx fSrc = {nullptr,0},
fDst = {nullptr,0};
void apply(SkColor src , float dst[4]);
void apply(const float src[4], float dst[4]);
};
*/
#endif//SkColorSpaceXformSteps_DEFINED