2014-06-05 14:18:03 +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.
|
|
|
|
*/
|
|
|
|
|
2020-08-03 17:21:46 +00:00
|
|
|
#include <memory>
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "bench/Benchmark.h"
|
|
|
|
#include "include/core/SkSize.h"
|
|
|
|
#include "include/private/SkTDArray.h"
|
|
|
|
#include "include/utils/SkRandom.h"
|
2014-06-05 14:18:03 +00:00
|
|
|
|
2022-04-20 21:24:55 +00:00
|
|
|
#include "src/gpu/RectanizerPow2.h"
|
|
|
|
#include "src/gpu/RectanizerSkyline.h"
|
|
|
|
|
|
|
|
using namespace skgpu;
|
2014-06-05 14:18:03 +00:00
|
|
|
|
|
|
|
/**
|
2022-04-20 21:24:55 +00:00
|
|
|
* This bench exercises the GPU backend's Rectanizer classes. It exercises the following
|
2014-06-05 14:18:03 +00:00
|
|
|
* rectanizers:
|
|
|
|
* Pow2 Rectanizer
|
|
|
|
* Skyline Rectanizer
|
|
|
|
* in the following cases:
|
|
|
|
* random rects (e.g., pull-save-layers forward use case)
|
|
|
|
* random power of two rects
|
|
|
|
* small constant sized power of 2 rects (e.g., glyph cache use case)
|
|
|
|
*/
|
2014-06-19 19:32:29 +00:00
|
|
|
class RectanizerBench : public Benchmark {
|
2014-06-05 14:18:03 +00:00
|
|
|
public:
|
2021-10-08 22:48:26 +00:00
|
|
|
inline static constexpr int kWidth = 1024;
|
|
|
|
inline static constexpr int kHeight = 1024;
|
2014-06-05 14:18:03 +00:00
|
|
|
|
|
|
|
enum RectanizerType {
|
2020-05-19 17:57:53 +00:00
|
|
|
kPow2_RectanizerType,
|
2014-06-05 14:18:03 +00:00
|
|
|
kSkyline_RectanizerType,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum RectType {
|
|
|
|
kRand_RectType,
|
|
|
|
kRandPow2_RectType,
|
|
|
|
kSmallPow2_RectType
|
|
|
|
};
|
|
|
|
|
2016-03-29 16:03:52 +00:00
|
|
|
RectanizerBench(RectanizerType rectanizerType, RectType rectType)
|
2014-06-05 14:18:03 +00:00
|
|
|
: fName("rectanizer_")
|
2020-05-19 17:57:53 +00:00
|
|
|
, fRectanizerType(rectanizerType)
|
2014-06-05 14:18:03 +00:00
|
|
|
, fRectType(rectType) {
|
|
|
|
|
2020-05-19 17:57:53 +00:00
|
|
|
if (kPow2_RectanizerType == fRectanizerType) {
|
|
|
|
fName.append("pow2_");
|
|
|
|
} else {
|
|
|
|
SkASSERT(kSkyline_RectanizerType == fRectanizerType);
|
|
|
|
fName.append("skyline_");
|
|
|
|
}
|
2014-06-05 14:18:03 +00:00
|
|
|
|
|
|
|
if (kRand_RectType == fRectType) {
|
|
|
|
fName.append("rand");
|
|
|
|
} else if (kRandPow2_RectType == fRectType) {
|
|
|
|
fName.append("rand2");
|
|
|
|
} else {
|
|
|
|
SkASSERT(kSmallPow2_RectType == fRectType);
|
|
|
|
fName.append("sm2");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
bool isSuitableFor(Backend backend) override {
|
2014-06-05 14:18:03 +00:00
|
|
|
return kNonRendering_Backend == backend;
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2014-06-05 14:18:03 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2015-09-30 19:11:07 +00:00
|
|
|
void onDelayedSetup() override {
|
2015-08-27 14:41:13 +00:00
|
|
|
SkASSERT(nullptr == fRectanizer.get());
|
2014-06-05 14:18:03 +00:00
|
|
|
|
2020-05-19 17:57:53 +00:00
|
|
|
if (kPow2_RectanizerType == fRectanizerType) {
|
2022-04-20 21:24:55 +00:00
|
|
|
fRectanizer = std::make_unique<RectanizerPow2>(kWidth, kHeight);
|
2020-05-19 17:57:53 +00:00
|
|
|
} else {
|
|
|
|
SkASSERT(kSkyline_RectanizerType == fRectanizerType);
|
2022-04-20 21:24:55 +00:00
|
|
|
fRectanizer = std::make_unique<RectanizerSkyline>(kWidth, kHeight);
|
2020-05-19 17:57:53 +00:00
|
|
|
}
|
2014-06-05 14:18:03 +00:00
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2014-06-05 14:18:03 +00:00
|
|
|
SkRandom rand;
|
|
|
|
SkIPoint16 loc;
|
|
|
|
SkISize size;
|
|
|
|
|
|
|
|
for (int i = 0; i < loops; ++i) {
|
|
|
|
if (kRand_RectType == fRectType) {
|
|
|
|
size = SkISize::Make(rand.nextRangeU(1, kWidth / 2),
|
|
|
|
rand.nextRangeU(1, kHeight / 2));
|
|
|
|
} else if (kRandPow2_RectType == fRectType) {
|
|
|
|
size = SkISize::Make(GrNextPow2(rand.nextRangeU(1, kWidth / 2)),
|
|
|
|
GrNextPow2(rand.nextRangeU(1, kHeight / 2)));
|
|
|
|
} else {
|
|
|
|
SkASSERT(kSmallPow2_RectType == fRectType);
|
|
|
|
size = SkISize::Make(128, 128);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!fRectanizer->addRect(size.fWidth, size.fHeight, &loc)) {
|
|
|
|
// insert failed so clear out the rectanizer and give the
|
|
|
|
// current rect another try
|
|
|
|
fRectanizer->reset();
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fRectanizer->reset();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
SkString fName;
|
2020-05-19 17:57:53 +00:00
|
|
|
RectanizerType fRectanizerType;
|
2014-06-05 14:18:03 +00:00
|
|
|
RectType fRectType;
|
2022-04-20 21:24:55 +00:00
|
|
|
std::unique_ptr<Rectanizer> fRectanizer;
|
2014-06-05 14:18:03 +00:00
|
|
|
|
2020-09-03 02:42:33 +00:00
|
|
|
using INHERITED = Benchmark;
|
2014-06-05 14:18:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2020-05-19 17:57:53 +00:00
|
|
|
DEF_BENCH(return new RectanizerBench(RectanizerBench::kPow2_RectanizerType,
|
|
|
|
RectanizerBench::kRand_RectType);)
|
|
|
|
DEF_BENCH(return new RectanizerBench(RectanizerBench::kPow2_RectanizerType,
|
|
|
|
RectanizerBench::kRandPow2_RectType);)
|
|
|
|
DEF_BENCH(return new RectanizerBench(RectanizerBench::kPow2_RectanizerType,
|
|
|
|
RectanizerBench::kSmallPow2_RectType);)
|
2014-06-05 14:18:03 +00:00
|
|
|
DEF_BENCH(return new RectanizerBench(RectanizerBench::kSkyline_RectanizerType,
|
|
|
|
RectanizerBench::kRand_RectType);)
|
|
|
|
DEF_BENCH(return new RectanizerBench(RectanizerBench::kSkyline_RectanizerType,
|
|
|
|
RectanizerBench::kRandPow2_RectType);)
|
|
|
|
DEF_BENCH(return new RectanizerBench(RectanizerBench::kSkyline_RectanizerType,
|
|
|
|
RectanizerBench::kSmallPow2_RectType);)
|