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

Side by Side Diff: bench/nanobench.cpp

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