blob: 32af36916417e4201284bc4ab2027811101a75e0 [file] [log] [blame]
Mike Klein68c50d02019-05-29 12:57:54 -05001/*
2 * Copyright 2019 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#include "bench/Benchmark.h"
9#include "src/core/SkOpts.h"
10#include "src/core/SkVM.h"
Mike Klein7b7077c2019-06-03 17:10:59 -050011#include "tools/SkVMBuilders.h"
Mike Klein68c50d02019-05-29 12:57:54 -050012
Mike Klein68c50d02019-05-29 12:57:54 -050013namespace {
14
Mike Klein45d9cc82020-04-13 13:26:45 -050015 enum Mode {Opts, RP, F32, I32_Naive};
16 static const char* kMode_name[] = { "Opts", "RP","F32", "I32_Naive" };
Mike Klein68c50d02019-05-29 12:57:54 -050017
Mike Klein68c50d02019-05-29 12:57:54 -050018}
19
20class SkVMBench : public Benchmark {
21public:
22 SkVMBench(int pixels, Mode mode)
23 : fPixels(pixels)
24 , fMode(mode)
25 , fName(SkStringPrintf("SkVM_%d_%s", pixels, kMode_name[mode]))
26 {}
27
28private:
29 const char* onGetName() override { return fName.c_str(); }
30 bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
31
32 void onDelayedSetup() override {
33 this->setUnits(fPixels);
34 fSrc.resize(fPixels, 0x7f123456); // Arbitrary non-opaque non-transparent value.
35 fDst.resize(fPixels, 0xff987654); // Arbitrary value.
36
Mike Klein397fc882019-06-20 11:37:10 -050037 if (fMode == F32 ) { fProgram = SrcoverBuilder_F32 {}.done(); }
38 if (fMode == I32_Naive) { fProgram = SrcoverBuilder_I32_Naive{}.done(); }
Mike Klein68c50d02019-05-29 12:57:54 -050039
40 if (fMode == RP) {
41 fSrcCtx = { fSrc.data(), 0 };
42 fDstCtx = { fDst.data(), 0 };
43 fPipeline.append(SkRasterPipeline::load_8888 , &fSrcCtx);
44 fPipeline.append(SkRasterPipeline::load_8888_dst, &fDstCtx);
45 fPipeline.append(SkRasterPipeline::srcover);
46 fPipeline.append(SkRasterPipeline::store_8888, &fDstCtx);
47 }
Mike Klein03ce6752019-06-03 14:53:15 -050048
49 // Trigger one run now so we can do a quick correctness check.
50 this->draw(1,nullptr);
51 for (int i = 0; i < fPixels; i++) {
Mike Klein244ba552019-06-21 11:21:35 -050052 SkASSERTF(fDst[i] == 0xff5e6f80, "Want 0xff5e6f80, got %08x", fDst[i]);
Mike Klein03ce6752019-06-03 14:53:15 -050053 }
Mike Klein68c50d02019-05-29 12:57:54 -050054 }
55
56 void onDraw(int loops, SkCanvas*) override {
57 while (loops --> 0) {
58 if (fMode == Opts) {
59 SkOpts::blit_row_s32a_opaque(fDst.data(), fSrc.data(), fPixels, 0xff);
60 } else if (fMode == RP) {
61 fPipeline.run(0,0,fPixels,1);
62 } else {
63 fProgram.eval(fPixels, fSrc.data(), fDst.data());
64 }
65 }
66 }
67
68 int fPixels;
69 Mode fMode;
70 SkString fName;
71 std::vector<uint32_t> fSrc,
72 fDst;
73 skvm::Program fProgram;
74
75 SkRasterPipeline_MemoryCtx fSrcCtx,
76 fDstCtx;
77 SkRasterPipeline_<256> fPipeline;
78};
79
80DEF_BENCH(return (new SkVMBench{ 1, Opts});)
81DEF_BENCH(return (new SkVMBench{ 4, Opts});)
Mike Klein5b5dabc2019-07-12 15:50:09 -050082DEF_BENCH(return (new SkVMBench{ 15, Opts});)
83DEF_BENCH(return (new SkVMBench{ 63, Opts});)
Mike Klein68c50d02019-05-29 12:57:54 -050084DEF_BENCH(return (new SkVMBench{ 256, Opts});)
85DEF_BENCH(return (new SkVMBench{1024, Opts});)
86DEF_BENCH(return (new SkVMBench{4096, Opts});)
87
88DEF_BENCH(return (new SkVMBench{ 1, RP});)
89DEF_BENCH(return (new SkVMBench{ 4, RP});)
Mike Klein5b5dabc2019-07-12 15:50:09 -050090DEF_BENCH(return (new SkVMBench{ 15, RP});)
91DEF_BENCH(return (new SkVMBench{ 63, RP});)
Mike Klein68c50d02019-05-29 12:57:54 -050092DEF_BENCH(return (new SkVMBench{ 256, RP});)
93DEF_BENCH(return (new SkVMBench{1024, RP});)
94DEF_BENCH(return (new SkVMBench{4096, RP});)
95
96DEF_BENCH(return (new SkVMBench{ 1, F32});)
97DEF_BENCH(return (new SkVMBench{ 4, F32});)
Mike Klein5b5dabc2019-07-12 15:50:09 -050098DEF_BENCH(return (new SkVMBench{ 15, F32});)
99DEF_BENCH(return (new SkVMBench{ 63, F32});)
Mike Klein68c50d02019-05-29 12:57:54 -0500100DEF_BENCH(return (new SkVMBench{ 256, F32});)
101DEF_BENCH(return (new SkVMBench{1024, F32});)
102DEF_BENCH(return (new SkVMBench{4096, F32});)
103
Mike Klein397fc882019-06-20 11:37:10 -0500104DEF_BENCH(return (new SkVMBench{ 1, I32_Naive});)
105DEF_BENCH(return (new SkVMBench{ 4, I32_Naive});)
Mike Klein5b5dabc2019-07-12 15:50:09 -0500106DEF_BENCH(return (new SkVMBench{ 15, I32_Naive});)
107DEF_BENCH(return (new SkVMBench{ 63, I32_Naive});)
Mike Klein397fc882019-06-20 11:37:10 -0500108DEF_BENCH(return (new SkVMBench{ 256, I32_Naive});)
109DEF_BENCH(return (new SkVMBench{1024, I32_Naive});)
110DEF_BENCH(return (new SkVMBench{4096, I32_Naive});)
111
Mike Klein8b5cf822019-06-22 08:35:13 -0500112class SkVM_Overhead : public Benchmark {
113public:
Mike Klein1ae6ac82019-06-24 15:00:35 -0400114 explicit SkVM_Overhead(bool rp) : fRP(rp) {}
Mike Klein8b5cf822019-06-22 08:35:13 -0500115
116private:
Mike Klein1ae6ac82019-06-24 15:00:35 -0400117 const char* onGetName() override { return fRP ? "SkVM_Overhead_RP" : "SkVM_Overhead_VM"; }
Mike Klein8b5cf822019-06-22 08:35:13 -0500118 bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
119
120 void onDraw(int loops, SkCanvas*) override {
Mike Klein1ae6ac82019-06-24 15:00:35 -0400121 float dummy;
122 if (fRP) {
123 while (loops --> 0) {
124 SkRasterPipeline_<256> rp;
125 SkRasterPipeline_MemoryCtx src = { &dummy, 0},
126 dst = { &dummy, 0};
127 rp.append_load (SkColorType::kRGBA_F32_SkColorType, &src);
128 rp.append_load_dst(SkColorType::kRGBA_F32_SkColorType, &dst);
129 rp.append (SkRasterPipeline::srcover);
130 rp.append_store (SkColorType::kRGBA_F32_SkColorType, &dst);
131
132 (void)rp.compile();
133 }
134 } else {
135 while (loops --> 0) {
136 skvm::Program program = SrcoverBuilder_F32{}.done();
137 program.eval(0, &dummy, &dummy);
138 }
Mike Klein8b5cf822019-06-22 08:35:13 -0500139 }
140 }
Mike Klein1ae6ac82019-06-24 15:00:35 -0400141
142 bool fRP;
Mike Klein8b5cf822019-06-22 08:35:13 -0500143};
Mike Klein1ae6ac82019-06-24 15:00:35 -0400144DEF_BENCH(return new SkVM_Overhead{ true};)
145DEF_BENCH(return new SkVM_Overhead{false};)