mtklein | 281b33f | 2016-07-12 15:01:26 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016 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 "Benchmark.h" |
Mike Klein | baaf8ad | 2016-09-29 09:04:15 -0400 | [diff] [blame] | 9 | #include "SkOpts.h" |
mtklein | 281b33f | 2016-07-12 15:01:26 -0700 | [diff] [blame] | 10 | #include "SkRasterPipeline.h" |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 11 | #include "../src/jumper/SkJumper.h" |
mtklein | 281b33f | 2016-07-12 15:01:26 -0700 | [diff] [blame] | 12 | |
Mike Klein | cb79393 | 2017-02-27 09:39:38 -0500 | [diff] [blame] | 13 | static const int N = 15; |
mtklein | 281b33f | 2016-07-12 15:01:26 -0700 | [diff] [blame] | 14 | |
Mike Klein | afb48b6 | 2016-10-03 15:14:04 -0400 | [diff] [blame] | 15 | static uint64_t dst[N]; // sRGB or F16 |
| 16 | static uint32_t src[N]; // sRGB |
| 17 | static uint8_t mask[N]; // 8-bit linear |
mtklein | 281b33f | 2016-07-12 15:01:26 -0700 | [diff] [blame] | 18 | |
| 19 | // We'll build up a somewhat realistic useful pipeline: |
| 20 | // - load srgb src |
| 21 | // - scale src by 8-bit mask |
Mike Klein | afb48b6 | 2016-10-03 15:14:04 -0400 | [diff] [blame] | 22 | // - load srgb/f16 dst |
mtklein | 281b33f | 2016-07-12 15:01:26 -0700 | [diff] [blame] | 23 | // - src = srcover(dst, src) |
Mike Klein | afb48b6 | 2016-10-03 15:14:04 -0400 | [diff] [blame] | 24 | // - store src back as srgb/f16 |
mtklein | 281b33f | 2016-07-12 15:01:26 -0700 | [diff] [blame] | 25 | |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 26 | template <bool kF16> |
mtklein | 281b33f | 2016-07-12 15:01:26 -0700 | [diff] [blame] | 27 | class SkRasterPipelineBench : public Benchmark { |
| 28 | public: |
mtklein | 281b33f | 2016-07-12 15:01:26 -0700 | [diff] [blame] | 29 | bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; } |
Mike Klein | afb48b6 | 2016-10-03 15:14:04 -0400 | [diff] [blame] | 30 | const char* onGetName() override { |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 31 | switch ((int)kF16) { |
| 32 | case 0: return "SkRasterPipeline_srgb"; |
| 33 | case 1: return "SkRasterPipeline_f16"; |
Mike Klein | a2d25ec | 2017-01-05 15:03:53 -0500 | [diff] [blame] | 34 | } |
| 35 | return "whoops"; |
Mike Klein | afb48b6 | 2016-10-03 15:14:04 -0400 | [diff] [blame] | 36 | } |
mtklein | 281b33f | 2016-07-12 15:01:26 -0700 | [diff] [blame] | 37 | |
| 38 | void onDraw(int loops, SkCanvas*) override { |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 39 | SkJumper_MemoryCtx mask_ctx = {mask, 0}, |
| 40 | src_ctx = {src, 0}, |
| 41 | dst_ctx = {dst, 0}; |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 42 | |
Mike Klein | b24704d | 2017-05-24 07:53:00 -0400 | [diff] [blame] | 43 | SkRasterPipeline_<256> p; |
Mike Klein | 729b582 | 2016-11-28 18:23:23 -0500 | [diff] [blame] | 44 | p.append(SkRasterPipeline::load_8888, &src_ctx); |
Mike Klein | f1f1162 | 2017-12-18 14:07:31 -0500 | [diff] [blame] | 45 | p.append(SkRasterPipeline::from_srgb); |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 46 | p.append(SkRasterPipeline::scale_u8, &mask_ctx); |
Mike Klein | 8c8cb5b | 2017-01-06 10:21:56 -0500 | [diff] [blame] | 47 | p.append(SkRasterPipeline::move_src_dst); |
Mike Klein | e03339a | 2016-11-28 13:24:27 -0500 | [diff] [blame] | 48 | if (kF16) { |
Mike Klein | 8c8cb5b | 2017-01-06 10:21:56 -0500 | [diff] [blame] | 49 | p.append(SkRasterPipeline::load_f16, &dst_ctx); |
Mike Klein | e03339a | 2016-11-28 13:24:27 -0500 | [diff] [blame] | 50 | } else { |
Mike Klein | 8c8cb5b | 2017-01-06 10:21:56 -0500 | [diff] [blame] | 51 | p.append(SkRasterPipeline::load_8888, &dst_ctx); |
Mike Klein | f1f1162 | 2017-12-18 14:07:31 -0500 | [diff] [blame] | 52 | p.append(SkRasterPipeline::from_srgb); |
Mike Klein | e03339a | 2016-11-28 13:24:27 -0500 | [diff] [blame] | 53 | } |
Mike Klein | 8c8cb5b | 2017-01-06 10:21:56 -0500 | [diff] [blame] | 54 | p.append(SkRasterPipeline::dstover); |
Mike Klein | e03339a | 2016-11-28 13:24:27 -0500 | [diff] [blame] | 55 | if (kF16) { |
| 56 | p.append(SkRasterPipeline::store_f16, &dst_ctx); |
| 57 | } else { |
| 58 | p.append(SkRasterPipeline::to_srgb); |
| 59 | p.append(SkRasterPipeline::store_8888, &dst_ctx); |
| 60 | } |
Mike Klein | e9f74b8 | 2016-10-25 13:31:21 -0400 | [diff] [blame] | 61 | |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 62 | while (loops --> 0) { |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 63 | p.run(0,0,N,1); |
mtklein | 281b33f | 2016-07-12 15:01:26 -0700 | [diff] [blame] | 64 | } |
| 65 | } |
| 66 | }; |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 67 | DEF_BENCH( return (new SkRasterPipelineBench< true>); ) |
| 68 | DEF_BENCH( return (new SkRasterPipelineBench<false>); ) |
Mike Klein | f768856 | 2017-01-17 10:24:15 -0500 | [diff] [blame] | 69 | |
Mike Klein | 0a76b41 | 2017-05-22 12:01:59 -0400 | [diff] [blame] | 70 | class SkRasterPipelineCompileVsRunBench : public Benchmark { |
Mike Klein | f768856 | 2017-01-17 10:24:15 -0500 | [diff] [blame] | 71 | public: |
Mike Klein | 0a76b41 | 2017-05-22 12:01:59 -0400 | [diff] [blame] | 72 | explicit SkRasterPipelineCompileVsRunBench(bool compile) : fCompile(compile) {} |
Mike Klein | f768856 | 2017-01-17 10:24:15 -0500 | [diff] [blame] | 73 | bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; } |
| 74 | const char* onGetName() override { |
Mike Klein | 0a76b41 | 2017-05-22 12:01:59 -0400 | [diff] [blame] | 75 | return fCompile ? "SkRasterPipeline_compile" |
| 76 | : "SkRasterPipeline_run"; |
Mike Klein | f768856 | 2017-01-17 10:24:15 -0500 | [diff] [blame] | 77 | } |
| 78 | |
| 79 | void onDraw(int loops, SkCanvas*) override { |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 80 | SkJumper_MemoryCtx src_ctx = {src, 0}, |
| 81 | dst_ctx = {dst, 0}; |
Mike Klein | f768856 | 2017-01-17 10:24:15 -0500 | [diff] [blame] | 82 | |
Mike Klein | b24704d | 2017-05-24 07:53:00 -0400 | [diff] [blame] | 83 | SkRasterPipeline_<256> p; |
Mike Klein | f768856 | 2017-01-17 10:24:15 -0500 | [diff] [blame] | 84 | p.append(SkRasterPipeline::load_8888, &dst_ctx); |
| 85 | p.append(SkRasterPipeline::move_src_dst); |
| 86 | p.append(SkRasterPipeline::load_8888, &src_ctx); |
| 87 | p.append(SkRasterPipeline::srcover); |
| 88 | p.append(SkRasterPipeline::store_8888, &dst_ctx); |
| 89 | |
Mike Klein | 0a76b41 | 2017-05-22 12:01:59 -0400 | [diff] [blame] | 90 | if (fCompile) { |
Mike Klein | b24704d | 2017-05-24 07:53:00 -0400 | [diff] [blame] | 91 | auto fn = p.compile(); |
Mike Klein | 0a76b41 | 2017-05-22 12:01:59 -0400 | [diff] [blame] | 92 | while (loops --> 0) { |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 93 | fn(0,0,N,1); |
Mike Klein | 0a76b41 | 2017-05-22 12:01:59 -0400 | [diff] [blame] | 94 | } |
| 95 | } else { |
| 96 | while (loops --> 0) { |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 97 | p.run(0,0,N,1); |
Mike Klein | 0a76b41 | 2017-05-22 12:01:59 -0400 | [diff] [blame] | 98 | } |
Mike Klein | f768856 | 2017-01-17 10:24:15 -0500 | [diff] [blame] | 99 | } |
| 100 | } |
Mike Klein | 0a76b41 | 2017-05-22 12:01:59 -0400 | [diff] [blame] | 101 | private: |
| 102 | bool fCompile; |
Mike Klein | f768856 | 2017-01-17 10:24:15 -0500 | [diff] [blame] | 103 | }; |
Mike Klein | 0a76b41 | 2017-05-22 12:01:59 -0400 | [diff] [blame] | 104 | DEF_BENCH( return (new SkRasterPipelineCompileVsRunBench(true )); ) |
| 105 | DEF_BENCH( return (new SkRasterPipelineCompileVsRunBench(false)); ) |
Mike Klein | 795c5b1 | 2017-04-21 12:05:01 -0400 | [diff] [blame] | 106 | |
Mike Klein | c7be003 | 2017-04-25 15:51:23 -0400 | [diff] [blame] | 107 | static SkColorSpaceTransferFn gamma(float g) { |
| 108 | SkColorSpaceTransferFn fn = {0,0,0,0,0,0,0}; |
| 109 | fn.fG = g; |
| 110 | fn.fA = 1; |
| 111 | return fn; |
| 112 | } |
| 113 | |
Mike Klein | 795c5b1 | 2017-04-21 12:05:01 -0400 | [diff] [blame] | 114 | class SkRasterPipeline_2dot2 : public Benchmark { |
| 115 | public: |
Mike Klein | a07e430 | 2017-08-09 13:51:35 -0400 | [diff] [blame] | 116 | SkRasterPipeline_2dot2(bool parametric) : fParametric(parametric) {} |
| 117 | |
Mike Klein | 795c5b1 | 2017-04-21 12:05:01 -0400 | [diff] [blame] | 118 | bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; } |
| 119 | const char* onGetName() override { |
Mike Klein | a07e430 | 2017-08-09 13:51:35 -0400 | [diff] [blame] | 120 | return fParametric ? "SkRasterPipeline_2dot2_parametric" |
| 121 | : "SkRasterPipeline_2dot2_gamma"; |
Mike Klein | 795c5b1 | 2017-04-21 12:05:01 -0400 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | void onDraw(int loops, SkCanvas*) override { |
| 125 | SkColor4f c = { 1.0f, 1.0f, 1.0f, 1.0f }; |
Mike Klein | c7be003 | 2017-04-25 15:51:23 -0400 | [diff] [blame] | 126 | |
| 127 | SkColorSpaceTransferFn from_2dot2 = gamma( 2.2f), |
| 128 | to_2dot2 = gamma(1/2.2f); |
Mike Klein | 16776df | 2017-08-03 10:22:42 -0400 | [diff] [blame] | 129 | SkSTArenaAlloc<256> alloc; |
| 130 | SkRasterPipeline p(&alloc); |
| 131 | p.append_constant_color(&alloc, c); |
Mike Klein | a07e430 | 2017-08-09 13:51:35 -0400 | [diff] [blame] | 132 | if (fParametric) { |
| 133 | p.append(SkRasterPipeline::parametric_r, &from_2dot2); |
| 134 | p.append(SkRasterPipeline::parametric_g, &from_2dot2); |
| 135 | p.append(SkRasterPipeline::parametric_b, &from_2dot2); |
| 136 | p.append(SkRasterPipeline::parametric_r, & to_2dot2); |
| 137 | p.append(SkRasterPipeline::parametric_g, & to_2dot2); |
| 138 | p.append(SkRasterPipeline::parametric_b, & to_2dot2); |
| 139 | } else { |
| 140 | p.append(SkRasterPipeline::gamma, &from_2dot2.fG); |
| 141 | p.append(SkRasterPipeline::gamma, & to_2dot2.fG); |
| 142 | } |
Mike Klein | 795c5b1 | 2017-04-21 12:05:01 -0400 | [diff] [blame] | 143 | |
| 144 | while (loops --> 0) { |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 145 | p.run(0,0,N,1); |
Mike Klein | 795c5b1 | 2017-04-21 12:05:01 -0400 | [diff] [blame] | 146 | } |
| 147 | } |
Mike Klein | a07e430 | 2017-08-09 13:51:35 -0400 | [diff] [blame] | 148 | private: |
| 149 | bool fParametric; |
Mike Klein | 795c5b1 | 2017-04-21 12:05:01 -0400 | [diff] [blame] | 150 | }; |
Mike Klein | a07e430 | 2017-08-09 13:51:35 -0400 | [diff] [blame] | 151 | DEF_BENCH( return (new SkRasterPipeline_2dot2( true)); ) |
| 152 | DEF_BENCH( return (new SkRasterPipeline_2dot2(false)); ) |
Mike Klein | f45e3d7 | 2017-05-15 17:36:59 -0400 | [diff] [blame] | 153 | |
| 154 | class SkRasterPipelineToSRGB : public Benchmark { |
| 155 | public: |
| 156 | bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; } |
| 157 | const char* onGetName() override { |
| 158 | return "SkRasterPipeline_to_srgb"; |
| 159 | } |
| 160 | |
| 161 | void onDraw(int loops, SkCanvas*) override { |
Mike Klein | b24704d | 2017-05-24 07:53:00 -0400 | [diff] [blame] | 162 | SkRasterPipeline_<256> p; |
Mike Klein | f45e3d7 | 2017-05-15 17:36:59 -0400 | [diff] [blame] | 163 | p.append(SkRasterPipeline::to_srgb); |
| 164 | |
| 165 | while (loops --> 0) { |
Mike Klein | 45c16fa | 2017-07-18 18:15:13 -0400 | [diff] [blame] | 166 | p.run(0,0,N,1); |
Mike Klein | f45e3d7 | 2017-05-15 17:36:59 -0400 | [diff] [blame] | 167 | } |
| 168 | } |
| 169 | }; |
| 170 | DEF_BENCH( return (new SkRasterPipelineToSRGB); ) |