Add loopSKP flag to nanobench

Adds a loopSKP flag that forces SKPBenches to draw with only 1 loop.

BUG=skia:

Review URL: https://codereview.chromium.org/1203193002
This commit is contained in:
cdalton 2015-06-25 10:51:56 -07:00 committed by Commit bot
parent b0c5071a37
commit b4022965a2
6 changed files with 26 additions and 13 deletions

View File

@ -65,6 +65,10 @@ public:
return backend != kNonRendering_Backend;
}
virtual int calculateLoops(int defaultLoops) const {
return defaultLoops;
}
// Call before draw, allows the benchmark to do setup work outside of the
// timer. When a benchmark is repeatedly drawn, this should be called once
// before the initial draw.

View File

@ -10,9 +10,9 @@
#include "SkMultiPictureDraw.h"
#include "SkSurface.h"
SKPAnimationBench::SKPAnimationBench(const char* name, const SkPicture* pic,
const SkIRect& clip, SkMatrix animationMatrix, int steps)
: INHERITED(name, pic, clip, 1.0, false)
SKPAnimationBench::SKPAnimationBench(const char* name, const SkPicture* pic, const SkIRect& clip,
SkMatrix animationMatrix, int steps, bool doLooping)
: INHERITED(name, pic, clip, 1.0, false, doLooping)
, fSteps(steps)
, fAnimationMatrix(animationMatrix)
, fName(name) {

View File

@ -17,7 +17,7 @@
class SKPAnimationBench : public SKPBench {
public:
SKPAnimationBench(const char* name, const SkPicture*, const SkIRect& devClip,
SkMatrix viewMatrix, int steps);
SkMatrix viewMatrix, int steps, bool doLooping);
protected:
const char* onGetName() override;

View File

@ -18,12 +18,13 @@ DEFINE_int32(GPUbenchTileW, 1600, "Tile width used for GPU SKP playback.");
DEFINE_int32(GPUbenchTileH, 512, "Tile height used for GPU SKP playback.");
SKPBench::SKPBench(const char* name, const SkPicture* pic, const SkIRect& clip, SkScalar scale,
bool useMultiPictureDraw)
bool useMultiPictureDraw, bool doLooping)
: fPic(SkRef(pic))
, fClip(clip)
, fScale(scale)
, fName(name)
, fUseMultiPictureDraw(useMultiPictureDraw) {
, fUseMultiPictureDraw(useMultiPictureDraw)
, fDoLooping(doLooping) {
fUniqueName.printf("%s_%.2g", name, scale); // Scale makes this unqiue for perf.skia.org traces.
if (useMultiPictureDraw) {
fUniqueName.append("_mpd");
@ -104,6 +105,7 @@ SkIPoint SKPBench::onGetSize() {
}
void SKPBench::onDraw(const int loops, SkCanvas* canvas) {
SkASSERT(fDoLooping || 1 == loops);
if (fUseMultiPictureDraw) {
for (int i = 0; i < loops; i++) {
this->drawMPDPicture();

View File

@ -18,9 +18,13 @@
class SKPBench : public Benchmark {
public:
SKPBench(const char* name, const SkPicture*, const SkIRect& devClip, SkScalar scale,
bool useMultiPictureDraw);
bool useMultiPictureDraw, bool doLooping);
~SKPBench() override;
int calculateLoops(int defaultLoops) const override {
return fDoLooping ? defaultLoops : 1;
}
protected:
const char* onGetName() override;
const char* onGetUniqueName() override;
@ -48,6 +52,8 @@ private:
SkTDArray<SkSurface*> fSurfaces; // for MultiPictureDraw
SkTDArray<SkIRect> fTileRects; // for MultiPictureDraw
const bool fDoLooping;
typedef Benchmark INHERITED;
};

View File

@ -92,6 +92,7 @@ DEFINE_string(scales, "1.0", "Space-separated scales for SKPs.");
DEFINE_string(zoom, "1.0,1", "Comma-separated scale,step zoom factors for SKPs.");
DEFINE_bool(bbh, true, "Build a BBH for SKPs?");
DEFINE_bool(mpd, true, "Use MultiPictureDraw for the SKPs?");
DEFINE_bool(loopSKP, true, "Loop SKPs like we do for micro benches?");
DEFINE_int32(flushEvery, 10, "Flush --outResultsFile every Nth run.");
DEFINE_bool(resetGpuContext, true, "Reset the GrContext before running each test.");
DEFINE_bool(gpuStats, false, "Print GPU stats after each gpu benchmark?");
@ -272,7 +273,8 @@ static int cpu_bench(const double overhead, Target* target, Benchmark* bench, do
// First figure out approximately how many loops of bench it takes to make overhead negligible.
double bench_plus_overhead = 0.0;
int round = 0;
if (kAutoTuneLoops == FLAGS_loops) {
int loops = bench->calculateLoops(FLAGS_loops);
if (kAutoTuneLoops == loops) {
while (bench_plus_overhead < overhead) {
if (round++ == FLAGS_maxCalibrationAttempts) {
SkDebugf("WARNING: Can't estimate loops for %s (%s vs. %s); skipping.\n",
@ -299,7 +301,6 @@ static int cpu_bench(const double overhead, Target* target, Benchmark* bench, do
// bench_plus_overhead - overhead)
//
// Luckily, this also works well in practice. :)
int loops = FLAGS_loops;
if (kAutoTuneLoops == loops) {
const double numer = overhead / FLAGS_overheadGoal - overhead;
const double denom = bench_plus_overhead - overhead;
@ -320,7 +321,7 @@ static int gpu_bench(Target* target,
double* samples,
int maxGpuFrameLag) {
// First, figure out how many loops it'll take to get a frame up to FLAGS_gpuMs.
int loops = FLAGS_loops;
int loops = bench->calculateLoops(FLAGS_loops);
if (kAutoTuneLoops == loops) {
loops = 1;
double elapsed = 0;
@ -715,8 +716,8 @@ public:
fSourceType = "skp";
fBenchType = "playback";
return SkNEW_ARGS(SKPBench,
(name.c_str(), pic.get(), fClip,
fScales[fCurrentScale], fUseMPDs[fCurrentUseMPD++]));
(name.c_str(), pic.get(), fClip, fScales[fCurrentScale],
fUseMPDs[fCurrentUseMPD++], FLAGS_loopSKP));
}
fCurrentUseMPD = 0;
@ -741,7 +742,7 @@ public:
SkMatrix anim = SkMatrix::I();
anim.setScale(fZoomScale, fZoomScale);
return SkNEW_ARGS(SKPAnimationBench, (name.c_str(), pic.get(), fClip, anim,
fZoomSteps));
fZoomSteps, FLAGS_loopSKP));
}
}