Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include <ctype.h> | 8 #include <ctype.h> |
| 9 | 9 |
| 10 #include "nanobench.h" | 10 #include "nanobench.h" |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 178 this->con fig.ctxOptions), | 178 this->con fig.ctxOptions), |
| 179 SkSurface::kNo_Budgeted , info, | 179 SkSurface::kNo_Budgeted , info, |
| 180 this->config.samples, & props)); | 180 this->config.samples, & props)); |
| 181 this->gl = gGrFactory->getContextInfo(this->config.ctxType, | 181 this->gl = gGrFactory->getContextInfo(this->config.ctxType, |
| 182 this->config.ctxOptions).fGLContex t; | 182 this->config.ctxOptions).fGLContex t; |
| 183 if (!this->surface.get()) { | 183 if (!this->surface.get()) { |
| 184 return false; | 184 return false; |
| 185 } | 185 } |
| 186 if (!this->gl->fenceSyncSupport()) { | 186 if (!this->gl->fenceSyncSupport()) { |
| 187 SkDebugf("WARNING: GL context for config \"%s\" does not support fen ce sync. " | 187 SkDebugf("WARNING: GL context for config \"%s\" does not support fen ce sync. " |
| 188 "Timings might not be accurate.\n", this->config.name); | 188 "Timings might not be accurate.\n", this->config.name.c_str ()); |
| 189 } | 189 } |
| 190 return true; | 190 return true; |
| 191 } | 191 } |
| 192 void fillOptions(ResultsWriter* log) override { | 192 void fillOptions(ResultsWriter* log) override { |
| 193 const GrGLubyte* version; | 193 const GrGLubyte* version; |
| 194 SK_GL_RET(*this->gl, version, GetString(GR_GL_VERSION)); | 194 SK_GL_RET(*this->gl, version, GetString(GR_GL_VERSION)); |
| 195 log->configOption("GL_VERSION", (const char*)(version)); | 195 log->configOption("GL_VERSION", (const char*)(version)); |
| 196 | 196 |
| 197 SK_GL_RET(*this->gl, version, GetString(GR_GL_RENDERER)); | 197 SK_GL_RET(*this->gl, version, GetString(GR_GL_RENDERER)); |
| 198 log->configOption("GL_RENDERER", (const char*) version); | 198 log->configOption("GL_RENDERER", (const char*) version); |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 365 | 365 |
| 366 // Pretty much the same deal as the calibration: do some warmup to make | 366 // Pretty much the same deal as the calibration: do some warmup to make |
| 367 // sure we're timing steady-state pipelined frames. | 367 // sure we're timing steady-state pipelined frames. |
| 368 for (int i = 0; i < maxGpuFrameLag - 1; i++) { | 368 for (int i = 0; i < maxGpuFrameLag - 1; i++) { |
| 369 time(loops, bench, target); | 369 time(loops, bench, target); |
| 370 } | 370 } |
| 371 | 371 |
| 372 return loops; | 372 return loops; |
| 373 } | 373 } |
| 374 | 374 |
| 375 static SkString to_lower(const char* str) { | 375 static bool is_cpu_config_allowed(const char* name, const SkCommandLineConfig* c onfig) { |
|
Kimmo Kinnunen
2016/01/21 12:50:01
I guess this could be removed now, if it doesn't d
Sami Väisänen
2016/01/21 13:30:12
Done.
| |
| 376 SkString lower(str); | 376 const auto& tag = config->getTag(); |
| 377 for (size_t i = 0; i < lower.size(); i++) { | 377 return tag.equals(name); |
| 378 lower[i] = tolower(lower[i]); | |
| 379 } | |
| 380 return lower; | |
| 381 } | 378 } |
| 382 | 379 |
| 383 static bool is_cpu_config_allowed(const char* name) { | |
| 384 for (int i = 0; i < FLAGS_config.count(); i++) { | |
| 385 if (to_lower(FLAGS_config[i]).equals(name)) { | |
| 386 return true; | |
| 387 } | |
| 388 } | |
| 389 return false; | |
| 390 } | |
| 391 | |
| 392 #if SK_SUPPORT_GPU | |
| 393 static bool is_gpu_config_allowed(const char* name, GrContextFactory::GLContextT ype ctxType, | |
| 394 GrContextFactory::GLContextOptions ctxOptions, | |
| 395 int sampleCnt) { | |
| 396 if (!is_cpu_config_allowed(name)) { | |
| 397 return false; | |
| 398 } | |
| 399 if (const GrContext* ctx = gGrFactory->get(ctxType, ctxOptions)) { | |
| 400 return sampleCnt <= ctx->caps()->maxSampleCount(); | |
| 401 } | |
| 402 return false; | |
| 403 } | |
| 404 #endif | |
| 405 | |
| 406 #if SK_SUPPORT_GPU | 380 #if SK_SUPPORT_GPU |
| 407 #define kBogusGLContextType GrContextFactory::kNative_GLContextType | 381 #define kBogusGLContextType GrContextFactory::kNative_GLContextType |
| 408 #define kBogusGLContextOptions GrContextFactory::kNone_GLContextOptions | 382 #define kBogusGLContextOptions GrContextFactory::kNone_GLContextOptions |
| 409 #else | 383 #else |
| 410 #define kBogusGLContextType 0 | 384 #define kBogusGLContextType 0 |
| 411 #define kBogusGLContextOptions 0 | 385 #define kBogusGLContextOptions 0 |
| 412 #endif | 386 #endif |
| 413 | 387 |
| 414 // Append all configs that are enabled and supported. | 388 static void create_config(const SkCommandLineConfig* config, SkTArray<Config>* c onfigs) { |
| 415 static void create_configs(SkTDArray<Config>* configs) { | 389 |
| 416 #define CPU_CONFIG(name, backend, color, alpha) \ | 390 #if SK_SUPPORT_GPU |
| 417 if (is_cpu_config_allowed(#name)) { \ | 391 if (const auto* gpuConfig = config->asConfigGpu()) { |
| 418 Config config = { #name, Benchmark::backend, color, alpha, 0, \ | 392 if (!FLAGS_gpu) |
| 419 kBogusGLContextType, kBogusGLContextOptions, \ | 393 return; |
| 420 false }; \ | 394 |
| 421 configs->push(config); \ | 395 const auto ctxOptions = gpuConfig->getUseNVPR() ? GrContextFactory::kEna bleNVPR_GLContextOptions : |
| 396 GrContextFactory::kNone_GLContextOptions; | |
|
Kimmo Kinnunen
2016/01/21 12:50:01
Sometimes I've gotten the request to align this pa
Sami Väisänen
2016/01/21 13:30:12
Done.
| |
| 397 const auto ctxType = gpuConfig->getContextType(); | |
| 398 const auto sampleCount = gpuConfig->getSamples(); | |
| 399 | |
| 400 if (const GrContext* ctx = gGrFactory->get(ctxType, ctxOptions)) { | |
| 401 const auto maxSampleCount = ctx->caps()->maxSampleCount(); | |
| 402 if (sampleCount > ctx->caps()->maxSampleCount()) { | |
| 403 SkDebugf("Configuration sample count %d exceeds maximum %d.\n", | |
| 404 sampleCount, maxSampleCount); | |
| 405 return; | |
| 406 } | |
| 407 } else { | |
| 408 SkDebugf("No context was available matching config type and options. \n"); | |
| 409 return; | |
| 410 } | |
| 411 | |
| 412 Config target = { | |
| 413 config->getTag(), | |
| 414 Benchmark::kGPU_Backend, | |
| 415 kN32_SkColorType, | |
| 416 kPremul_SkAlphaType, | |
| 417 sampleCount, | |
| 418 ctxType, | |
| 419 ctxOptions, | |
| 420 false }; | |
| 421 | |
| 422 configs->push_back(target); | |
| 423 return; | |
| 424 } | |
| 425 #endif | |
| 426 | |
| 427 #define CPU_CONFIG(name, backend, color, alpha) \ | |
| 428 if (is_cpu_config_allowed(#name, config)) { \ | |
| 429 Config config = { SkString(#name), Benchmark::backend, color, alpha, 0, \ | |
| 430 kBogusGLContextType, kBogusGLContextOptions, \ | |
| 431 false }; \ | |
| 432 configs->push_back(config); \ | |
| 433 return; \ | |
| 422 } | 434 } |
| 423 | 435 |
| 424 if (FLAGS_cpu) { | 436 if (FLAGS_cpu) { |
| 425 CPU_CONFIG(nonrendering, kNonRendering_Backend, kUnknown_SkColorType, kU npremul_SkAlphaType) | 437 CPU_CONFIG(nonrendering, kNonRendering_Backend, kUnknown_SkColorType, kU npremul_SkAlphaType) |
| 426 CPU_CONFIG(8888, kRaster_Backend, kN32_SkColorType, kPremul_SkAlphaType) | 438 CPU_CONFIG(8888, kRaster_Backend, kN32_SkColorType, kPremul_SkAlphaType) |
| 427 CPU_CONFIG(565, kRaster_Backend, kRGB_565_SkColorType, kOpaque_SkAlphaTy pe) | 439 CPU_CONFIG(565, kRaster_Backend, kRGB_565_SkColorType, kOpaque_SkAlphaTy pe) |
| 428 } | 440 } |
| 429 | 441 |
| 430 #if SK_SUPPORT_GPU | 442 #undef CPU_CONFIG |
| 431 #define GPU_CONFIG(name, ctxType, ctxOptions, samples, useDFText) \ | |
| 432 if (is_gpu_config_allowed(#name, GrContextFactory::ctxType, \ | |
| 433 GrContextFactory::ctxOptions, samples)) { \ | |
| 434 Config config = { \ | |
| 435 #name, \ | |
| 436 Benchmark::kGPU_Backend, \ | |
| 437 kN32_SkColorType, \ | |
| 438 kPremul_SkAlphaType, \ | |
| 439 samples, \ | |
| 440 GrContextFactory::ctxType, \ | |
| 441 GrContextFactory::ctxOptions, \ | |
| 442 useDFText }; \ | |
| 443 configs->push(config); \ | |
| 444 } | |
| 445 | |
| 446 if (FLAGS_gpu) { | |
| 447 GPU_CONFIG(gpu, kNative_GLContextType, kNone_GLContextOptions, 0, false) | |
| 448 GPU_CONFIG(msaa4, kNative_GLContextType, kNone_GLContextOptions, 4, fals e) | |
| 449 GPU_CONFIG(msaa16, kNative_GLContextType, kNone_GLContextOptions, 16, fa lse) | |
| 450 GPU_CONFIG(nvprmsaa4, kNative_GLContextType, kEnableNVPR_GLContextOption s, 4, false) | |
| 451 GPU_CONFIG(nvprmsaa16, kNative_GLContextType, kEnableNVPR_GLContextOptio ns, 16, false) | |
| 452 GPU_CONFIG(gpudft, kNative_GLContextType, kNone_GLContextOptions, 0, tru e) | |
| 453 GPU_CONFIG(debug, kDebug_GLContextType, kNone_GLContextOptions, 0, false ) | |
| 454 GPU_CONFIG(nullgpu, kNull_GLContextType, kNone_GLContextOptions, 0, fals e) | |
| 455 #if SK_ANGLE | |
| 456 #ifdef SK_BUILD_FOR_WIN | |
| 457 GPU_CONFIG(angle, kANGLE_GLContextType, kNone_GLContextOptions, 0, false ) | |
| 458 #endif | |
| 459 GPU_CONFIG(angle-gl, kANGLE_GL_GLContextType, kNone_GLContextOptions, 0, false) | |
| 460 #endif | |
| 461 #if SK_COMMAND_BUFFER | |
| 462 GPU_CONFIG(commandbuffer, kCommandBuffer_GLContextType, kNone_GLContextO ptions, 0, false) | |
| 463 #endif | |
| 464 #if SK_MESA | |
| 465 GPU_CONFIG(mesa, kMESA_GLContextType, kNone_GLContextOptions, 0, false) | |
| 466 #endif | |
| 467 } | |
| 468 #endif | |
| 469 | 443 |
| 470 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK | 444 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 471 if (is_cpu_config_allowed("hwui")) { | 445 if (is_cpu_config_allowed("hwui", config)) { |
| 472 Config config = { "hwui", Benchmark::kHWUI_Backend, kRGBA_8888_SkColorTy pe, | 446 Config config = { "hwui", Benchmark::kHWUI_Backend, kRGBA_8888_SkColorTy pe, |
| 473 kPremul_SkAlphaType, 0, kBogusGLContextType, kBogusGLC ontextOptions, | 447 kPremul_SkAlphaType, 0, kBogusGLContextType, kBogusGLC ontextOptions, |
| 474 false }; | 448 false }; |
| 475 configs->push(config); | 449 configs->push_back(config); |
| 450 return; | |
| 476 } | 451 } |
| 477 #endif | 452 #endif |
| 478 } | 453 } |
| 479 | 454 |
| 455 // Append all configs that are enabled and supported. | |
| 456 void create_configs(SkTArray<Config>* configs) { | |
| 457 SkCommandLineConfigArray array; | |
| 458 ParseConfigs(FLAGS_config, &array); | |
| 459 for (int i = 0; i < array.count(); ++i) { | |
| 460 create_config(array[i], configs); | |
| 461 } | |
| 462 } | |
| 463 | |
| 480 // If bench is enabled for config, returns a Target* for it, otherwise nullptr. | 464 // If bench is enabled for config, returns a Target* for it, otherwise nullptr. |
| 481 static Target* is_enabled(Benchmark* bench, const Config& config) { | 465 static Target* is_enabled(Benchmark* bench, const Config& config) { |
| 482 if (!bench->isSuitableFor(config.backend)) { | 466 if (!bench->isSuitableFor(config.backend)) { |
| 483 return nullptr; | 467 return nullptr; |
| 484 } | 468 } |
| 485 | 469 |
| 486 SkImageInfo info = SkImageInfo::Make(bench->getSize().fX, bench->getSize().f Y, | 470 SkImageInfo info = SkImageInfo::Make(bench->getSize().fX, bench->getSize().f Y, |
| 487 config.color, config.alpha); | 471 config.color, config.alpha); |
| 488 | 472 |
| 489 Target* target = nullptr; | 473 Target* target = nullptr; |
| (...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1083 } else if (FLAGS_quiet) { | 1067 } else if (FLAGS_quiet) { |
| 1084 SkDebugf("! -> high variance, ? -> moderate variance\n"); | 1068 SkDebugf("! -> high variance, ? -> moderate variance\n"); |
| 1085 SkDebugf(" micros \tbench\n"); | 1069 SkDebugf(" micros \tbench\n"); |
| 1086 } else if (FLAGS_ms) { | 1070 } else if (FLAGS_ms) { |
| 1087 SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\tsamples\tc onfig\tbench\n"); | 1071 SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\tsamples\tc onfig\tbench\n"); |
| 1088 } else { | 1072 } else { |
| 1089 SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\t%-*s\tconf ig\tbench\n", | 1073 SkDebugf("curr/maxrss\tloops\tmin\tmedian\tmean\tmax\tstddev\t%-*s\tconf ig\tbench\n", |
| 1090 FLAGS_samples, "samples"); | 1074 FLAGS_samples, "samples"); |
| 1091 } | 1075 } |
| 1092 | 1076 |
| 1093 SkTDArray<Config> configs; | 1077 SkTArray<Config> configs; |
| 1094 create_configs(&configs); | 1078 create_configs(&configs); |
| 1095 | 1079 |
| 1096 if (FLAGS_keepAlive) { | 1080 if (FLAGS_keepAlive) { |
| 1097 start_keepalive(); | 1081 start_keepalive(); |
| 1098 } | 1082 } |
| 1099 | 1083 |
| 1100 int runs = 0; | 1084 int runs = 0; |
| 1101 BenchmarkStream benchStream; | 1085 BenchmarkStream benchStream; |
| 1102 while (Benchmark* b = benchStream.next()) { | 1086 while (Benchmark* b = benchStream.next()) { |
| 1103 SkAutoTDelete<Benchmark> bench(b); | 1087 SkAutoTDelete<Benchmark> bench(b); |
| 1104 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName())) { | 1088 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName())) { |
| 1105 continue; | 1089 continue; |
| 1106 } | 1090 } |
| 1107 | 1091 |
| 1108 if (!configs.isEmpty()) { | 1092 if (!configs.empty()) { |
| 1109 log->bench(bench->getUniqueName(), bench->getSize().fX, bench->getSi ze().fY); | 1093 log->bench(bench->getUniqueName(), bench->getSize().fX, bench->getSi ze().fY); |
| 1110 bench->delayedSetup(); | 1094 bench->delayedSetup(); |
| 1111 } | 1095 } |
| 1112 for (int i = 0; i < configs.count(); ++i) { | 1096 for (int i = 0; i < configs.count(); ++i) { |
| 1113 Target* target = is_enabled(b, configs[i]); | 1097 Target* target = is_enabled(b, configs[i]); |
| 1114 if (!target) { | 1098 if (!target) { |
| 1115 continue; | 1099 continue; |
| 1116 } | 1100 } |
| 1117 | 1101 |
| 1118 // During HWUI output this canvas may be nullptr. | 1102 // During HWUI output this canvas may be nullptr. |
| 1119 SkCanvas* canvas = target->getCanvas(); | 1103 SkCanvas* canvas = target->getCanvas(); |
| 1120 const char* config = target->config.name; | 1104 const char* config = target->config.name.c_str(); |
| 1121 | 1105 |
| 1122 target->setup(); | 1106 target->setup(); |
| 1123 bench->perCanvasPreDraw(canvas); | 1107 bench->perCanvasPreDraw(canvas); |
| 1124 | 1108 |
| 1125 int maxFrameLag; | 1109 int maxFrameLag; |
| 1126 int loops = target->needsFrameTiming(&maxFrameLag) | 1110 int loops = target->needsFrameTiming(&maxFrameLag) |
| 1127 ? setup_gpu_bench(target, bench.get(), maxFrameLag) | 1111 ? setup_gpu_bench(target, bench.get(), maxFrameLag) |
| 1128 : setup_cpu_bench(overhead, target, bench.get()); | 1112 : setup_cpu_bench(overhead, target, bench.get()); |
| 1129 | 1113 |
| 1130 if (FLAGS_ms) { | 1114 if (FLAGS_ms) { |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1253 | 1237 |
| 1254 return 0; | 1238 return 0; |
| 1255 } | 1239 } |
| 1256 | 1240 |
| 1257 #if !defined SK_BUILD_FOR_IOS | 1241 #if !defined SK_BUILD_FOR_IOS |
| 1258 int main(int argc, char** argv) { | 1242 int main(int argc, char** argv) { |
| 1259 SkCommandLineFlags::Parse(argc, argv); | 1243 SkCommandLineFlags::Parse(argc, argv); |
| 1260 return nanobench_main(); | 1244 return nanobench_main(); |
| 1261 } | 1245 } |
| 1262 #endif | 1246 #endif |
| OLD | NEW |