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

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: Fix bug in scaled tile placement 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') | no next file » | 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"
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
62 DEFINE_int32(gpuFrameLag, 5, "Overestimate of maximum number of frames GPU allow s to lag."); 62 DEFINE_int32(gpuFrameLag, 5, "Overestimate of maximum number of frames GPU allow s to lag.");
63 DEFINE_bool(gpuCompressAlphaMasks, false, "Compress masks generated from falling back to " 63 DEFINE_bool(gpuCompressAlphaMasks, false, "Compress masks generated from falling back to "
64 "software path rendering."); 64 "software path rendering.");
65 65
66 DEFINE_string(outResultsFile, "", "If given, write results here as JSON."); 66 DEFINE_string(outResultsFile, "", "If given, write results here as JSON.");
67 DEFINE_int32(maxCalibrationAttempts, 3, 67 DEFINE_int32(maxCalibrationAttempts, 3,
68 "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.");
69 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.");
70 DEFINE_string(clip, "0,0,1000,1000", "Clip for SKPs."); 70 DEFINE_string(clip, "0,0,1000,1000", "Clip for SKPs.");
71 DEFINE_string(scales, "1.0", "Space-separated scales for SKPs."); 71 DEFINE_string(scales, "1.0", "Space-separated scales for SKPs.");
72 DEFINE_bool(bbh, true, "Build a BBH for SKPs?"); 72 DEFINE_bool(bbh, true, "Build a BBH for SKPs?");
mtklein 2014/11/19 19:12:37 Seems like bbh and mpd don't really need to be fla
robertphillips 2014/11/19 19:58:58 I was mainly following the pattern. It does seem l
73 DEFINE_bool(mpd, true, "Use MultiPictureDraw for the SKPs?");
73 DEFINE_int32(flushEvery, 10, "Flush --outResultsFile every Nth run."); 74 DEFINE_int32(flushEvery, 10, "Flush --outResultsFile every Nth run.");
74 75
75 static SkString humanize(double ms) { 76 static SkString humanize(double ms) {
76 if (FLAGS_verbose) return SkStringPrintf("%llu", (uint64_t)(ms*1e6)); 77 if (FLAGS_verbose) return SkStringPrintf("%llu", (uint64_t)(ms*1e6));
77 if (ms > 1e+3) return SkStringPrintf("%.3gs", ms/1e3); 78 if (ms > 1e+3) return SkStringPrintf("%.3gs", ms/1e3);
78 if (ms < 1e-3) return SkStringPrintf("%.3gns", ms*1e6); 79 if (ms < 1e-3) return SkStringPrintf("%.3gns", ms*1e6);
79 #ifdef SK_BUILD_FOR_WIN 80 #ifdef SK_BUILD_FOR_WIN
80 if (ms < 1) return SkStringPrintf("%.3gus", ms*1e3); 81 if (ms < 1) return SkStringPrintf("%.3gus", ms*1e3);
81 #else 82 #else
82 if (ms < 1) return SkStringPrintf("%.3gµs", ms*1e3); 83 if (ms < 1) return SkStringPrintf("%.3gµs", ms*1e3);
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
430 log->configOption("GL_SHADING_LANGUAGE_VERSION", (const char*) version); 431 log->configOption("GL_SHADING_LANGUAGE_VERSION", (const char*) version);
431 } 432 }
432 #endif 433 #endif
433 434
434 class BenchmarkStream { 435 class BenchmarkStream {
435 public: 436 public:
436 BenchmarkStream() : fBenches(BenchRegistry::Head()) 437 BenchmarkStream() : fBenches(BenchRegistry::Head())
437 , fGMs(skiagm::GMRegistry::Head()) 438 , fGMs(skiagm::GMRegistry::Head())
438 , fCurrentRecording(0) 439 , fCurrentRecording(0)
439 , fCurrentScale(0) 440 , fCurrentScale(0)
440 , fCurrentSKP(0) { 441 , fCurrentSKP(0)
442 , fCurrentUseMPD(0) {
441 for (int i = 0; i < FLAGS_skps.count(); i++) { 443 for (int i = 0; i < FLAGS_skps.count(); i++) {
442 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) { 444 if (SkStrEndsWith(FLAGS_skps[i], ".skp")) {
443 fSKPs.push_back() = FLAGS_skps[i]; 445 fSKPs.push_back() = FLAGS_skps[i];
444 } else { 446 } else {
445 SkOSFile::Iter it(FLAGS_skps[i], ".skp"); 447 SkOSFile::Iter it(FLAGS_skps[i], ".skp");
446 SkString path; 448 SkString path;
447 while (it.next(&path)) { 449 while (it.next(&path)) {
448 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str ()); 450 fSKPs.push_back() = SkOSPath::Join(FLAGS_skps[0], path.c_str ());
449 } 451 }
450 } 452 }
451 } 453 }
452 454
453 if (4 != sscanf(FLAGS_clip[0], "%d,%d,%d,%d", 455 if (4 != sscanf(FLAGS_clip[0], "%d,%d,%d,%d",
454 &fClip.fLeft, &fClip.fTop, &fClip.fRight, &fClip.fBottom )) { 456 &fClip.fLeft, &fClip.fTop, &fClip.fRight, &fClip.fBottom )) {
455 SkDebugf("Can't parse %s from --clip as an SkIRect.\n", FLAGS_clip[0 ]); 457 SkDebugf("Can't parse %s from --clip as an SkIRect.\n", FLAGS_clip[0 ]);
456 exit(1); 458 exit(1);
457 } 459 }
458 460
459 for (int i = 0; i < FLAGS_scales.count(); i++) { 461 for (int i = 0; i < FLAGS_scales.count(); i++) {
460 if (1 != sscanf(FLAGS_scales[i], "%f", &fScales.push_back())) { 462 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]); 463 SkDebugf("Can't parse %s from --scales as an SkScalar.\n", FLAGS _scales[i]);
462 exit(1); 464 exit(1);
463 } 465 }
464 } 466 }
467
468 fUseMPDs.push_back() = false;
469 if (FLAGS_mpd) {
470 fUseMPDs.push_back() = true;
471 }
465 } 472 }
466 473
467 static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic) { 474 static bool ReadPicture(const char* path, SkAutoTUnref<SkPicture>* pic) {
468 // Not strictly necessary, as it will be checked again later, 475 // 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. 476 // but helps to avoid a lot of pointless work if we're going to skip it.
470 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) { 477 if (SkCommandLineFlags::ShouldSkip(FLAGS_match, path)) {
471 return false; 478 return false;
472 } 479 }
473 480
474 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path)); 481 SkAutoTUnref<SkStream> stream(SkStream::NewFromFile(path));
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 } 520 }
514 SkString name = SkOSPath::Basename(path.c_str()); 521 SkString name = SkOSPath::Basename(path.c_str());
515 fSourceType = "skp"; 522 fSourceType = "skp";
516 fBenchType = "recording"; 523 fBenchType = "recording";
517 return SkNEW_ARGS(RecordingBench, (name.c_str(), pic.get(), FLAGS_bb h)); 524 return SkNEW_ARGS(RecordingBench, (name.c_str(), pic.get(), FLAGS_bb h));
518 } 525 }
519 526
520 // Then once each for each scale as SKPBenches (playback). 527 // Then once each for each scale as SKPBenches (playback).
521 while (fCurrentScale < fScales.count()) { 528 while (fCurrentScale < fScales.count()) {
522 while (fCurrentSKP < fSKPs.count()) { 529 while (fCurrentSKP < fSKPs.count()) {
523 const SkString& path = fSKPs[fCurrentSKP++]; 530 while (fCurrentUseMPD < fUseMPDs.count()) {
mtklein 2014/11/19 19:12:37 I seem to be falling into an infinite loop when I
robertphillips 2014/11/19 19:58:58 Done.
524 SkAutoTUnref<SkPicture> pic; 531 const SkString& path = fSKPs[fCurrentSKP];
525 if (!ReadPicture(path.c_str(), &pic)) { 532 SkAutoTUnref<SkPicture> pic;
526 continue; 533 if (!ReadPicture(path.c_str(), &pic)) {
534 continue;
535 }
536 if (FLAGS_bbh) {
537 // The SKP we read off disk doesn't have a BBH. Re-reco rd so it grows one.
538 SkRTreeFactory factory;
539 SkPictureRecorder recorder;
540 static const int kFlags = SkPictureRecorder::kComputeSav eLayerInfo_RecordFlag;
541 pic->playback(recorder.beginRecording(pic->cullRect().wi dth(),
542 pic->cullRect().he ight(),
543 &factory, kFlags)) ;
544 pic.reset(recorder.endRecording());
545 }
546 SkString name = SkOSPath::Basename(path.c_str());
547 fSourceType = "skp";
548 fBenchType = "playback";
549 return SkNEW_ARGS(SKPBench,
550 (name.c_str(), pic.get(), fClip,
551 fScales[fCurrentScale], fUseMPDs[fCurrentUseMPD++]) );
527 } 552 }
528 if (FLAGS_bbh) { 553 fCurrentUseMPD = 0;
529 // The SKP we read off disk doesn't have a BBH. Re-record s o it grows one. 554 fCurrentSKP++;
530 SkRTreeFactory factory;
531 SkPictureRecorder recorder;
532 pic->playback(recorder.beginRecording(pic->cullRect().width( ),
533 pic->cullRect().height (),
534 &factory));
535 pic.reset(recorder.endRecording());
536 }
537 SkString name = SkOSPath::Basename(path.c_str());
538 fSourceType = "skp";
539 fBenchType = "playback";
540 return SkNEW_ARGS(SKPBench,
541 (name.c_str(), pic.get(), fClip, fScales[fCurrentScale]) );
542 } 555 }
543 fCurrentSKP = 0; 556 fCurrentSKP = 0;
544 fCurrentScale++; 557 fCurrentScale++;
545 } 558 }
546 559
547 return NULL; 560 return NULL;
548 } 561 }
549 562
550 void fillCurrentOptions(ResultsWriter* log) const { 563 void fillCurrentOptions(ResultsWriter* log) const {
551 log->configOption("source_type", fSourceType); 564 log->configOption("source_type", fSourceType);
552 log->configOption("bench_type", fBenchType); 565 log->configOption("bench_type", fBenchType);
553 if (0 == strcmp(fSourceType, "skp")) { 566 if (0 == strcmp(fSourceType, "skp")) {
554 log->configOption("clip", 567 log->configOption("clip",
555 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop, 568 SkStringPrintf("%d %d %d %d", fClip.fLeft, fClip.fTop,
556 fClip.fRight, fClip.fBottom).c _str()); 569 fClip.fRight, fClip.fBottom).c _str());
557 log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentSc ale]).c_str()); 570 log->configOption("scale", SkStringPrintf("%.2g", fScales[fCurrentSc ale]).c_str());
571 log->configOption("multi_picture_draw", fUseMPDs[fCurrentUseMPD-1] ? "true" : "false");
558 } 572 }
559 } 573 }
560 574
561 private: 575 private:
562 const BenchRegistry* fBenches; 576 const BenchRegistry* fBenches;
563 const skiagm::GMRegistry* fGMs; 577 const skiagm::GMRegistry* fGMs;
564 SkIRect fClip; 578 SkIRect fClip;
565 SkTArray<SkScalar> fScales; 579 SkTArray<SkScalar> fScales;
566 SkTArray<SkString> fSKPs; 580 SkTArray<SkString> fSKPs;
581 SkTArray<bool> fUseMPDs;
567 582
568 const char* fSourceType; // What we're benching: bench, GM, SKP, ... 583 const char* fSourceType; // What we're benching: bench, GM, SKP, ...
569 const char* fBenchType; // How we bench it: micro, recording, playback, .. . 584 const char* fBenchType; // How we bench it: micro, recording, playback, .. .
570 int fCurrentRecording; 585 int fCurrentRecording;
571 int fCurrentScale; 586 int fCurrentScale;
572 int fCurrentSKP; 587 int fCurrentSKP;
588 int fCurrentUseMPD;
573 }; 589 };
574 590
575 int nanobench_main(); 591 int nanobench_main();
576 int nanobench_main() { 592 int nanobench_main() {
577 SetupCrashHandler(); 593 SetupCrashHandler();
578 SkAutoGraphics ag; 594 SkAutoGraphics ag;
579 595
mtklein 2014/11/19 19:12:36 Let's add "SkTaskGroup::Enabler enabled;" here (a
robertphillips 2014/11/19 19:58:58 Done.
580 #if SK_SUPPORT_GPU 596 #if SK_SUPPORT_GPU
581 GrContext::Options grContextOpts; 597 GrContext::Options grContextOpts;
582 grContextOpts.fDrawPathToCompressedTexture = FLAGS_gpuCompressAlphaMasks; 598 grContextOpts.fDrawPathToCompressedTexture = FLAGS_gpuCompressAlphaMasks;
583 gGrFactory.reset(SkNEW_ARGS(GrContextFactory, (grContextOpts))); 599 gGrFactory.reset(SkNEW_ARGS(GrContextFactory, (grContextOpts)));
584 #endif 600 #endif
585 601
586 if (FLAGS_veryVerbose) { 602 if (FLAGS_veryVerbose) {
587 FLAGS_verbose = true; 603 FLAGS_verbose = true;
588 } 604 }
589 605
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
652 create_targets(&targets, bench.get(), configs); 668 create_targets(&targets, bench.get(), configs);
653 669
654 if (!targets.isEmpty()) { 670 if (!targets.isEmpty()) {
655 log->bench(bench->getUniqueName(), bench->getSize().fX, bench->getSi ze().fY); 671 log->bench(bench->getUniqueName(), bench->getSize().fX, bench->getSi ze().fY);
656 bench->preDraw(); 672 bench->preDraw();
657 } 673 }
658 for (int j = 0; j < targets.count(); j++) { 674 for (int j = 0; j < targets.count(); j++) {
659 SkCanvas* canvas = targets[j]->surface.get() ? targets[j]->surface-> getCanvas() : NULL; 675 SkCanvas* canvas = targets[j]->surface.get() ? targets[j]->surface-> getCanvas() : NULL;
660 const char* config = targets[j]->config.name; 676 const char* config = targets[j]->config.name;
661 677
678 bench->perCanvasPreDraw(canvas);
679
662 const int loops = 680 const int loops =
663 #if SK_SUPPORT_GPU 681 #if SK_SUPPORT_GPU
664 Benchmark::kGPU_Backend == targets[j]->config.backend 682 Benchmark::kGPU_Backend == targets[j]->config.backend
665 ? gpu_bench(targets[j]->gl, bench.get(), canvas, samples.get()) 683 ? gpu_bench(targets[j]->gl, bench.get(), canvas, samples.get())
666 : 684 :
667 #endif 685 #endif
668 cpu_bench( overhead, bench.get(), canvas, samples.get()); 686 cpu_bench( overhead, bench.get(), canvas, samples.get());
669 687
688 bench->perCanvasPostDraw(canvas);
689
670 if (canvas && !FLAGS_writePath.isEmpty() && FLAGS_writePath[0]) { 690 if (canvas && !FLAGS_writePath.isEmpty() && FLAGS_writePath[0]) {
671 SkString pngFilename = SkOSPath::Join(FLAGS_writePath[0], config ); 691 SkString pngFilename = SkOSPath::Join(FLAGS_writePath[0], config );
672 pngFilename = SkOSPath::Join(pngFilename.c_str(), bench->getUniq ueName()); 692 pngFilename = SkOSPath::Join(pngFilename.c_str(), bench->getUniq ueName());
673 pngFilename.append(".png"); 693 pngFilename.append(".png");
674 write_canvas_png(canvas, pngFilename); 694 write_canvas_png(canvas, pngFilename);
675 } 695 }
676 696
677 if (kFailedLoops == loops) { 697 if (kFailedLoops == loops) {
678 // Can't be timed. A warning note has already been printed. 698 // Can't be timed. A warning note has already been printed.
679 continue; 699 continue;
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
751 771
752 return 0; 772 return 0;
753 } 773 }
754 774
755 #if !defined SK_BUILD_FOR_IOS 775 #if !defined SK_BUILD_FOR_IOS
756 int main(int argc, char** argv) { 776 int main(int argc, char** argv) {
757 SkCommandLineFlags::Parse(argc, argv); 777 SkCommandLineFlags::Parse(argc, argv);
758 return nanobench_main(); 778 return nanobench_main();
759 } 779 }
760 #endif 780 #endif
OLDNEW
« no previous file with comments | « bench/SKPBench.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698