Mike Klein | 68c50d0 | 2019-05-29 12:57:54 -0500 | [diff] [blame] | 1 | /* |
| 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 Klein | 7b7077c | 2019-06-03 17:10:59 -0500 | [diff] [blame] | 11 | #include "tools/SkVMBuilders.h" |
Mike Klein | 68c50d0 | 2019-05-29 12:57:54 -0500 | [diff] [blame] | 12 | |
Mike Klein | 68c50d0 | 2019-05-29 12:57:54 -0500 | [diff] [blame] | 13 | namespace { |
| 14 | |
Mike Klein | 45d9cc8 | 2020-04-13 13:26:45 -0500 | [diff] [blame] | 15 | enum Mode {Opts, RP, F32, I32_Naive}; |
| 16 | static const char* kMode_name[] = { "Opts", "RP","F32", "I32_Naive" }; |
Mike Klein | 68c50d0 | 2019-05-29 12:57:54 -0500 | [diff] [blame] | 17 | |
Mike Klein | 68c50d0 | 2019-05-29 12:57:54 -0500 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | class SkVMBench : public Benchmark { |
| 21 | public: |
| 22 | SkVMBench(int pixels, Mode mode) |
| 23 | : fPixels(pixels) |
| 24 | , fMode(mode) |
| 25 | , fName(SkStringPrintf("SkVM_%d_%s", pixels, kMode_name[mode])) |
| 26 | {} |
| 27 | |
| 28 | private: |
| 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 Klein | 397fc88 | 2019-06-20 11:37:10 -0500 | [diff] [blame] | 37 | if (fMode == F32 ) { fProgram = SrcoverBuilder_F32 {}.done(); } |
| 38 | if (fMode == I32_Naive) { fProgram = SrcoverBuilder_I32_Naive{}.done(); } |
Mike Klein | 68c50d0 | 2019-05-29 12:57:54 -0500 | [diff] [blame] | 39 | |
| 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 Klein | 03ce675 | 2019-06-03 14:53:15 -0500 | [diff] [blame] | 48 | |
| 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 Klein | 244ba55 | 2019-06-21 11:21:35 -0500 | [diff] [blame] | 52 | SkASSERTF(fDst[i] == 0xff5e6f80, "Want 0xff5e6f80, got %08x", fDst[i]); |
Mike Klein | 03ce675 | 2019-06-03 14:53:15 -0500 | [diff] [blame] | 53 | } |
Mike Klein | 68c50d0 | 2019-05-29 12:57:54 -0500 | [diff] [blame] | 54 | } |
| 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 | |
| 80 | DEF_BENCH(return (new SkVMBench{ 1, Opts});) |
| 81 | DEF_BENCH(return (new SkVMBench{ 4, Opts});) |
Mike Klein | 5b5dabc | 2019-07-12 15:50:09 -0500 | [diff] [blame] | 82 | DEF_BENCH(return (new SkVMBench{ 15, Opts});) |
| 83 | DEF_BENCH(return (new SkVMBench{ 63, Opts});) |
Mike Klein | 68c50d0 | 2019-05-29 12:57:54 -0500 | [diff] [blame] | 84 | DEF_BENCH(return (new SkVMBench{ 256, Opts});) |
| 85 | DEF_BENCH(return (new SkVMBench{1024, Opts});) |
| 86 | DEF_BENCH(return (new SkVMBench{4096, Opts});) |
| 87 | |
| 88 | DEF_BENCH(return (new SkVMBench{ 1, RP});) |
| 89 | DEF_BENCH(return (new SkVMBench{ 4, RP});) |
Mike Klein | 5b5dabc | 2019-07-12 15:50:09 -0500 | [diff] [blame] | 90 | DEF_BENCH(return (new SkVMBench{ 15, RP});) |
| 91 | DEF_BENCH(return (new SkVMBench{ 63, RP});) |
Mike Klein | 68c50d0 | 2019-05-29 12:57:54 -0500 | [diff] [blame] | 92 | DEF_BENCH(return (new SkVMBench{ 256, RP});) |
| 93 | DEF_BENCH(return (new SkVMBench{1024, RP});) |
| 94 | DEF_BENCH(return (new SkVMBench{4096, RP});) |
| 95 | |
| 96 | DEF_BENCH(return (new SkVMBench{ 1, F32});) |
| 97 | DEF_BENCH(return (new SkVMBench{ 4, F32});) |
Mike Klein | 5b5dabc | 2019-07-12 15:50:09 -0500 | [diff] [blame] | 98 | DEF_BENCH(return (new SkVMBench{ 15, F32});) |
| 99 | DEF_BENCH(return (new SkVMBench{ 63, F32});) |
Mike Klein | 68c50d0 | 2019-05-29 12:57:54 -0500 | [diff] [blame] | 100 | DEF_BENCH(return (new SkVMBench{ 256, F32});) |
| 101 | DEF_BENCH(return (new SkVMBench{1024, F32});) |
| 102 | DEF_BENCH(return (new SkVMBench{4096, F32});) |
| 103 | |
Mike Klein | 397fc88 | 2019-06-20 11:37:10 -0500 | [diff] [blame] | 104 | DEF_BENCH(return (new SkVMBench{ 1, I32_Naive});) |
| 105 | DEF_BENCH(return (new SkVMBench{ 4, I32_Naive});) |
Mike Klein | 5b5dabc | 2019-07-12 15:50:09 -0500 | [diff] [blame] | 106 | DEF_BENCH(return (new SkVMBench{ 15, I32_Naive});) |
| 107 | DEF_BENCH(return (new SkVMBench{ 63, I32_Naive});) |
Mike Klein | 397fc88 | 2019-06-20 11:37:10 -0500 | [diff] [blame] | 108 | DEF_BENCH(return (new SkVMBench{ 256, I32_Naive});) |
| 109 | DEF_BENCH(return (new SkVMBench{1024, I32_Naive});) |
| 110 | DEF_BENCH(return (new SkVMBench{4096, I32_Naive});) |
| 111 | |
Mike Klein | 8b5cf82 | 2019-06-22 08:35:13 -0500 | [diff] [blame] | 112 | class SkVM_Overhead : public Benchmark { |
| 113 | public: |
Mike Klein | 1ae6ac8 | 2019-06-24 15:00:35 -0400 | [diff] [blame] | 114 | explicit SkVM_Overhead(bool rp) : fRP(rp) {} |
Mike Klein | 8b5cf82 | 2019-06-22 08:35:13 -0500 | [diff] [blame] | 115 | |
| 116 | private: |
Mike Klein | 1ae6ac8 | 2019-06-24 15:00:35 -0400 | [diff] [blame] | 117 | const char* onGetName() override { return fRP ? "SkVM_Overhead_RP" : "SkVM_Overhead_VM"; } |
Mike Klein | 8b5cf82 | 2019-06-22 08:35:13 -0500 | [diff] [blame] | 118 | bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; } |
| 119 | |
| 120 | void onDraw(int loops, SkCanvas*) override { |
Mike Klein | 1ae6ac8 | 2019-06-24 15:00:35 -0400 | [diff] [blame] | 121 | 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 Klein | 8b5cf82 | 2019-06-22 08:35:13 -0500 | [diff] [blame] | 139 | } |
| 140 | } |
Mike Klein | 1ae6ac8 | 2019-06-24 15:00:35 -0400 | [diff] [blame] | 141 | |
| 142 | bool fRP; |
Mike Klein | 8b5cf82 | 2019-06-22 08:35:13 -0500 | [diff] [blame] | 143 | }; |
Mike Klein | 1ae6ac8 | 2019-06-24 15:00:35 -0400 | [diff] [blame] | 144 | DEF_BENCH(return new SkVM_Overhead{ true};) |
| 145 | DEF_BENCH(return new SkVM_Overhead{false};) |