| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2016 Google Inc. | 2 * Copyright 2016 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 "GrContextFactory.h" | 8 #include "GrContextFactory.h" |
| 9 #include "SkCanvas.h" | 9 #include "SkCanvas.h" |
| 10 #include "SkOSFile.h" | 10 #include "SkOSFile.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 * This is a minimalist program whose sole purpose is to open an skp file, bench
mark it on a single | 26 * This is a minimalist program whose sole purpose is to open an skp file, bench
mark it on a single |
| 27 * config, and exit. It is intended to be used through skpbench.py rather than i
nvoked directly. | 27 * config, and exit. It is intended to be used through skpbench.py rather than i
nvoked directly. |
| 28 * Limiting the entire process to a single config/skp pair helps to keep the res
ults repeatable. | 28 * Limiting the entire process to a single config/skp pair helps to keep the res
ults repeatable. |
| 29 * | 29 * |
| 30 * No tiling, looping, or other fanciness is used; it just draws the skp whole i
nto a size-matched | 30 * No tiling, looping, or other fanciness is used; it just draws the skp whole i
nto a size-matched |
| 31 * render target and syncs the GPU after each draw. | 31 * render target and syncs the GPU after each draw. |
| 32 * | 32 * |
| 33 * Currently, only GPU configs are supported. | 33 * Currently, only GPU configs are supported. |
| 34 */ | 34 */ |
| 35 | 35 |
| 36 using sk_gpu_test::PlatformFence; | |
| 37 using sk_gpu_test::kInvalidPlatformFence; | |
| 38 using sk_gpu_test::FenceSync; | |
| 39 | |
| 40 DEFINE_int32(duration, 5000, "number of milliseconds to run the benchmark"); | 36 DEFINE_int32(duration, 5000, "number of milliseconds to run the benchmark"); |
| 41 DEFINE_int32(sampleMs, 50, "minimum duration of a sample"); | 37 DEFINE_int32(sampleMs, 50, "minimum duration of a sample"); |
| 42 DEFINE_bool(fps, false, "use fps instead of ms"); | 38 DEFINE_bool(fps, false, "use fps instead of ms"); |
| 43 DEFINE_string(skp, "", "path to a single .skp file to benchmark"); | 39 DEFINE_string(skp, "", "path to a single .skp file to benchmark"); |
| 44 DEFINE_string(png, "", "if set, save a .png proof to disk at this file location"
); | 40 DEFINE_string(png, "", "if set, save a .png proof to disk at this file location"
); |
| 45 DEFINE_int32(verbosity, 4, "level of verbosity (0=none to 5=debug)"); | 41 DEFINE_int32(verbosity, 4, "level of verbosity (0=none to 5=debug)"); |
| 46 DEFINE_bool(suppressHeader, false, "don't print a header row before the results"
); | 42 DEFINE_bool(suppressHeader, false, "don't print a header row before the results"
); |
| 47 | 43 |
| 48 static const char* header = | 44 static const char* header = |
| 49 " accum median max min stddev samples sample_ms metric
config bench"; | 45 " accum median max min stddev samples sample_ms metric
config bench"; |
| 50 | 46 |
| 51 static const char* resultFormat = | 47 static const char* resultFormat = |
| 52 "%8.4g %8.4g %8.4g %8.4g %6.3g%% %7li %9i %-6s %-9s %s"; | 48 "%8.4g %8.4g %8.4g %8.4g %6.3g%% %7li %9i %-6s %-9s %s"; |
| 53 | 49 |
| 54 struct Sample { | 50 struct Sample { |
| 55 using clock = std::chrono::high_resolution_clock; | 51 using clock = std::chrono::high_resolution_clock; |
| 56 | 52 |
| 57 Sample() : fFrames(0), fDuration(0) {} | 53 Sample() : fFrames(0), fDuration(0) {} |
| 58 double seconds() const { return std::chrono::duration<double>(fDuration).cou
nt(); } | 54 double seconds() const { return std::chrono::duration<double>(fDuration).cou
nt(); } |
| 59 double ms() const { return std::chrono::duration<double, std::milli>(fDurati
on).count(); } | 55 double ms() const { return std::chrono::duration<double, std::milli>(fDurati
on).count(); } |
| 60 double value() const { return FLAGS_fps ? fFrames / this->seconds() : this->
ms() / fFrames; } | 56 double value() const { return FLAGS_fps ? fFrames / this->seconds() : this->
ms() / fFrames; } |
| 61 static const char* metric() { return FLAGS_fps ? "fps" : "ms"; } | 57 static const char* metric() { return FLAGS_fps ? "fps" : "ms"; } |
| 62 | 58 |
| 63 int fFrames; | 59 int fFrames; |
| 64 clock::duration fDuration; | 60 clock::duration fDuration; |
| 65 }; | 61 }; |
| 66 | 62 |
| 67 class GpuSync { | 63 class GpuSync { |
| 68 public: | 64 public: |
| 69 GpuSync(const FenceSync* fenceSync); | 65 GpuSync(const SkGpuFenceSync* fenceSync); |
| 70 ~GpuSync(); | 66 ~GpuSync(); |
| 71 | 67 |
| 72 void syncToPreviousFrame(); | 68 void syncToPreviousFrame(); |
| 73 | 69 |
| 74 private: | 70 private: |
| 75 void updateFence(); | 71 void updateFence(); |
| 76 | 72 |
| 77 const FenceSync* const fFenceSync; | 73 const SkGpuFenceSync* const fFenceSync; |
| 78 PlatformFence fFence; | 74 SkPlatformGpuFence fFence; |
| 79 }; | 75 }; |
| 80 | 76 |
| 81 enum class ExitErr { | 77 enum class ExitErr { |
| 82 kOk = 0, | 78 kOk = 0, |
| 83 kUsage = 64, | 79 kUsage = 64, |
| 84 kData = 65, | 80 kData = 65, |
| 85 kUnavailable = 69, | 81 kUnavailable = 69, |
| 86 kIO = 74, | 82 kIO = 74, |
| 87 kSoftware = 70 | 83 kSoftware = 70 |
| 88 }; | 84 }; |
| 89 | 85 |
| 90 static void draw_skp_and_flush(SkCanvas*, const SkPicture*); | 86 static void draw_skp_and_flush(SkCanvas*, const SkPicture*); |
| 91 static bool mkdir_p(const SkString& name); | 87 static bool mkdir_p(const SkString& name); |
| 92 static SkString join(const SkCommandLineFlags::StringArray&); | 88 static SkString join(const SkCommandLineFlags::StringArray&); |
| 93 static void exitf(ExitErr, const char* format, ...); | 89 static void exitf(ExitErr, const char* format, ...); |
| 94 | 90 |
| 95 static void run_benchmark(const FenceSync* fenceSync, SkCanvas* canvas, const Sk
Picture* skp, | 91 static void run_benchmark(const SkGpuFenceSync* fenceSync, SkCanvas* canvas, con
st SkPicture* skp, |
| 96 std::vector<Sample>* samples) { | 92 std::vector<Sample>* samples) { |
| 97 using clock = Sample::clock; | 93 using clock = Sample::clock; |
| 98 const clock::duration sampleDuration = std::chrono::milliseconds(FLAGS_sampl
eMs); | 94 const clock::duration sampleDuration = std::chrono::milliseconds(FLAGS_sampl
eMs); |
| 99 const clock::duration benchDuration = std::chrono::milliseconds(FLAGS_durati
on); | 95 const clock::duration benchDuration = std::chrono::milliseconds(FLAGS_durati
on); |
| 100 | 96 |
| 101 draw_skp_and_flush(canvas, skp); | 97 draw_skp_and_flush(canvas, skp); |
| 102 GpuSync gpuSync(fenceSync); | 98 GpuSync gpuSync(fenceSync); |
| 103 | 99 |
| 104 draw_skp_and_flush(canvas, skp); | 100 draw_skp_and_flush(canvas, skp); |
| 105 gpuSync.syncToPreviousFrame(); | 101 gpuSync.syncToPreviousFrame(); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 static void exitf(ExitErr err, const char* format, ...) { | 289 static void exitf(ExitErr err, const char* format, ...) { |
| 294 fprintf(stderr, ExitErr::kSoftware == err ? "INTERNAL ERROR: " : "ERROR: "); | 290 fprintf(stderr, ExitErr::kSoftware == err ? "INTERNAL ERROR: " : "ERROR: "); |
| 295 va_list args; | 291 va_list args; |
| 296 va_start(args, format); | 292 va_start(args, format); |
| 297 vfprintf(stderr, format, args); | 293 vfprintf(stderr, format, args); |
| 298 va_end(args); | 294 va_end(args); |
| 299 fprintf(stderr, ExitErr::kSoftware == err ? "; this should never happen.\n":
".\n"); | 295 fprintf(stderr, ExitErr::kSoftware == err ? "; this should never happen.\n":
".\n"); |
| 300 exit((int)err); | 296 exit((int)err); |
| 301 } | 297 } |
| 302 | 298 |
| 303 GpuSync::GpuSync(const FenceSync* fenceSync) | 299 GpuSync::GpuSync(const SkGpuFenceSync* fenceSync) |
| 304 : fFenceSync(fenceSync) { | 300 : fFenceSync(fenceSync) { |
| 305 this->updateFence(); | 301 this->updateFence(); |
| 306 } | 302 } |
| 307 | 303 |
| 308 GpuSync::~GpuSync() { | 304 GpuSync::~GpuSync() { |
| 309 fFenceSync->deleteFence(fFence); | 305 fFenceSync->deleteFence(fFence); |
| 310 } | 306 } |
| 311 | 307 |
| 312 void GpuSync::syncToPreviousFrame() { | 308 void GpuSync::syncToPreviousFrame() { |
| 313 if (kInvalidPlatformFence == fFence) { | 309 if (kInvalidPlatformGpuFence == fFence) { |
| 314 exitf(ExitErr::kSoftware, "attempted to sync with invalid fence"); | 310 exitf(ExitErr::kSoftware, "attempted to sync with invalid fence"); |
| 315 } | 311 } |
| 316 if (!fFenceSync->waitFence(fFence)) { | 312 if (!fFenceSync->waitFence(fFence)) { |
| 317 exitf(ExitErr::kUnavailable, "failed to wait for fence"); | 313 exitf(ExitErr::kUnavailable, "failed to wait for fence"); |
| 318 } | 314 } |
| 319 fFenceSync->deleteFence(fFence); | 315 fFenceSync->deleteFence(fFence); |
| 320 this->updateFence(); | 316 this->updateFence(); |
| 321 } | 317 } |
| 322 | 318 |
| 323 void GpuSync::updateFence() { | 319 void GpuSync::updateFence() { |
| 324 fFence = fFenceSync->insertFence(); | 320 fFence = fFenceSync->insertFence(); |
| 325 if (kInvalidPlatformFence == fFence) { | 321 if (kInvalidPlatformGpuFence == fFence) { |
| 326 exitf(ExitErr::kUnavailable, "failed to insert fence"); | 322 exitf(ExitErr::kUnavailable, "failed to insert fence"); |
| 327 } | 323 } |
| 328 } | 324 } |
| OLD | NEW |