2015-03-25 20:43:34 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2015 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/SkColor.h"
|
2022-05-20 20:42:50 +00:00
|
|
|
#include "include/private/SkVx.h"
|
2015-03-03 16:03:27 +00:00
|
|
|
|
2016-02-09 19:03:40 +00:00
|
|
|
// Writing into this array prevents the loops from being compiled away.
|
|
|
|
static volatile float blackhole[4];
|
2015-02-23 18:04:34 +00:00
|
|
|
|
2016-02-07 03:38:39 +00:00
|
|
|
template <typename T>
|
|
|
|
struct Sk4fRoundtripBench : public Benchmark {
|
|
|
|
Sk4fRoundtripBench() {}
|
|
|
|
|
|
|
|
const char* onGetName() override {
|
|
|
|
switch (sizeof(T)) {
|
|
|
|
case 1: return "Sk4f_roundtrip_u8";
|
|
|
|
case 2: return "Sk4f_roundtrip_u16";
|
2016-02-09 19:03:40 +00:00
|
|
|
case 4: return "Sk4f_roundtrip_int";
|
2016-02-07 03:38:39 +00:00
|
|
|
}
|
|
|
|
SkASSERT(false);
|
|
|
|
return "";
|
|
|
|
}
|
2015-02-23 18:04:34 +00:00
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
|
2015-02-23 18:04:34 +00:00
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2022-05-20 20:42:50 +00:00
|
|
|
skvx::float4 fs(1,2,3,4);
|
2016-02-09 19:03:40 +00:00
|
|
|
while (loops --> 0) {
|
2022-05-20 20:42:50 +00:00
|
|
|
fs = skvx::cast<float>(skvx::cast<T>(fs));
|
2015-02-23 18:04:34 +00:00
|
|
|
}
|
2016-02-09 19:03:40 +00:00
|
|
|
fs.store((float*)blackhole);
|
2015-02-23 18:04:34 +00:00
|
|
|
}
|
|
|
|
};
|
2016-02-07 03:38:39 +00:00
|
|
|
DEF_BENCH(return new Sk4fRoundtripBench<uint8_t>;)
|
|
|
|
DEF_BENCH(return new Sk4fRoundtripBench<uint16_t>;)
|
2016-02-09 19:03:40 +00:00
|
|
|
DEF_BENCH(return new Sk4fRoundtripBench<int>;)
|
2015-03-26 01:13:02 +00:00
|
|
|
|
2016-02-09 23:41:36 +00:00
|
|
|
struct Sk4fFloorBench : public Benchmark {
|
|
|
|
Sk4fFloorBench() {}
|
|
|
|
|
|
|
|
const char* onGetName() override { return "Sk4f_floor"; }
|
|
|
|
bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
|
|
|
|
|
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2022-05-20 20:42:50 +00:00
|
|
|
skvx::float4 fs(1,2,3,4);
|
2016-02-09 23:41:36 +00:00
|
|
|
while (loops --> 0) {
|
2022-05-20 20:42:50 +00:00
|
|
|
fs = floor(fs);
|
2016-02-09 23:41:36 +00:00
|
|
|
}
|
|
|
|
fs.store((float*)blackhole);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
DEF_BENCH(return new Sk4fFloorBench;)
|
|
|
|
|
2015-08-31 22:26:08 +00:00
|
|
|
struct Sk4fGradientBench : public Benchmark {
|
|
|
|
const char* onGetName() override { return "Sk4f_gradient"; }
|
2015-03-26 01:13:02 +00:00
|
|
|
bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
|
|
|
|
|
|
|
|
SkPMColor fDevice[100];
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas*) override {
|
2022-05-20 20:42:50 +00:00
|
|
|
skvx::float4 c0(0,0,255,255),
|
|
|
|
c1(255,0,0,255),
|
|
|
|
dc = c1 - c0,
|
|
|
|
fx(0.1f),
|
|
|
|
dx(0.002f),
|
|
|
|
dcdx(dc*dx),
|
|
|
|
dcdx4(dcdx+dcdx+dcdx+dcdx);
|
2015-03-26 01:13:02 +00:00
|
|
|
|
|
|
|
for (int n = 0; n < loops; n++) {
|
2022-05-20 20:42:50 +00:00
|
|
|
auto a = c0 + dc*fx + 0.5f, // add an extra 0.5f to get rounding for free.
|
2015-03-26 01:13:02 +00:00
|
|
|
b = a + dcdx,
|
|
|
|
c = b + dcdx,
|
|
|
|
d = c + dcdx;
|
2022-06-16 20:31:31 +00:00
|
|
|
for (size_t i = 0; i < std::size(fDevice); i += 4) {
|
2022-05-20 20:42:50 +00:00
|
|
|
skvx::cast<uint8_t>(a).store(fDevice + i + 0);
|
|
|
|
skvx::cast<uint8_t>(b).store(fDevice + i + 1);
|
|
|
|
skvx::cast<uint8_t>(c).store(fDevice + i + 2);
|
|
|
|
skvx::cast<uint8_t>(d).store(fDevice + i + 3);
|
2015-06-10 15:57:28 +00:00
|
|
|
a = a + dcdx4;
|
|
|
|
b = b + dcdx4;
|
|
|
|
c = c + dcdx4;
|
|
|
|
d = d + dcdx4;
|
2015-03-26 01:13:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2015-08-31 22:26:08 +00:00
|
|
|
DEF_BENCH(return new Sk4fGradientBench;)
|