2014-08-01 14:46:52 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2014 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 "bench/SKPBench.h"
|
|
|
|
#include "include/core/SkSurface.h"
|
2020-07-06 17:45:34 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2022-04-07 15:20:24 +00:00
|
|
|
#include "src/gpu/ganesh/GrDirectContextPriv.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tools/flags/CommandLineFlags.h"
|
2014-10-21 19:29:25 +00:00
|
|
|
|
2015-10-26 20:45:29 +00:00
|
|
|
|
2015-06-16 17:41:27 +00:00
|
|
|
// These CPU tile sizes are not good per se, but they are similar to what Chrome uses.
|
2019-03-21 16:42:21 +00:00
|
|
|
static DEFINE_int(CPUbenchTileW, 256, "Tile width used for CPU SKP playback.");
|
|
|
|
static DEFINE_int(CPUbenchTileH, 256, "Tile height used for CPU SKP playback.");
|
2015-06-16 17:41:27 +00:00
|
|
|
|
2019-03-21 16:42:21 +00:00
|
|
|
static DEFINE_int(GPUbenchTileW, 1600, "Tile width used for GPU SKP playback.");
|
|
|
|
static DEFINE_int(GPUbenchTileH, 512, "Tile height used for GPU SKP playback.");
|
2014-08-01 14:46:52 +00:00
|
|
|
|
2014-11-21 14:19:36 +00:00
|
|
|
SKPBench::SKPBench(const char* name, const SkPicture* pic, const SkIRect& clip, SkScalar scale,
|
2020-08-27 14:54:36 +00:00
|
|
|
bool doLooping)
|
2014-08-01 14:46:52 +00:00
|
|
|
: fPic(SkRef(pic))
|
|
|
|
, fClip(clip)
|
2014-09-10 19:05:59 +00:00
|
|
|
, fScale(scale)
|
2014-11-21 14:19:36 +00:00
|
|
|
, fName(name)
|
2015-06-25 17:51:56 +00:00
|
|
|
, fDoLooping(doLooping) {
|
2015-01-26 14:47:55 +00:00
|
|
|
fUniqueName.printf("%s_%.2g", name, scale); // Scale makes this unqiue for perf.skia.org traces.
|
2014-11-21 14:19:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
SKPBench::~SKPBench() {
|
|
|
|
for (int i = 0; i < fSurfaces.count(); ++i) {
|
|
|
|
fSurfaces[i]->unref();
|
|
|
|
}
|
2014-08-01 14:46:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const char* SKPBench::onGetName() {
|
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2014-09-10 19:05:59 +00:00
|
|
|
const char* SKPBench::onGetUniqueName() {
|
|
|
|
return fUniqueName.c_str();
|
|
|
|
}
|
|
|
|
|
2014-11-21 14:19:36 +00:00
|
|
|
void SKPBench::onPerCanvasPreDraw(SkCanvas* canvas) {
|
2017-01-23 16:39:45 +00:00
|
|
|
SkIRect bounds = canvas->getDeviceClipBounds();
|
2021-04-27 05:09:31 +00:00
|
|
|
bounds.intersect(fClip);
|
|
|
|
bounds.intersect(fPic->cullRect().roundOut());
|
2017-01-23 16:39:45 +00:00
|
|
|
SkAssertResult(!bounds.isEmpty());
|
2014-11-21 14:19:36 +00:00
|
|
|
|
2020-07-06 17:45:34 +00:00
|
|
|
const bool gpu = canvas->recordingContext() != nullptr;
|
2015-06-16 17:41:27 +00:00
|
|
|
int tileW = gpu ? FLAGS_GPUbenchTileW : FLAGS_CPUbenchTileW,
|
|
|
|
tileH = gpu ? FLAGS_GPUbenchTileH : FLAGS_CPUbenchTileH;
|
|
|
|
|
2020-02-07 15:36:46 +00:00
|
|
|
tileW = std::min(tileW, bounds.width());
|
|
|
|
tileH = std::min(tileH, bounds.height());
|
2015-03-05 21:42:27 +00:00
|
|
|
|
|
|
|
int xTiles = SkScalarCeilToInt(bounds.width() / SkIntToScalar(tileW));
|
|
|
|
int yTiles = SkScalarCeilToInt(bounds.height() / SkIntToScalar(tileH));
|
2014-11-21 14:19:36 +00:00
|
|
|
|
2020-10-14 20:57:41 +00:00
|
|
|
fSurfaces.reserve_back(xTiles * yTiles);
|
2014-11-21 14:19:36 +00:00
|
|
|
fTileRects.setReserve(xTiles * yTiles);
|
|
|
|
|
2015-03-05 21:42:27 +00:00
|
|
|
SkImageInfo ii = canvas->imageInfo().makeWH(tileW, tileH);
|
2014-11-21 14:19:36 +00:00
|
|
|
|
2015-03-05 21:42:27 +00:00
|
|
|
for (int y = bounds.fTop; y < bounds.fBottom; y += tileH) {
|
|
|
|
for (int x = bounds.fLeft; x < bounds.fRight; x += tileW) {
|
|
|
|
const SkIRect tileRect = SkIRect::MakeXYWH(x, y, tileW, tileH);
|
2014-12-04 16:31:02 +00:00
|
|
|
*fTileRects.append() = tileRect;
|
2018-07-12 17:30:47 +00:00
|
|
|
fSurfaces.emplace_back(canvas->makeSurface(ii));
|
2014-12-04 16:31:02 +00:00
|
|
|
|
|
|
|
// Never want the contents of a tile to include stuff the parent
|
|
|
|
// canvas clips out
|
|
|
|
SkRect clip = SkRect::Make(bounds);
|
|
|
|
clip.offset(-SkIntToScalar(tileRect.fLeft), -SkIntToScalar(tileRect.fTop));
|
2018-07-12 17:30:47 +00:00
|
|
|
fSurfaces.back()->getCanvas()->clipRect(clip);
|
2014-12-04 16:31:02 +00:00
|
|
|
|
2020-12-03 16:21:31 +00:00
|
|
|
fSurfaces.back()->getCanvas()->setMatrix(canvas->getLocalToDevice());
|
2018-07-12 17:30:47 +00:00
|
|
|
fSurfaces.back()->getCanvas()->scale(fScale, fScale);
|
2014-11-21 14:19:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SKPBench::onPerCanvasPostDraw(SkCanvas* canvas) {
|
2020-07-27 18:52:19 +00:00
|
|
|
// Draw the last set of tiles into the main canvas in case we're
|
2014-11-21 14:19:36 +00:00
|
|
|
// saving the images
|
|
|
|
for (int i = 0; i < fTileRects.count(); ++i) {
|
2016-03-17 17:51:11 +00:00
|
|
|
sk_sp<SkImage> image(fSurfaces[i]->makeImageSnapshot());
|
2014-11-21 14:53:00 +00:00
|
|
|
canvas->drawImage(image,
|
2014-11-21 14:19:36 +00:00
|
|
|
SkIntToScalar(fTileRects[i].fLeft), SkIntToScalar(fTileRects[i].fTop));
|
|
|
|
}
|
|
|
|
|
2018-07-12 17:30:47 +00:00
|
|
|
fSurfaces.reset();
|
2014-11-21 14:19:36 +00:00
|
|
|
fTileRects.rewind();
|
|
|
|
}
|
|
|
|
|
2014-08-01 14:46:52 +00:00
|
|
|
bool SKPBench::isSuitableFor(Backend backend) {
|
|
|
|
return backend != kNonRendering_Backend;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkIPoint SKPBench::onGetSize() {
|
|
|
|
return SkIPoint::Make(fClip.width(), fClip.height());
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void SKPBench::onDraw(int loops, SkCanvas* canvas) {
|
2015-06-25 17:51:56 +00:00
|
|
|
SkASSERT(fDoLooping || 1 == loops);
|
2016-02-22 16:08:25 +00:00
|
|
|
while (1) {
|
2020-08-27 14:54:36 +00:00
|
|
|
this->drawPicture();
|
2016-02-22 16:08:25 +00:00
|
|
|
if (0 == --loops) {
|
|
|
|
break;
|
|
|
|
}
|
2020-07-06 17:45:34 +00:00
|
|
|
|
|
|
|
auto direct = canvas->recordingContext() ? canvas->recordingContext()->asDirectContext()
|
|
|
|
: nullptr;
|
2016-12-21 16:14:46 +00:00
|
|
|
// Ensure the GrContext doesn't combine ops across draw loops.
|
2020-07-06 17:45:34 +00:00
|
|
|
if (direct) {
|
|
|
|
direct->flushAndSubmit();
|
2016-02-22 16:08:25 +00:00
|
|
|
}
|
|
|
|
}
|
2014-08-01 14:46:52 +00:00
|
|
|
}
|
2015-04-27 16:16:57 +00:00
|
|
|
|
|
|
|
void SKPBench::drawMPDPicture() {
|
2019-11-15 15:39:50 +00:00
|
|
|
// TODO: remove me
|
2015-04-27 16:16:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SKPBench::drawPicture() {
|
|
|
|
for (int j = 0; j < fTileRects.count(); ++j) {
|
2020-05-21 16:11:27 +00:00
|
|
|
const SkMatrix trans = SkMatrix::Translate(-fTileRects[j].fLeft / fScale,
|
2015-04-27 16:16:57 +00:00
|
|
|
-fTileRects[j].fTop / fScale);
|
2016-11-04 17:02:54 +00:00
|
|
|
fSurfaces[j]->getCanvas()->drawPicture(fPic.get(), &trans, nullptr);
|
2015-04-27 16:16:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int j = 0; j < fTileRects.count(); ++j) {
|
2020-11-20 18:49:37 +00:00
|
|
|
fSurfaces[j]->flush();
|
2015-04-27 16:16:57 +00:00
|
|
|
}
|
|
|
|
}
|
2015-12-02 17:05:37 +00:00
|
|
|
|
2022-04-07 15:20:24 +00:00
|
|
|
#include "src/gpu/ganesh/GrGpu.h"
|
2020-11-20 18:49:37 +00:00
|
|
|
static void draw_pic_for_stats(SkCanvas* canvas,
|
|
|
|
GrDirectContext* dContext,
|
|
|
|
const SkPicture* picture,
|
|
|
|
SkTArray<SkString>* keys,
|
|
|
|
SkTArray<double>* values) {
|
|
|
|
dContext->priv().resetGpuStats();
|
|
|
|
dContext->priv().resetContextStats();
|
2015-12-02 17:05:37 +00:00
|
|
|
canvas->drawPicture(picture);
|
2020-11-20 18:49:37 +00:00
|
|
|
dContext->flush();
|
2015-12-02 17:05:37 +00:00
|
|
|
|
2020-11-20 18:49:37 +00:00
|
|
|
dContext->priv().dumpGpuStatsKeyValuePairs(keys, values);
|
|
|
|
dContext->priv().dumpCacheStatsKeyValuePairs(keys, values);
|
|
|
|
dContext->priv().dumpContextStatsKeyValuePairs(keys, values);
|
2015-12-02 17:05:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void SKPBench::getGpuStats(SkCanvas* canvas, SkTArray<SkString>* keys, SkTArray<double>* values) {
|
|
|
|
// we do a special single draw and then dump the key / value pairs
|
2020-07-06 17:45:34 +00:00
|
|
|
auto direct = canvas->recordingContext() ? canvas->recordingContext()->asDirectContext()
|
|
|
|
: nullptr;
|
|
|
|
if (!direct) {
|
2015-12-02 17:05:37 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO refactor this out if we want to test other subclasses of skpbench
|
2020-07-06 17:45:34 +00:00
|
|
|
direct->flushAndSubmit();
|
|
|
|
direct->freeGpuResources();
|
|
|
|
direct->resetContext();
|
|
|
|
direct->priv().getGpu()->resetShaderCacheForTesting();
|
|
|
|
draw_pic_for_stats(canvas, direct, fPic.get(), keys, values);
|
2015-12-02 17:05:37 +00:00
|
|
|
}
|
2021-04-30 23:16:12 +00:00
|
|
|
|
|
|
|
bool SKPBench::getDMSAAStats(GrRecordingContext* rContext) {
|
|
|
|
if (!rContext || !rContext->asDirectContext()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Clear the current DMSAA stats then do a single tiled draw that resets them to the specific
|
|
|
|
// values for our SKP.
|
|
|
|
rContext->asDirectContext()->flushAndSubmit();
|
|
|
|
rContext->priv().dmsaaStats() = {};
|
|
|
|
this->drawPicture(); // Draw tiled for DMSAA stats.
|
|
|
|
rContext->asDirectContext()->flush();
|
|
|
|
return true;
|
|
|
|
}
|