Chromium Code Reviews| Index: tools/gpu/GpuTimer.h |
| diff --git a/tools/gpu/GpuTimer.h b/tools/gpu/GpuTimer.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..6d973e4a61d2d73cda4295e47ab19f08af97bf97 |
| --- /dev/null |
| +++ b/tools/gpu/GpuTimer.h |
| @@ -0,0 +1,77 @@ |
| +/* |
| + * 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 GpuTimer_DEFINED |
| +#define GpuTimer_DEFINED |
| + |
| +#include "SkTypes.h" |
| +#include "SkExchange.h" |
| +#include <chrono> |
| + |
| +namespace sk_gpu_test { |
| + |
| +using PlatformGpuTimerQuery = intptr_t; |
| +constexpr static PlatformGpuTimerQuery kInvalidGpuTimerQuery = 0; |
| + |
| +/** |
| + * Platform-independent interface for timing operations on the GPU. |
| + */ |
| +class GpuTimer { |
| +public: |
| + GpuTimer(bool disjointSupport) |
| + : fDisjointSupport(disjointSupport) |
| + , fActiveTimer(kInvalidGpuTimerQuery) { |
| + } |
| + virtual ~GpuTimer() { 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. |
| + */ |
| + PlatformGpuTimerQuery SK_WARN_UNUSED_RESULT queueStop() { |
| + SkASSERT(fActiveTimer); |
| + this->onQueueTimerStop(fActiveTimer); |
| + return skstd::exchange(fActiveTimer, kInvalidGpuTimerQuery); |
| + } |
| + |
| + 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(PlatformGpuTimerQuery) = 0; |
| + virtual std::chrono::nanoseconds getTimeElapsed(PlatformGpuTimerQuery) = 0; |
| + virtual void deleteQuery(PlatformGpuTimerQuery) = 0; |
| + |
| +private: |
| + virtual PlatformGpuTimerQuery onQueueTimerStart() const = 0; |
| + virtual void onQueueTimerStop(PlatformGpuTimerQuery) const = 0; |
| + |
| + bool const fDisjointSupport; |
| + PlatformGpuTimerQuery fActiveTimer; |
| +}; |
| + |
| +} |
|
bsalomon
2016/10/04 18:00:01
I think most of the other files in here would have
csmartdalton
2016/10/04 19:06:35
Done.
|
| + |
| +#endif |