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.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkCanvas.h"
|
2020-02-21 19:24:40 +00:00
|
|
|
#include "include/core/SkDeferredDisplayList.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkGraphics.h"
|
|
|
|
#include "include/core/SkPicture.h"
|
|
|
|
#include "include/core/SkPictureRecorder.h"
|
|
|
|
#include "include/core/SkStream.h"
|
|
|
|
#include "include/core/SkSurface.h"
|
|
|
|
#include "include/core/SkSurfaceProps.h"
|
|
|
|
#include "include/effects/SkPerlinNoiseShader.h"
|
2020-07-01 20:09:43 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/core/SkOSFile.h"
|
|
|
|
#include "src/core/SkTaskGroup.h"
|
|
|
|
#include "src/gpu/GrCaps.h"
|
|
|
|
#include "src/gpu/GrContextPriv.h"
|
|
|
|
#include "src/gpu/SkGr.h"
|
2019-07-26 13:44:46 +00:00
|
|
|
#include "src/utils/SkMultiPictureDocument.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/utils/SkOSPath.h"
|
|
|
|
#include "tools/DDLPromiseImageHelper.h"
|
|
|
|
#include "tools/DDLTileHelper.h"
|
2019-07-26 15:32:46 +00:00
|
|
|
#include "tools/SkSharingProc.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/ToolUtils.h"
|
|
|
|
#include "tools/flags/CommandLineFlags.h"
|
|
|
|
#include "tools/flags/CommonFlags.h"
|
|
|
|
#include "tools/flags/CommonFlagsConfig.h"
|
2020-02-21 20:46:27 +00:00
|
|
|
#include "tools/gpu/FlushFinishTracker.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/gpu/GpuTimer.h"
|
|
|
|
#include "tools/gpu/GrContextFactory.h"
|
2016-09-19 18:03:58 +00:00
|
|
|
|
2018-06-26 16:13:06 +00:00
|
|
|
#ifdef SK_XML
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "experimental/svg/model/SkSVGDOM.h"
|
|
|
|
#include "src/xml/SkDOM.h"
|
2018-06-26 16:13:06 +00:00
|
|
|
#endif
|
|
|
|
|
2018-09-19 15:31:27 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <algorithm>
|
|
|
|
#include <array>
|
|
|
|
#include <chrono>
|
|
|
|
#include <cmath>
|
|
|
|
#include <vector>
|
2018-06-26 16:13:06 +00:00
|
|
|
|
2016-09-19 18:03:58 +00:00
|
|
|
/**
|
2018-06-26 16:13:06 +00:00
|
|
|
* This is a minimalist program whose sole purpose is to open a .skp or .svg 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.
|
2016-09-19 18:03:58 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
2019-07-26 13:44:46 +00:00
|
|
|
* Well, maybe a little fanciness, MSKP's can be loaded and played. The animation is played as many
|
|
|
|
* times as necessary to reach the target sample duration and FPS is reported.
|
|
|
|
*
|
2016-09-19 18:03:58 +00:00
|
|
|
* Currently, only GPU configs are supported.
|
|
|
|
*/
|
|
|
|
|
2019-03-21 16:31:36 +00:00
|
|
|
static DEFINE_bool(ddl, false, "record the skp into DDLs before rendering");
|
2020-05-18 14:21:53 +00:00
|
|
|
static DEFINE_int(ddlNumRecordingThreads, 0, "number of DDL recording threads (0=num_cores)");
|
2019-03-21 16:42:21 +00:00
|
|
|
static DEFINE_int(ddlTilingWidthHeight, 0, "number of tiles along one edge when in DDL mode");
|
2020-03-06 20:26:28 +00:00
|
|
|
|
|
|
|
static DEFINE_bool(comparableDDL, false, "render in a way that is comparable to 'comparableSKP'");
|
|
|
|
static DEFINE_bool(comparableSKP, false, "report in a way that is comparable to 'comparableDDL'");
|
2018-05-29 20:13:26 +00:00
|
|
|
|
2019-03-21 16:42:21 +00:00
|
|
|
static DEFINE_int(duration, 5000, "number of milliseconds to run the benchmark");
|
|
|
|
static DEFINE_int(sampleMs, 50, "minimum duration of a sample");
|
2019-03-21 16:31:36 +00:00
|
|
|
static DEFINE_bool(gpuClock, false, "time on the gpu clock (gpu work only)");
|
|
|
|
static DEFINE_bool(fps, false, "use fps instead of ms");
|
|
|
|
static DEFINE_string(src, "",
|
|
|
|
"path to a single .skp or .svg file, or 'warmup' for a builtin warmup run");
|
|
|
|
static DEFINE_string(png, "", "if set, save a .png proof to disk at this file location");
|
2019-03-21 16:42:21 +00:00
|
|
|
static DEFINE_int(verbosity, 4, "level of verbosity (0=none to 5=debug)");
|
2019-03-21 16:31:36 +00:00
|
|
|
static DEFINE_bool(suppressHeader, false, "don't print a header row before the results");
|
2020-01-16 21:45:57 +00:00
|
|
|
static DEFINE_double(scale, 1, "Scale the size of the canvas and the zoom level by this factor.");
|
2016-09-19 18:03:58 +00:00
|
|
|
|
2020-05-05 19:57:46 +00:00
|
|
|
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
|
|
|
|
2020-05-05 19:57:46 +00:00
|
|
|
static const char resultFormat[] =
|
|
|
|
"%8.4g %8.4g %8.4g %8.4g %6.3g%% %7zu %9i %-5s %-6s %-9s %s";
|
2016-09-19 18:03:58 +00:00
|
|
|
|
2018-06-24 19:08:57 +00:00
|
|
|
static constexpr int kNumFlushesToPrimeCache = 3;
|
|
|
|
|
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:
|
2020-02-21 20:46:27 +00:00
|
|
|
GpuSync() {}
|
|
|
|
~GpuSync() {}
|
2016-09-28 21:53:07 +00:00
|
|
|
|
2020-02-21 20:46:27 +00:00
|
|
|
void waitIfNeeded();
|
2016-09-28 21:53:07 +00:00
|
|
|
|
2020-07-01 20:09:43 +00:00
|
|
|
sk_gpu_test::FlushFinishTracker* newFlushTracker(GrDirectContext* context);
|
2016-09-28 21:53:07 +00:00
|
|
|
|
2020-02-21 20:46:27 +00:00
|
|
|
private:
|
|
|
|
enum { kMaxFrameLag = 3 };
|
|
|
|
sk_sp<sk_gpu_test::FlushFinishTracker> fFinishTrackers[kMaxFrameLag - 1];
|
|
|
|
int fCurrentFlushIdx = 0;
|
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
|
|
|
|
};
|
|
|
|
|
2020-07-01 20:09:43 +00:00
|
|
|
static void flush_with_sync(GrDirectContext*, GpuSync&);
|
|
|
|
static void draw_skp_and_flush_with_sync(GrDirectContext*, SkSurface*, const SkPicture*, GpuSync&);
|
2016-10-12 01:28:54 +00:00
|
|
|
static sk_sp<SkPicture> create_warmup_skp();
|
2018-06-26 16:13:06 +00:00
|
|
|
static sk_sp<SkPicture> create_skp_from_svg(SkStream*, const char* filename);
|
2016-09-19 18:03:58 +00:00
|
|
|
static bool mkdir_p(const SkString& name);
|
2019-03-20 15:50:33 +00:00
|
|
|
static SkString join(const CommandLineFlags::StringArray&);
|
2016-09-19 18:03:58 +00:00
|
|
|
static void exitf(ExitErr, const char* format, ...);
|
|
|
|
|
2019-07-26 13:44:46 +00:00
|
|
|
// An interface used by both static SKPs and animated SKPs
|
|
|
|
class SkpProducer {
|
2020-02-21 20:46:27 +00:00
|
|
|
public:
|
|
|
|
virtual ~SkpProducer() {}
|
|
|
|
// Draw an SkPicture to the provided surface, flush the surface, and sync the GPU.
|
|
|
|
// You may use the static draw_skp_and_flush_with_sync declared above.
|
|
|
|
// returned int tells how many draw/flush/sync were done.
|
2020-07-01 20:09:43 +00:00
|
|
|
virtual int drawAndFlushAndSync(GrDirectContext*, SkSurface* surface, GpuSync& gpuSync) = 0;
|
2019-07-26 13:44:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class StaticSkp : public SkpProducer {
|
2020-02-21 20:46:27 +00:00
|
|
|
public:
|
|
|
|
StaticSkp(sk_sp<SkPicture> skp) : fSkp(skp) {}
|
2019-07-26 13:44:46 +00:00
|
|
|
|
2020-07-01 20:09:43 +00:00
|
|
|
int drawAndFlushAndSync(GrDirectContext* context,
|
|
|
|
SkSurface* surface,
|
|
|
|
GpuSync& gpuSync) override {
|
2020-02-21 20:46:27 +00:00
|
|
|
draw_skp_and_flush_with_sync(context, surface, fSkp.get(), gpuSync);
|
2019-07-26 13:44:46 +00:00
|
|
|
return 1;
|
|
|
|
}
|
2020-02-21 20:46:27 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
sk_sp<SkPicture> fSkp;
|
2019-07-26 13:44:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// A class for playing/benchmarking a multi frame SKP file.
|
|
|
|
// the recorded frames are looped over repeatedly.
|
|
|
|
// This type of benchmark may have a much higher std dev in frame times.
|
|
|
|
class MultiFrameSkp : public SkpProducer {
|
|
|
|
public:
|
|
|
|
MultiFrameSkp(const std::vector<SkDocumentPage>& frames) : fFrames(frames){}
|
|
|
|
|
|
|
|
static std::unique_ptr<MultiFrameSkp> MakeFromFile(const SkString& path) {
|
|
|
|
// Load the multi frame skp at the given filename.
|
|
|
|
std::unique_ptr<SkStreamAsset> stream = SkStream::MakeFromFile(path.c_str());
|
|
|
|
if (!stream) { return nullptr; }
|
|
|
|
|
|
|
|
// Attempt to deserialize with an image sharing serial proc.
|
|
|
|
auto deserialContext = std::make_unique<SkSharingDeserialContext>();
|
|
|
|
SkDeserialProcs procs;
|
|
|
|
procs.fImageProc = SkSharingDeserialContext::deserializeImage;
|
|
|
|
procs.fImageCtx = deserialContext.get();
|
|
|
|
|
|
|
|
// The outer format of multi-frame skps is the multi-picture document, which is a
|
|
|
|
// skp file containing subpictures separated by annotations.
|
|
|
|
int page_count = SkMultiPictureDocumentReadPageCount(stream.get());
|
|
|
|
if (!page_count) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
std::vector<SkDocumentPage> frames(page_count); // can't call reserve, why?
|
|
|
|
if (!SkMultiPictureDocumentRead(stream.get(), frames.data(), page_count, &procs)) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::make_unique<MultiFrameSkp>(frames);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Draw the whole animation once.
|
2020-07-01 20:09:43 +00:00
|
|
|
int drawAndFlushAndSync(GrDirectContext* context,
|
|
|
|
SkSurface* surface,
|
|
|
|
GpuSync& gpuSync) override {
|
2019-07-26 13:44:46 +00:00
|
|
|
for (int i=0; i<this->count(); i++){
|
2020-02-21 20:46:27 +00:00
|
|
|
draw_skp_and_flush_with_sync(context, surface, this->frame(i).get(), gpuSync);
|
2019-07-26 13:44:46 +00:00
|
|
|
}
|
|
|
|
return this->count();
|
|
|
|
}
|
|
|
|
// Return the requested frame.
|
|
|
|
sk_sp<SkPicture> frame(int n) const { return fFrames[n].fPicture; }
|
|
|
|
// Return the number of frames in the recording.
|
|
|
|
int count() const { return fFrames.size(); }
|
|
|
|
private:
|
|
|
|
std::vector<SkDocumentPage> fFrames;
|
|
|
|
};
|
|
|
|
|
2020-07-01 20:09:43 +00:00
|
|
|
static void ddl_sample(GrDirectContext* context, DDLTileHelper* tiles, GpuSync& gpuSync,
|
2020-05-18 14:21:53 +00:00
|
|
|
Sample* sample, SkTaskGroup* recordingTaskGroup, SkTaskGroup* gpuTaskGroup,
|
2018-05-29 20:13:26 +00:00
|
|
|
std::chrono::high_resolution_clock::time_point* startStopTime) {
|
|
|
|
using clock = std::chrono::high_resolution_clock;
|
|
|
|
|
|
|
|
clock::time_point start = *startStopTime;
|
|
|
|
|
2020-03-06 20:26:28 +00:00
|
|
|
if (FLAGS_comparableDDL) {
|
|
|
|
SkASSERT(!FLAGS_comparableSKP);
|
|
|
|
|
|
|
|
// In this mode we simply alternate between creating a DDL and drawing it - all on one
|
|
|
|
// thread. The interleaving is so that we don't starve the GPU.
|
|
|
|
// One unfortunate side effect of this is that we can't delete the DDLs until after
|
|
|
|
// the GPU work is flushed.
|
|
|
|
tiles->interleaveDDLCreationAndDraw(context);
|
|
|
|
} else if (FLAGS_comparableSKP) {
|
|
|
|
// In this mode simply draw the re-inflated per-tile SKPs directly to the GPU w/o going
|
|
|
|
// through a DDL.
|
|
|
|
tiles->drawAllTilesDirectly(context);
|
|
|
|
} else {
|
2020-05-18 14:21:53 +00:00
|
|
|
tiles->kickOffThreadedWork(recordingTaskGroup, gpuTaskGroup, context);
|
|
|
|
recordingTaskGroup->wait();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (gpuTaskGroup) {
|
|
|
|
gpuTaskGroup->add([&]{
|
|
|
|
flush_with_sync(context, gpuSync);
|
|
|
|
});
|
|
|
|
gpuTaskGroup->wait();
|
|
|
|
} else {
|
|
|
|
flush_with_sync(context, gpuSync);
|
2018-05-29 20:13:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
*startStopTime = clock::now();
|
|
|
|
|
|
|
|
if (sample) {
|
|
|
|
sample->fDuration += *startStopTime - start;
|
|
|
|
sample->fFrames++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-01 20:09:43 +00:00
|
|
|
static void run_ddl_benchmark(sk_gpu_test::TestContext* testContext, GrDirectContext *context,
|
2020-05-18 14:21:53 +00:00
|
|
|
sk_sp<SkSurface> dstSurface, SkPicture* inputPicture,
|
|
|
|
std::vector<Sample>* samples) {
|
2018-05-29 20:13:26 +00:00
|
|
|
using clock = std::chrono::high_resolution_clock;
|
|
|
|
const Sample::duration sampleDuration = std::chrono::milliseconds(FLAGS_sampleMs);
|
|
|
|
const clock::duration benchDuration = std::chrono::milliseconds(FLAGS_duration);
|
|
|
|
|
2020-02-26 15:27:07 +00:00
|
|
|
SkSurfaceCharacterization dstCharacterization;
|
2020-04-23 19:10:03 +00:00
|
|
|
SkAssertResult(dstSurface->characterize(&dstCharacterization));
|
2020-02-26 15:27:07 +00:00
|
|
|
|
2020-04-23 19:10:03 +00:00
|
|
|
SkIRect viewport = dstSurface->imageInfo().bounds();
|
2018-05-29 20:13:26 +00:00
|
|
|
|
|
|
|
DDLPromiseImageHelper promiseImageHelper;
|
|
|
|
sk_sp<SkData> compressedPictureData = promiseImageHelper.deflateSKP(inputPicture);
|
|
|
|
if (!compressedPictureData) {
|
|
|
|
exitf(ExitErr::kUnavailable, "DDL: conversion of skp failed");
|
|
|
|
}
|
|
|
|
|
2020-02-14 17:36:37 +00:00
|
|
|
promiseImageHelper.createCallbackContexts(context);
|
|
|
|
|
|
|
|
promiseImageHelper.uploadAllToGPU(nullptr, context);
|
2018-05-29 20:13:26 +00:00
|
|
|
|
2020-04-23 19:10:03 +00:00
|
|
|
DDLTileHelper tiles(context, dstCharacterization, viewport, FLAGS_ddlTilingWidthHeight);
|
2018-05-29 20:13:26 +00:00
|
|
|
|
2020-04-16 20:27:45 +00:00
|
|
|
tiles.createBackendTextures(nullptr, context);
|
|
|
|
|
2018-05-29 20:13:26 +00:00
|
|
|
tiles.createSKPPerTile(compressedPictureData.get(), promiseImageHelper);
|
|
|
|
|
2020-05-18 14:21:53 +00:00
|
|
|
// In comparable modes, there is no GPU thread. The following pointers are all null.
|
|
|
|
// Otherwise, we transfer testContext onto the GPU thread until after the bench.
|
|
|
|
std::unique_ptr<SkExecutor> gpuThread;
|
|
|
|
std::unique_ptr<SkTaskGroup> gpuTaskGroup;
|
|
|
|
std::unique_ptr<SkExecutor> recordingThreadPool;
|
|
|
|
std::unique_ptr<SkTaskGroup> recordingTaskGroup;
|
|
|
|
if (!FLAGS_comparableDDL && !FLAGS_comparableSKP) {
|
|
|
|
gpuThread = SkExecutor::MakeFIFOThreadPool(1, false);
|
|
|
|
gpuTaskGroup = std::make_unique<SkTaskGroup>(*gpuThread);
|
|
|
|
recordingThreadPool = SkExecutor::MakeFIFOThreadPool(FLAGS_ddlNumRecordingThreads, false);
|
|
|
|
recordingTaskGroup = std::make_unique<SkTaskGroup>(*recordingThreadPool);
|
|
|
|
testContext->makeNotCurrent();
|
|
|
|
gpuTaskGroup->add([=]{ testContext->makeCurrent(); });
|
|
|
|
}
|
2018-06-21 15:18:25 +00:00
|
|
|
|
2018-05-29 20:13:26 +00:00
|
|
|
clock::time_point startStopTime = clock::now();
|
|
|
|
|
2020-02-21 20:46:27 +00:00
|
|
|
GpuSync gpuSync;
|
2020-05-18 14:21:53 +00:00
|
|
|
ddl_sample(context, &tiles, gpuSync, nullptr, recordingTaskGroup.get(),
|
|
|
|
gpuTaskGroup.get(), &startStopTime);
|
2018-05-29 20:13:26 +00:00
|
|
|
|
|
|
|
clock::duration cumulativeDuration = std::chrono::milliseconds(0);
|
|
|
|
|
|
|
|
do {
|
|
|
|
samples->emplace_back();
|
|
|
|
Sample& sample = samples->back();
|
|
|
|
|
|
|
|
do {
|
2020-03-06 20:26:28 +00:00
|
|
|
tiles.resetAllTiles();
|
2020-05-18 14:21:53 +00:00
|
|
|
ddl_sample(context, &tiles, gpuSync, &sample, recordingTaskGroup.get(),
|
|
|
|
gpuTaskGroup.get(), &startStopTime);
|
2018-05-29 20:13:26 +00:00
|
|
|
} while (sample.fDuration < sampleDuration);
|
|
|
|
|
|
|
|
cumulativeDuration += sample.fDuration;
|
|
|
|
} while (cumulativeDuration < benchDuration || 0 == samples->size() % 2);
|
|
|
|
|
2020-05-18 14:21:53 +00:00
|
|
|
// Move the context back to this thread now that we're done benching.
|
|
|
|
if (gpuTaskGroup) {
|
|
|
|
gpuTaskGroup->add([=]{
|
|
|
|
testContext->makeNotCurrent();
|
|
|
|
});
|
|
|
|
gpuTaskGroup->wait();
|
|
|
|
testContext->makeCurrent();
|
|
|
|
}
|
|
|
|
|
2018-05-29 20:13:26 +00:00
|
|
|
if (!FLAGS_png.isEmpty()) {
|
|
|
|
// The user wants to see the final result
|
2020-04-23 19:10:03 +00:00
|
|
|
dstSurface->draw(tiles.composeDDL());
|
2020-05-14 19:45:44 +00:00
|
|
|
dstSurface->flushAndSubmit();
|
2018-05-29 20:13:26 +00:00
|
|
|
}
|
2019-12-16 20:37:19 +00:00
|
|
|
|
2020-03-06 20:26:28 +00:00
|
|
|
tiles.resetAllTiles();
|
|
|
|
|
2019-12-16 20:37:19 +00:00
|
|
|
// Make sure the gpu has finished all its work before we exit this function and delete the
|
|
|
|
// fence.
|
2020-06-30 17:42:46 +00:00
|
|
|
context->flush();
|
2020-05-14 19:45:44 +00:00
|
|
|
context->submit(true);
|
2020-04-16 20:27:45 +00:00
|
|
|
|
|
|
|
promiseImageHelper.deleteAllFromGPU(nullptr, context);
|
|
|
|
|
|
|
|
tiles.deleteBackendTextures(nullptr, context);
|
|
|
|
|
2018-05-29 20:13:26 +00:00
|
|
|
}
|
|
|
|
|
2020-07-01 20:09:43 +00:00
|
|
|
static void run_benchmark(GrDirectContext* context, SkSurface* surface, SkpProducer* skpp,
|
2020-02-21 20:46:27 +00:00
|
|
|
std::vector<Sample>* samples) {
|
2016-10-05 15:42:03 +00:00
|
|
|
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
|
|
|
|
2020-02-21 20:46:27 +00:00
|
|
|
GpuSync gpuSync;
|
2019-07-26 13:44:46 +00:00
|
|
|
int i = 0;
|
|
|
|
do {
|
2020-02-21 20:46:27 +00:00
|
|
|
i += skpp->drawAndFlushAndSync(context, surface, gpuSync);
|
2019-07-26 13:44:46 +00:00
|
|
|
} while(i < kNumFlushesToPrimeCache);
|
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 {
|
2020-02-21 20:46:27 +00:00
|
|
|
sample.fFrames += skpp->drawAndFlushAndSync(context, surface, gpuSync);
|
|
|
|
now = clock::now();
|
|
|
|
sample.fDuration = now - sampleStart;
|
2016-09-28 20:56:01 +00:00
|
|
|
} while (sample.fDuration < sampleDuration);
|
|
|
|
} while (now < endTime || 0 == samples->size() % 2);
|
2019-12-16 20:37:19 +00:00
|
|
|
|
|
|
|
// Make sure the gpu has finished all its work before we exit this function and delete the
|
|
|
|
// fence.
|
2020-06-30 17:42:46 +00:00
|
|
|
surface->flush();
|
2020-05-14 19:45:44 +00:00
|
|
|
context->submit(true);
|
2016-09-19 18:03:58 +00:00
|
|
|
}
|
|
|
|
|
2020-07-01 20:09:43 +00:00
|
|
|
static void run_gpu_time_benchmark(sk_gpu_test::GpuTimer* gpuTimer, GrDirectContext* context,
|
2020-02-21 20:46:27 +00:00
|
|
|
SkSurface* surface, const SkPicture* skp,
|
|
|
|
std::vector<Sample>* samples) {
|
2016-10-05 15:42:03 +00:00
|
|
|
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");
|
|
|
|
}
|
|
|
|
|
2020-02-21 20:46:27 +00:00
|
|
|
GpuSync gpuSync;
|
|
|
|
draw_skp_and_flush_with_sync(context, surface, skp, gpuSync);
|
2016-10-05 15:42:03 +00:00
|
|
|
|
2018-06-24 19:08:57 +00:00
|
|
|
PlatformTimerQuery previousTime = 0;
|
|
|
|
for (int i = 1; i < kNumFlushesToPrimeCache; ++i) {
|
|
|
|
gpuTimer->queueStart();
|
2020-02-21 20:46:27 +00:00
|
|
|
draw_skp_and_flush_with_sync(context, surface, skp, gpuSync);
|
2018-06-24 19:08:57 +00:00
|
|
|
previousTime = gpuTimer->queueStop();
|
|
|
|
}
|
2016-10-05 15:42:03 +00:00
|
|
|
|
|
|
|
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();
|
2020-02-21 20:46:27 +00:00
|
|
|
draw_skp_and_flush_with_sync(context, surface, skp, gpuSync);
|
2016-10-05 15:42:03 +00:00
|
|
|
PlatformTimerQuery time = gpuTimer->queueStop();
|
|
|
|
|
|
|
|
switch (gpuTimer->checkQueryStatus(previousTime)) {
|
|
|
|
using QueryStatus = sk_gpu_test::GpuTimer::QueryStatus;
|
|
|
|
case QueryStatus::kInvalid:
|
|
|
|
exitf(ExitErr::kUnavailable, "GPU timer failed");
|
2020-06-11 21:55:07 +00:00
|
|
|
break;
|
2016-10-05 15:42:03 +00:00
|
|
|
case QueryStatus::kPending:
|
|
|
|
exitf(ExitErr::kUnavailable, "timer query still not ready after fence sync");
|
2020-06-11 21:55:07 +00:00
|
|
|
break;
|
2016-10-05 15:42:03 +00:00
|
|
|
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);
|
2019-12-16 20:37:19 +00:00
|
|
|
|
|
|
|
// Make sure the gpu has finished all its work before we exit this function and delete the
|
|
|
|
// fence.
|
2020-06-30 17:42:46 +00:00
|
|
|
surface->flush();
|
2020-05-14 19:45:44 +00:00
|
|
|
context->submit(true);
|
2016-10-05 15:42:03 +00:00
|
|
|
}
|
|
|
|
|
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) {
|
2019-03-20 15:50:33 +00:00
|
|
|
CommandLineFlags::SetUsage(
|
|
|
|
"Use skpbench.py instead. "
|
|
|
|
"You usually don't want to use this program directly.");
|
|
|
|
CommandLineFlags::Parse(argc, argv);
|
2016-09-19 18:03:58 +00:00
|
|
|
|
|
|
|
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.
|
2018-06-26 16:13:06 +00:00
|
|
|
if (FLAGS_src.count() != 1) {
|
|
|
|
exitf(ExitErr::kUsage,
|
|
|
|
"invalid input '%s': must specify a single .skp or .svg file, or 'warmup'",
|
|
|
|
join(FLAGS_src).c_str());
|
2016-09-19 18:03:58 +00:00
|
|
|
}
|
2018-05-29 20:13:26 +00:00
|
|
|
|
|
|
|
SkGraphics::Init();
|
|
|
|
|
2016-10-12 01:28:54 +00:00
|
|
|
sk_sp<SkPicture> skp;
|
2019-07-26 13:44:46 +00:00
|
|
|
std::unique_ptr<MultiFrameSkp> mskp; // populated if the file is multi frame.
|
2018-06-26 16:13:06 +00:00
|
|
|
SkString srcname;
|
|
|
|
if (0 == strcmp(FLAGS_src[0], "warmup")) {
|
2016-10-12 01:28:54 +00:00
|
|
|
skp = create_warmup_skp();
|
2018-06-26 16:13:06 +00:00
|
|
|
srcname = "warmup";
|
2016-10-12 01:28:54 +00:00
|
|
|
} else {
|
2018-06-26 16:13:06 +00:00
|
|
|
SkString srcfile(FLAGS_src[0]);
|
|
|
|
std::unique_ptr<SkStream> srcstream(SkStream::MakeFromFile(srcfile.c_str()));
|
|
|
|
if (!srcstream) {
|
|
|
|
exitf(ExitErr::kIO, "failed to open file %s", srcfile.c_str());
|
|
|
|
}
|
|
|
|
if (srcfile.endsWith(".svg")) {
|
|
|
|
skp = create_skp_from_svg(srcstream.get(), srcfile.c_str());
|
2019-07-26 13:44:46 +00:00
|
|
|
} else if (srcfile.endsWith(".mskp")) {
|
|
|
|
mskp = MultiFrameSkp::MakeFromFile(srcfile);
|
|
|
|
// populate skp with it's first frame, for width height determination.
|
|
|
|
skp = mskp->frame(0);
|
2018-06-26 16:13:06 +00:00
|
|
|
} else {
|
|
|
|
skp = SkPicture::MakeFromStream(srcstream.get());
|
2016-10-12 01:28:54 +00:00
|
|
|
}
|
|
|
|
if (!skp) {
|
2018-06-26 16:13:06 +00:00
|
|
|
exitf(ExitErr::kData, "failed to parse file %s", srcfile.c_str());
|
2016-10-12 01:28:54 +00:00
|
|
|
}
|
2018-06-26 16:13:06 +00:00
|
|
|
srcname = SkOSPath::Basename(srcfile.c_str());
|
2016-09-19 18:03:58 +00:00
|
|
|
}
|
2020-02-07 15:36:46 +00:00
|
|
|
int width = std::min(SkScalarCeilToInt(skp->cullRect().width()), 2048),
|
|
|
|
height = std::min(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",
|
2018-06-26 16:13:06 +00:00
|
|
|
srcname.c_str(), SkScalarCeilToInt(skp->cullRect().width()),
|
2016-09-19 18:03:58 +00:00
|
|
|
SkScalarCeilToInt(skp->cullRect().height()), width, height);
|
|
|
|
}
|
2020-01-16 21:45:57 +00:00
|
|
|
if (FLAGS_scale != 1) {
|
|
|
|
width *= FLAGS_scale;
|
|
|
|
height *= FLAGS_scale;
|
|
|
|
if (FLAGS_verbosity >= 3) {
|
|
|
|
fprintf(stderr, "Scale factor of %.2f: scaling to %ix%i.\n",
|
|
|
|
FLAGS_scale, width, height);
|
|
|
|
}
|
|
|
|
}
|
2016-09-19 18:03:58 +00:00
|
|
|
|
2018-03-09 14:01:53 +00:00
|
|
|
if (config->getSurfType() != SkCommandLineConfigGpu::SurfType::kDefault) {
|
|
|
|
exitf(ExitErr::kUnavailable, "This tool only supports the default surface type. (%s)",
|
|
|
|
config->getTag().c_str());
|
|
|
|
}
|
|
|
|
|
2016-09-19 18:03:58 +00:00
|
|
|
// 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());
|
2020-07-01 20:59:17 +00:00
|
|
|
auto ctx = ctxInfo.directContext();
|
2016-09-19 18:03:58 +00:00
|
|
|
if (!ctx) {
|
|
|
|
exitf(ExitErr::kUnavailable, "failed to create context for config %s",
|
|
|
|
config->getTag().c_str());
|
|
|
|
}
|
2020-02-07 15:36:46 +00:00
|
|
|
if (ctx->maxRenderTargetSize() < std::max(width, height)) {
|
2016-09-19 18:03:58 +00:00
|
|
|
exitf(ExitErr::kUnavailable, "render target size %ix%i not supported by platform (max: %i)",
|
2018-05-11 14:14:21 +00:00
|
|
|
width, height, ctx->maxRenderTargetSize());
|
2016-09-19 18:03:58 +00:00
|
|
|
}
|
2019-08-07 19:52:37 +00:00
|
|
|
GrBackendFormat format = ctx->defaultBackendFormat(config->getColorType(), GrRenderable::kYes);
|
|
|
|
if (!format.isValid()) {
|
|
|
|
exitf(ExitErr::kUnavailable, "failed to get GrBackendFormat from SkColorType: %d",
|
2018-02-21 18:02:32 +00:00
|
|
|
config->getColorType());
|
|
|
|
}
|
2019-02-04 18:26:26 +00:00
|
|
|
int supportedSampleCount = ctx->priv().caps()->getRenderTargetSampleCount(
|
2019-08-07 19:52:37 +00:00
|
|
|
config->getSamples(), format);
|
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());
|
2020-01-16 21:45:57 +00:00
|
|
|
if (FLAGS_scale != 1) {
|
|
|
|
canvas->scale(FLAGS_scale, FLAGS_scale);
|
|
|
|
}
|
2016-10-05 15:42:03 +00:00
|
|
|
if (!FLAGS_gpuClock) {
|
2018-05-29 20:13:26 +00:00
|
|
|
if (FLAGS_ddl) {
|
2020-05-18 14:21:53 +00:00
|
|
|
run_ddl_benchmark(testCtx, ctx, surface, skp.get(), &samples);
|
2019-07-26 13:44:46 +00:00
|
|
|
} else if (!mskp) {
|
|
|
|
auto s = std::make_unique<StaticSkp>(skp);
|
2020-02-21 20:46:27 +00:00
|
|
|
run_benchmark(ctx, surface.get(), s.get(), &samples);
|
2018-05-29 20:13:26 +00:00
|
|
|
} else {
|
2020-02-21 20:46:27 +00:00
|
|
|
run_benchmark(ctx, surface.get(), mskp.get(), &samples);
|
2018-05-29 20:13:26 +00:00
|
|
|
}
|
2016-10-05 15:42:03 +00:00
|
|
|
} else {
|
2018-05-29 20:13:26 +00:00
|
|
|
if (FLAGS_ddl) {
|
|
|
|
exitf(ExitErr::kUnavailable, "DDL: GPU-only timing not supported");
|
|
|
|
}
|
2016-10-05 15:42:03 +00:00
|
|
|
if (!testCtx->gpuTimingSupport()) {
|
|
|
|
exitf(ExitErr::kUnavailable, "GPU does not support timing");
|
|
|
|
}
|
2020-02-21 20:46:27 +00:00
|
|
|
run_gpu_time_benchmark(testCtx->gpuTimer(), ctx, surface.get(), skp.get(), &samples);
|
2016-10-05 15:42:03 +00:00
|
|
|
}
|
2018-06-26 16:13:06 +00:00
|
|
|
print_result(samples, config->getTag().c_str(), srcname.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");
|
|
|
|
}
|
2018-08-09 13:46:53 +00:00
|
|
|
if (!mkdir_p(SkOSPath::Dirname(FLAGS_png[0]))) {
|
|
|
|
exitf(ExitErr::kIO, "failed to create directory for png \"%s\"", FLAGS_png[0]);
|
2016-09-19 18:03:58 +00:00
|
|
|
}
|
2019-03-20 16:12:10 +00:00
|
|
|
if (!ToolUtils::EncodeImageToFile(FLAGS_png[0], bmp, SkEncodedImageFormat::kPNG, 100)) {
|
2016-09-19 18:03:58 +00:00
|
|
|
exitf(ExitErr::kIO, "failed to save png to \"%s\"", FLAGS_png[0]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-12-16 20:37:19 +00:00
|
|
|
return(0);
|
2016-09-19 18:03:58 +00:00
|
|
|
}
|
|
|
|
|
2020-07-01 20:09:43 +00:00
|
|
|
static void flush_with_sync(GrDirectContext* context, GpuSync& gpuSync) {
|
2020-02-21 20:46:27 +00:00
|
|
|
gpuSync.waitIfNeeded();
|
|
|
|
|
|
|
|
GrFlushInfo flushInfo;
|
|
|
|
flushInfo.fFinishedProc = sk_gpu_test::FlushFinishTracker::FlushFinished;
|
|
|
|
flushInfo.fFinishedContext = gpuSync.newFlushTracker(context);
|
|
|
|
|
|
|
|
context->flush(flushInfo);
|
2020-05-14 19:45:44 +00:00
|
|
|
context->submit();
|
2020-02-21 20:46:27 +00:00
|
|
|
}
|
|
|
|
|
2020-07-01 20:09:43 +00:00
|
|
|
static void draw_skp_and_flush_with_sync(GrDirectContext* context, SkSurface* surface,
|
2020-02-21 20:46:27 +00:00
|
|
|
const SkPicture* skp, GpuSync& gpuSync) {
|
2019-03-04 16:00:10 +00:00
|
|
|
auto canvas = surface->getCanvas();
|
2016-09-19 18:03:58 +00:00
|
|
|
canvas->drawPicture(skp);
|
2020-02-21 20:46:27 +00:00
|
|
|
|
|
|
|
flush_with_sync(context, gpuSync);
|
2016-09-19 18:03:58 +00:00
|
|
|
}
|
|
|
|
|
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;
|
2019-03-20 16:12:10 +00:00
|
|
|
ToolUtils::make_big_path(bigPath);
|
2016-10-12 01:28:54 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2018-06-26 16:13:06 +00:00
|
|
|
static sk_sp<SkPicture> create_skp_from_svg(SkStream* stream, const char* filename) {
|
|
|
|
#ifdef SK_XML
|
|
|
|
SkDOM xml;
|
|
|
|
if (!xml.build(*stream)) {
|
|
|
|
exitf(ExitErr::kData, "failed to parse xml in file %s", filename);
|
|
|
|
}
|
|
|
|
sk_sp<SkSVGDOM> svg = SkSVGDOM::MakeFromDOM(xml);
|
|
|
|
if (!svg) {
|
|
|
|
exitf(ExitErr::kData, "failed to build svg dom from file %s", filename);
|
|
|
|
}
|
|
|
|
|
|
|
|
static constexpr SkRect bounds{0, 0, 1200, 1200};
|
|
|
|
SkPictureRecorder recorder;
|
|
|
|
SkCanvas* recording = recorder.beginRecording(bounds);
|
|
|
|
|
|
|
|
svg->setContainerSize(SkSize::Make(recording->getBaseLayerSize()));
|
|
|
|
svg->render(recording);
|
|
|
|
|
|
|
|
return recorder.finishRecordingAsPicture();
|
|
|
|
#endif
|
|
|
|
exitf(ExitErr::kData, "SK_XML is disabled; cannot open svg file %s", filename);
|
2018-07-31 20:38:43 +00:00
|
|
|
return nullptr;
|
2018-06-26 16:13:06 +00:00
|
|
|
}
|
|
|
|
|
2016-09-19 18:03:58 +00:00
|
|
|
bool mkdir_p(const SkString& dirname) {
|
2019-04-01 18:40:06 +00:00
|
|
|
if (dirname.isEmpty() || dirname == SkString("/")) {
|
2016-09-19 18:03:58 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return mkdir_p(SkOSPath::Dirname(dirname.c_str())) && sk_mkdir(dirname.c_str());
|
|
|
|
}
|
|
|
|
|
2019-03-20 15:50:33 +00:00
|
|
|
static SkString join(const CommandLineFlags::StringArray& stringArray) {
|
2016-09-19 18:03:58 +00:00
|
|
|
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
|
|
|
|
2020-02-21 20:46:27 +00:00
|
|
|
void GpuSync::waitIfNeeded() {
|
|
|
|
if (fFinishTrackers[fCurrentFlushIdx]) {
|
|
|
|
fFinishTrackers[fCurrentFlushIdx]->waitTillFinished();
|
|
|
|
}
|
2016-09-28 21:53:07 +00:00
|
|
|
}
|
|
|
|
|
2020-07-01 20:09:43 +00:00
|
|
|
sk_gpu_test::FlushFinishTracker* GpuSync::newFlushTracker(GrDirectContext* context) {
|
2020-02-21 20:46:27 +00:00
|
|
|
fFinishTrackers[fCurrentFlushIdx].reset(new sk_gpu_test::FlushFinishTracker(context));
|
2016-09-28 21:53:07 +00:00
|
|
|
|
2020-02-21 20:46:27 +00:00
|
|
|
sk_gpu_test::FlushFinishTracker* tracker = fFinishTrackers[fCurrentFlushIdx].get();
|
|
|
|
// We add an additional ref to the current flush tracker here. This ref is owned by the finish
|
|
|
|
// callback on the flush call. The finish callback will unref the tracker when called.
|
|
|
|
tracker->ref();
|
2016-09-28 21:53:07 +00:00
|
|
|
|
2020-02-21 20:46:27 +00:00
|
|
|
fCurrentFlushIdx = (fCurrentFlushIdx + 1) % SK_ARRAY_COUNT(fFinishTrackers);
|
|
|
|
return tracker;
|
2016-09-28 21:53:07 +00:00
|
|
|
}
|