Index: tools/skpbench/skpbench.cpp |
diff --git a/tools/skpbench/skpbench.cpp b/tools/skpbench/skpbench.cpp |
index 6d0381a28d75dcd3cfde5658bb737ea75b584930..adb6af0b146669f6a1c44fa253f2ad7a5e7614a6 100644 |
--- a/tools/skpbench/skpbench.cpp |
+++ b/tools/skpbench/skpbench.cpp |
@@ -5,7 +5,6 @@ |
* found in the LICENSE file. |
*/ |
-#include "GpuTimer.h" |
#include "GrContextFactory.h" |
#include "SkCanvas.h" |
#include "SkOSFile.h" |
@@ -34,9 +33,12 @@ |
* Currently, only GPU configs are supported. |
*/ |
+using sk_gpu_test::PlatformFence; |
+using sk_gpu_test::kInvalidPlatformFence; |
+using sk_gpu_test::FenceSync; |
+ |
DEFINE_int32(duration, 5000, "number of milliseconds to run the benchmark"); |
DEFINE_int32(sampleMs, 50, "minimum duration of a sample"); |
-DEFINE_bool(gpuClock, false, "time on the gpu clock (gpu work only)"); |
DEFINE_bool(fps, false, "use fps instead of ms"); |
DEFINE_string(skp, "", "path to a single .skp file to benchmark"); |
DEFINE_string(png, "", "if set, save a .png proof to disk at this file location"); |
@@ -44,13 +46,13 @@ |
DEFINE_bool(suppressHeader, false, "don't print a header row before the results"); |
static const char* header = |
-" accum median max min stddev samples sample_ms clock metric config bench"; |
+ " accum median max min stddev samples sample_ms metric config bench"; |
static const char* resultFormat = |
-"%8.4g %8.4g %8.4g %8.4g %6.3g%% %7li %9i %-5s %-6s %-9s %s"; |
+ "%8.4g %8.4g %8.4g %8.4g %6.3g%% %7li %9i %-6s %-9s %s"; |
struct Sample { |
- using duration = std::chrono::nanoseconds; |
+ using clock = std::chrono::high_resolution_clock; |
Sample() : fFrames(0), fDuration(0) {} |
double seconds() const { return std::chrono::duration<double>(fDuration).count(); } |
@@ -58,13 +60,13 @@ |
double value() const { return FLAGS_fps ? fFrames / this->seconds() : this->ms() / fFrames; } |
static const char* metric() { return FLAGS_fps ? "fps" : "ms"; } |
- int fFrames; |
- duration fDuration; |
+ int fFrames; |
+ clock::duration fDuration; |
}; |
class GpuSync { |
public: |
- GpuSync(const sk_gpu_test::FenceSync* fenceSync); |
+ GpuSync(const FenceSync* fenceSync); |
~GpuSync(); |
void syncToPreviousFrame(); |
@@ -72,8 +74,8 @@ |
private: |
void updateFence(); |
- const sk_gpu_test::FenceSync* const fFenceSync; |
- sk_gpu_test::PlatformFence fFence; |
+ const FenceSync* const fFenceSync; |
+ PlatformFence fFence; |
}; |
enum class ExitErr { |
@@ -90,10 +92,10 @@ |
static SkString join(const SkCommandLineFlags::StringArray&); |
static void exitf(ExitErr, const char* format, ...); |
-static void run_benchmark(const sk_gpu_test::FenceSync* fenceSync, SkCanvas* canvas, |
- const SkPicture* skp, std::vector<Sample>* samples) { |
- using clock = std::chrono::high_resolution_clock; |
- const Sample::duration sampleDuration = std::chrono::milliseconds(FLAGS_sampleMs); |
+static void run_benchmark(const FenceSync* fenceSync, SkCanvas* canvas, const SkPicture* skp, |
+ std::vector<Sample>* samples) { |
+ using clock = Sample::clock; |
+ const clock::duration sampleDuration = std::chrono::milliseconds(FLAGS_sampleMs); |
const clock::duration benchDuration = std::chrono::milliseconds(FLAGS_duration); |
draw_skp_and_flush(canvas, skp); |
@@ -119,66 +121,6 @@ |
++sample.fFrames; |
} while (sample.fDuration < sampleDuration); |
} while (now < endTime || 0 == samples->size() % 2); |
-} |
- |
-static void run_gpu_time_benchmark(sk_gpu_test::GpuTimer* gpuTimer, |
- const sk_gpu_test::FenceSync* fenceSync, SkCanvas* canvas, |
- const SkPicture* skp, std::vector<Sample>* samples) { |
- using sk_gpu_test::PlatformTimerQuery; |
- using clock = std::chrono::steady_clock; |
- const clock::duration sampleDuration = std::chrono::milliseconds(FLAGS_sampleMs); |
- const clock::duration benchDuration = std::chrono::milliseconds(FLAGS_duration); |
- |
- if (!gpuTimer->disjointSupport()) { |
- fprintf(stderr, "WARNING: GPU timer cannot detect disjoint operations; " |
- "results may be unreliable\n"); |
- } |
- |
- draw_skp_and_flush(canvas, skp); |
- GpuSync gpuSync(fenceSync); |
- |
- gpuTimer->queueStart(); |
- draw_skp_and_flush(canvas, skp); |
- PlatformTimerQuery previousTime = gpuTimer->queueStop(); |
- gpuSync.syncToPreviousFrame(); |
- |
- clock::time_point now = clock::now(); |
- const clock::time_point endTime = now + benchDuration; |
- |
- do { |
- const clock::time_point sampleEndTime = now + sampleDuration; |
- samples->emplace_back(); |
- Sample& sample = samples->back(); |
- |
- do { |
- gpuTimer->queueStart(); |
- draw_skp_and_flush(canvas, skp); |
- PlatformTimerQuery time = gpuTimer->queueStop(); |
- gpuSync.syncToPreviousFrame(); |
- |
- switch (gpuTimer->checkQueryStatus(previousTime)) { |
- using QueryStatus = sk_gpu_test::GpuTimer::QueryStatus; |
- case QueryStatus::kInvalid: |
- exitf(ExitErr::kUnavailable, "GPU timer failed"); |
- case QueryStatus::kPending: |
- exitf(ExitErr::kUnavailable, "timer query still not ready after fence sync"); |
- case QueryStatus::kDisjoint: |
- if (FLAGS_verbosity >= 4) { |
- fprintf(stderr, "discarding timer query due to disjoint operations.\n"); |
- } |
- break; |
- case QueryStatus::kAccurate: |
- sample.fDuration += gpuTimer->getTimeElapsed(previousTime); |
- ++sample.fFrames; |
- break; |
- } |
- gpuTimer->deleteQuery(previousTime); |
- previousTime = time; |
- now = clock::now(); |
- } while (now < sampleEndTime || 0 == sample.fFrames); |
- } while (now < endTime || 0 == samples->size() % 2); |
- |
- gpuTimer->deleteQuery(previousTime); |
} |
void print_result(const std::vector<Sample>& samples, const char* config, const char* bench) { |
@@ -207,8 +149,7 @@ |
const double stddev = 100/*%*/ * sqrt(variance) / accumValue; |
printf(resultFormat, accumValue, values[values.size() / 2], values.back(), values.front(), |
- stddev, values.size(), FLAGS_sampleMs, FLAGS_gpuClock ? "gpu" : "cpu", Sample::metric(), |
- config, bench); |
+ stddev, values.size(), FLAGS_sampleMs, Sample::metric(), config, bench); |
printf("\n"); |
fflush(stdout); |
} |
@@ -306,15 +247,7 @@ |
// Run the benchmark. |
SkCanvas* canvas = surface->getCanvas(); |
canvas->translate(-skp->cullRect().x(), -skp->cullRect().y()); |
- if (!FLAGS_gpuClock) { |
- run_benchmark(testCtx->fenceSync(), canvas, skp.get(), &samples); |
- } else { |
- if (!testCtx->gpuTimingSupport()) { |
- exitf(ExitErr::kUnavailable, "GPU does not support timing"); |
- } |
- run_gpu_time_benchmark(testCtx->gpuTimer(), testCtx->fenceSync(), canvas, skp.get(), |
- &samples); |
- } |
+ run_benchmark(testCtx->fenceSync(), canvas, skp.get(), &samples); |
print_result(samples, config->getTag().c_str(), SkOSPath::Basename(skpfile).c_str()); |
// Save a proof (if one was requested). |
@@ -367,7 +300,7 @@ |
exit((int)err); |
} |
-GpuSync::GpuSync(const sk_gpu_test::FenceSync* fenceSync) |
+GpuSync::GpuSync(const FenceSync* fenceSync) |
: fFenceSync(fenceSync) { |
this->updateFence(); |
} |
@@ -377,7 +310,7 @@ |
} |
void GpuSync::syncToPreviousFrame() { |
- if (sk_gpu_test::kInvalidFence == fFence) { |
+ if (kInvalidPlatformFence == fFence) { |
exitf(ExitErr::kSoftware, "attempted to sync with invalid fence"); |
} |
if (!fFenceSync->waitFence(fFence)) { |
@@ -389,7 +322,7 @@ |
void GpuSync::updateFence() { |
fFence = fFenceSync->insertFence(); |
- if (sk_gpu_test::kInvalidFence == fFence) { |
+ if (kInvalidPlatformFence == fFence) { |
exitf(ExitErr::kUnavailable, "failed to insert fence"); |
} |
} |