2016-09-19 18:03:58 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2016 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2016-10-05 15:42:03 +00:00
|
|
|
#include "GpuTimer.h"
|
2016-09-19 18:03:58 +00:00
|
|
|
#include "GrContextFactory.h"
|
2017-07-19 18:47:42 +00:00
|
|
|
#include "SkGr.h"
|
|
|
|
|
2016-09-19 18:03:58 +00:00
|
|
|
#include "SkCanvas.h"
|
2017-10-13 18:35:50 +00:00
|
|
|
#include "SkCommonFlags.h"
|
2017-12-18 21:22:34 +00:00
|
|
|
#include "SkCommonFlagsGpu.h"
|
2016-09-19 18:03:58 +00:00
|
|
|
#include "SkOSFile.h"
|
2016-11-07 23:05:29 +00:00
|
|
|
#include "SkOSPath.h"
|
2016-10-12 01:28:54 +00:00
|
|
|
#include "SkPerlinNoiseShader.h"
|
2016-09-19 18:03:58 +00:00
|
|
|
#include "SkPicture.h"
|
2016-10-12 01:28:54 +00:00
|
|
|
#include "SkPictureRecorder.h"
|
2016-09-19 18:03:58 +00:00
|
|
|
#include "SkStream.h"
|
|
|
|
#include "SkSurface.h"
|
|
|
|
#include "SkSurfaceProps.h"
|
|
|
|
#include "picture_utils.h"
|
2016-10-12 01:28:54 +00:00
|
|
|
#include "sk_tool_utils.h"
|
2016-09-19 18:03:58 +00:00
|
|
|
#include "flags/SkCommandLineFlags.h"
|
|
|
|
#include "flags/SkCommonFlagsConfig.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <array>
|
|
|
|
#include <chrono>
|
|
|
|
#include <cmath>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This is a minimalist program whose sole purpose is to open an skp file, benchmark it on a single
|
|
|
|
* config, and exit. It is intended to be used through skpbench.py rather than invoked directly.
|
|
|
|
* Limiting the entire process to a single config/skp pair helps to keep the results repeatable.
|
|
|
|
*
|
|
|
|
* No tiling, looping, or other fanciness is used; it just draws the skp whole into a size-matched
|
|
|
|
* render target and syncs the GPU after each draw.
|
|
|
|
*
|
|
|
|
* Currently, only GPU configs are supported.
|
|
|
|
*/
|
|
|
|
|
2016-09-28 20:56:01 +00:00
|
|
|
DEFINE_int32(duration, 5000, "number of milliseconds to run the benchmark");
|
|
|
|
DEFINE_int32(sampleMs, 50, "minimum duration of a sample");
|
2016-10-05 15:42:03 +00:00
|
|
|
DEFINE_bool(gpuClock, false, "time on the gpu clock (gpu work only)");
|
2016-09-19 18:03:58 +00:00
|
|
|
DEFINE_bool(fps, false, "use fps instead of ms");
|
2016-10-12 01:28:54 +00:00
|
|
|
DEFINE_string(skp, "", "path to a single .skp file, or 'warmup' for a builtin warmup run");
|
2016-09-19 18:03:58 +00:00
|
|
|
DEFINE_string(png, "", "if set, save a .png proof to disk at this file location");
|
|
|
|
DEFINE_int32(verbosity, 4, "level of verbosity (0=none to 5=debug)");
|
|
|
|
DEFINE_bool(suppressHeader, false, "don't print a header row before the results");
|
|
|
|
|
|
|
|
static const char* header =
|
2016-10-05 15:42:03 +00:00
|
|
|
" accum median max min stddev samples sample_ms clock metric config bench";
|
2016-09-19 18:03:58 +00:00
|
|
|
|
|
|
|
static const char* resultFormat =
|
2016-10-05 15:42:03 +00:00
|
|
|
"%8.4g %8.4g %8.4g %8.4g %6.3g%% %7li %9i %-5s %-6s %-9s %s";
|
2016-09-19 18:03:58 +00:00
|
|
|
|
|
|
|
struct Sample {
|
2016-10-05 15:42:03 +00:00
|
|
|
using duration = std::chrono::nanoseconds;
|
2016-09-19 18:03:58 +00:00
|
|
|
|
|
|
|
Sample() : fFrames(0), fDuration(0) {}
|
|
|
|
double seconds() const { return std::chrono::duration<double>(fDuration).count(); }
|
|
|
|
double ms() const { return std::chrono::duration<double, std::milli>(fDuration).count(); }
|
|
|
|
double value() const { return FLAGS_fps ? fFrames / this->seconds() : this->ms() / fFrames; }
|
|
|
|
static const char* metric() { return FLAGS_fps ? "fps" : "ms"; }
|
|
|
|
|
2016-10-05 15:42:03 +00:00
|
|
|
int fFrames;
|
|
|
|
duration fDuration;
|
2016-09-19 18:03:58 +00:00
|
|
|
};
|
|
|
|
|
2016-09-28 21:53:07 +00:00
|
|
|
class GpuSync {
|
|
|
|
public:
|
2016-10-05 15:42:03 +00:00
|
|
|
GpuSync(const sk_gpu_test::FenceSync* fenceSync);
|
2016-09-28 21:53:07 +00:00
|
|
|
~GpuSync();
|
|
|
|
|
|
|
|
void syncToPreviousFrame();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void updateFence();
|
|
|
|
|
2016-10-05 15:42:03 +00:00
|
|
|
const sk_gpu_test::FenceSync* const fFenceSync;
|
|
|
|
sk_gpu_test::PlatformFence fFence;
|
2016-09-28 21:53:07 +00:00
|
|
|
};
|
|
|
|
|
2016-09-19 18:03:58 +00:00
|
|
|
enum class ExitErr {
|
|
|
|
kOk = 0,
|
|
|
|
kUsage = 64,
|
|
|
|
kData = 65,
|
|
|
|
kUnavailable = 69,
|
|
|
|
kIO = 74,
|
|
|
|
kSoftware = 70
|
|
|
|
};
|
|
|
|
|
|
|
|
static void draw_skp_and_flush(SkCanvas*, const SkPicture*);
|
2016-10-12 01:28:54 +00:00
|
|
|
static sk_sp<SkPicture> create_warmup_skp();
|
2016-09-19 18:03:58 +00:00
|
|
|
static bool mkdir_p(const SkString& name);
|
|
|
|
static SkString join(const SkCommandLineFlags::StringArray&);
|
|
|
|
static void exitf(ExitErr, const char* format, ...);
|
|
|
|
|
2016-10-05 15:42:03 +00:00
|
|
|
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);
|
2016-09-28 20:56:01 +00:00
|
|
|
const clock::duration benchDuration = std::chrono::milliseconds(FLAGS_duration);
|
2016-09-19 18:03:58 +00:00
|
|
|
|
2016-09-28 21:53:07 +00:00
|
|
|
draw_skp_and_flush(canvas, skp);
|
|
|
|
GpuSync gpuSync(fenceSync);
|
2016-09-19 18:03:58 +00:00
|
|
|
|
2016-09-28 21:53:07 +00:00
|
|
|
draw_skp_and_flush(canvas, skp);
|
|
|
|
gpuSync.syncToPreviousFrame();
|
2016-09-19 18:03:58 +00:00
|
|
|
|
2016-09-28 20:56:01 +00:00
|
|
|
clock::time_point now = clock::now();
|
|
|
|
const clock::time_point endTime = now + benchDuration;
|
|
|
|
|
|
|
|
do {
|
|
|
|
clock::time_point sampleStart = now;
|
|
|
|
samples->emplace_back();
|
|
|
|
Sample& sample = samples->back();
|
2016-09-19 18:03:58 +00:00
|
|
|
|
|
|
|
do {
|
|
|
|
draw_skp_and_flush(canvas, skp);
|
2016-09-28 21:53:07 +00:00
|
|
|
gpuSync.syncToPreviousFrame();
|
2016-09-19 18:03:58 +00:00
|
|
|
|
2016-09-28 20:56:01 +00:00
|
|
|
now = clock::now();
|
|
|
|
sample.fDuration = now - sampleStart;
|
2016-09-19 18:03:58 +00:00
|
|
|
++sample.fFrames;
|
2016-09-28 20:56:01 +00:00
|
|
|
} while (sample.fDuration < sampleDuration);
|
|
|
|
} while (now < endTime || 0 == samples->size() % 2);
|
2016-09-19 18:03:58 +00:00
|
|
|
}
|
|
|
|
|
2016-10-05 15:42:03 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2016-09-19 18:03:58 +00:00
|
|
|
void print_result(const std::vector<Sample>& samples, const char* config, const char* bench) {
|
|
|
|
if (0 == (samples.size() % 2)) {
|
|
|
|
exitf(ExitErr::kSoftware, "attempted to gather stats on even number of samples");
|
|
|
|
}
|
|
|
|
|
|
|
|
Sample accum = Sample();
|
|
|
|
std::vector<double> values;
|
|
|
|
values.reserve(samples.size());
|
|
|
|
for (const Sample& sample : samples) {
|
|
|
|
accum.fFrames += sample.fFrames;
|
|
|
|
accum.fDuration += sample.fDuration;
|
|
|
|
values.push_back(sample.value());
|
|
|
|
}
|
|
|
|
std::sort(values.begin(), values.end());
|
|
|
|
|
2016-09-29 13:23:23 +00:00
|
|
|
const double accumValue = accum.value();
|
2016-09-19 18:03:58 +00:00
|
|
|
double variance = 0;
|
2016-09-28 20:56:01 +00:00
|
|
|
for (double value : values) {
|
|
|
|
const double delta = value - accumValue;
|
2016-09-19 18:03:58 +00:00
|
|
|
variance += delta * delta;
|
|
|
|
}
|
2016-09-28 20:56:01 +00:00
|
|
|
variance /= values.size();
|
2016-09-19 18:03:58 +00:00
|
|
|
// Technically, this is the relative standard deviation.
|
2016-09-28 20:56:01 +00:00
|
|
|
const double stddev = 100/*%*/ * sqrt(variance) / accumValue;
|
2016-09-19 18:03:58 +00:00
|
|
|
|
2016-09-29 13:23:23 +00:00
|
|
|
printf(resultFormat, accumValue, values[values.size() / 2], values.back(), values.front(),
|
2016-10-05 15:42:03 +00:00
|
|
|
stddev, values.size(), FLAGS_sampleMs, FLAGS_gpuClock ? "gpu" : "cpu", Sample::metric(),
|
|
|
|
config, bench);
|
2016-09-19 18:03:58 +00:00
|
|
|
printf("\n");
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv) {
|
|
|
|
SkCommandLineFlags::SetUsage("Use skpbench.py instead. "
|
|
|
|
"You usually don't want to use this program directly.");
|
|
|
|
SkCommandLineFlags::Parse(argc, argv);
|
|
|
|
|
|
|
|
if (!FLAGS_suppressHeader) {
|
|
|
|
printf("%s\n", header);
|
|
|
|
}
|
2016-09-28 20:56:01 +00:00
|
|
|
if (FLAGS_duration <= 0) {
|
2016-09-19 18:03:58 +00:00
|
|
|
exit(0); // This can be used to print the header and quit.
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse the config.
|
|
|
|
const SkCommandLineConfigGpu* config = nullptr; // Initialize for spurious warning.
|
|
|
|
SkCommandLineConfigArray configs;
|
|
|
|
ParseConfigs(FLAGS_config, &configs);
|
|
|
|
if (configs.count() != 1 || !(config = configs[0]->asConfigGpu())) {
|
2016-10-12 01:28:54 +00:00
|
|
|
exitf(ExitErr::kUsage, "invalid config '%s': must specify one (and only one) GPU config",
|
2016-09-19 18:03:58 +00:00
|
|
|
join(FLAGS_config).c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Parse the skp.
|
|
|
|
if (FLAGS_skp.count() != 1) {
|
2016-10-12 01:28:54 +00:00
|
|
|
exitf(ExitErr::kUsage, "invalid skp '%s': must specify a single skp file, or 'warmup'",
|
2016-09-19 18:03:58 +00:00
|
|
|
join(FLAGS_skp).c_str());
|
|
|
|
}
|
2016-10-12 01:28:54 +00:00
|
|
|
sk_sp<SkPicture> skp;
|
|
|
|
SkString skpname;
|
|
|
|
if (0 == strcmp(FLAGS_skp[0], "warmup")) {
|
|
|
|
skp = create_warmup_skp();
|
|
|
|
skpname = "warmup";
|
|
|
|
} else {
|
|
|
|
const char* skpfile = FLAGS_skp[0];
|
|
|
|
std::unique_ptr<SkStream> skpstream(SkStream::MakeFromFile(skpfile));
|
|
|
|
if (!skpstream) {
|
|
|
|
exitf(ExitErr::kIO, "failed to open skp file %s", skpfile);
|
|
|
|
}
|
|
|
|
skp = SkPicture::MakeFromStream(skpstream.get());
|
|
|
|
if (!skp) {
|
|
|
|
exitf(ExitErr::kData, "failed to parse skp file %s", skpfile);
|
|
|
|
}
|
|
|
|
skpname = SkOSPath::Basename(skpfile);
|
2016-09-19 18:03:58 +00:00
|
|
|
}
|
|
|
|
int width = SkTMin(SkScalarCeilToInt(skp->cullRect().width()), 2048),
|
|
|
|
height = SkTMin(SkScalarCeilToInt(skp->cullRect().height()), 2048);
|
2016-09-22 12:10:02 +00:00
|
|
|
if (FLAGS_verbosity >= 3 &&
|
2016-09-19 18:03:58 +00:00
|
|
|
(width != skp->cullRect().width() || height != skp->cullRect().height())) {
|
2016-09-22 12:10:02 +00:00
|
|
|
fprintf(stderr, "%s is too large (%ix%i), cropping to %ix%i.\n",
|
2016-10-12 01:28:54 +00:00
|
|
|
skpname.c_str(), SkScalarCeilToInt(skp->cullRect().width()),
|
2016-09-19 18:03:58 +00:00
|
|
|
SkScalarCeilToInt(skp->cullRect().height()), width, height);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a context.
|
2017-02-22 19:00:42 +00:00
|
|
|
GrContextOptions ctxOptions;
|
2017-12-18 21:22:34 +00:00
|
|
|
SetCtxOptionsFromCommonFlags(&ctxOptions);
|
2017-02-22 19:00:42 +00:00
|
|
|
sk_gpu_test::GrContextFactory factory(ctxOptions);
|
2016-09-19 18:03:58 +00:00
|
|
|
sk_gpu_test::ContextInfo ctxInfo =
|
2017-02-21 19:36:05 +00:00
|
|
|
factory.getContextInfo(config->getContextType(), config->getContextOverrides());
|
2016-09-19 18:03:58 +00:00
|
|
|
GrContext* ctx = ctxInfo.grContext();
|
|
|
|
if (!ctx) {
|
|
|
|
exitf(ExitErr::kUnavailable, "failed to create context for config %s",
|
|
|
|
config->getTag().c_str());
|
|
|
|
}
|
|
|
|
if (ctx->caps()->maxRenderTargetSize() < SkTMax(width, height)) {
|
|
|
|
exitf(ExitErr::kUnavailable, "render target size %ix%i not supported by platform (max: %i)",
|
|
|
|
width, height, ctx->caps()->maxRenderTargetSize());
|
|
|
|
}
|
2017-07-19 18:47:42 +00:00
|
|
|
GrPixelConfig grPixConfig = SkImageInfo2GrPixelConfig(config->getColorType(),
|
|
|
|
config->getColorSpace(),
|
|
|
|
*ctx->caps());
|
2018-02-03 01:32:49 +00:00
|
|
|
int supportedSampleCount =
|
|
|
|
ctx->caps()->getRenderTargetSampleCount(config->getSamples(), grPixConfig);
|
2017-07-19 18:47:42 +00:00
|
|
|
if (supportedSampleCount != config->getSamples()) {
|
|
|
|
exitf(ExitErr::kUnavailable, "sample count %i not supported by platform",
|
|
|
|
config->getSamples());
|
2016-09-19 18:03:58 +00:00
|
|
|
}
|
|
|
|
sk_gpu_test::TestContext* testCtx = ctxInfo.testContext();
|
|
|
|
if (!testCtx) {
|
|
|
|
exitf(ExitErr::kSoftware, "testContext is null");
|
|
|
|
}
|
|
|
|
if (!testCtx->fenceSyncSupport()) {
|
|
|
|
exitf(ExitErr::kUnavailable, "GPU does not support fence sync");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create a render target.
|
2017-07-17 15:31:31 +00:00
|
|
|
SkImageInfo info =
|
|
|
|
SkImageInfo::Make(width, height, config->getColorType(), config->getAlphaType(),
|
|
|
|
sk_ref_sp(config->getColorSpace()));
|
2016-09-19 18:03:58 +00:00
|
|
|
uint32_t flags = config->getUseDIText() ? SkSurfaceProps::kUseDeviceIndependentFonts_Flag : 0;
|
|
|
|
SkSurfaceProps props(flags, SkSurfaceProps::kLegacyFontHost_InitType);
|
|
|
|
sk_sp<SkSurface> surface =
|
|
|
|
SkSurface::MakeRenderTarget(ctx, SkBudgeted::kNo, info, config->getSamples(), &props);
|
|
|
|
if (!surface) {
|
|
|
|
exitf(ExitErr::kUnavailable, "failed to create %ix%i render target for config %s",
|
|
|
|
width, height, config->getTag().c_str());
|
|
|
|
}
|
|
|
|
|
2016-10-12 01:28:54 +00:00
|
|
|
// Run the benchmark.
|
2016-09-19 18:03:58 +00:00
|
|
|
std::vector<Sample> samples;
|
2016-09-28 20:56:01 +00:00
|
|
|
if (FLAGS_sampleMs > 0) {
|
|
|
|
// +1 because we might take one more sample in order to have an odd number.
|
|
|
|
samples.reserve(1 + (FLAGS_duration + FLAGS_sampleMs - 1) / FLAGS_sampleMs);
|
|
|
|
} else {
|
|
|
|
samples.reserve(2 * FLAGS_duration);
|
|
|
|
}
|
2016-09-19 18:03:58 +00:00
|
|
|
SkCanvas* canvas = surface->getCanvas();
|
|
|
|
canvas->translate(-skp->cullRect().x(), -skp->cullRect().y());
|
2016-10-05 15:42:03 +00:00
|
|
|
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);
|
|
|
|
}
|
2016-10-12 01:28:54 +00:00
|
|
|
print_result(samples, config->getTag().c_str(), skpname.c_str());
|
2016-09-19 18:03:58 +00:00
|
|
|
|
|
|
|
// Save a proof (if one was requested).
|
|
|
|
if (!FLAGS_png.isEmpty()) {
|
|
|
|
SkBitmap bmp;
|
2017-04-17 14:53:29 +00:00
|
|
|
bmp.allocPixels(info);
|
|
|
|
if (!surface->getCanvas()->readPixels(bmp, 0, 0)) {
|
2016-09-19 18:03:58 +00:00
|
|
|
exitf(ExitErr::kUnavailable, "failed to read canvas pixels for png");
|
|
|
|
}
|
|
|
|
const SkString &dirname = SkOSPath::Dirname(FLAGS_png[0]),
|
|
|
|
&basename = SkOSPath::Basename(FLAGS_png[0]);
|
|
|
|
if (!mkdir_p(dirname)) {
|
|
|
|
exitf(ExitErr::kIO, "failed to create directory \"%s\" for png", dirname.c_str());
|
|
|
|
}
|
|
|
|
if (!sk_tools::write_bitmap_to_disk(bmp, dirname, nullptr, basename)) {
|
|
|
|
exitf(ExitErr::kIO, "failed to save png to \"%s\"", FLAGS_png[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void draw_skp_and_flush(SkCanvas* canvas, const SkPicture* skp) {
|
|
|
|
canvas->drawPicture(skp);
|
|
|
|
canvas->flush();
|
|
|
|
}
|
|
|
|
|
2016-10-12 01:28:54 +00:00
|
|
|
static sk_sp<SkPicture> create_warmup_skp() {
|
|
|
|
static constexpr SkRect bounds{0, 0, 500, 500};
|
|
|
|
SkPictureRecorder recorder;
|
|
|
|
SkCanvas* recording = recorder.beginRecording(bounds);
|
|
|
|
|
|
|
|
recording->clear(SK_ColorWHITE);
|
|
|
|
|
|
|
|
SkPaint stroke;
|
|
|
|
stroke.setStyle(SkPaint::kStroke_Style);
|
|
|
|
stroke.setStrokeWidth(2);
|
|
|
|
|
|
|
|
// Use a big path to (theoretically) warmup the CPU.
|
|
|
|
SkPath bigPath;
|
|
|
|
sk_tool_utils::make_big_path(bigPath);
|
|
|
|
recording->drawPath(bigPath, stroke);
|
|
|
|
|
|
|
|
// Use a perlin shader to warmup the GPU.
|
|
|
|
SkPaint perlin;
|
|
|
|
perlin.setShader(SkPerlinNoiseShader::MakeTurbulence(0.1f, 0.1f, 1, 0, nullptr));
|
|
|
|
recording->drawRect(bounds, perlin);
|
|
|
|
|
|
|
|
return recorder.finishRecordingAsPicture();
|
|
|
|
}
|
|
|
|
|
2016-09-19 18:03:58 +00:00
|
|
|
bool mkdir_p(const SkString& dirname) {
|
|
|
|
if (dirname.isEmpty()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return mkdir_p(SkOSPath::Dirname(dirname.c_str())) && sk_mkdir(dirname.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
static SkString join(const SkCommandLineFlags::StringArray& stringArray) {
|
|
|
|
SkString joined;
|
2016-10-12 01:28:54 +00:00
|
|
|
for (int i = 0; i < stringArray.count(); ++i) {
|
|
|
|
joined.appendf(i ? " %s" : "%s", stringArray[i]);
|
2016-09-19 18:03:58 +00:00
|
|
|
}
|
|
|
|
return joined;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void exitf(ExitErr err, const char* format, ...) {
|
|
|
|
fprintf(stderr, ExitErr::kSoftware == err ? "INTERNAL ERROR: " : "ERROR: ");
|
|
|
|
va_list args;
|
|
|
|
va_start(args, format);
|
|
|
|
vfprintf(stderr, format, args);
|
|
|
|
va_end(args);
|
|
|
|
fprintf(stderr, ExitErr::kSoftware == err ? "; this should never happen.\n": ".\n");
|
|
|
|
exit((int)err);
|
|
|
|
}
|
2016-09-28 21:53:07 +00:00
|
|
|
|
2016-10-05 15:42:03 +00:00
|
|
|
GpuSync::GpuSync(const sk_gpu_test::FenceSync* fenceSync)
|
2016-09-28 21:53:07 +00:00
|
|
|
: fFenceSync(fenceSync) {
|
|
|
|
this->updateFence();
|
|
|
|
}
|
|
|
|
|
|
|
|
GpuSync::~GpuSync() {
|
|
|
|
fFenceSync->deleteFence(fFence);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GpuSync::syncToPreviousFrame() {
|
2016-10-05 15:42:03 +00:00
|
|
|
if (sk_gpu_test::kInvalidFence == fFence) {
|
2016-09-28 21:53:07 +00:00
|
|
|
exitf(ExitErr::kSoftware, "attempted to sync with invalid fence");
|
|
|
|
}
|
|
|
|
if (!fFenceSync->waitFence(fFence)) {
|
|
|
|
exitf(ExitErr::kUnavailable, "failed to wait for fence");
|
|
|
|
}
|
|
|
|
fFenceSync->deleteFence(fFence);
|
|
|
|
this->updateFence();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GpuSync::updateFence() {
|
|
|
|
fFence = fFenceSync->insertFence();
|
2016-10-05 15:42:03 +00:00
|
|
|
if (sk_gpu_test::kInvalidFence == fFence) {
|
2016-09-28 21:53:07 +00:00
|
|
|
exitf(ExitErr::kUnavailable, "failed to insert fence");
|
|
|
|
}
|
|
|
|
}
|