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

Unified Diff: include/private/SkGpuTimer.h

Issue 2388433003: skpbench: add option for gpu timing (Closed)
Patch Set: Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/gpu/TestContext.h » ('j') | tools/gpu/gl/GLTestContext.cpp » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/private/SkGpuTimer.h
diff --git a/include/private/SkGpuTimer.h b/include/private/SkGpuTimer.h
new file mode 100644
index 0000000000000000000000000000000000000000..4037bbb7d6c1d20bb3102ff887a3dd52230095c2
--- /dev/null
+++ b/include/private/SkGpuTimer.h
@@ -0,0 +1,73 @@
+/*
+ * Copyright 2016 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkGpuTimer_DEFINED
+#define SkGpuTimer_DEFINED
+
+#include "SkTypes.h"
+#include "SkExchange.h"
+#include <chrono>
+
+using SkPlatformGpuTimerQuery = intptr_t;
bsalomon 2016/09/30 18:37:16 What do you think about putting this in sk_gpu_tes
csmartdalton 2016/10/03 16:52:24 Done.
+constexpr static SkPlatformGpuTimerQuery SK_InvalidGpuTimerQuery = 0;
+
+/**
+ * Platform-independent interface for timing operations on the GPU.
+ */
+class SkGpuTimer {
+public:
+ SkGpuTimer(bool disjointSupport)
+ : fDisjointSupport(disjointSupport)
+ , fActiveTimer(SK_InvalidGpuTimerQuery) {
+ }
+ virtual ~SkGpuTimer() { SkASSERT(!fActiveTimer); }
+
+ /**
+ * Returns whether this timer can detect disjoint GPU operations while timing. If false, a query
+ * has less confidence when it completes with QueryStatus::kAccurate.
+ */
+ bool disjointSupport() const { return fDisjointSupport; }
+
+ /**
+ * Inserts a "start timing" command in the GPU command stream.
+ */
+ void queueStart() {
+ SkASSERT(!fActiveTimer);
+ fActiveTimer = this->onQueueTimerStart();
+ }
+
+ /**
+ * Inserts a "stop timing" command in the GPU command stream.
+ *
+ * @return a query object that can retrieve the time elapsed once the timer has completed.
+ */
+ SkPlatformGpuTimerQuery SK_WARN_UNUSED_RESULT queueStop() {
+ SkASSERT(fActiveTimer);
+ this->onQueueTimerStop(fActiveTimer);
+ return skstd::exchange(fActiveTimer, SK_InvalidGpuTimerQuery);
+ }
+
+ enum class QueryStatus {
+ kInvalid, //<! the timer query is invalid.
+ kPending, //<! the timer is still running on the GPU.
+ kDisjoint, //<! the query is complete, but dubious due to disjoint GPU operations.
+ kAccurate //<! the query is complete and reliable.
+ };
+
+ virtual QueryStatus checkQueryStatus(SkPlatformGpuTimerQuery) = 0;
+ virtual std::chrono::nanoseconds getTimeElapsed(SkPlatformGpuTimerQuery) = 0;
+ virtual void deleteQuery(SkPlatformGpuTimerQuery) = 0;
+
+private:
+ virtual SkPlatformGpuTimerQuery onQueueTimerStart() const = 0;
+ virtual void onQueueTimerStop(SkPlatformGpuTimerQuery) const = 0;
+
+ bool const fDisjointSupport;
+ SkPlatformGpuTimerQuery fActiveTimer;
+};
+
+#endif
« no previous file with comments | « no previous file | tools/gpu/TestContext.h » ('j') | tools/gpu/gl/GLTestContext.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698