mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 8 | #include <ctype.h> |
| 9 | |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 10 | #include "nanobench.h" |
| 11 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 12 | #include "Benchmark.h" |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 13 | #include "BitmapRegionDecoderBench.h" |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 14 | #include "CodecBench.h" |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 15 | #include "CodecBenchPriv.h" |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 16 | #include "CrashHandler.h" |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 17 | #include "DecodingBench.h" |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 18 | #include "GMBench.h" |
mtklein | afb4379 | 2014-08-19 15:55:55 -0700 | [diff] [blame] | 19 | #include "ProcStats.h" |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 20 | #include "ResultsWriter.h" |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 21 | #include "RecordingBench.h" |
joshualitt | 261c3ad | 2015-04-27 09:16:57 -0700 | [diff] [blame] | 22 | #include "SKPAnimationBench.h" |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 23 | #include "SKPBench.h" |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 24 | #include "SubsetSingleBench.h" |
| 25 | #include "SubsetTranslateBench.h" |
| 26 | #include "SubsetZoomBench.h" |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 27 | #include "Stats.h" |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 28 | |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 29 | #include "SkBitmapRegionDecoderInterface.h" |
mtklein | 6838d85 | 2014-10-29 14:15:10 -0700 | [diff] [blame] | 30 | #include "SkBBoxHierarchy.h" |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 31 | #include "SkCanvas.h" |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 32 | #include "SkCodec.h" |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 33 | #include "SkCommonFlags.h" |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 34 | #include "SkData.h" |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 35 | #include "SkForceLinking.h" |
| 36 | #include "SkGraphics.h" |
mtklein | 2084050 | 2014-08-21 15:51:22 -0700 | [diff] [blame] | 37 | #include "SkOSFile.h" |
| 38 | #include "SkPictureRecorder.h" |
mtklein | 051e56d | 2014-12-04 08:46:51 -0800 | [diff] [blame] | 39 | #include "SkPictureUtils.h" |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 40 | #include "SkString.h" |
| 41 | #include "SkSurface.h" |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 42 | #include "SkTaskGroup.h" |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 43 | |
bungeman | 60e0fee | 2015-08-26 05:15:46 -0700 | [diff] [blame] | 44 | #include <stdlib.h> |
| 45 | |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 46 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 47 | #include "nanobenchAndroid.h" |
| 48 | #endif |
| 49 | |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 50 | #if SK_SUPPORT_GPU |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 51 | #include "gl/GrGLDefines.h" |
bsalomon | 7622863 | 2015-05-29 08:02:10 -0700 | [diff] [blame] | 52 | #include "GrCaps.h" |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 53 | #include "GrContextFactory.h" |
krajcevski | 69a5560 | 2014-08-13 10:46:31 -0700 | [diff] [blame] | 54 | SkAutoTDelete<GrContextFactory> gGrFactory; |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 55 | #endif |
| 56 | |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 57 | struct GrContextOptions; |
| 58 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 59 | __SK_FORCE_IMAGE_DECODER_LINKING; |
| 60 | |
reed | 5324978 | 2014-10-10 09:09:52 -0700 | [diff] [blame] | 61 | static const int kAutoTuneLoops = 0; |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 62 | |
mtklein | b511042 | 2014-08-07 15:20:02 -0700 | [diff] [blame] | 63 | static const int kDefaultLoops = |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 64 | #ifdef SK_DEBUG |
| 65 | 1; |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 66 | #else |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 67 | kAutoTuneLoops; |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 68 | #endif |
| 69 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 70 | static SkString loops_help_txt() { |
| 71 | SkString help; |
| 72 | help.printf("Number of times to run each bench. Set this to %d to auto-" |
| 73 | "tune for each bench. Timings are only reported when auto-tuning.", |
| 74 | kAutoTuneLoops); |
| 75 | return help; |
| 76 | } |
| 77 | |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 78 | static SkString to_string(int n) { |
| 79 | SkString str; |
| 80 | str.appendS32(n); |
| 81 | return str; |
| 82 | } |
| 83 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 84 | DEFINE_int32(loops, kDefaultLoops, loops_help_txt().c_str()); |
| 85 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 86 | DEFINE_int32(samples, 10, "Number of samples to measure for each bench."); |
mtklein | bbba168 | 2015-10-28 11:36:30 -0700 | [diff] [blame] | 87 | DEFINE_int32(ms, 0, "If >0, run each bench for this many ms instead of obeying --samples."); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 88 | DEFINE_int32(overheadLoops, 100000, "Loops to estimate timer overhead."); |
| 89 | DEFINE_double(overheadGoal, 0.0001, |
| 90 | "Loop until timer overhead is at most this fraction of our measurments."); |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 91 | DEFINE_double(gpuMs, 5, "Target bench time in millseconds for GPU."); |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 92 | DEFINE_int32(gpuFrameLag, 5, "If unknown, estimated maximum number of frames GPU allows to lag."); |
krajcevski | 12b3544 | 2014-08-13 12:06:26 -0700 | [diff] [blame] | 93 | DEFINE_bool(gpuCompressAlphaMasks, false, "Compress masks generated from falling back to " |
| 94 | "software path rendering."); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 95 | |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 96 | DEFINE_string(outResultsFile, "", "If given, write results here as JSON."); |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 97 | DEFINE_int32(maxCalibrationAttempts, 3, |
| 98 | "Try up to this many times to guess loops for a bench, or skip the bench."); |
| 99 | DEFINE_int32(maxLoops, 1000000, "Never run a bench more times than this."); |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 100 | DEFINE_string(clip, "0,0,1000,1000", "Clip for SKPs."); |
| 101 | DEFINE_string(scales, "1.0", "Space-separated scales for SKPs."); |
cdalton | 63a8285 | 2015-06-29 14:06:10 -0700 | [diff] [blame] | 102 | DEFINE_string(zoom, "1.0,0", "Comma-separated zoomMax,zoomPeriodMs factors for a periodic SKP zoom " |
| 103 | "function that ping-pongs between 1.0 and zoomMax."); |
mtklein | 2084050 | 2014-08-21 15:51:22 -0700 | [diff] [blame] | 104 | DEFINE_bool(bbh, true, "Build a BBH for SKPs?"); |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 105 | DEFINE_bool(mpd, true, "Use MultiPictureDraw for the SKPs?"); |
cdalton | b402296 | 2015-06-25 10:51:56 -0700 | [diff] [blame] | 106 | DEFINE_bool(loopSKP, true, "Loop SKPs like we do for micro benches?"); |
mtklein | e070c2b | 2014-10-14 08:40:43 -0700 | [diff] [blame] | 107 | DEFINE_int32(flushEvery, 10, "Flush --outResultsFile every Nth run."); |
mtklein | 55e88b2 | 2015-01-21 15:50:13 -0800 | [diff] [blame] | 108 | DEFINE_bool(resetGpuContext, true, "Reset the GrContext before running each test."); |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 109 | DEFINE_bool(gpuStats, false, "Print GPU stats after each gpu benchmark?"); |
scroggo | 2da1a85 | 2015-10-13 13:33:33 -0700 | [diff] [blame] | 110 | DEFINE_bool(pngBuildTileIndex, false, "If supported, use png buildTileIndex/decodeSubset."); |
scroggo | 860e8a6 | 2015-10-15 07:51:28 -0700 | [diff] [blame] | 111 | DEFINE_bool(jpgBuildTileIndex, false, "If supported, use jpg buildTileIndex/decodeSubset."); |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 112 | |
mtklein | bbba168 | 2015-10-28 11:36:30 -0700 | [diff] [blame] | 113 | static double now_ms() { return SkTime::GetNSecs() * 1e-6; } |
| 114 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 115 | static SkString humanize(double ms) { |
mtklein | dc5bbab | 2014-09-24 06:34:09 -0700 | [diff] [blame] | 116 | if (FLAGS_verbose) return SkStringPrintf("%llu", (uint64_t)(ms*1e6)); |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 117 | return HumanizeMs(ms); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 118 | } |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 119 | #define HUMANIZE(ms) humanize(ms).c_str() |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 120 | |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 121 | bool Target::init(SkImageInfo info, Benchmark* bench) { |
| 122 | if (Benchmark::kRaster_Backend == config.backend) { |
| 123 | this->surface.reset(SkSurface::NewRaster(info)); |
| 124 | if (!this->surface.get()) { |
| 125 | return false; |
| 126 | } |
| 127 | } |
| 128 | return true; |
| 129 | } |
| 130 | bool Target::capturePixels(SkBitmap* bmp) { |
tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 131 | SkCanvas* canvas = this->getCanvas(); |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 132 | if (!canvas) { |
| 133 | return false; |
| 134 | } |
| 135 | bmp->setInfo(canvas->imageInfo()); |
| 136 | if (!canvas->readPixels(bmp, 0, 0)) { |
| 137 | SkDebugf("Can't read canvas pixels.\n"); |
| 138 | return false; |
| 139 | } |
| 140 | return true; |
| 141 | } |
| 142 | |
| 143 | #if SK_SUPPORT_GPU |
| 144 | struct GPUTarget : public Target { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 145 | explicit GPUTarget(const Config& c) : Target(c), gl(nullptr) { } |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 146 | SkGLContext* gl; |
| 147 | |
| 148 | void setup() override { |
| 149 | this->gl->makeCurrent(); |
| 150 | // Make sure we're done with whatever came before. |
| 151 | SK_GL(*this->gl, Finish()); |
| 152 | } |
| 153 | void endTiming() override { |
| 154 | if (this->gl) { |
| 155 | SK_GL(*this->gl, Flush()); |
| 156 | this->gl->swapBuffers(); |
| 157 | } |
| 158 | } |
| 159 | void fence() override { |
| 160 | SK_GL(*this->gl, Finish()); |
| 161 | } |
mtklein | d75c466 | 2015-04-30 07:11:22 -0700 | [diff] [blame] | 162 | |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 163 | bool needsFrameTiming(int* maxFrameLag) const override { |
| 164 | if (!this->gl->getMaxGpuFrameLag(maxFrameLag)) { |
| 165 | // Frame lag is unknown. |
| 166 | *maxFrameLag = FLAGS_gpuFrameLag; |
| 167 | } |
| 168 | return true; |
| 169 | } |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 170 | bool init(SkImageInfo info, Benchmark* bench) override { |
bsalomon | afcd7cd | 2015-08-31 12:39:41 -0700 | [diff] [blame] | 171 | uint32_t flags = this->config.useDFText ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag : |
| 172 | 0; |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 173 | SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType); |
| 174 | this->surface.reset(SkSurface::NewRenderTarget(gGrFactory->get(this->config.ctxType), |
| 175 | SkSurface::kNo_Budgeted, info, |
| 176 | this->config.samples, &props)); |
| 177 | this->gl = gGrFactory->getGLContext(this->config.ctxType); |
| 178 | if (!this->surface.get()) { |
| 179 | return false; |
| 180 | } |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 181 | if (!this->gl->fenceSyncSupport()) { |
| 182 | SkDebugf("WARNING: GL context for config \"%s\" does not support fence sync. " |
| 183 | "Timings might not be accurate.\n", this->config.name); |
| 184 | } |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 185 | return true; |
| 186 | } |
| 187 | void fillOptions(ResultsWriter* log) override { |
| 188 | const GrGLubyte* version; |
| 189 | SK_GL_RET(*this->gl, version, GetString(GR_GL_VERSION)); |
| 190 | log->configOption("GL_VERSION", (const char*)(version)); |
| 191 | |
| 192 | SK_GL_RET(*this->gl, version, GetString(GR_GL_RENDERER)); |
| 193 | log->configOption("GL_RENDERER", (const char*) version); |
| 194 | |
| 195 | SK_GL_RET(*this->gl, version, GetString(GR_GL_VENDOR)); |
| 196 | log->configOption("GL_VENDOR", (const char*) version); |
| 197 | |
| 198 | SK_GL_RET(*this->gl, version, GetString(GR_GL_SHADING_LANGUAGE_VERSION)); |
| 199 | log->configOption("GL_SHADING_LANGUAGE_VERSION", (const char*) version); |
| 200 | } |
| 201 | }; |
mtklein | d75c466 | 2015-04-30 07:11:22 -0700 | [diff] [blame] | 202 | |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 203 | #endif |
| 204 | |
tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 205 | static double time(int loops, Benchmark* bench, Target* target) { |
| 206 | SkCanvas* canvas = target->getCanvas(); |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 207 | if (canvas) { |
| 208 | canvas->clear(SK_ColorWHITE); |
| 209 | } |
joshualitt | 8a6697a | 2015-09-30 12:11:07 -0700 | [diff] [blame] | 210 | bench->preDraw(canvas); |
mtklein | bbba168 | 2015-10-28 11:36:30 -0700 | [diff] [blame] | 211 | double start = now_ms(); |
tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 212 | canvas = target->beginTiming(canvas); |
| 213 | bench->draw(loops, canvas); |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 214 | if (canvas) { |
| 215 | canvas->flush(); |
| 216 | } |
tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 217 | target->endTiming(); |
mtklein | bbba168 | 2015-10-28 11:36:30 -0700 | [diff] [blame] | 218 | double elapsed = now_ms() - start; |
joshualitt | 8a6697a | 2015-09-30 12:11:07 -0700 | [diff] [blame] | 219 | bench->postDraw(canvas); |
mtklein | bbba168 | 2015-10-28 11:36:30 -0700 | [diff] [blame] | 220 | return elapsed; |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 221 | } |
| 222 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 223 | static double estimate_timer_overhead() { |
| 224 | double overhead = 0; |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 225 | for (int i = 0; i < FLAGS_overheadLoops; i++) { |
mtklein | bbba168 | 2015-10-28 11:36:30 -0700 | [diff] [blame] | 226 | double start = now_ms(); |
| 227 | overhead += now_ms() - start; |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 228 | } |
| 229 | return overhead / FLAGS_overheadLoops; |
| 230 | } |
| 231 | |
reed | 5324978 | 2014-10-10 09:09:52 -0700 | [diff] [blame] | 232 | static int detect_forever_loops(int loops) { |
| 233 | // look for a magic run-forever value |
| 234 | if (loops < 0) { |
| 235 | loops = SK_MaxS32; |
| 236 | } |
| 237 | return loops; |
| 238 | } |
| 239 | |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 240 | static int clamp_loops(int loops) { |
| 241 | if (loops < 1) { |
mtklein | 527930f | 2014-11-06 08:04:34 -0800 | [diff] [blame] | 242 | SkDebugf("ERROR: clamping loops from %d to 1. " |
| 243 | "There's probably something wrong with the bench.\n", loops); |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 244 | return 1; |
| 245 | } |
| 246 | if (loops > FLAGS_maxLoops) { |
| 247 | SkDebugf("WARNING: clamping loops from %d to FLAGS_maxLoops, %d.\n", loops, FLAGS_maxLoops); |
| 248 | return FLAGS_maxLoops; |
| 249 | } |
| 250 | return loops; |
| 251 | } |
| 252 | |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 253 | static bool write_canvas_png(Target* target, const SkString& filename) { |
| 254 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 255 | if (filename.isEmpty()) { |
| 256 | return false; |
| 257 | } |
tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 258 | if (target->getCanvas() && |
| 259 | kUnknown_SkColorType == target->getCanvas()->imageInfo().colorType()) { |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 260 | return false; |
| 261 | } |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 262 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 263 | SkBitmap bmp; |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 264 | |
| 265 | if (!target->capturePixels(&bmp)) { |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 266 | return false; |
| 267 | } |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 268 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 269 | SkString dir = SkOSPath::Dirname(filename.c_str()); |
| 270 | if (!sk_mkdir(dir.c_str())) { |
| 271 | SkDebugf("Can't make dir %s.\n", dir.c_str()); |
| 272 | return false; |
| 273 | } |
| 274 | SkFILEWStream stream(filename.c_str()); |
| 275 | if (!stream.isValid()) { |
| 276 | SkDebugf("Can't write %s.\n", filename.c_str()); |
| 277 | return false; |
| 278 | } |
| 279 | if (!SkImageEncoder::EncodeStream(&stream, bmp, SkImageEncoder::kPNG_Type, 100)) { |
| 280 | SkDebugf("Can't encode a PNG.\n"); |
| 281 | return false; |
| 282 | } |
| 283 | return true; |
| 284 | } |
| 285 | |
| 286 | static int kFailedLoops = -2; |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 287 | static int setup_cpu_bench(const double overhead, Target* target, Benchmark* bench) { |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 288 | // First figure out approximately how many loops of bench it takes to make overhead negligible. |
mtklein | 2069e22 | 2014-08-04 13:57:39 -0700 | [diff] [blame] | 289 | double bench_plus_overhead = 0.0; |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 290 | int round = 0; |
cdalton | b402296 | 2015-06-25 10:51:56 -0700 | [diff] [blame] | 291 | int loops = bench->calculateLoops(FLAGS_loops); |
| 292 | if (kAutoTuneLoops == loops) { |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 293 | while (bench_plus_overhead < overhead) { |
| 294 | if (round++ == FLAGS_maxCalibrationAttempts) { |
| 295 | SkDebugf("WARNING: Can't estimate loops for %s (%s vs. %s); skipping.\n", |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame] | 296 | bench->getUniqueName(), HUMANIZE(bench_plus_overhead), HUMANIZE(overhead)); |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 297 | return kFailedLoops; |
| 298 | } |
tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 299 | bench_plus_overhead = time(1, bench, target); |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 300 | } |
mtklein | 2069e22 | 2014-08-04 13:57:39 -0700 | [diff] [blame] | 301 | } |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 302 | |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 303 | // Later we'll just start and stop the timer once but loop N times. |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 304 | // We'll pick N to make timer overhead negligible: |
| 305 | // |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 306 | // overhead |
| 307 | // ------------------------- < FLAGS_overheadGoal |
| 308 | // overhead + N * Bench Time |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 309 | // |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 310 | // where bench_plus_overhead ≈ overhead + Bench Time. |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 311 | // |
| 312 | // Doing some math, we get: |
| 313 | // |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 314 | // (overhead / FLAGS_overheadGoal) - overhead |
| 315 | // ------------------------------------------ < N |
| 316 | // bench_plus_overhead - overhead) |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 317 | // |
| 318 | // Luckily, this also works well in practice. :) |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 319 | if (kAutoTuneLoops == loops) { |
| 320 | const double numer = overhead / FLAGS_overheadGoal - overhead; |
| 321 | const double denom = bench_plus_overhead - overhead; |
| 322 | loops = (int)ceil(numer / denom); |
reed | 5324978 | 2014-10-10 09:09:52 -0700 | [diff] [blame] | 323 | loops = clamp_loops(loops); |
| 324 | } else { |
| 325 | loops = detect_forever_loops(loops); |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 326 | } |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 327 | |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 328 | return loops; |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 329 | } |
| 330 | |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 331 | static int setup_gpu_bench(Target* target, Benchmark* bench, int maxGpuFrameLag) { |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 332 | // First, figure out how many loops it'll take to get a frame up to FLAGS_gpuMs. |
cdalton | b402296 | 2015-06-25 10:51:56 -0700 | [diff] [blame] | 333 | int loops = bench->calculateLoops(FLAGS_loops); |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 334 | if (kAutoTuneLoops == loops) { |
| 335 | loops = 1; |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 336 | double elapsed = 0; |
| 337 | do { |
mtklein | 527930f | 2014-11-06 08:04:34 -0800 | [diff] [blame] | 338 | if (1<<30 == loops) { |
| 339 | // We're about to wrap. Something's wrong with the bench. |
| 340 | loops = 0; |
| 341 | break; |
| 342 | } |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 343 | loops *= 2; |
| 344 | // If the GPU lets frames lag at all, we need to make sure we're timing |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 345 | // _this_ round, not still timing last round. |
| 346 | for (int i = 0; i < maxGpuFrameLag; i++) { |
tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 347 | elapsed = time(loops, bench, target); |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 348 | } |
| 349 | } while (elapsed < FLAGS_gpuMs); |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 350 | |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 351 | // We've overshot at least a little. Scale back linearly. |
| 352 | loops = (int)ceil(loops * FLAGS_gpuMs / elapsed); |
reed | 5324978 | 2014-10-10 09:09:52 -0700 | [diff] [blame] | 353 | loops = clamp_loops(loops); |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 354 | |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 355 | // Make sure we're not still timing our calibration. |
| 356 | target->fence(); |
reed | 5324978 | 2014-10-10 09:09:52 -0700 | [diff] [blame] | 357 | } else { |
| 358 | loops = detect_forever_loops(loops); |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 359 | } |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 360 | |
| 361 | // Pretty much the same deal as the calibration: do some warmup to make |
| 362 | // sure we're timing steady-state pipelined frames. |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 363 | for (int i = 0; i < maxGpuFrameLag - 1; i++) { |
tomhudson | 75a0ebb | 2015-03-27 12:11:44 -0700 | [diff] [blame] | 364 | time(loops, bench, target); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 365 | } |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 366 | |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 367 | return loops; |
| 368 | } |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 369 | |
| 370 | static SkString to_lower(const char* str) { |
| 371 | SkString lower(str); |
| 372 | for (size_t i = 0; i < lower.size(); i++) { |
| 373 | lower[i] = tolower(lower[i]); |
| 374 | } |
| 375 | return lower; |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 376 | } |
| 377 | |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 378 | static bool is_cpu_config_allowed(const char* name) { |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 379 | for (int i = 0; i < FLAGS_config.count(); i++) { |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 380 | if (to_lower(FLAGS_config[i]).equals(name)) { |
| 381 | return true; |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 382 | } |
| 383 | } |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 384 | return false; |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 385 | } |
| 386 | |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 387 | #if SK_SUPPORT_GPU |
| 388 | static bool is_gpu_config_allowed(const char* name, GrContextFactory::GLContextType ctxType, |
| 389 | int sampleCnt) { |
| 390 | if (!is_cpu_config_allowed(name)) { |
| 391 | return false; |
| 392 | } |
krajcevski | 69a5560 | 2014-08-13 10:46:31 -0700 | [diff] [blame] | 393 | if (const GrContext* ctx = gGrFactory->get(ctxType)) { |
bsalomon | 7622863 | 2015-05-29 08:02:10 -0700 | [diff] [blame] | 394 | return sampleCnt <= ctx->caps()->maxSampleCount(); |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 395 | } |
| 396 | return false; |
| 397 | } |
| 398 | #endif |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 399 | |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 400 | #if SK_SUPPORT_GPU |
| 401 | #define kBogusGLContextType GrContextFactory::kNative_GLContextType |
| 402 | #else |
| 403 | #define kBogusGLContextType 0 |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 404 | #endif |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 405 | |
| 406 | // Append all configs that are enabled and supported. |
| 407 | static void create_configs(SkTDArray<Config>* configs) { |
jvanverth | 4736e14 | 2014-11-07 07:12:46 -0800 | [diff] [blame] | 408 | #define CPU_CONFIG(name, backend, color, alpha) \ |
| 409 | if (is_cpu_config_allowed(#name)) { \ |
| 410 | Config config = { #name, Benchmark::backend, color, alpha, 0, \ |
| 411 | kBogusGLContextType, false }; \ |
| 412 | configs->push(config); \ |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 413 | } |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 414 | |
mtklein | 40b32be | 2014-07-09 08:46:49 -0700 | [diff] [blame] | 415 | if (FLAGS_cpu) { |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 416 | CPU_CONFIG(nonrendering, kNonRendering_Backend, kUnknown_SkColorType, kUnpremul_SkAlphaType) |
| 417 | CPU_CONFIG(8888, kRaster_Backend, kN32_SkColorType, kPremul_SkAlphaType) |
| 418 | CPU_CONFIG(565, kRaster_Backend, kRGB_565_SkColorType, kOpaque_SkAlphaType) |
mtklein | 40b32be | 2014-07-09 08:46:49 -0700 | [diff] [blame] | 419 | } |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 420 | |
| 421 | #if SK_SUPPORT_GPU |
jvanverth | 4736e14 | 2014-11-07 07:12:46 -0800 | [diff] [blame] | 422 | #define GPU_CONFIG(name, ctxType, samples, useDFText) \ |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 423 | if (is_gpu_config_allowed(#name, GrContextFactory::ctxType, samples)) { \ |
| 424 | Config config = { \ |
| 425 | #name, \ |
| 426 | Benchmark::kGPU_Backend, \ |
| 427 | kN32_SkColorType, \ |
| 428 | kPremul_SkAlphaType, \ |
| 429 | samples, \ |
jvanverth | 4736e14 | 2014-11-07 07:12:46 -0800 | [diff] [blame] | 430 | GrContextFactory::ctxType, \ |
| 431 | useDFText }; \ |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 432 | configs->push(config); \ |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 433 | } |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 434 | |
mtklein | 40b32be | 2014-07-09 08:46:49 -0700 | [diff] [blame] | 435 | if (FLAGS_gpu) { |
jvanverth | 4736e14 | 2014-11-07 07:12:46 -0800 | [diff] [blame] | 436 | GPU_CONFIG(gpu, kNative_GLContextType, 0, false) |
| 437 | GPU_CONFIG(msaa4, kNative_GLContextType, 4, false) |
| 438 | GPU_CONFIG(msaa16, kNative_GLContextType, 16, false) |
| 439 | GPU_CONFIG(nvprmsaa4, kNVPR_GLContextType, 4, false) |
| 440 | GPU_CONFIG(nvprmsaa16, kNVPR_GLContextType, 16, false) |
| 441 | GPU_CONFIG(gpudft, kNative_GLContextType, 0, true) |
| 442 | GPU_CONFIG(debug, kDebug_GLContextType, 0, false) |
| 443 | GPU_CONFIG(nullgpu, kNull_GLContextType, 0, false) |
bsalomon | 3b4d077 | 2014-08-06 10:52:33 -0700 | [diff] [blame] | 444 | #ifdef SK_ANGLE |
jvanverth | 4736e14 | 2014-11-07 07:12:46 -0800 | [diff] [blame] | 445 | GPU_CONFIG(angle, kANGLE_GLContextType, 0, false) |
hendrikw | eddbefb | 2015-09-11 13:07:29 -0700 | [diff] [blame] | 446 | GPU_CONFIG(angle-gl, kANGLE_GL_GLContextType, 0, false) |
bsalomon | 3b4d077 | 2014-08-06 10:52:33 -0700 | [diff] [blame] | 447 | #endif |
hendrikw | 885bf09 | 2015-08-27 10:38:39 -0700 | [diff] [blame] | 448 | #ifdef SK_COMMAND_BUFFER |
| 449 | GPU_CONFIG(commandbuffer, kCommandBuffer_GLContextType, 0, false) |
| 450 | #endif |
cdalton | d416a5b | 2015-06-23 13:23:44 -0700 | [diff] [blame] | 451 | #if SK_MESA |
| 452 | GPU_CONFIG(mesa, kMESA_GLContextType, 0, false) |
| 453 | #endif |
mtklein | 40b32be | 2014-07-09 08:46:49 -0700 | [diff] [blame] | 454 | } |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 455 | #endif |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 456 | |
| 457 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 458 | if (is_cpu_config_allowed("hwui")) { |
| 459 | Config config = { "hwui", Benchmark::kHWUI_Backend, kRGBA_8888_SkColorType, |
| 460 | kPremul_SkAlphaType, 0, kBogusGLContextType, false }; |
| 461 | configs->push(config); |
| 462 | } |
| 463 | #endif |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 464 | } |
| 465 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 466 | // If bench is enabled for config, returns a Target* for it, otherwise nullptr. |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 467 | static Target* is_enabled(Benchmark* bench, const Config& config) { |
| 468 | if (!bench->isSuitableFor(config.backend)) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 469 | return nullptr; |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 470 | } |
| 471 | |
reed | e5ea500 | 2014-09-03 11:54:58 -0700 | [diff] [blame] | 472 | SkImageInfo info = SkImageInfo::Make(bench->getSize().fX, bench->getSize().fY, |
| 473 | config.color, config.alpha); |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 474 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 475 | Target* target = nullptr; |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 476 | |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 477 | switch (config.backend) { |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 478 | #if SK_SUPPORT_GPU |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 479 | case Benchmark::kGPU_Backend: |
| 480 | target = new GPUTarget(config); |
| 481 | break; |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 482 | #endif |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 483 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 484 | case Benchmark::kHWUI_Backend: |
| 485 | target = new HWUITarget(config, bench); |
| 486 | break; |
| 487 | #endif |
| 488 | default: |
| 489 | target = new Target(config); |
| 490 | break; |
| 491 | } |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 492 | |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 493 | if (!target->init(info, bench)) { |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 494 | delete target; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 495 | return nullptr; |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 496 | } |
| 497 | return target; |
| 498 | } |
| 499 | |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 500 | /* |
scroggo | ab12c27 | 2015-10-08 12:01:39 -0700 | [diff] [blame] | 501 | * We only run our subset benches on files that are supported by BitmapRegionDecoder: |
| 502 | * i.e. PNG, JPEG, and WEBP. We do *not* test WEBP when using codec, since we do not |
| 503 | * have a scanline decoder for WEBP, which is necessary for running the subset bench. |
| 504 | * (Another bench must be used to test WEBP, which decodes subsets natively.) |
| 505 | */ |
| 506 | static bool run_subset_bench(const SkString& path, bool useCodec) { |
| 507 | static const char* const exts[] = { |
scroggo | 2da1a85 | 2015-10-13 13:33:33 -0700 | [diff] [blame] | 508 | "jpg", "jpeg", |
| 509 | "JPG", "JPEG", |
scroggo | ab12c27 | 2015-10-08 12:01:39 -0700 | [diff] [blame] | 510 | }; |
| 511 | |
scroggo | 860e8a6 | 2015-10-15 07:51:28 -0700 | [diff] [blame] | 512 | if (useCodec || FLAGS_jpgBuildTileIndex) { |
| 513 | for (uint32_t i = 0; i < SK_ARRAY_COUNT(exts); i++) { |
| 514 | if (path.endsWith(exts[i])) { |
| 515 | return true; |
| 516 | } |
scroggo | ab12c27 | 2015-10-08 12:01:39 -0700 | [diff] [blame] | 517 | } |
| 518 | } |
| 519 | |
scroggo | 2da1a85 | 2015-10-13 13:33:33 -0700 | [diff] [blame] | 520 | // Test png in SkCodec, and optionally on SkImageDecoder. SkImageDecoder is |
| 521 | // disabled by default because it leaks memory. |
| 522 | // skbug.com/4360 |
| 523 | if ((useCodec || FLAGS_pngBuildTileIndex) && (path.endsWith("png") || path.endsWith("PNG"))) { |
| 524 | return true; |
| 525 | } |
| 526 | |
| 527 | if (!useCodec && (path.endsWith("webp") || path.endsWith("WEBP"))) { |
| 528 | return true; |
| 529 | } |
| 530 | |
| 531 | return false; |
scroggo | ab12c27 | 2015-10-08 12:01:39 -0700 | [diff] [blame] | 532 | } |
| 533 | |
| 534 | /* |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 535 | * Returns true if set up for a subset decode succeeds, false otherwise |
| 536 | * If the set-up succeeds, the width and height parameters will be set |
| 537 | */ |
| 538 | static bool valid_subset_bench(const SkString& path, SkColorType colorType, bool useCodec, |
| 539 | int* width, int* height) { |
| 540 | SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); |
| 541 | SkAutoTDelete<SkMemoryStream> stream(new SkMemoryStream(encoded)); |
| 542 | |
msarett | ab80e35 | 2015-06-17 10:28:22 -0700 | [diff] [blame] | 543 | // Check that we can create a codec or image decoder. |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 544 | if (useCodec) { |
| 545 | SkAutoTDelete<SkCodec> codec(SkCodec::NewFromStream(stream.detach())); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 546 | if (nullptr == codec) { |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 547 | SkDebugf("Could not create codec for %s. Skipping bench.\n", path.c_str()); |
| 548 | return false; |
| 549 | } |
| 550 | |
| 551 | // These will be initialized by SkCodec if the color type is kIndex8 and |
| 552 | // unused otherwise. |
| 553 | SkPMColor colors[256]; |
| 554 | int colorCount; |
| 555 | const SkImageInfo info = codec->getInfo().makeColorType(colorType); |
scroggo | 46c5747 | 2015-09-30 08:57:13 -0700 | [diff] [blame] | 556 | if (codec->startScanlineDecode(info, nullptr, colors, &colorCount) != SkCodec::kSuccess) |
scroggo | 1c005e4 | 2015-08-04 09:24:45 -0700 | [diff] [blame] | 557 | { |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 558 | SkDebugf("Could not create scanline decoder for %s with color type %s. " |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 559 | "Skipping bench.\n", path.c_str(), color_type_to_str(colorType)); |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 560 | return false; |
| 561 | } |
| 562 | *width = info.width(); |
| 563 | *height = info.height(); |
| 564 | } else { |
| 565 | SkAutoTDelete<SkImageDecoder> decoder(SkImageDecoder::Factory(stream)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 566 | if (nullptr == decoder) { |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 567 | SkDebugf("Could not create decoder for %s. Skipping bench.\n", path.c_str()); |
| 568 | return false; |
| 569 | } |
| 570 | //FIXME: See skbug.com/3921 |
| 571 | if (kIndex_8_SkColorType == colorType || kGray_8_SkColorType == colorType) { |
| 572 | SkDebugf("Cannot use image subset decoder for %s with color type %s. " |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 573 | "Skipping bench.\n", path.c_str(), color_type_to_str(colorType)); |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 574 | return false; |
| 575 | } |
| 576 | if (!decoder->buildTileIndex(stream.detach(), width, height)) { |
| 577 | SkDebugf("Could not build tile index for %s. Skipping bench.\n", path.c_str()); |
| 578 | return false; |
| 579 | } |
| 580 | } |
msarett | ab80e35 | 2015-06-17 10:28:22 -0700 | [diff] [blame] | 581 | |
| 582 | // Check if the image is large enough for a meaningful subset benchmark. |
| 583 | if (*width <= 512 && *height <= 512) { |
| 584 | // This should not print a message since it is not an error. |
| 585 | return false; |
| 586 | } |
| 587 | |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 588 | return true; |
| 589 | } |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 590 | |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 591 | static bool valid_brd_bench(SkData* encoded, SkBitmapRegionDecoderInterface::Strategy strategy, |
| 592 | SkColorType colorType, uint32_t sampleSize, uint32_t minOutputSize, int* width, |
| 593 | int* height) { |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 594 | SkAutoTDelete<SkBitmapRegionDecoderInterface> brd( |
msarett | 26ad17b | 2015-10-22 07:29:19 -0700 | [diff] [blame] | 595 | SkBitmapRegionDecoderInterface::CreateBitmapRegionDecoder(encoded, strategy)); |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 596 | if (nullptr == brd.get()) { |
| 597 | // This is indicates that subset decoding is not supported for a particular image format. |
| 598 | return false; |
| 599 | } |
| 600 | |
msarett | 35e5d1b | 2015-10-27 12:50:25 -0700 | [diff] [blame] | 601 | SkBitmap bitmap; |
| 602 | if (!brd->decodeRegion(&bitmap, nullptr, SkIRect::MakeXYWH(0, 0, brd->width(), brd->height()), |
| 603 | 1, colorType, false)) { |
| 604 | return false; |
| 605 | } |
| 606 | if (colorType != bitmap.colorType()) { |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 607 | // This indicates that conversion to the requested color type is not supported for the |
| 608 | // particular image. |
| 609 | return false; |
| 610 | } |
| 611 | |
| 612 | if (sampleSize * minOutputSize > (uint32_t) brd->width() || sampleSize * minOutputSize > |
| 613 | (uint32_t) brd->height()) { |
| 614 | // This indicates that the image is not large enough to decode a |
| 615 | // minOutputSize x minOutputSize subset at the given sampleSize. |
| 616 | return false; |
| 617 | } |
| 618 | |
| 619 | // Set the image width and height. The calling code will use this to choose subsets to decode. |
| 620 | *width = brd->width(); |
| 621 | *height = brd->height(); |
| 622 | return true; |
| 623 | } |
| 624 | |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 625 | static void cleanup_run(Target* target) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 626 | delete target; |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 627 | #if SK_SUPPORT_GPU |
| 628 | if (FLAGS_abandonGpuContext) { |
| 629 | gGrFactory->abandonContexts(); |
| 630 | } |
| 631 | if (FLAGS_resetGpuContext || FLAGS_abandonGpuContext) { |
| 632 | gGrFactory->destroyContexts(); |
| 633 | } |
| 634 | #endif |
| 635 | } |
| 636 | |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 637 | class BenchmarkStream { |
| 638 | public: |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 639 | BenchmarkStream() : fBenches(BenchRegistry::Head()) |
| 640 | , fGMs(skiagm::GMRegistry::Head()) |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 641 | , fCurrentRecording(0) |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 642 | , fCurrentScale(0) |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 643 | , fCurrentSKP(0) |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 644 | , fCurrentUseMPD(0) |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 645 | , fCurrentCodec(0) |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 646 | , fCurrentImage(0) |
| 647 | , fCurrentSubsetImage(0) |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 648 | , fCurrentBRDImage(0) |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 649 | , fCurrentColorType(0) |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 650 | , fCurrentSubsetType(0) |
| 651 | , fUseCodec(0) |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 652 | , fCurrentBRDStrategy(0) |
| 653 | , fCurrentBRDSampleSize(0) |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 654 | , fCurrentAnimSKP(0) { |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 655 | for (int i = 0; i < FLAGS_skps.count(); i++) { |
| 656 | if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { |
| 657 | fSKPs.push_back() = FLAGS_skps[i]; |
| 658 | } else { |
| 659 | SkOSFile::Iter it(FLAGS_skps[i], ".skp"); |
| 660 | SkString path; |
| 661 | while (it.next(&path)) { |
| 662 | fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str()); |
| 663 | } |
| 664 | } |
| 665 | } |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 666 | |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 667 | if (4 != sscanf(FLAGS_clip[0], "%d,%d,%d,%d", |
| 668 | &fClip.fLeft, &fClip.fTop, &fClip.fRight, &fClip.fBottom)) { |
| 669 | SkDebugf("Can't parse %s from --clip as an SkIRect.\n", FLAGS_clip[0]); |
| 670 | exit(1); |
| 671 | } |
| 672 | |
| 673 | for (int i = 0; i < FLAGS_scales.count(); i++) { |
| 674 | if (1 != sscanf(FLAGS_scales[i], "%f", &fScales.push_back())) { |
| 675 | SkDebugf("Can't parse %s from --scales as an SkScalar.\n", FLAGS_scales[i]); |
| 676 | exit(1); |
| 677 | } |
| 678 | } |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 679 | |
cdalton | 63a8285 | 2015-06-29 14:06:10 -0700 | [diff] [blame] | 680 | if (2 != sscanf(FLAGS_zoom[0], "%f,%lf", &fZoomMax, &fZoomPeriodMs)) { |
| 681 | SkDebugf("Can't parse %s from --zoom as a zoomMax,zoomPeriodMs.\n", FLAGS_zoom[0]); |
joshualitt | 261c3ad | 2015-04-27 09:16:57 -0700 | [diff] [blame] | 682 | exit(1); |
| 683 | } |
| 684 | |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 685 | if (FLAGS_mpd) { |
| 686 | fUseMPDs.push_back() = true; |
| 687 | } |
mtklein | c751ecb | 2015-06-15 08:56:38 -0700 | [diff] [blame] | 688 | fUseMPDs.push_back() = false; |
mtklein | 95553d9 | 2015-03-12 08:24:21 -0700 | [diff] [blame] | 689 | |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 690 | // Prepare the images for decoding |
| 691 | for (int i = 0; i < FLAGS_images.count(); i++) { |
| 692 | const char* flag = FLAGS_images[i]; |
| 693 | if (sk_isdir(flag)) { |
| 694 | // If the value passed in is a directory, add all the images |
| 695 | SkOSFile::Iter it(flag); |
| 696 | SkString file; |
| 697 | while (it.next(&file)) { |
| 698 | fImages.push_back() = SkOSPath::Join(flag, file.c_str()); |
| 699 | } |
| 700 | } else if (sk_exists(flag)) { |
| 701 | // Also add the value if it is a single image |
| 702 | fImages.push_back() = flag; |
| 703 | } |
| 704 | } |
mtklein | 95553d9 | 2015-03-12 08:24:21 -0700 | [diff] [blame] | 705 | |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 706 | // Choose the candidate color types for image decoding |
| 707 | const SkColorType colorTypes[] = |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 708 | { kN32_SkColorType, |
| 709 | kRGB_565_SkColorType, |
| 710 | kAlpha_8_SkColorType, |
| 711 | kIndex_8_SkColorType, |
| 712 | kGray_8_SkColorType }; |
msarett | 74deb98 | 2015-10-20 16:45:56 -0700 | [diff] [blame] | 713 | fColorTypes.reset(colorTypes, SK_ARRAY_COUNT(colorTypes)); |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 714 | } |
| 715 | |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 716 | static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic) { |
| 717 | // Not strictly necessary, as it will be checked again later, |
| 718 | // but helps to avoid a lot of pointless work if we're going to skip it. |
| 719 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) { |
| 720 | return false; |
| 721 | } |
| 722 | |
scroggo | a1193e4 | 2015-01-21 12:09:53 -0800 | [diff] [blame] | 723 | SkAutoTDelete<SkStream> stream(SkStream::NewFromFile(path)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 724 | if (stream.get() == nullptr) { |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 725 | SkDebugf("Could not read %s.\n", path); |
| 726 | return false; |
| 727 | } |
| 728 | |
mtklein | 57f27bd | 2015-02-09 11:58:41 -0800 | [diff] [blame] | 729 | pic->reset(SkPicture::CreateFromStream(stream.get())); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 730 | if (pic->get() == nullptr) { |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 731 | SkDebugf("Could not read %s as an SkPicture.\n", path); |
| 732 | return false; |
| 733 | } |
| 734 | return true; |
| 735 | } |
| 736 | |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 737 | Benchmark* next() { |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 738 | if (fBenches) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 739 | Benchmark* bench = fBenches->factory()(nullptr); |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 740 | fBenches = fBenches->next(); |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 741 | fSourceType = "bench"; |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 742 | fBenchType = "micro"; |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 743 | return bench; |
| 744 | } |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 745 | |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 746 | while (fGMs) { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 747 | SkAutoTDelete<skiagm::GM> gm(fGMs->factory()(nullptr)); |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 748 | fGMs = fGMs->next(); |
mtklein | cf5d9c9 | 2015-01-23 10:31:45 -0800 | [diff] [blame] | 749 | if (gm->runAsBench()) { |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 750 | fSourceType = "gm"; |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 751 | fBenchType = "micro"; |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 752 | return new GMBench(gm.detach()); |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 753 | } |
| 754 | } |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 755 | |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 756 | // First add all .skps as RecordingBenches. |
| 757 | while (fCurrentRecording < fSKPs.count()) { |
| 758 | const SkString& path = fSKPs[fCurrentRecording++]; |
| 759 | SkAutoTUnref<SkPicture> pic; |
| 760 | if (!ReadPicture(path.c_str(), &pic)) { |
| 761 | continue; |
| 762 | } |
| 763 | SkString name = SkOSPath::Basename(path.c_str()); |
| 764 | fSourceType = "skp"; |
| 765 | fBenchType = "recording"; |
bsalomon | 0aa5cea | 2014-12-15 09:13:35 -0800 | [diff] [blame] | 766 | fSKPBytes = static_cast<double>(SkPictureUtils::ApproximateBytesUsed(pic)); |
mtklein | 051e56d | 2014-12-04 08:46:51 -0800 | [diff] [blame] | 767 | fSKPOps = pic->approximateOpCount(); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 768 | return new RecordingBench(name.c_str(), pic.get(), FLAGS_bbh); |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 769 | } |
| 770 | |
| 771 | // Then once each for each scale as SKPBenches (playback). |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 772 | while (fCurrentScale < fScales.count()) { |
| 773 | while (fCurrentSKP < fSKPs.count()) { |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 774 | const SkString& path = fSKPs[fCurrentSKP]; |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 775 | SkAutoTUnref<SkPicture> pic; |
| 776 | if (!ReadPicture(path.c_str(), &pic)) { |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 777 | fCurrentSKP++; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 778 | continue; |
| 779 | } |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 780 | |
| 781 | while (fCurrentUseMPD < fUseMPDs.count()) { |
| 782 | if (FLAGS_bbh) { |
| 783 | // The SKP we read off disk doesn't have a BBH. Re-record so it grows one. |
| 784 | SkRTreeFactory factory; |
| 785 | SkPictureRecorder recorder; |
| 786 | static const int kFlags = SkPictureRecorder::kComputeSaveLayerInfo_RecordFlag; |
| 787 | pic->playback(recorder.beginRecording(pic->cullRect().width(), |
| 788 | pic->cullRect().height(), |
mtklein | 748ca3b | 2015-01-15 10:56:12 -0800 | [diff] [blame] | 789 | &factory, |
robertphillips | e451c4d | 2014-12-09 10:28:00 -0800 | [diff] [blame] | 790 | fUseMPDs[fCurrentUseMPD] ? kFlags : 0)); |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 791 | pic.reset(recorder.endRecording()); |
| 792 | } |
| 793 | SkString name = SkOSPath::Basename(path.c_str()); |
| 794 | fSourceType = "skp"; |
| 795 | fBenchType = "playback"; |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 796 | return new SKPBench(name.c_str(), pic.get(), fClip, fScales[fCurrentScale], |
| 797 | fUseMPDs[fCurrentUseMPD++], FLAGS_loopSKP); |
mtklein | 2084050 | 2014-08-21 15:51:22 -0700 | [diff] [blame] | 798 | } |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 799 | fCurrentUseMPD = 0; |
| 800 | fCurrentSKP++; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 801 | } |
| 802 | fCurrentSKP = 0; |
| 803 | fCurrentScale++; |
| 804 | } |
| 805 | |
joshualitt | 261c3ad | 2015-04-27 09:16:57 -0700 | [diff] [blame] | 806 | // Now loop over each skp again if we have an animation |
cdalton | 63a8285 | 2015-06-29 14:06:10 -0700 | [diff] [blame] | 807 | if (fZoomMax != 1.0f && fZoomPeriodMs > 0) { |
joshualitt | 261c3ad | 2015-04-27 09:16:57 -0700 | [diff] [blame] | 808 | while (fCurrentAnimSKP < fSKPs.count()) { |
| 809 | const SkString& path = fSKPs[fCurrentAnimSKP]; |
| 810 | SkAutoTUnref<SkPicture> pic; |
| 811 | if (!ReadPicture(path.c_str(), &pic)) { |
| 812 | fCurrentAnimSKP++; |
| 813 | continue; |
| 814 | } |
| 815 | |
| 816 | fCurrentAnimSKP++; |
| 817 | SkString name = SkOSPath::Basename(path.c_str()); |
cdalton | 63a8285 | 2015-06-29 14:06:10 -0700 | [diff] [blame] | 818 | SkAutoTUnref<SKPAnimationBench::Animation> animation( |
| 819 | SKPAnimationBench::CreateZoomAnimation(fZoomMax, fZoomPeriodMs)); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 820 | return new SKPAnimationBench(name.c_str(), pic.get(), fClip, animation, |
| 821 | FLAGS_loopSKP); |
joshualitt | 261c3ad | 2015-04-27 09:16:57 -0700 | [diff] [blame] | 822 | } |
| 823 | } |
| 824 | |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 825 | for (; fCurrentCodec < fImages.count(); fCurrentCodec++) { |
scroggo | 303fa35 | 2015-10-05 11:03:34 -0700 | [diff] [blame] | 826 | fSourceType = "image"; |
| 827 | fBenchType = "skcodec"; |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 828 | const SkString& path = fImages[fCurrentCodec]; |
| 829 | SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); |
| 830 | SkAutoTDelete<SkCodec> codec(SkCodec::NewFromData(encoded)); |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 831 | if (!codec) { |
| 832 | // Nothing to time. |
msarett | 9d9725c | 2015-04-24 11:41:55 -0700 | [diff] [blame] | 833 | SkDebugf("Cannot find codec for %s\n", path.c_str()); |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 834 | continue; |
| 835 | } |
scroggo | 2102799 | 2015-04-02 13:22:38 -0700 | [diff] [blame] | 836 | |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 837 | while (fCurrentColorType < fColorTypes.count()) { |
scroggo | 2102799 | 2015-04-02 13:22:38 -0700 | [diff] [blame] | 838 | const SkColorType colorType = fColorTypes[fCurrentColorType]; |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 839 | fCurrentColorType++; |
scroggo | 2102799 | 2015-04-02 13:22:38 -0700 | [diff] [blame] | 840 | |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 841 | // Make sure we can decode to this color type. |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 842 | SkImageInfo info = codec->getInfo().makeColorType(colorType); |
scroggo | 2102799 | 2015-04-02 13:22:38 -0700 | [diff] [blame] | 843 | SkAlphaType alphaType; |
| 844 | if (!SkColorTypeValidateAlphaType(colorType, info.alphaType(), |
| 845 | &alphaType)) { |
| 846 | continue; |
| 847 | } |
| 848 | if (alphaType != info.alphaType()) { |
| 849 | info = info.makeAlphaType(alphaType); |
| 850 | } |
| 851 | |
| 852 | const size_t rowBytes = info.minRowBytes(); |
| 853 | SkAutoMalloc storage(info.getSafeSize(rowBytes)); |
| 854 | |
| 855 | // Used if fCurrentColorType is kIndex_8_SkColorType |
| 856 | int colorCount = 256; |
| 857 | SkPMColor colors[256]; |
| 858 | |
scroggo | eb602a5 | 2015-07-09 08:16:03 -0700 | [diff] [blame] | 859 | const SkCodec::Result result = codec->getPixels( |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 860 | info, storage.get(), rowBytes, nullptr, colors, |
scroggo | 2102799 | 2015-04-02 13:22:38 -0700 | [diff] [blame] | 861 | &colorCount); |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 862 | switch (result) { |
scroggo | eb602a5 | 2015-07-09 08:16:03 -0700 | [diff] [blame] | 863 | case SkCodec::kSuccess: |
| 864 | case SkCodec::kIncompleteInput: |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 865 | return new CodecBench(SkOSPath::Basename(path.c_str()), |
| 866 | encoded, colorType); |
scroggo | eb602a5 | 2015-07-09 08:16:03 -0700 | [diff] [blame] | 867 | case SkCodec::kInvalidConversion: |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 868 | // This is okay. Not all conversions are valid. |
| 869 | break; |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 870 | default: |
| 871 | // This represents some sort of failure. |
| 872 | SkASSERT(false); |
| 873 | break; |
| 874 | } |
| 875 | } |
| 876 | fCurrentColorType = 0; |
| 877 | } |
| 878 | |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 879 | // Run the DecodingBenches |
| 880 | while (fCurrentImage < fImages.count()) { |
scroggo | 303fa35 | 2015-10-05 11:03:34 -0700 | [diff] [blame] | 881 | fSourceType = "image"; |
| 882 | fBenchType = "skimagedecoder"; |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 883 | while (fCurrentColorType < fColorTypes.count()) { |
| 884 | const SkString& path = fImages[fCurrentImage]; |
| 885 | SkColorType colorType = fColorTypes[fCurrentColorType]; |
| 886 | fCurrentColorType++; |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 887 | // Check if the image decodes to the right color type |
| 888 | // before creating the benchmark |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 889 | SkBitmap bitmap; |
| 890 | if (SkImageDecoder::DecodeFile(path.c_str(), &bitmap, |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 891 | colorType, SkImageDecoder::kDecodePixels_Mode) |
| 892 | && bitmap.colorType() == colorType) { |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 893 | return new DecodingBench(path, colorType); |
| 894 | } |
| 895 | } |
| 896 | fCurrentColorType = 0; |
| 897 | fCurrentImage++; |
| 898 | } |
| 899 | |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 900 | // Run the SubsetBenches |
| 901 | bool useCodecOpts[] = { true, false }; |
| 902 | while (fUseCodec < 2) { |
| 903 | bool useCodec = useCodecOpts[fUseCodec]; |
scroggo | 303fa35 | 2015-10-05 11:03:34 -0700 | [diff] [blame] | 904 | fSourceType = "image"; |
| 905 | fBenchType = useCodec ? "skcodec" : "skimagedecoder"; |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 906 | while (fCurrentSubsetImage < fImages.count()) { |
scroggo | ab12c27 | 2015-10-08 12:01:39 -0700 | [diff] [blame] | 907 | const SkString& path = fImages[fCurrentSubsetImage]; |
| 908 | if (!run_subset_bench(path, useCodec)) { |
| 909 | fCurrentSubsetImage++; |
| 910 | continue; |
| 911 | } |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 912 | while (fCurrentColorType < fColorTypes.count()) { |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 913 | SkColorType colorType = fColorTypes[fCurrentColorType]; |
| 914 | while (fCurrentSubsetType <= kLast_SubsetType) { |
| 915 | int width = 0; |
| 916 | int height = 0; |
| 917 | int currentSubsetType = fCurrentSubsetType++; |
| 918 | if (valid_subset_bench(path, colorType, useCodec, &width, &height)) { |
| 919 | switch (currentSubsetType) { |
| 920 | case kTopLeft_SubsetType: |
msarett | ab80e35 | 2015-06-17 10:28:22 -0700 | [diff] [blame] | 921 | return new SubsetSingleBench(path, colorType, width/3, |
| 922 | height/3, 0, 0, useCodec); |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 923 | case kTopRight_SubsetType: |
msarett | ab80e35 | 2015-06-17 10:28:22 -0700 | [diff] [blame] | 924 | return new SubsetSingleBench(path, colorType, width/3, |
| 925 | height/3, 2*width/3, 0, useCodec); |
| 926 | case kMiddle_SubsetType: |
| 927 | return new SubsetSingleBench(path, colorType, width/3, |
| 928 | height/3, width/3, height/3, useCodec); |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 929 | case kBottomLeft_SubsetType: |
msarett | ab80e35 | 2015-06-17 10:28:22 -0700 | [diff] [blame] | 930 | return new SubsetSingleBench(path, colorType, width/3, |
| 931 | height/3, 0, 2*height/3, useCodec); |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 932 | case kBottomRight_SubsetType: |
msarett | ab80e35 | 2015-06-17 10:28:22 -0700 | [diff] [blame] | 933 | return new SubsetSingleBench(path, colorType, width/3, |
| 934 | height/3, 2*width/3, 2*height/3, useCodec); |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 935 | case kTranslate_SubsetType: |
| 936 | return new SubsetTranslateBench(path, colorType, 512, 512, |
| 937 | useCodec); |
| 938 | case kZoom_SubsetType: |
| 939 | return new SubsetZoomBench(path, colorType, 512, 512, |
| 940 | useCodec); |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 941 | } |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 942 | } else { |
| 943 | break; |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 944 | } |
| 945 | } |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 946 | fCurrentSubsetType = 0; |
| 947 | fCurrentColorType++; |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 948 | } |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 949 | fCurrentColorType = 0; |
| 950 | fCurrentSubsetImage++; |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 951 | } |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 952 | fCurrentSubsetImage = 0; |
| 953 | fUseCodec++; |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 954 | } |
| 955 | |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 956 | // Run the BRDBenches |
| 957 | // We will benchmark multiple BRD strategies. |
scroggo | 303fa35 | 2015-10-05 11:03:34 -0700 | [diff] [blame] | 958 | static const struct { |
| 959 | SkBitmapRegionDecoderInterface::Strategy fStrategy; |
| 960 | const char* fName; |
| 961 | } strategies[] = { |
msarett | 26ad17b | 2015-10-22 07:29:19 -0700 | [diff] [blame] | 962 | { SkBitmapRegionDecoderInterface::kOriginal_Strategy, "BRD" }, |
| 963 | { SkBitmapRegionDecoderInterface::kCanvas_Strategy, "BRD_canvas" }, |
| 964 | { SkBitmapRegionDecoderInterface::kAndroidCodec_Strategy, "BRD_android_codec" }, |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 965 | }; |
| 966 | |
| 967 | // We intend to create benchmarks that model the use cases in |
| 968 | // android/libraries/social/tiledimage. In this library, an image is decoded in 512x512 |
| 969 | // tiles. The image can be translated freely, so the location of a tile may be anywhere in |
| 970 | // the image. For that reason, we will benchmark decodes in five representative locations |
| 971 | // in the image. Additionally, this use case utilizes power of two scaling, so we will |
| 972 | // test on power of two sample sizes. The output tile is always 512x512, so, when a |
| 973 | // sampleSize is used, the size of the subset that is decoded is always |
| 974 | // (sampleSize*512)x(sampleSize*512). |
| 975 | // There are a few good reasons to only test on power of two sample sizes at this time: |
| 976 | // JPEG decodes using kOriginal_Strategy are broken for non-powers of two. |
| 977 | // skbug.com/4319 |
| 978 | // All use cases we are aware of only scale by powers of two. |
| 979 | // PNG decodes use the indicated sampling strategy regardless of the sample size, so |
| 980 | // these tests are sufficient to provide good coverage of our scaling options. |
scroggo | 501b734 | 2015-11-03 07:55:11 -0800 | [diff] [blame] | 981 | const uint32_t sampleSizes[] = { 1, 2, 4, 8, 16, 32, 64 }; |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 982 | const uint32_t minOutputSize = 512; |
| 983 | while (fCurrentBRDImage < fImages.count()) { |
| 984 | while (fCurrentBRDStrategy < (int) SK_ARRAY_COUNT(strategies)) { |
scroggo | 303fa35 | 2015-10-05 11:03:34 -0700 | [diff] [blame] | 985 | fSourceType = "image"; |
| 986 | fBenchType = strategies[fCurrentBRDStrategy].fName; |
scroggo | 860e8a6 | 2015-10-15 07:51:28 -0700 | [diff] [blame] | 987 | |
| 988 | const SkString& path = fImages[fCurrentBRDImage]; |
| 989 | const SkBitmapRegionDecoderInterface::Strategy strategy = |
| 990 | strategies[fCurrentBRDStrategy].fStrategy; |
| 991 | |
| 992 | if (SkBitmapRegionDecoderInterface::kOriginal_Strategy == strategy) { |
| 993 | // Disable png and jpeg for SkImageDecoder: |
| 994 | if (!FLAGS_jpgBuildTileIndex) { |
| 995 | if (path.endsWith("JPEG") || path.endsWith("JPG") || |
| 996 | path.endsWith("jpeg") || path.endsWith("jpg")) |
| 997 | { |
| 998 | fCurrentBRDStrategy++; |
| 999 | continue; |
| 1000 | } |
| 1001 | } |
| 1002 | if (!FLAGS_pngBuildTileIndex) { |
| 1003 | if (path.endsWith("PNG") || path.endsWith("png")) { |
| 1004 | fCurrentBRDStrategy++; |
| 1005 | continue; |
| 1006 | } |
| 1007 | } |
| 1008 | } |
| 1009 | |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 1010 | while (fCurrentColorType < fColorTypes.count()) { |
| 1011 | while (fCurrentBRDSampleSize < (int) SK_ARRAY_COUNT(sampleSizes)) { |
| 1012 | while (fCurrentSubsetType <= kLastSingle_SubsetType) { |
scroggo | 860e8a6 | 2015-10-15 07:51:28 -0700 | [diff] [blame] | 1013 | |
| 1014 | |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 1015 | SkAutoTUnref<SkData> encoded(SkData::NewFromFileName(path.c_str())); |
| 1016 | const SkColorType colorType = fColorTypes[fCurrentColorType]; |
| 1017 | uint32_t sampleSize = sampleSizes[fCurrentBRDSampleSize]; |
| 1018 | int currentSubsetType = fCurrentSubsetType++; |
| 1019 | |
| 1020 | int width = 0; |
| 1021 | int height = 0; |
| 1022 | if (!valid_brd_bench(encoded.get(), strategy, colorType, sampleSize, |
| 1023 | minOutputSize, &width, &height)) { |
| 1024 | break; |
| 1025 | } |
| 1026 | |
| 1027 | SkString basename = SkOSPath::Basename(path.c_str()); |
| 1028 | SkIRect subset; |
| 1029 | const uint32_t subsetSize = sampleSize * minOutputSize; |
| 1030 | switch (currentSubsetType) { |
| 1031 | case kTopLeft_SubsetType: |
| 1032 | basename.append("_TopLeft"); |
| 1033 | subset = SkIRect::MakeXYWH(0, 0, subsetSize, subsetSize); |
| 1034 | break; |
| 1035 | case kTopRight_SubsetType: |
| 1036 | basename.append("_TopRight"); |
| 1037 | subset = SkIRect::MakeXYWH(width - subsetSize, 0, subsetSize, |
| 1038 | subsetSize); |
| 1039 | break; |
| 1040 | case kMiddle_SubsetType: |
| 1041 | basename.append("_Middle"); |
| 1042 | subset = SkIRect::MakeXYWH((width - subsetSize) / 2, |
| 1043 | (height - subsetSize) / 2, subsetSize, subsetSize); |
| 1044 | break; |
| 1045 | case kBottomLeft_SubsetType: |
| 1046 | basename.append("_BottomLeft"); |
| 1047 | subset = SkIRect::MakeXYWH(0, height - subsetSize, subsetSize, |
| 1048 | subsetSize); |
| 1049 | break; |
| 1050 | case kBottomRight_SubsetType: |
| 1051 | basename.append("_BottomRight"); |
| 1052 | subset = SkIRect::MakeXYWH(width - subsetSize, |
| 1053 | height - subsetSize, subsetSize, subsetSize); |
| 1054 | break; |
| 1055 | default: |
| 1056 | SkASSERT(false); |
| 1057 | } |
| 1058 | |
| 1059 | return new BitmapRegionDecoderBench(basename.c_str(), encoded.get(), |
| 1060 | strategy, colorType, sampleSize, subset); |
| 1061 | } |
| 1062 | fCurrentSubsetType = 0; |
| 1063 | fCurrentBRDSampleSize++; |
| 1064 | } |
| 1065 | fCurrentBRDSampleSize = 0; |
| 1066 | fCurrentColorType++; |
| 1067 | } |
| 1068 | fCurrentColorType = 0; |
| 1069 | fCurrentBRDStrategy++; |
| 1070 | } |
| 1071 | fCurrentBRDStrategy = 0; |
| 1072 | fCurrentBRDImage++; |
| 1073 | } |
| 1074 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1075 | return nullptr; |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 1076 | } |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 1077 | |
| 1078 | void fillCurrentOptions(ResultsWriter* log) const { |
| 1079 | log->configOption("source_type", fSourceType); |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 1080 | log->configOption("bench_type", fBenchType); |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 1081 | if (0 == strcmp(fSourceType, "skp")) { |
| 1082 | log->configOption("clip", |
| 1083 | SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop, |
| 1084 | fClip.fRight, fClip.fBottom).c_str()); |
mtklein | 4dfdbb1 | 2015-10-20 07:45:29 -0700 | [diff] [blame] | 1085 | SK_ALWAYSBREAK(fCurrentScale < fScales.count()); // debugging paranoia |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 1086 | log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentScale]).c_str()); |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 1087 | if (fCurrentUseMPD > 0) { |
| 1088 | SkASSERT(1 == fCurrentUseMPD || 2 == fCurrentUseMPD); |
| 1089 | log->configOption("multi_picture_draw", fUseMPDs[fCurrentUseMPD-1] ? "true" : "false"); |
| 1090 | } |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 1091 | } |
mtklein | 051e56d | 2014-12-04 08:46:51 -0800 | [diff] [blame] | 1092 | if (0 == strcmp(fBenchType, "recording")) { |
| 1093 | log->metric("bytes", fSKPBytes); |
| 1094 | log->metric("ops", fSKPOps); |
| 1095 | } |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 1096 | } |
| 1097 | |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 1098 | private: |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 1099 | enum SubsetType { |
| 1100 | kTopLeft_SubsetType = 0, |
| 1101 | kTopRight_SubsetType = 1, |
msarett | ab80e35 | 2015-06-17 10:28:22 -0700 | [diff] [blame] | 1102 | kMiddle_SubsetType = 2, |
| 1103 | kBottomLeft_SubsetType = 3, |
| 1104 | kBottomRight_SubsetType = 4, |
| 1105 | kTranslate_SubsetType = 5, |
| 1106 | kZoom_SubsetType = 6, |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 1107 | kLast_SubsetType = kZoom_SubsetType, |
| 1108 | kLastSingle_SubsetType = kBottomRight_SubsetType, |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 1109 | }; |
| 1110 | |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 1111 | const BenchRegistry* fBenches; |
| 1112 | const skiagm::GMRegistry* fGMs; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 1113 | SkIRect fClip; |
| 1114 | SkTArray<SkScalar> fScales; |
| 1115 | SkTArray<SkString> fSKPs; |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 1116 | SkTArray<bool> fUseMPDs; |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 1117 | SkTArray<SkString> fImages; |
msarett | 74deb98 | 2015-10-20 16:45:56 -0700 | [diff] [blame] | 1118 | SkTArray<SkColorType, true> fColorTypes; |
cdalton | 63a8285 | 2015-06-29 14:06:10 -0700 | [diff] [blame] | 1119 | SkScalar fZoomMax; |
| 1120 | double fZoomPeriodMs; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 1121 | |
mtklein | 051e56d | 2014-12-04 08:46:51 -0800 | [diff] [blame] | 1122 | double fSKPBytes, fSKPOps; |
| 1123 | |
mtklein | fd731ce | 2014-09-10 12:19:30 -0700 | [diff] [blame] | 1124 | const char* fSourceType; // What we're benching: bench, GM, SKP, ... |
| 1125 | const char* fBenchType; // How we bench it: micro, recording, playback, ... |
| 1126 | int fCurrentRecording; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 1127 | int fCurrentScale; |
| 1128 | int fCurrentSKP; |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 1129 | int fCurrentUseMPD; |
scroggo | 60869a4 | 2015-04-01 12:09:17 -0700 | [diff] [blame] | 1130 | int fCurrentCodec; |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 1131 | int fCurrentImage; |
| 1132 | int fCurrentSubsetImage; |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 1133 | int fCurrentBRDImage; |
msarett | 95f192d | 2015-02-13 09:05:41 -0800 | [diff] [blame] | 1134 | int fCurrentColorType; |
msarett | b23e6aa | 2015-06-09 13:56:10 -0700 | [diff] [blame] | 1135 | int fCurrentSubsetType; |
| 1136 | int fUseCodec; |
msarett | 7f69144 | 2015-09-22 11:56:16 -0700 | [diff] [blame] | 1137 | int fCurrentBRDStrategy; |
| 1138 | int fCurrentBRDSampleSize; |
joshualitt | 261c3ad | 2015-04-27 09:16:57 -0700 | [diff] [blame] | 1139 | int fCurrentAnimSKP; |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 1140 | }; |
| 1141 | |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 1142 | int nanobench_main(); |
caryclark | 17f0b6d | 2014-07-22 10:15:34 -0700 | [diff] [blame] | 1143 | int nanobench_main() { |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 1144 | SetupCrashHandler(); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1145 | SkAutoGraphics ag; |
mtklein | cc29d26 | 2015-07-09 10:04:56 -0700 | [diff] [blame] | 1146 | SkTaskGroup::Enabler enabled(FLAGS_threads); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1147 | |
krajcevski | 69a5560 | 2014-08-13 10:46:31 -0700 | [diff] [blame] | 1148 | #if SK_SUPPORT_GPU |
bsalomon | 682c269 | 2015-05-22 14:01:46 -0700 | [diff] [blame] | 1149 | GrContextOptions grContextOpts; |
krajcevski | 12b3544 | 2014-08-13 12:06:26 -0700 | [diff] [blame] | 1150 | grContextOpts.fDrawPathToCompressedTexture = FLAGS_gpuCompressAlphaMasks; |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 1151 | gGrFactory.reset(new GrContextFactory(grContextOpts)); |
krajcevski | 69a5560 | 2014-08-13 10:46:31 -0700 | [diff] [blame] | 1152 | #endif |
| 1153 | |
bsalomon | 06cddec | 2014-10-24 10:40:50 -0700 | [diff] [blame] | 1154 | if (FLAGS_veryVerbose) { |
| 1155 | FLAGS_verbose = true; |
| 1156 | } |
| 1157 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 1158 | if (kAutoTuneLoops != FLAGS_loops) { |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 1159 | FLAGS_samples = 1; |
| 1160 | FLAGS_gpuFrameLag = 0; |
| 1161 | } |
| 1162 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 1163 | if (!FLAGS_writePath.isEmpty()) { |
| 1164 | SkDebugf("Writing files to %s.\n", FLAGS_writePath[0]); |
| 1165 | if (!sk_mkdir(FLAGS_writePath[0])) { |
| 1166 | SkDebugf("Could not create %s. Files won't be written.\n", FLAGS_writePath[0]); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1167 | FLAGS_writePath.set(0, nullptr); |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 1168 | } |
| 1169 | } |
| 1170 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 1171 | SkAutoTDelete<ResultsWriter> log(new ResultsWriter); |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 1172 | if (!FLAGS_outResultsFile.isEmpty()) { |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 1173 | log.reset(new NanoJSONResultsWriter(FLAGS_outResultsFile[0])); |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 1174 | } |
mtklein | 1915b62 | 2014-08-20 11:45:00 -0700 | [diff] [blame] | 1175 | |
| 1176 | if (1 == FLAGS_properties.count() % 2) { |
| 1177 | SkDebugf("ERROR: --properties must be passed with an even number of arguments.\n"); |
| 1178 | return 1; |
| 1179 | } |
| 1180 | for (int i = 1; i < FLAGS_properties.count(); i += 2) { |
| 1181 | log->property(FLAGS_properties[i-1], FLAGS_properties[i]); |
| 1182 | } |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 1183 | |
| 1184 | if (1 == FLAGS_key.count() % 2) { |
| 1185 | SkDebugf("ERROR: --key must be passed with an even number of arguments.\n"); |
| 1186 | return 1; |
| 1187 | } |
| 1188 | for (int i = 1; i < FLAGS_key.count(); i += 2) { |
mtklein | 1915b62 | 2014-08-20 11:45:00 -0700 | [diff] [blame] | 1189 | log->key(FLAGS_key[i-1], FLAGS_key[i]); |
mtklein | 94e5156 | 2014-08-19 12:41:53 -0700 | [diff] [blame] | 1190 | } |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 1191 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1192 | const double overhead = estimate_timer_overhead(); |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 1193 | SkDebugf("Timer overhead: %s\n", HUMANIZE(overhead)); |
Mike Klein | 9129477 | 2014-07-16 19:59:32 -0400 | [diff] [blame] | 1194 | |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 1195 | SkTArray<double> samples; |
mtklein | bb6a028 | 2014-07-01 08:43:42 -0700 | [diff] [blame] | 1196 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 1197 | if (kAutoTuneLoops != FLAGS_loops) { |
| 1198 | SkDebugf("Fixed number of loops; times would only be misleading so we won't print them.\n"); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1199 | } else if (FLAGS_quiet) { |
mtklein | 40b32be | 2014-07-09 08:46:49 -0700 | [diff] [blame] | 1200 | SkDebugf("median\tbench\tconfig\n"); |
mtklein | bbba168 | 2015-10-28 11:36:30 -0700 | [diff] [blame] | 1201 | } else if (FLAGS_ms) { |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 1202 | SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\tsamples\tconfig\tbench\n"); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1203 | } else { |
mtklein | d75c466 | 2015-04-30 07:11:22 -0700 | [diff] [blame] | 1204 | SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\t%-*s\tconfig\tbench\n", |
qiankun.miao | 8247ec3 | 2014-09-09 19:24:36 -0700 | [diff] [blame] | 1205 | FLAGS_samples, "samples"); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1206 | } |
| 1207 | |
bsalomon | c255337 | 2014-07-22 13:09:05 -0700 | [diff] [blame] | 1208 | SkTDArray<Config> configs; |
| 1209 | create_configs(&configs); |
| 1210 | |
mtklein | e070c2b | 2014-10-14 08:40:43 -0700 | [diff] [blame] | 1211 | int runs = 0; |
mtklein | 9200758 | 2014-08-01 07:46:52 -0700 | [diff] [blame] | 1212 | BenchmarkStream benchStream; |
| 1213 | while (Benchmark* b = benchStream.next()) { |
mtklein | e714e75 | 2014-07-31 12:13:48 -0700 | [diff] [blame] | 1214 | SkAutoTDelete<Benchmark> bench(b); |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame] | 1215 | if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName())) { |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1216 | continue; |
| 1217 | } |
| 1218 | |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1219 | if (!configs.isEmpty()) { |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame] | 1220 | log->bench(bench->getUniqueName(), bench->getSize().fX, bench->getSize().fY); |
joshualitt | 8a6697a | 2015-09-30 12:11:07 -0700 | [diff] [blame] | 1221 | bench->delayedSetup(); |
jcgregorio | bf5e523 | 2014-07-17 13:14:16 -0700 | [diff] [blame] | 1222 | } |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1223 | for (int i = 0; i < configs.count(); ++i) { |
| 1224 | Target* target = is_enabled(b, configs[i]); |
| 1225 | if (!target) { |
| 1226 | continue; |
| 1227 | } |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1228 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1229 | // During HWUI output this canvas may be nullptr. |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1230 | SkCanvas* canvas = target->getCanvas(); |
| 1231 | const char* config = target->config.name; |
| 1232 | |
| 1233 | target->setup(); |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 1234 | bench->perCanvasPreDraw(canvas); |
| 1235 | |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 1236 | int maxFrameLag; |
mtklein | a1ebeb2 | 2015-10-01 09:43:39 -0700 | [diff] [blame] | 1237 | int loops = target->needsFrameTiming(&maxFrameLag) |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1238 | ? setup_gpu_bench(target, bench.get(), maxFrameLag) |
| 1239 | : setup_cpu_bench(overhead, target, bench.get()); |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 1240 | |
mtklein | bbba168 | 2015-10-28 11:36:30 -0700 | [diff] [blame] | 1241 | if (FLAGS_ms) { |
| 1242 | samples.reset(); |
| 1243 | auto stop = now_ms() + FLAGS_ms; |
| 1244 | do { |
| 1245 | samples.push_back(time(loops, bench, target) / loops); |
| 1246 | } while (now_ms() < stop); |
| 1247 | } else { |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 1248 | samples.reset(FLAGS_samples); |
| 1249 | for (int s = 0; s < FLAGS_samples; s++) { |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1250 | samples[s] = time(loops, bench, target) / loops; |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 1251 | } |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 1252 | } |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1253 | |
robertphillips | 5b69377 | 2014-11-21 06:19:36 -0800 | [diff] [blame] | 1254 | bench->perCanvasPostDraw(canvas); |
| 1255 | |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1256 | if (Benchmark::kNonRendering_Backend != target->config.backend && |
tomhudson | d968a6f | 2015-03-26 11:28:06 -0700 | [diff] [blame] | 1257 | !FLAGS_writePath.isEmpty() && FLAGS_writePath[0]) { |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 1258 | SkString pngFilename = SkOSPath::Join(FLAGS_writePath[0], config); |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame] | 1259 | pngFilename = SkOSPath::Join(pngFilename.c_str(), bench->getUniqueName()); |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 1260 | pngFilename.append(".png"); |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1261 | write_canvas_png(target, pngFilename); |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | if (kFailedLoops == loops) { |
mtklein | 2069e22 | 2014-08-04 13:57:39 -0700 | [diff] [blame] | 1265 | // Can't be timed. A warning note has already been printed. |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1266 | cleanup_run(target); |
Mike Klein | e363136 | 2014-07-15 17:56:37 -0400 | [diff] [blame] | 1267 | continue; |
| 1268 | } |
| 1269 | |
cdalton | e1b8958 | 2015-06-25 19:17:08 -0700 | [diff] [blame] | 1270 | Stats stats(samples); |
mtklein | 1915b62 | 2014-08-20 11:45:00 -0700 | [diff] [blame] | 1271 | log->config(config); |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame] | 1272 | log->configOption("name", bench->getName()); |
mtklein | 1915b62 | 2014-08-20 11:45:00 -0700 | [diff] [blame] | 1273 | benchStream.fillCurrentOptions(log.get()); |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1274 | target->fillOptions(log.get()); |
mtklein | 051e56d | 2014-12-04 08:46:51 -0800 | [diff] [blame] | 1275 | log->metric("min_ms", stats.min); |
mtklein | e070c2b | 2014-10-14 08:40:43 -0700 | [diff] [blame] | 1276 | if (runs++ % FLAGS_flushEvery == 0) { |
| 1277 | log->flush(); |
| 1278 | } |
mtklein | 60317d0f | 2014-07-14 11:30:37 -0700 | [diff] [blame] | 1279 | |
bsalomon | 6eb03cc | 2014-08-07 14:28:50 -0700 | [diff] [blame] | 1280 | if (kAutoTuneLoops != FLAGS_loops) { |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1281 | if (configs.count() == 1) { |
mtklein | a189ccd | 2014-07-14 12:28:47 -0700 | [diff] [blame] | 1282 | config = ""; // Only print the config if we run the same bench on more than one. |
| 1283 | } |
mtklein | d75c466 | 2015-04-30 07:11:22 -0700 | [diff] [blame] | 1284 | SkDebugf("%4d/%-4dMB\t%s\t%s\n" |
| 1285 | , sk_tools::getCurrResidentSetSizeMB() |
| 1286 | , sk_tools::getMaxResidentSetSizeMB() |
mtklein | 53d2562 | 2014-09-18 07:39:42 -0700 | [diff] [blame] | 1287 | , bench->getUniqueName() |
| 1288 | , config); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1289 | } else if (FLAGS_quiet) { |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1290 | if (configs.count() == 1) { |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1291 | config = ""; // Only print the config if we run the same bench on more than one. |
| 1292 | } |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame] | 1293 | SkDebugf("%s\t%s\t%s\n", HUMANIZE(stats.median), bench->getUniqueName(), config); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1294 | } else { |
| 1295 | const double stddev_percent = 100 * sqrt(stats.var) / stats.mean; |
mtklein | d75c466 | 2015-04-30 07:11:22 -0700 | [diff] [blame] | 1296 | SkDebugf("%4d/%-4dMB\t%d\t%s\t%s\t%s\t%s\t%.0f%%\t%s\t%s\t%s\n" |
| 1297 | , sk_tools::getCurrResidentSetSizeMB() |
| 1298 | , sk_tools::getMaxResidentSetSizeMB() |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1299 | , loops |
mtklein | 55b0ffc | 2014-07-17 08:38:23 -0700 | [diff] [blame] | 1300 | , HUMANIZE(stats.min) |
| 1301 | , HUMANIZE(stats.median) |
| 1302 | , HUMANIZE(stats.mean) |
| 1303 | , HUMANIZE(stats.max) |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1304 | , stddev_percent |
mtklein | bbba168 | 2015-10-28 11:36:30 -0700 | [diff] [blame] | 1305 | , FLAGS_ms ? to_string(samples.count()).c_str() : stats.plot.c_str() |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1306 | , config |
mtklein | 9628905 | 2014-09-10 12:05:59 -0700 | [diff] [blame] | 1307 | , bench->getUniqueName() |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1308 | ); |
| 1309 | } |
bsalomon | b12ea41 | 2015-02-02 21:19:50 -0800 | [diff] [blame] | 1310 | #if SK_SUPPORT_GPU |
| 1311 | if (FLAGS_gpuStats && |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1312 | Benchmark::kGPU_Backend == configs[i].backend) { |
| 1313 | gGrFactory->get(configs[i].ctxType)->printCacheStats(); |
| 1314 | gGrFactory->get(configs[i].ctxType)->printGpuStats(); |
bsalomon | 06cddec | 2014-10-24 10:40:50 -0700 | [diff] [blame] | 1315 | } |
| 1316 | #endif |
cdalton | 2c56ba5 | 2015-06-26 13:32:53 -0700 | [diff] [blame] | 1317 | if (FLAGS_verbose) { |
| 1318 | SkDebugf("Samples: "); |
| 1319 | for (int i = 0; i < samples.count(); i++) { |
| 1320 | SkDebugf("%s ", HUMANIZE(samples[i])); |
| 1321 | } |
| 1322 | SkDebugf("%s\n", bench->getUniqueName()); |
| 1323 | } |
egdaniel | 3bf9206 | 2015-06-26 08:12:46 -0700 | [diff] [blame] | 1324 | cleanup_run(target); |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1325 | } |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1326 | } |
| 1327 | |
mtklein | e109145 | 2014-12-04 10:47:02 -0800 | [diff] [blame] | 1328 | log->bench("memory_usage", 0,0); |
| 1329 | log->config("meta"); |
| 1330 | log->metric("max_rss_mb", sk_tools::getMaxResidentSetSizeMB()); |
| 1331 | |
joshualitt | e0b19d4 | 2015-03-26 10:41:02 -0700 | [diff] [blame] | 1332 | #if SK_SUPPORT_GPU |
| 1333 | // Make sure we clean up the global GrContextFactory here, otherwise we might race with the |
| 1334 | // SkEventTracer destructor |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1335 | gGrFactory.reset(nullptr); |
joshualitt | e0b19d4 | 2015-03-26 10:41:02 -0700 | [diff] [blame] | 1336 | #endif |
| 1337 | |
mtklein | f372321 | 2014-06-25 14:08:00 -0700 | [diff] [blame] | 1338 | return 0; |
| 1339 | } |
| 1340 | |
jcgregorio | 3b27ade | 2014-11-13 08:06:40 -0800 | [diff] [blame] | 1341 | #if !defined SK_BUILD_FOR_IOS |
| 1342 | int main(int argc, char** argv) { |
| 1343 | SkCommandLineFlags::Parse(argc, argv); |
| 1344 | return nanobench_main(); |
| 1345 | } |
| 1346 | #endif |