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" |
mtklein | 281b33f | 2016-07-12 15:01:26 -0700 | [diff] [blame] | 11 | |
Mike Klein | cb79393 | 2017-02-27 09:39:38 -0500 | [diff] [blame] | 12 | static const int N = 15; |
mtklein | 281b33f | 2016-07-12 15:01:26 -0700 | [diff] [blame] | 13 | |
Mike Klein | afb48b6 | 2016-10-03 15:14:04 -0400 | [diff] [blame] | 14 | static uint64_t dst[N]; // sRGB or F16 |
| 15 | static uint32_t src[N]; // sRGB |
| 16 | static uint8_t mask[N]; // 8-bit linear |
mtklein | 281b33f | 2016-07-12 15:01:26 -0700 | [diff] [blame] | 17 | |
| 18 | // We'll build up a somewhat realistic useful pipeline: |
| 19 | // - load srgb src |
| 20 | // - scale src by 8-bit mask |
Mike Klein | afb48b6 | 2016-10-03 15:14:04 -0400 | [diff] [blame] | 21 | // - load srgb/f16 dst |
mtklein | 281b33f | 2016-07-12 15:01:26 -0700 | [diff] [blame] | 22 | // - src = srcover(dst, src) |
Mike Klein | afb48b6 | 2016-10-03 15:14:04 -0400 | [diff] [blame] | 23 | // - store src back as srgb/f16 |
mtklein | 281b33f | 2016-07-12 15:01:26 -0700 | [diff] [blame] | 24 | |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 25 | template <bool kF16> |
mtklein | 281b33f | 2016-07-12 15:01:26 -0700 | [diff] [blame] | 26 | class SkRasterPipelineBench : public Benchmark { |
| 27 | public: |
mtklein | 281b33f | 2016-07-12 15:01:26 -0700 | [diff] [blame] | 28 | bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; } |
Mike Klein | afb48b6 | 2016-10-03 15:14:04 -0400 | [diff] [blame] | 29 | const char* onGetName() override { |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 30 | switch ((int)kF16) { |
| 31 | case 0: return "SkRasterPipeline_srgb"; |
| 32 | case 1: return "SkRasterPipeline_f16"; |
Mike Klein | a2d25ec | 2017-01-05 15:03:53 -0500 | [diff] [blame] | 33 | } |
| 34 | return "whoops"; |
Mike Klein | afb48b6 | 2016-10-03 15:14:04 -0400 | [diff] [blame] | 35 | } |
mtklein | 281b33f | 2016-07-12 15:01:26 -0700 | [diff] [blame] | 36 | |
| 37 | void onDraw(int loops, SkCanvas*) override { |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 38 | void* mask_ctx = mask; |
| 39 | void* src_ctx = src; |
| 40 | void* dst_ctx = dst; |
| 41 | |
Mike Klein | e9f74b8 | 2016-10-25 13:31:21 -0400 | [diff] [blame] | 42 | SkRasterPipeline p; |
Mike Klein | 729b582 | 2016-11-28 18:23:23 -0500 | [diff] [blame] | 43 | p.append(SkRasterPipeline::load_8888, &src_ctx); |
Mike Klein | d37d5d9 | 2016-12-14 13:38:24 +0000 | [diff] [blame] | 44 | p.append_from_srgb(kUnpremul_SkAlphaType); |
Mike Klein | bd3fe47 | 2016-10-25 15:43:46 -0400 | [diff] [blame] | 45 | p.append(SkRasterPipeline::scale_u8, &mask_ctx); |
Mike Klein | 8c8cb5b | 2017-01-06 10:21:56 -0500 | [diff] [blame] | 46 | p.append(SkRasterPipeline::move_src_dst); |
Mike Klein | e03339a | 2016-11-28 13:24:27 -0500 | [diff] [blame] | 47 | if (kF16) { |
Mike Klein | 8c8cb5b | 2017-01-06 10:21:56 -0500 | [diff] [blame] | 48 | p.append(SkRasterPipeline::load_f16, &dst_ctx); |
Mike Klein | e03339a | 2016-11-28 13:24:27 -0500 | [diff] [blame] | 49 | } else { |
Mike Klein | 8c8cb5b | 2017-01-06 10:21:56 -0500 | [diff] [blame] | 50 | p.append(SkRasterPipeline::load_8888, &dst_ctx); |
| 51 | p.append_from_srgb(kPremul_SkAlphaType); |
Mike Klein | e03339a | 2016-11-28 13:24:27 -0500 | [diff] [blame] | 52 | } |
Mike Klein | 8c8cb5b | 2017-01-06 10:21:56 -0500 | [diff] [blame] | 53 | p.append(SkRasterPipeline::dstover); |
Mike Klein | e03339a | 2016-11-28 13:24:27 -0500 | [diff] [blame] | 54 | if (kF16) { |
| 55 | p.append(SkRasterPipeline::store_f16, &dst_ctx); |
| 56 | } else { |
| 57 | p.append(SkRasterPipeline::to_srgb); |
| 58 | p.append(SkRasterPipeline::store_8888, &dst_ctx); |
| 59 | } |
Mike Klein | e9f74b8 | 2016-10-25 13:31:21 -0400 | [diff] [blame] | 60 | |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 61 | while (loops --> 0) { |
| 62 | p.run(0,N); |
mtklein | 281b33f | 2016-07-12 15:01:26 -0700 | [diff] [blame] | 63 | } |
| 64 | } |
| 65 | }; |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 66 | DEF_BENCH( return (new SkRasterPipelineBench< true>); ) |
| 67 | DEF_BENCH( return (new SkRasterPipelineBench<false>); ) |
Mike Klein | f768856 | 2017-01-17 10:24:15 -0500 | [diff] [blame] | 68 | |
Mike Klein | f768856 | 2017-01-17 10:24:15 -0500 | [diff] [blame] | 69 | class SkRasterPipelineLegacyBench : public Benchmark { |
| 70 | public: |
| 71 | bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; } |
| 72 | const char* onGetName() override { |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 73 | return "SkRasterPipeline_legacy"; |
Mike Klein | f768856 | 2017-01-17 10:24:15 -0500 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | void onDraw(int loops, SkCanvas*) override { |
| 77 | void* src_ctx = src; |
| 78 | void* dst_ctx = dst; |
| 79 | |
| 80 | SkRasterPipeline p; |
| 81 | p.append(SkRasterPipeline::load_8888, &dst_ctx); |
| 82 | p.append(SkRasterPipeline::move_src_dst); |
| 83 | p.append(SkRasterPipeline::load_8888, &src_ctx); |
| 84 | p.append(SkRasterPipeline::srcover); |
| 85 | p.append(SkRasterPipeline::store_8888, &dst_ctx); |
| 86 | |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 87 | while (loops --> 0) { |
| 88 | p.run(0,N); |
Mike Klein | f768856 | 2017-01-17 10:24:15 -0500 | [diff] [blame] | 89 | } |
| 90 | } |
| 91 | }; |
Mike Klein | 8729e5b | 2017-02-16 06:51:48 -0500 | [diff] [blame] | 92 | DEF_BENCH( return (new SkRasterPipelineLegacyBench); ) |