2012-12-03 21:19:52 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2012 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/Benchmark.h"
|
|
|
|
#include "include/core/SkMatrix44.h"
|
|
|
|
#include "include/core/SkString.h"
|
2020-01-08 15:40:39 +00:00
|
|
|
#include "include/private/SkM44.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/utils/SkRandom.h"
|
2012-12-03 21:19:52 +00:00
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class Matrix44Bench : public Benchmark {
|
2012-12-03 21:19:52 +00:00
|
|
|
SkString fName;
|
|
|
|
public:
|
2013-10-31 17:28:30 +00:00
|
|
|
Matrix44Bench(const char name[]) {
|
2012-12-03 21:19:52 +00:00
|
|
|
fName.printf("matrix44_%s", name);
|
2013-11-21 06:21:58 +00:00
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool isSuitableFor(Backend backend) override {
|
2013-11-21 06:21:58 +00:00
|
|
|
return backend == kNonRendering_Backend;
|
2012-12-03 21:19:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void performTest() = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual int mulLoopCount() const { return 1; }
|
|
|
|
|
2015-07-13 13:18:39 +00:00
|
|
|
const char* onGetName() override {
|
2012-12-03 21:19:52 +00:00
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; i++) {
|
2012-12-03 21:19:52 +00:00
|
|
|
this->performTest();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2012-12-03 21:19:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class EqualsMatrix44Bench : public Matrix44Bench {
|
|
|
|
public:
|
2013-10-31 17:28:30 +00:00
|
|
|
EqualsMatrix44Bench()
|
|
|
|
: INHERITED("equals")
|
|
|
|
{
|
2012-12-03 21:19:52 +00:00
|
|
|
fM1.set(0, 0, 0);
|
|
|
|
fM2.set(3, 3, 0);
|
|
|
|
}
|
|
|
|
protected:
|
2015-07-13 13:18:39 +00:00
|
|
|
void performTest() override {
|
2012-12-03 21:19:52 +00:00
|
|
|
for (int i = 0; i < 10; ++i) {
|
2013-01-07 16:47:43 +00:00
|
|
|
(void) (fM0 == fM1);
|
|
|
|
(void) (fM1 == fM2);
|
|
|
|
(void) (fM2 == fM0);
|
2012-12-03 21:19:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
SkMatrix44 fM0, fM1, fM2;
|
|
|
|
typedef Matrix44Bench INHERITED;
|
|
|
|
};
|
|
|
|
|
2013-08-28 05:07:26 +00:00
|
|
|
class SetIdentityMatrix44Bench : public Matrix44Bench {
|
|
|
|
public:
|
2013-10-31 17:28:30 +00:00
|
|
|
SetIdentityMatrix44Bench()
|
|
|
|
: INHERITED("setidentity")
|
|
|
|
{
|
2013-08-28 05:07:26 +00:00
|
|
|
double rowMajor[16] =
|
|
|
|
{ 1, 2, 3, 4,
|
|
|
|
5, 6, 7, 8,
|
|
|
|
9, 10, 11, 12,
|
|
|
|
13, 14, 15, 16};
|
|
|
|
mat.setRowMajord(rowMajor);
|
|
|
|
}
|
|
|
|
protected:
|
2015-07-13 13:18:39 +00:00
|
|
|
void performTest() override {
|
2013-08-28 05:07:26 +00:00
|
|
|
for (int i = 0; i < 10; ++i) {
|
|
|
|
mat.setIdentity();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
SkMatrix44 mat;
|
|
|
|
typedef Matrix44Bench INHERITED;
|
|
|
|
};
|
|
|
|
|
2012-12-03 21:19:52 +00:00
|
|
|
class PreScaleMatrix44Bench : public Matrix44Bench {
|
|
|
|
public:
|
2013-10-31 17:28:30 +00:00
|
|
|
PreScaleMatrix44Bench()
|
|
|
|
: INHERITED("prescale")
|
|
|
|
{
|
2012-12-03 21:19:52 +00:00
|
|
|
fX = fY = fZ = SkDoubleToMScalar(1.5);
|
|
|
|
}
|
|
|
|
protected:
|
2015-07-13 13:18:39 +00:00
|
|
|
void performTest() override {
|
2012-12-03 21:19:52 +00:00
|
|
|
fM0.reset();
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
|
|
|
fM0.preScale(fX, fY, fZ);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
SkMatrix44 fM0;
|
|
|
|
SkMScalar fX, fY, fZ;
|
|
|
|
typedef Matrix44Bench INHERITED;
|
|
|
|
};
|
|
|
|
|
2012-12-13 09:55:42 +00:00
|
|
|
class InvertMatrix44Bench : public Matrix44Bench {
|
|
|
|
public:
|
2013-10-31 17:28:30 +00:00
|
|
|
InvertMatrix44Bench()
|
|
|
|
: INHERITED("invert")
|
|
|
|
{
|
2015-06-09 18:47:01 +00:00
|
|
|
fM0.setDouble(0, 0, -1.1);
|
|
|
|
fM0.setDouble(0, 1, 2.1);
|
|
|
|
fM0.setDouble(0, 2, -3.1);
|
|
|
|
fM0.setDouble(0, 3, 4.1);
|
|
|
|
fM0.setDouble(1, 0, 5.1);
|
|
|
|
fM0.setDouble(1, 1, -6.1);
|
|
|
|
fM0.setDouble(1, 2, 7.1);
|
|
|
|
fM0.setDouble(1, 3, 8.1);
|
|
|
|
fM0.setDouble(2, 0, -9.1);
|
|
|
|
fM0.setDouble(2, 1, 10.1);
|
|
|
|
fM0.setDouble(2, 2, 11.1);
|
|
|
|
fM0.setDouble(2, 3, -12.1);
|
|
|
|
fM0.setDouble(3, 0, -13.1);
|
|
|
|
fM0.setDouble(3, 1, 14.1);
|
|
|
|
fM0.setDouble(3, 2, -15.1);
|
|
|
|
fM0.setDouble(3, 3, 16.1);
|
2013-08-20 20:15:24 +00:00
|
|
|
}
|
|
|
|
protected:
|
2015-07-13 13:18:39 +00:00
|
|
|
void performTest() override {
|
2013-08-20 20:15:24 +00:00
|
|
|
for (int i = 0; i < 10; ++i) {
|
|
|
|
fM0.invert(&fM1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
SkMatrix44 fM0, fM1;
|
|
|
|
typedef Matrix44Bench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class InvertAffineMatrix44Bench : public Matrix44Bench {
|
|
|
|
public:
|
2013-10-31 17:28:30 +00:00
|
|
|
InvertAffineMatrix44Bench()
|
|
|
|
: INHERITED("invertaffine")
|
|
|
|
{
|
2015-06-09 18:47:01 +00:00
|
|
|
fM0.setDouble(0, 0, -1.1);
|
|
|
|
fM0.setDouble(0, 1, 2.1);
|
|
|
|
fM0.setDouble(0, 2, -3.1);
|
|
|
|
fM0.setDouble(0, 3, 4.1);
|
|
|
|
fM0.setDouble(1, 0, 5.1);
|
|
|
|
fM0.setDouble(1, 1, -6.1);
|
|
|
|
fM0.setDouble(1, 2, 7.1);
|
|
|
|
fM0.setDouble(1, 3, 8.1);
|
|
|
|
fM0.setDouble(2, 0, -9.1);
|
|
|
|
fM0.setDouble(2, 1, 10.1);
|
|
|
|
fM0.setDouble(2, 2, 11.1);
|
|
|
|
fM0.setDouble(2, 3, -12.1);
|
2013-08-20 20:15:24 +00:00
|
|
|
// bottom row (perspective component) remains (0, 0, 0, 1).
|
|
|
|
}
|
|
|
|
protected:
|
2015-07-13 13:18:39 +00:00
|
|
|
void performTest() override {
|
2013-08-20 20:15:24 +00:00
|
|
|
for (int i = 0; i < 10; ++i) {
|
|
|
|
fM0.invert(&fM1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
SkMatrix44 fM0, fM1;
|
|
|
|
typedef Matrix44Bench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class InvertScaleTranslateMatrix44Bench : public Matrix44Bench {
|
|
|
|
public:
|
2013-10-31 17:28:30 +00:00
|
|
|
InvertScaleTranslateMatrix44Bench()
|
|
|
|
: INHERITED("invertscaletranslate")
|
|
|
|
{
|
2015-06-09 18:47:01 +00:00
|
|
|
fM0.setDouble(0, 0, -1.1);
|
|
|
|
fM0.setDouble(0, 3, 4.1);
|
2013-08-20 20:15:24 +00:00
|
|
|
|
2015-06-09 18:47:01 +00:00
|
|
|
fM0.setDouble(1, 1, -6.1);
|
|
|
|
fM0.setDouble(1, 3, 8.1);
|
2013-08-20 20:15:24 +00:00
|
|
|
|
2015-06-09 18:47:01 +00:00
|
|
|
fM0.setDouble(2, 2, 11.1);
|
|
|
|
fM0.setDouble(2, 3, -12.1);
|
2013-08-20 20:15:24 +00:00
|
|
|
}
|
|
|
|
protected:
|
2015-07-13 13:18:39 +00:00
|
|
|
void performTest() override {
|
2013-08-20 20:15:24 +00:00
|
|
|
for (int i = 0; i < 10; ++i) {
|
|
|
|
fM0.invert(&fM1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
SkMatrix44 fM0, fM1;
|
|
|
|
typedef Matrix44Bench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class InvertTranslateMatrix44Bench : public Matrix44Bench {
|
|
|
|
public:
|
2013-10-31 17:28:30 +00:00
|
|
|
InvertTranslateMatrix44Bench()
|
|
|
|
: INHERITED("inverttranslate")
|
|
|
|
{
|
2015-06-09 18:47:01 +00:00
|
|
|
fM0.setDouble(0, 3, 4.1);
|
|
|
|
fM0.setDouble(1, 3, 8.1);
|
|
|
|
fM0.setDouble(2, 3, -12.1);
|
2012-12-13 09:55:42 +00:00
|
|
|
}
|
|
|
|
protected:
|
2015-07-13 13:18:39 +00:00
|
|
|
void performTest() override {
|
2012-12-13 09:55:42 +00:00
|
|
|
for (int i = 0; i < 10; ++i) {
|
|
|
|
fM0.invert(&fM1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
SkMatrix44 fM0, fM1;
|
|
|
|
typedef Matrix44Bench INHERITED;
|
|
|
|
};
|
|
|
|
|
2012-12-03 21:19:52 +00:00
|
|
|
class PostScaleMatrix44Bench : public Matrix44Bench {
|
|
|
|
public:
|
2013-10-31 17:28:30 +00:00
|
|
|
PostScaleMatrix44Bench()
|
|
|
|
: INHERITED("postscale")
|
|
|
|
{
|
2012-12-03 21:19:52 +00:00
|
|
|
fX = fY = fZ = SkDoubleToMScalar(1.5);
|
|
|
|
}
|
|
|
|
protected:
|
2015-07-13 13:18:39 +00:00
|
|
|
void performTest() override {
|
2012-12-03 21:19:52 +00:00
|
|
|
fM0.reset();
|
|
|
|
for (int i = 0; i < 10; ++i) {
|
|
|
|
fM0.postScale(fX, fY, fZ);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
SkMatrix44 fM0;
|
|
|
|
SkMScalar fX, fY, fZ;
|
|
|
|
typedef Matrix44Bench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class SetConcatMatrix44Bench : public Matrix44Bench {
|
|
|
|
public:
|
2015-06-09 11:44:07 +00:00
|
|
|
// SkMatrix44::setConcat() has a fast path for matrices that are at most scale+translate.
|
|
|
|
SetConcatMatrix44Bench(bool fastPath)
|
|
|
|
: INHERITED(fastPath ? "setconcat_fast" : "setconcat_general")
|
2013-10-31 17:28:30 +00:00
|
|
|
{
|
2015-06-09 11:44:07 +00:00
|
|
|
if (fastPath) {
|
|
|
|
const SkMScalar v = SkDoubleToMScalar(1.5);
|
|
|
|
fM1.setScale(v,v,v);
|
|
|
|
fM2.setTranslate(v,v,v);
|
|
|
|
} else {
|
|
|
|
SkRandom rand;
|
|
|
|
for (int x = 0; x < 4; x++) {
|
|
|
|
for (int y = 0; y < 4; y++) {
|
|
|
|
fM1.setFloat(x,y, rand.nextF());
|
|
|
|
fM2.setFloat(x,y, rand.nextF());
|
|
|
|
}}
|
|
|
|
}
|
2012-12-03 21:19:52 +00:00
|
|
|
}
|
|
|
|
protected:
|
2015-07-13 13:18:39 +00:00
|
|
|
void performTest() override {
|
2012-12-03 21:19:52 +00:00
|
|
|
fM0.reset(); // just to normalize this test with prescale/postscale
|
2015-06-09 16:29:12 +00:00
|
|
|
for (int i = 0; i < 10000; ++i) {
|
2012-12-03 21:19:52 +00:00
|
|
|
fM0.setConcat(fM1, fM2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
SkMatrix44 fM0, fM1, fM2;
|
|
|
|
typedef Matrix44Bench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class GetTypeMatrix44Bench : public Matrix44Bench {
|
|
|
|
public:
|
2013-10-31 17:28:30 +00:00
|
|
|
GetTypeMatrix44Bench()
|
|
|
|
: INHERITED("gettype")
|
|
|
|
{}
|
2012-12-03 21:19:52 +00:00
|
|
|
protected:
|
|
|
|
// Putting random generation of the matrix inside performTest()
|
|
|
|
// would help us avoid anomalous runs, but takes up 25% or
|
|
|
|
// more of the function time.
|
2015-07-13 13:18:39 +00:00
|
|
|
void performTest() override {
|
2012-12-03 21:19:52 +00:00
|
|
|
for (int i = 0; i < 20; ++i) {
|
|
|
|
fMatrix.set(1, 2, 1); // to invalidate the type-cache
|
|
|
|
fMatrix.getType();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
SkMatrix44 fMatrix;
|
|
|
|
typedef Matrix44Bench INHERITED;
|
|
|
|
};
|
|
|
|
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new SetIdentityMatrix44Bench(); )
|
|
|
|
DEF_BENCH( return new EqualsMatrix44Bench(); )
|
|
|
|
DEF_BENCH( return new PreScaleMatrix44Bench(); )
|
|
|
|
DEF_BENCH( return new PostScaleMatrix44Bench(); )
|
|
|
|
DEF_BENCH( return new InvertMatrix44Bench(); )
|
|
|
|
DEF_BENCH( return new InvertAffineMatrix44Bench(); )
|
|
|
|
DEF_BENCH( return new InvertScaleTranslateMatrix44Bench(); )
|
|
|
|
DEF_BENCH( return new InvertTranslateMatrix44Bench(); )
|
2015-06-09 11:44:07 +00:00
|
|
|
DEF_BENCH( return new SetConcatMatrix44Bench(true); )
|
|
|
|
DEF_BENCH( return new SetConcatMatrix44Bench(false); )
|
2013-09-13 19:52:27 +00:00
|
|
|
DEF_BENCH( return new GetTypeMatrix44Bench(); )
|
2020-01-08 15:40:39 +00:00
|
|
|
|
|
|
|
/////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
class M4Bench : public Benchmark {
|
|
|
|
SkString fName;
|
|
|
|
public:
|
|
|
|
M4Bench(const char name[]) {
|
|
|
|
fName.printf("m4_%s", name);
|
|
|
|
|
|
|
|
SkRandom rand;
|
|
|
|
float value[32];
|
|
|
|
for (auto& v : value) {
|
|
|
|
v = rand.nextF();
|
|
|
|
}
|
|
|
|
fM1.setColMajor(value + 0);
|
|
|
|
fM2.setColMajor(value + 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isSuitableFor(Backend backend) override {
|
|
|
|
return backend == kNonRendering_Backend;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void performTest() = 0;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
SkM44 fM0, fM1, fM2;
|
|
|
|
|
|
|
|
virtual int mulLoopCount() const { return 1; }
|
|
|
|
|
|
|
|
const char* onGetName() override {
|
|
|
|
return fName.c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
|
|
|
for (int i = 0; i < loops; i++) {
|
|
|
|
this->performTest();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
typedef Benchmark INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class M4NEQ : public M4Bench {
|
|
|
|
public:
|
|
|
|
M4NEQ() : INHERITED("neq") {}
|
|
|
|
protected:
|
|
|
|
void performTest() override {
|
|
|
|
for (int i = 0; i < 10000; ++i) {
|
|
|
|
fEQ = (fM2 == fM1); // should always be false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
bool fEQ;
|
|
|
|
typedef M4Bench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class M4EQ : public M4Bench {
|
|
|
|
public:
|
|
|
|
M4EQ() : INHERITED("eq") {}
|
|
|
|
protected:
|
|
|
|
void performTest() override {
|
|
|
|
fM2 = fM1;
|
|
|
|
for (int i = 0; i < 10000; ++i) {
|
|
|
|
fEQ = (fM2 == fM1); // should always be true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
bool fEQ;
|
|
|
|
typedef M4Bench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class M4Concat : public M4Bench {
|
|
|
|
public:
|
|
|
|
M4Concat() : INHERITED("op_concat") {}
|
|
|
|
protected:
|
|
|
|
void performTest() override {
|
|
|
|
for (int i = 0; i < 10000; ++i) {
|
|
|
|
fM0 = SkM44(fM1, fM2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
typedef M4Bench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
class M4SetConcat : public M4Bench {
|
|
|
|
public:
|
|
|
|
M4SetConcat() : INHERITED("set_concat") {}
|
|
|
|
protected:
|
|
|
|
void performTest() override {
|
|
|
|
for (int i = 0; i < 10000; ++i) {
|
|
|
|
fM0.setConcat(fM1, fM2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
typedef M4Bench INHERITED;
|
|
|
|
};
|
|
|
|
|
|
|
|
DEF_BENCH( return new M4EQ(); )
|
|
|
|
DEF_BENCH( return new M4NEQ(); )
|
|
|
|
DEF_BENCH( return new M4Concat(); )
|
|
|
|
DEF_BENCH( return new M4SetConcat(); )
|