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

Side by Side Diff: tools/skpbench/skpbench.cpp

Issue 2383383002: Move GPU fences into sk_gpu_test (Closed)
Patch Set: fix for windowsx Created 4 years, 2 months 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 | « tools/gpu/vk/VkTestContext.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 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
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
36 DEFINE_int32(duration, 5000, "number of milliseconds to run the benchmark"); 40 DEFINE_int32(duration, 5000, "number of milliseconds to run the benchmark");
37 DEFINE_int32(sampleMs, 50, "minimum duration of a sample"); 41 DEFINE_int32(sampleMs, 50, "minimum duration of a sample");
38 DEFINE_bool(fps, false, "use fps instead of ms"); 42 DEFINE_bool(fps, false, "use fps instead of ms");
39 DEFINE_string(skp, "", "path to a single .skp file to benchmark"); 43 DEFINE_string(skp, "", "path to a single .skp file to benchmark");
40 DEFINE_string(png, "", "if set, save a .png proof to disk at this file location" ); 44 DEFINE_string(png, "", "if set, save a .png proof to disk at this file location" );
41 DEFINE_int32(verbosity, 4, "level of verbosity (0=none to 5=debug)"); 45 DEFINE_int32(verbosity, 4, "level of verbosity (0=none to 5=debug)");
42 DEFINE_bool(suppressHeader, false, "don't print a header row before the results" ); 46 DEFINE_bool(suppressHeader, false, "don't print a header row before the results" );
43 47
44 static const char* header = 48 static const char* header =
45 " accum median max min stddev samples sample_ms metric config bench"; 49 " accum median max min stddev samples sample_ms metric config bench";
46 50
47 static const char* resultFormat = 51 static const char* resultFormat =
48 "%8.4g %8.4g %8.4g %8.4g %6.3g%% %7li %9i %-6s %-9s %s"; 52 "%8.4g %8.4g %8.4g %8.4g %6.3g%% %7li %9i %-6s %-9s %s";
49 53
50 struct Sample { 54 struct Sample {
51 using clock = std::chrono::high_resolution_clock; 55 using clock = std::chrono::high_resolution_clock;
52 56
53 Sample() : fFrames(0), fDuration(0) {} 57 Sample() : fFrames(0), fDuration(0) {}
54 double seconds() const { return std::chrono::duration<double>(fDuration).cou nt(); } 58 double seconds() const { return std::chrono::duration<double>(fDuration).cou nt(); }
55 double ms() const { return std::chrono::duration<double, std::milli>(fDurati on).count(); } 59 double ms() const { return std::chrono::duration<double, std::milli>(fDurati on).count(); }
56 double value() const { return FLAGS_fps ? fFrames / this->seconds() : this-> ms() / fFrames; } 60 double value() const { return FLAGS_fps ? fFrames / this->seconds() : this-> ms() / fFrames; }
57 static const char* metric() { return FLAGS_fps ? "fps" : "ms"; } 61 static const char* metric() { return FLAGS_fps ? "fps" : "ms"; }
58 62
59 int fFrames; 63 int fFrames;
60 clock::duration fDuration; 64 clock::duration fDuration;
61 }; 65 };
62 66
63 class GpuSync { 67 class GpuSync {
64 public: 68 public:
65 GpuSync(const SkGpuFenceSync* fenceSync); 69 GpuSync(const FenceSync* fenceSync);
66 ~GpuSync(); 70 ~GpuSync();
67 71
68 void syncToPreviousFrame(); 72 void syncToPreviousFrame();
69 73
70 private: 74 private:
71 void updateFence(); 75 void updateFence();
72 76
73 const SkGpuFenceSync* const fFenceSync; 77 const FenceSync* const fFenceSync;
74 SkPlatformGpuFence fFence; 78 PlatformFence fFence;
75 }; 79 };
76 80
77 enum class ExitErr { 81 enum class ExitErr {
78 kOk = 0, 82 kOk = 0,
79 kUsage = 64, 83 kUsage = 64,
80 kData = 65, 84 kData = 65,
81 kUnavailable = 69, 85 kUnavailable = 69,
82 kIO = 74, 86 kIO = 74,
83 kSoftware = 70 87 kSoftware = 70
84 }; 88 };
85 89
86 static void draw_skp_and_flush(SkCanvas*, const SkPicture*); 90 static void draw_skp_and_flush(SkCanvas*, const SkPicture*);
87 static bool mkdir_p(const SkString& name); 91 static bool mkdir_p(const SkString& name);
88 static SkString join(const SkCommandLineFlags::StringArray&); 92 static SkString join(const SkCommandLineFlags::StringArray&);
89 static void exitf(ExitErr, const char* format, ...); 93 static void exitf(ExitErr, const char* format, ...);
90 94
91 static void run_benchmark(const SkGpuFenceSync* fenceSync, SkCanvas* canvas, con st SkPicture* skp, 95 static void run_benchmark(const FenceSync* fenceSync, SkCanvas* canvas, const Sk Picture* skp,
92 std::vector<Sample>* samples) { 96 std::vector<Sample>* samples) {
93 using clock = Sample::clock; 97 using clock = Sample::clock;
94 const clock::duration sampleDuration = std::chrono::milliseconds(FLAGS_sampl eMs); 98 const clock::duration sampleDuration = std::chrono::milliseconds(FLAGS_sampl eMs);
95 const clock::duration benchDuration = std::chrono::milliseconds(FLAGS_durati on); 99 const clock::duration benchDuration = std::chrono::milliseconds(FLAGS_durati on);
96 100
97 draw_skp_and_flush(canvas, skp); 101 draw_skp_and_flush(canvas, skp);
98 GpuSync gpuSync(fenceSync); 102 GpuSync gpuSync(fenceSync);
99 103
100 draw_skp_and_flush(canvas, skp); 104 draw_skp_and_flush(canvas, skp);
101 gpuSync.syncToPreviousFrame(); 105 gpuSync.syncToPreviousFrame();
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 static void exitf(ExitErr err, const char* format, ...) { 293 static void exitf(ExitErr err, const char* format, ...) {
290 fprintf(stderr, ExitErr::kSoftware == err ? "INTERNAL ERROR: " : "ERROR: "); 294 fprintf(stderr, ExitErr::kSoftware == err ? "INTERNAL ERROR: " : "ERROR: ");
291 va_list args; 295 va_list args;
292 va_start(args, format); 296 va_start(args, format);
293 vfprintf(stderr, format, args); 297 vfprintf(stderr, format, args);
294 va_end(args); 298 va_end(args);
295 fprintf(stderr, ExitErr::kSoftware == err ? "; this should never happen.\n": ".\n"); 299 fprintf(stderr, ExitErr::kSoftware == err ? "; this should never happen.\n": ".\n");
296 exit((int)err); 300 exit((int)err);
297 } 301 }
298 302
299 GpuSync::GpuSync(const SkGpuFenceSync* fenceSync) 303 GpuSync::GpuSync(const FenceSync* fenceSync)
300 : fFenceSync(fenceSync) { 304 : fFenceSync(fenceSync) {
301 this->updateFence(); 305 this->updateFence();
302 } 306 }
303 307
304 GpuSync::~GpuSync() { 308 GpuSync::~GpuSync() {
305 fFenceSync->deleteFence(fFence); 309 fFenceSync->deleteFence(fFence);
306 } 310 }
307 311
308 void GpuSync::syncToPreviousFrame() { 312 void GpuSync::syncToPreviousFrame() {
309 if (kInvalidPlatformGpuFence == fFence) { 313 if (kInvalidPlatformFence == fFence) {
310 exitf(ExitErr::kSoftware, "attempted to sync with invalid fence"); 314 exitf(ExitErr::kSoftware, "attempted to sync with invalid fence");
311 } 315 }
312 if (!fFenceSync->waitFence(fFence)) { 316 if (!fFenceSync->waitFence(fFence)) {
313 exitf(ExitErr::kUnavailable, "failed to wait for fence"); 317 exitf(ExitErr::kUnavailable, "failed to wait for fence");
314 } 318 }
315 fFenceSync->deleteFence(fFence); 319 fFenceSync->deleteFence(fFence);
316 this->updateFence(); 320 this->updateFence();
317 } 321 }
318 322
319 void GpuSync::updateFence() { 323 void GpuSync::updateFence() {
320 fFence = fFenceSync->insertFence(); 324 fFence = fFenceSync->insertFence();
321 if (kInvalidPlatformGpuFence == fFence) { 325 if (kInvalidPlatformFence == fFence) {
322 exitf(ExitErr::kUnavailable, "failed to insert fence"); 326 exitf(ExitErr::kUnavailable, "failed to insert fence");
323 } 327 }
324 } 328 }
OLDNEW
« no previous file with comments | « tools/gpu/vk/VkTestContext.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698