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; 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 // 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 // timer. When a benchmark is repeatedly drawn, this should be called once
// before the initial draw. // before the initial draw.

View File

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

View File

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

View File

@ -18,9 +18,13 @@
class SKPBench : public Benchmark { class SKPBench : public Benchmark {
public: public:
SKPBench(const char* name, const SkPicture*, const SkIRect& devClip, SkScalar scale, SKPBench(const char* name, const SkPicture*, const SkIRect& devClip, SkScalar scale,
bool useMultiPictureDraw); bool useMultiPictureDraw, bool doLooping);
~SKPBench() override; ~SKPBench() override;
int calculateLoops(int defaultLoops) const override {
return fDoLooping ? defaultLoops : 1;
}
protected: protected:
const char* onGetName() override; const char* onGetName() override;
const char* onGetUniqueName() override; const char* onGetUniqueName() override;
@ -48,6 +52,8 @@ private:
SkTDArray<SkSurface*> fSurfaces; // for MultiPictureDraw SkTDArray<SkSurface*> fSurfaces; // for MultiPictureDraw
SkTDArray<SkIRect> fTileRects; // for MultiPictureDraw SkTDArray<SkIRect> fTileRects; // for MultiPictureDraw
const bool fDoLooping;
typedef Benchmark INHERITED; 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_string(zoom, "1.0,1", "Comma-separated scale,step zoom factors for SKPs.");
DEFINE_bool(bbh, true, "Build a BBH for SKPs?"); DEFINE_bool(bbh, true, "Build a BBH for SKPs?");
DEFINE_bool(mpd, true, "Use MultiPictureDraw for the 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_int32(flushEvery, 10, "Flush --outResultsFile every Nth run.");
DEFINE_bool(resetGpuContext, true, "Reset the GrContext before running each test."); DEFINE_bool(resetGpuContext, true, "Reset the GrContext before running each test.");
DEFINE_bool(gpuStats, false, "Print GPU stats after each gpu benchmark?"); 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. // First figure out approximately how many loops of bench it takes to make overhead negligible.
double bench_plus_overhead = 0.0; double bench_plus_overhead = 0.0;
int round = 0; int round = 0;
if (kAutoTuneLoops == FLAGS_loops) { int loops = bench->calculateLoops(FLAGS_loops);
if (kAutoTuneLoops == loops) {
while (bench_plus_overhead < overhead) { while (bench_plus_overhead < overhead) {
if (round++ == FLAGS_maxCalibrationAttempts) { if (round++ == FLAGS_maxCalibrationAttempts) {
SkDebugf("WARNING: Can't estimate loops for %s (%s vs. %s); skipping.\n", 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) // bench_plus_overhead - overhead)
// //
// Luckily, this also works well in practice. :) // Luckily, this also works well in practice. :)
int loops = FLAGS_loops;
if (kAutoTuneLoops == loops) { if (kAutoTuneLoops == loops) {
const double numer = overhead / FLAGS_overheadGoal - overhead; const double numer = overhead / FLAGS_overheadGoal - overhead;
const double denom = bench_plus_overhead - overhead; const double denom = bench_plus_overhead - overhead;
@ -320,7 +321,7 @@ static int gpu_bench(Target* target,
double* samples, double* samples,
int maxGpuFrameLag) { int maxGpuFrameLag) {
// First, figure out how many loops it'll take to get a frame up to FLAGS_gpuMs. // 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) { if (kAutoTuneLoops == loops) {
loops = 1; loops = 1;
double elapsed = 0; double elapsed = 0;
@ -715,8 +716,8 @@ public:
fSourceType = "skp"; fSourceType = "skp";
fBenchType = "playback"; fBenchType = "playback";
return SkNEW_ARGS(SKPBench, return SkNEW_ARGS(SKPBench,
(name.c_str(), pic.get(), fClip, (name.c_str(), pic.get(), fClip, fScales[fCurrentScale],
fScales[fCurrentScale], fUseMPDs[fCurrentUseMPD++])); fUseMPDs[fCurrentUseMPD++], FLAGS_loopSKP));
} }
fCurrentUseMPD = 0; fCurrentUseMPD = 0;
@ -741,7 +742,7 @@ public:
SkMatrix anim = SkMatrix::I(); SkMatrix anim = SkMatrix::I();
anim.setScale(fZoomScale, fZoomScale); anim.setScale(fZoomScale, fZoomScale);
return SkNEW_ARGS(SKPAnimationBench, (name.c_str(), pic.get(), fClip, anim, return SkNEW_ARGS(SKPAnimationBench, (name.c_str(), pic.get(), fClip, anim,
fZoomSteps)); fZoomSteps, FLAGS_loopSKP));
} }
} }