Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Side by Side Diff: bench/nanobench.cpp

Issue 750583002: Revert of Add MultiPictureDraw to nanobench (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « bench/SKPBench.cpp ('k') | include/core/SkColorTable.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "Benchmark.h" 10 #include "Benchmark.h"
11 #include "CrashHandler.h" 11 #include "CrashHandler.h"
12 #include "GMBench.h" 12 #include "GMBench.h"
13 #include "ProcStats.h" 13 #include "ProcStats.h"
14 #include "ResultsWriter.h" 14 #include "ResultsWriter.h"
15 #include "RecordingBench.h" 15 #include "RecordingBench.h"
16 #include "SKPBench.h" 16 #include "SKPBench.h"
17 #include "Stats.h" 17 #include "Stats.h"
18 #include "Timer.h" 18 #include "Timer.h"
19 19
20 #include "SkBBoxHierarchy.h" 20 #include "SkBBoxHierarchy.h"
21 #include "SkCanvas.h" 21 #include "SkCanvas.h"
22 #include "SkCommonFlags.h" 22 #include "SkCommonFlags.h"
23 #include "SkForceLinking.h" 23 #include "SkForceLinking.h"
24 #include "SkGraphics.h" 24 #include "SkGraphics.h"
25 #include "SkOSFile.h" 25 #include "SkOSFile.h"
26 #include "SkPictureRecorder.h" 26 #include "SkPictureRecorder.h"
27 #include "SkString.h" 27 #include "SkString.h"
28 #include "SkSurface.h" 28 #include "SkSurface.h"
29 #include "SkTaskGroup.h"
30 29
31 #if SK_SUPPORT_GPU 30 #if SK_SUPPORT_GPU
32 #include "gl/GrGLDefines.h" 31 #include "gl/GrGLDefines.h"
33 #include "GrContextFactory.h" 32 #include "GrContextFactory.h"
34 SkAutoTDelete<GrContextFactory> gGrFactory; 33 SkAutoTDelete<GrContextFactory> gGrFactory;
35 #endif 34 #endif
36 35
37 __SK_FORCE_IMAGE_DECODER_LINKING; 36 __SK_FORCE_IMAGE_DECODER_LINKING;
38 37
39 static const int kAutoTuneLoops = 0; 38 static const int kAutoTuneLoops = 0;
(...skipping 24 matching lines...) Expand all
64 DEFINE_bool(gpuCompressAlphaMasks, false, "Compress masks generated from falling back to " 63 DEFINE_bool(gpuCompressAlphaMasks, false, "Compress masks generated from falling back to "
65 "software path rendering."); 64 "software path rendering.");
66 65
67 DEFINE_string(outResultsFile, "", "If given, write results here as JSON."); 66 DEFINE_string(outResultsFile, "", "If given, write results here as JSON.");
68 DEFINE_int32(maxCalibrationAttempts, 3, 67 DEFINE_int32(maxCalibrationAttempts, 3,
69 "Try up to this many times to guess loops for a bench, or skip the bench."); 68 "Try up to this many times to guess loops for a bench, or skip the bench.");
70 DEFINE_int32(maxLoops, 1000000, "Never run a bench more times than this."); 69 DEFINE_int32(maxLoops, 1000000, "Never run a bench more times than this.");
71 DEFINE_string(clip, "0,0,1000,1000", "Clip for SKPs."); 70 DEFINE_string(clip, "0,0,1000,1000", "Clip for SKPs.");
72 DEFINE_string(scales, "1.0", "Space-separated scales for SKPs."); 71 DEFINE_string(scales, "1.0", "Space-separated scales for SKPs.");
73 DEFINE_bool(bbh, true, "Build a BBH for SKPs?"); 72 DEFINE_bool(bbh, true, "Build a BBH for SKPs?");
74 DEFINE_bool(mpd, true, "Use MultiPictureDraw for the SKPs?");
75 DEFINE_int32(flushEvery, 10, "Flush --outResultsFile every Nth run."); 73 DEFINE_int32(flushEvery, 10, "Flush --outResultsFile every Nth run.");
76 74
77 static SkString humanize(double ms) { 75 static SkString humanize(double ms) {
78 if (FLAGS_verbose) return SkStringPrintf("%llu", (uint64_t)(ms*1e6)); 76 if (FLAGS_verbose) return SkStringPrintf("%llu", (uint64_t)(ms*1e6));
79 if (ms > 1e+3) return SkStringPrintf("%.3gs", ms/1e3); 77 if (ms > 1e+3) return SkStringPrintf("%.3gs", ms/1e3);
80 if (ms < 1e-3) return SkStringPrintf("%.3gns", ms*1e6); 78 if (ms < 1e-3) return SkStringPrintf("%.3gns", ms*1e6);
81 #ifdef SK_BUILD_FOR_WIN 79 #ifdef SK_BUILD_FOR_WIN
82 if (ms < 1) return SkStringPrintf("%.3gus", ms*1e3); 80 if (ms < 1) return SkStringPrintf("%.3gus", ms*1e3);
83 #else 81 #else
84 if (ms < 1) return SkStringPrintf("%.3gµs", ms*1e3); 82 if (ms < 1) return SkStringPrintf("%.3gµs", ms*1e3);
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
210 loops = detect_forever_loops(loops); 208 loops = detect_forever_loops(loops);
211 } 209 }
212 210
213 for (int i = 0; i < FLAGS_samples; i++) { 211 for (int i = 0; i < FLAGS_samples; i++) {
214 samples[i] = time(loops, bench, canvas, NULL) / loops; 212 samples[i] = time(loops, bench, canvas, NULL) / loops;
215 } 213 }
216 return loops; 214 return loops;
217 } 215 }
218 216
219 #if SK_SUPPORT_GPU 217 #if SK_SUPPORT_GPU
220 static void setup_gl(SkGLContext* gl) {
221 gl->makeCurrent();
222 // Make sure we're done with whatever came before.
223 SK_GL(*gl, Finish());
224 }
225
226 static int gpu_bench(SkGLContext* gl, 218 static int gpu_bench(SkGLContext* gl,
227 Benchmark* bench, 219 Benchmark* bench,
228 SkCanvas* canvas, 220 SkCanvas* canvas,
229 double* samples) { 221 double* samples) {
222 gl->makeCurrent();
223 // Make sure we're done with whatever came before.
224 SK_GL(*gl, Finish());
225
230 // First, figure out how many loops it'll take to get a frame up to FLAGS_gp uMs. 226 // First, figure out how many loops it'll take to get a frame up to FLAGS_gp uMs.
231 int loops = FLAGS_loops; 227 int loops = FLAGS_loops;
232 if (kAutoTuneLoops == loops) { 228 if (kAutoTuneLoops == loops) {
233 loops = 1; 229 loops = 1;
234 double elapsed = 0; 230 double elapsed = 0;
235 do { 231 do {
236 if (1<<30 == loops) { 232 if (1<<30 == loops) {
237 // We're about to wrap. Something's wrong with the bench. 233 // We're about to wrap. Something's wrong with the bench.
238 loops = 0; 234 loops = 0;
239 break; 235 break;
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
434 log->configOption("GL_SHADING_LANGUAGE_VERSION", (const char*) version); 430 log->configOption("GL_SHADING_LANGUAGE_VERSION", (const char*) version);
435 } 431 }
436 #endif 432 #endif
437 433
438 class BenchmarkStream { 434 class BenchmarkStream {
439 public: 435 public:
440 BenchmarkStream() : fBenches(BenchRegistry::Head()) 436 BenchmarkStream() : fBenches(BenchRegistry::Head())
441 , fGMs(skiagm::GMRegistry::Head()) 437 , fGMs(skiagm::GMRegistry::Head())
442 , fCurrentRecording(0) 438 , fCurrentRecording(0)
443 , fCurrentScale(0) 439 , fCurrentScale(0)
444 , fCurrentSKP(0) 440 , fCurrentSKP(0) {
445 , fCurrentUseMPD(0) {
446 for (int i = 0; i < FLAGS_skps.count(); i++) { 441 for (int i = 0; i < FLAGS_skps.count(); i++) {
447 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { 442 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) {
448 fSKPs.push_back() = FLAGS_skps[i]; 443 fSKPs.push_back() = FLAGS_skps[i];
449 } else { 444 } else {
450 SkOSFile::Iter it(FLAGS_skps[i], ".skp"); 445 SkOSFile::Iter it(FLAGS_skps[i], ".skp");
451 SkString path; 446 SkString path;
452 while (it.next(&path)) { 447 while (it.next(&path)) {
453 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str ()); 448 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str ());
454 } 449 }
455 } 450 }
456 } 451 }
457 452
458 if (4 != sscanf(FLAGS_clip[0], "%d,%d,%d,%d", 453 if (4 != sscanf(FLAGS_clip[0], "%d,%d,%d,%d",
459 &fClip.fLeft, &fClip.fTop, &fClip.fRight, &fClip.fBottom )) { 454 &fClip.fLeft, &fClip.fTop, &fClip.fRight, &fClip.fBottom )) {
460 SkDebugf("Can't parse %s from --clip as an SkIRect.\n", FLAGS_clip[0 ]); 455 SkDebugf("Can't parse %s from --clip as an SkIRect.\n", FLAGS_clip[0 ]);
461 exit(1); 456 exit(1);
462 } 457 }
463 458
464 for (int i = 0; i < FLAGS_scales.count(); i++) { 459 for (int i = 0; i < FLAGS_scales.count(); i++) {
465 if (1 != sscanf(FLAGS_scales[i], "%f", &fScales.push_back())) { 460 if (1 != sscanf(FLAGS_scales[i], "%f", &fScales.push_back())) {
466 SkDebugf("Can't parse %s from --scales as an SkScalar.\n", FLAGS _scales[i]); 461 SkDebugf("Can't parse %s from --scales as an SkScalar.\n", FLAGS _scales[i]);
467 exit(1); 462 exit(1);
468 } 463 }
469 } 464 }
470
471 fUseMPDs.push_back() = false;
472 if (FLAGS_mpd) {
473 fUseMPDs.push_back() = true;
474 }
475 } 465 }
476 466
477 static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic) { 467 static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic) {
478 // Not strictly necessary, as it will be checked again later, 468 // Not strictly necessary, as it will be checked again later,
479 // but helps to avoid a lot of pointless work if we're going to skip it. 469 // but helps to avoid a lot of pointless work if we're going to skip it.
480 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) { 470 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) {
481 return false; 471 return false;
482 } 472 }
483 473
484 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); 474 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
523 } 513 }
524 SkString name = SkOSPath::Basename(path.c_str()); 514 SkString name = SkOSPath::Basename(path.c_str());
525 fSourceType = "skp"; 515 fSourceType = "skp";
526 fBenchType = "recording"; 516 fBenchType = "recording";
527 return SkNEW_ARGS(RecordingBench, (name.c_str(), pic.get(), FLAGS_bb h)); 517 return SkNEW_ARGS(RecordingBench, (name.c_str(), pic.get(), FLAGS_bb h));
528 } 518 }
529 519
530 // Then once each for each scale as SKPBenches (playback). 520 // Then once each for each scale as SKPBenches (playback).
531 while (fCurrentScale < fScales.count()) { 521 while (fCurrentScale < fScales.count()) {
532 while (fCurrentSKP < fSKPs.count()) { 522 while (fCurrentSKP < fSKPs.count()) {
533 const SkString& path = fSKPs[fCurrentSKP]; 523 const SkString& path = fSKPs[fCurrentSKP++];
534 SkAutoTUnref<SkPicture> pic; 524 SkAutoTUnref<SkPicture> pic;
535 if (!ReadPicture(path.c_str(), &pic)) { 525 if (!ReadPicture(path.c_str(), &pic)) {
536 fCurrentSKP++;
537 continue; 526 continue;
538 } 527 }
539 528 if (FLAGS_bbh) {
540 while (fCurrentUseMPD < fUseMPDs.count()) { 529 // The SKP we read off disk doesn't have a BBH. Re-record s o it grows one.
541 if (FLAGS_bbh) { 530 SkRTreeFactory factory;
542 // The SKP we read off disk doesn't have a BBH. Re-reco rd so it grows one. 531 SkPictureRecorder recorder;
543 SkRTreeFactory factory; 532 pic->playback(recorder.beginRecording(pic->cullRect().width( ),
544 SkPictureRecorder recorder; 533 pic->cullRect().height (),
545 static const int kFlags = SkPictureRecorder::kComputeSav eLayerInfo_RecordFlag; 534 &factory));
546 pic->playback(recorder.beginRecording(pic->cullRect().wi dth(), 535 pic.reset(recorder.endRecording());
547 pic->cullRect().he ight(),
548 &factory, kFlags)) ;
549 pic.reset(recorder.endRecording());
550 }
551 SkString name = SkOSPath::Basename(path.c_str());
552 fSourceType = "skp";
553 fBenchType = "playback";
554 return SkNEW_ARGS(SKPBench,
555 (name.c_str(), pic.get(), fClip,
556 fScales[fCurrentScale], fUseMPDs[fCurrentUseMPD++]) );
557 } 536 }
558 fCurrentUseMPD = 0; 537 SkString name = SkOSPath::Basename(path.c_str());
559 fCurrentSKP++; 538 fSourceType = "skp";
539 fBenchType = "playback";
540 return SkNEW_ARGS(SKPBench,
541 (name.c_str(), pic.get(), fClip, fScales[fCurrentScale]) );
560 } 542 }
561 fCurrentSKP = 0; 543 fCurrentSKP = 0;
562 fCurrentScale++; 544 fCurrentScale++;
563 } 545 }
564 546
565 return NULL; 547 return NULL;
566 } 548 }
567 549
568 void fillCurrentOptions(ResultsWriter* log) const { 550 void fillCurrentOptions(ResultsWriter* log) const {
569 log->configOption("source_type", fSourceType); 551 log->configOption("source_type", fSourceType);
570 log->configOption("bench_type", fBenchType); 552 log->configOption("bench_type", fBenchType);
571 if (0 == strcmp(fSourceType, "skp")) { 553 if (0 == strcmp(fSourceType, "skp")) {
572 log->configOption("clip", 554 log->configOption("clip",
573 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop, 555 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop,
574 fClip.fRight, fClip.fBottom).c _str()); 556 fClip.fRight, fClip.fBottom).c _str());
575 log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentSc ale]).c_str()); 557 log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentSc ale]).c_str());
576 if (fCurrentUseMPD > 0) {
577 SkASSERT(1 == fCurrentUseMPD || 2 == fCurrentUseMPD);
578 log->configOption("multi_picture_draw", fUseMPDs[fCurrentUseMPD- 1] ? "true" : "false");
579 }
580 } 558 }
581 } 559 }
582 560
583 private: 561 private:
584 const BenchRegistry* fBenches; 562 const BenchRegistry* fBenches;
585 const skiagm::GMRegistry* fGMs; 563 const skiagm::GMRegistry* fGMs;
586 SkIRect fClip; 564 SkIRect fClip;
587 SkTArray<SkScalar> fScales; 565 SkTArray<SkScalar> fScales;
588 SkTArray<SkString> fSKPs; 566 SkTArray<SkString> fSKPs;
589 SkTArray<bool> fUseMPDs;
590 567
591 const char* fSourceType; // What we're benching: bench, GM, SKP, ... 568 const char* fSourceType; // What we're benching: bench, GM, SKP, ...
592 const char* fBenchType; // How we bench it: micro, recording, playback, .. . 569 const char* fBenchType; // How we bench it: micro, recording, playback, .. .
593 int fCurrentRecording; 570 int fCurrentRecording;
594 int fCurrentScale; 571 int fCurrentScale;
595 int fCurrentSKP; 572 int fCurrentSKP;
596 int fCurrentUseMPD;
597 }; 573 };
598 574
599 int nanobench_main(); 575 int nanobench_main();
600 int nanobench_main() { 576 int nanobench_main() {
601 SetupCrashHandler(); 577 SetupCrashHandler();
602 SkAutoGraphics ag; 578 SkAutoGraphics ag;
603 SkTaskGroup::Enabler enabled;
604 579
605 #if SK_SUPPORT_GPU 580 #if SK_SUPPORT_GPU
606 GrContext::Options grContextOpts; 581 GrContext::Options grContextOpts;
607 grContextOpts.fDrawPathToCompressedTexture = FLAGS_gpuCompressAlphaMasks; 582 grContextOpts.fDrawPathToCompressedTexture = FLAGS_gpuCompressAlphaMasks;
608 gGrFactory.reset(SkNEW_ARGS(GrContextFactory, (grContextOpts))); 583 gGrFactory.reset(SkNEW_ARGS(GrContextFactory, (grContextOpts)));
609 #endif 584 #endif
610 585
611 if (FLAGS_veryVerbose) { 586 if (FLAGS_veryVerbose) {
612 FLAGS_verbose = true; 587 FLAGS_verbose = true;
613 } 588 }
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
677 create_targets(&targets, bench.get(), configs); 652 create_targets(&targets, bench.get(), configs);
678 653
679 if (!targets.isEmpty()) { 654 if (!targets.isEmpty()) {
680 log->bench(bench->getUniqueName(), bench->getSize().fX, bench->getSi ze().fY); 655 log->bench(bench->getUniqueName(), bench->getSize().fX, bench->getSi ze().fY);
681 bench->preDraw(); 656 bench->preDraw();
682 } 657 }
683 for (int j = 0; j < targets.count(); j++) { 658 for (int j = 0; j < targets.count(); j++) {
684 SkCanvas* canvas = targets[j]->surface.get() ? targets[j]->surface-> getCanvas() : NULL; 659 SkCanvas* canvas = targets[j]->surface.get() ? targets[j]->surface-> getCanvas() : NULL;
685 const char* config = targets[j]->config.name; 660 const char* config = targets[j]->config.name;
686 661
687 #if SK_SUPPORT_GPU
688 if (Benchmark::kGPU_Backend == targets[j]->config.backend) {
689 setup_gl(targets[j]->gl);
690 }
691 #endif
692
693 bench->perCanvasPreDraw(canvas);
694
695 const int loops = 662 const int loops =
696 #if SK_SUPPORT_GPU 663 #if SK_SUPPORT_GPU
697 Benchmark::kGPU_Backend == targets[j]->config.backend 664 Benchmark::kGPU_Backend == targets[j]->config.backend
698 ? gpu_bench(targets[j]->gl, bench.get(), canvas, samples.get()) 665 ? gpu_bench(targets[j]->gl, bench.get(), canvas, samples.get())
699 : 666 :
700 #endif 667 #endif
701 cpu_bench( overhead, bench.get(), canvas, samples.get()); 668 cpu_bench( overhead, bench.get(), canvas, samples.get());
702 669
703 bench->perCanvasPostDraw(canvas);
704
705 if (canvas && !FLAGS_writePath.isEmpty() && FLAGS_writePath[0]) { 670 if (canvas && !FLAGS_writePath.isEmpty() && FLAGS_writePath[0]) {
706 SkString pngFilename = SkOSPath::Join(FLAGS_writePath[0], config ); 671 SkString pngFilename = SkOSPath::Join(FLAGS_writePath[0], config );
707 pngFilename = SkOSPath::Join(pngFilename.c_str(), bench->getUniq ueName()); 672 pngFilename = SkOSPath::Join(pngFilename.c_str(), bench->getUniq ueName());
708 pngFilename.append(".png"); 673 pngFilename.append(".png");
709 write_canvas_png(canvas, pngFilename); 674 write_canvas_png(canvas, pngFilename);
710 } 675 }
711 676
712 if (kFailedLoops == loops) { 677 if (kFailedLoops == loops) {
713 // Can't be timed. A warning note has already been printed. 678 // Can't be timed. A warning note has already been printed.
714 continue; 679 continue;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
786 751
787 return 0; 752 return 0;
788 } 753 }
789 754
790 #if !defined SK_BUILD_FOR_IOS 755 #if !defined SK_BUILD_FOR_IOS
791 int main(int argc, char** argv) { 756 int main(int argc, char** argv) {
792 SkCommandLineFlags::Parse(argc, argv); 757 SkCommandLineFlags::Parse(argc, argv);
793 return nanobench_main(); 758 return nanobench_main();
794 } 759 }
795 #endif 760 #endif
OLDNEW
« no previous file with comments | « bench/SKPBench.cpp ('k') | include/core/SkColorTable.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698