blob: 5ddf43dd21969571a85ab4a6ea4978db3022b4bc [file] [log] [blame]
mtklein281b33f2016-07-12 15:01:26 -07001/*
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 Kleinbaaf8ad2016-09-29 09:04:15 -04009#include "SkOpts.h"
mtklein281b33f2016-07-12 15:01:26 -070010#include "SkRasterPipeline.h"
Mike Klein45c16fa2017-07-18 18:15:13 -040011#include "../src/jumper/SkJumper.h"
mtklein281b33f2016-07-12 15:01:26 -070012
Mike Kleincb793932017-02-27 09:39:38 -050013static const int N = 15;
mtklein281b33f2016-07-12 15:01:26 -070014
Mike Kleinafb48b62016-10-03 15:14:04 -040015static uint64_t dst[N]; // sRGB or F16
16static uint32_t src[N]; // sRGB
17static uint8_t mask[N]; // 8-bit linear
mtklein281b33f2016-07-12 15:01:26 -070018
19// We'll build up a somewhat realistic useful pipeline:
20// - load srgb src
21// - scale src by 8-bit mask
Mike Kleinafb48b62016-10-03 15:14:04 -040022// - load srgb/f16 dst
mtklein281b33f2016-07-12 15:01:26 -070023// - src = srcover(dst, src)
Mike Kleinafb48b62016-10-03 15:14:04 -040024// - store src back as srgb/f16
mtklein281b33f2016-07-12 15:01:26 -070025
Mike Klein8729e5b2017-02-16 06:51:48 -050026template <bool kF16>
mtklein281b33f2016-07-12 15:01:26 -070027class SkRasterPipelineBench : public Benchmark {
28public:
mtklein281b33f2016-07-12 15:01:26 -070029 bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
Mike Kleinafb48b62016-10-03 15:14:04 -040030 const char* onGetName() override {
Mike Klein8729e5b2017-02-16 06:51:48 -050031 switch ((int)kF16) {
32 case 0: return "SkRasterPipeline_srgb";
33 case 1: return "SkRasterPipeline_f16";
Mike Kleina2d25ec2017-01-05 15:03:53 -050034 }
35 return "whoops";
Mike Kleinafb48b62016-10-03 15:14:04 -040036 }
mtklein281b33f2016-07-12 15:01:26 -070037
38 void onDraw(int loops, SkCanvas*) override {
Mike Klein45c16fa2017-07-18 18:15:13 -040039 SkJumper_MemoryCtx mask_ctx = {mask, 0},
40 src_ctx = {src, 0},
41 dst_ctx = {dst, 0};
Mike Kleinbd3fe472016-10-25 15:43:46 -040042
Mike Kleinb24704d2017-05-24 07:53:00 -040043 SkRasterPipeline_<256> p;
Mike Klein729b5822016-11-28 18:23:23 -050044 p.append(SkRasterPipeline::load_8888, &src_ctx);
Mike Kleinf1f11622017-12-18 14:07:31 -050045 p.append(SkRasterPipeline::from_srgb);
Mike Kleinbd3fe472016-10-25 15:43:46 -040046 p.append(SkRasterPipeline::scale_u8, &mask_ctx);
Mike Klein8c8cb5b2017-01-06 10:21:56 -050047 p.append(SkRasterPipeline::move_src_dst);
Mike Kleine03339a2016-11-28 13:24:27 -050048 if (kF16) {
Mike Klein8c8cb5b2017-01-06 10:21:56 -050049 p.append(SkRasterPipeline::load_f16, &dst_ctx);
Mike Kleine03339a2016-11-28 13:24:27 -050050 } else {
Mike Klein8c8cb5b2017-01-06 10:21:56 -050051 p.append(SkRasterPipeline::load_8888, &dst_ctx);
Mike Kleinf1f11622017-12-18 14:07:31 -050052 p.append(SkRasterPipeline::from_srgb);
Mike Kleine03339a2016-11-28 13:24:27 -050053 }
Mike Klein8c8cb5b2017-01-06 10:21:56 -050054 p.append(SkRasterPipeline::dstover);
Mike Kleine03339a2016-11-28 13:24:27 -050055 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 Kleine9f74b82016-10-25 13:31:21 -040061
Mike Klein8729e5b2017-02-16 06:51:48 -050062 while (loops --> 0) {
Mike Klein45c16fa2017-07-18 18:15:13 -040063 p.run(0,0,N,1);
mtklein281b33f2016-07-12 15:01:26 -070064 }
65 }
66};
Mike Klein8729e5b2017-02-16 06:51:48 -050067DEF_BENCH( return (new SkRasterPipelineBench< true>); )
68DEF_BENCH( return (new SkRasterPipelineBench<false>); )
Mike Kleinf7688562017-01-17 10:24:15 -050069
Mike Klein0a76b412017-05-22 12:01:59 -040070class SkRasterPipelineCompileVsRunBench : public Benchmark {
Mike Kleinf7688562017-01-17 10:24:15 -050071public:
Mike Klein0a76b412017-05-22 12:01:59 -040072 explicit SkRasterPipelineCompileVsRunBench(bool compile) : fCompile(compile) {}
Mike Kleinf7688562017-01-17 10:24:15 -050073 bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
74 const char* onGetName() override {
Mike Klein0a76b412017-05-22 12:01:59 -040075 return fCompile ? "SkRasterPipeline_compile"
76 : "SkRasterPipeline_run";
Mike Kleinf7688562017-01-17 10:24:15 -050077 }
78
79 void onDraw(int loops, SkCanvas*) override {
Mike Klein45c16fa2017-07-18 18:15:13 -040080 SkJumper_MemoryCtx src_ctx = {src, 0},
81 dst_ctx = {dst, 0};
Mike Kleinf7688562017-01-17 10:24:15 -050082
Mike Kleinb24704d2017-05-24 07:53:00 -040083 SkRasterPipeline_<256> p;
Mike Kleinf7688562017-01-17 10:24:15 -050084 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 Klein0a76b412017-05-22 12:01:59 -040090 if (fCompile) {
Mike Kleinb24704d2017-05-24 07:53:00 -040091 auto fn = p.compile();
Mike Klein0a76b412017-05-22 12:01:59 -040092 while (loops --> 0) {
Mike Klein45c16fa2017-07-18 18:15:13 -040093 fn(0,0,N,1);
Mike Klein0a76b412017-05-22 12:01:59 -040094 }
95 } else {
96 while (loops --> 0) {
Mike Klein45c16fa2017-07-18 18:15:13 -040097 p.run(0,0,N,1);
Mike Klein0a76b412017-05-22 12:01:59 -040098 }
Mike Kleinf7688562017-01-17 10:24:15 -050099 }
100 }
Mike Klein0a76b412017-05-22 12:01:59 -0400101private:
102 bool fCompile;
Mike Kleinf7688562017-01-17 10:24:15 -0500103};
Mike Klein0a76b412017-05-22 12:01:59 -0400104DEF_BENCH( return (new SkRasterPipelineCompileVsRunBench(true )); )
105DEF_BENCH( return (new SkRasterPipelineCompileVsRunBench(false)); )
Mike Klein795c5b12017-04-21 12:05:01 -0400106
Mike Kleinc7be0032017-04-25 15:51:23 -0400107static 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 Klein795c5b12017-04-21 12:05:01 -0400114class SkRasterPipeline_2dot2 : public Benchmark {
115public:
Mike Kleina07e4302017-08-09 13:51:35 -0400116 SkRasterPipeline_2dot2(bool parametric) : fParametric(parametric) {}
117
Mike Klein795c5b12017-04-21 12:05:01 -0400118 bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; }
119 const char* onGetName() override {
Mike Kleina07e4302017-08-09 13:51:35 -0400120 return fParametric ? "SkRasterPipeline_2dot2_parametric"
121 : "SkRasterPipeline_2dot2_gamma";
Mike Klein795c5b12017-04-21 12:05:01 -0400122 }
123
124 void onDraw(int loops, SkCanvas*) override {
125 SkColor4f c = { 1.0f, 1.0f, 1.0f, 1.0f };
Mike Kleinc7be0032017-04-25 15:51:23 -0400126
127 SkColorSpaceTransferFn from_2dot2 = gamma( 2.2f),
128 to_2dot2 = gamma(1/2.2f);
Mike Klein16776df2017-08-03 10:22:42 -0400129 SkSTArenaAlloc<256> alloc;
130 SkRasterPipeline p(&alloc);
131 p.append_constant_color(&alloc, c);
Mike Kleina07e4302017-08-09 13:51:35 -0400132 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 Klein795c5b12017-04-21 12:05:01 -0400143
144 while (loops --> 0) {
Mike Klein45c16fa2017-07-18 18:15:13 -0400145 p.run(0,0,N,1);
Mike Klein795c5b12017-04-21 12:05:01 -0400146 }
147 }
Mike Kleina07e4302017-08-09 13:51:35 -0400148private:
149 bool fParametric;
Mike Klein795c5b12017-04-21 12:05:01 -0400150};
Mike Kleina07e4302017-08-09 13:51:35 -0400151DEF_BENCH( return (new SkRasterPipeline_2dot2( true)); )
152DEF_BENCH( return (new SkRasterPipeline_2dot2(false)); )
Mike Kleinf45e3d72017-05-15 17:36:59 -0400153
154class SkRasterPipelineToSRGB : public Benchmark {
155public:
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 Kleinb24704d2017-05-24 07:53:00 -0400162 SkRasterPipeline_<256> p;
Mike Kleinf45e3d72017-05-15 17:36:59 -0400163 p.append(SkRasterPipeline::to_srgb);
164
165 while (loops --> 0) {
Mike Klein45c16fa2017-07-18 18:15:13 -0400166 p.run(0,0,N,1);
Mike Kleinf45e3d72017-05-15 17:36:59 -0400167 }
168 }
169};
170DEF_BENCH( return (new SkRasterPipelineToSRGB); )