SkRasterPipelineBench.cpp revision f76885694d4345363cb541170d18040a5c3f01cc
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" 9#include "SkOpts.h" 10#include "SkRasterPipeline.h" 11 12static const int N = 1023; 13 14static uint64_t dst[N]; // sRGB or F16 15static uint32_t src[N]; // sRGB 16static uint8_t mask[N]; // 8-bit linear 17 18// We'll build up a somewhat realistic useful pipeline: 19// - load srgb src 20// - scale src by 8-bit mask 21// - load srgb/f16 dst 22// - src = srcover(dst, src) 23// - store src back as srgb/f16 24 25template <bool kF16, bool kCompiled> 26class SkRasterPipelineBench : public Benchmark { 27public: 28 bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; } 29 const char* onGetName() override { 30 switch ((int)kCompiled << 1 | (int)kF16) { 31 case 0: return "SkRasterPipeline_srgb_run"; 32 case 1: return "SkRasterPipeline_f16_run"; 33 case 2: return "SkRasterPipeline_srgb_compile"; 34 case 3: return "SkRasterPipeline_f16_compile"; 35 } 36 return "whoops"; 37 } 38 39 void onDraw(int loops, SkCanvas*) override { 40 void* mask_ctx = mask; 41 void* src_ctx = src; 42 void* dst_ctx = dst; 43 44 SkRasterPipeline p; 45 p.append(SkRasterPipeline::load_8888, &src_ctx); 46 p.append_from_srgb(kUnpremul_SkAlphaType); 47 p.append(SkRasterPipeline::scale_u8, &mask_ctx); 48 p.append(SkRasterPipeline::move_src_dst); 49 if (kF16) { 50 p.append(SkRasterPipeline::load_f16, &dst_ctx); 51 } else { 52 p.append(SkRasterPipeline::load_8888, &dst_ctx); 53 p.append_from_srgb(kPremul_SkAlphaType); 54 } 55 p.append(SkRasterPipeline::dstover); 56 if (kF16) { 57 p.append(SkRasterPipeline::store_f16, &dst_ctx); 58 } else { 59 p.append(SkRasterPipeline::to_srgb); 60 p.append(SkRasterPipeline::store_8888, &dst_ctx); 61 } 62 63 if (kCompiled) { 64 auto compiled = p.compile(); 65 while (loops --> 0) { 66 compiled(0,0, N); 67 } 68 } else { 69 while (loops --> 0) { 70 p.run(0,0, N); 71 } 72 } 73 } 74}; 75DEF_BENCH( return (new SkRasterPipelineBench< true, true>); ) 76DEF_BENCH( return (new SkRasterPipelineBench<false, true>); ) 77DEF_BENCH( return (new SkRasterPipelineBench< true, false>); ) 78DEF_BENCH( return (new SkRasterPipelineBench<false, false>); ) 79 80template <bool kCompiled> 81class SkRasterPipelineLegacyBench : public Benchmark { 82public: 83 bool isSuitableFor(Backend backend) override { return backend == kNonRendering_Backend; } 84 const char* onGetName() override { 85 return kCompiled ? "SkRasterPipeline_legacy_compile" 86 : "SkRasterPipeline_legacy_run"; 87 } 88 89 void onDraw(int loops, SkCanvas*) override { 90 void* src_ctx = src; 91 void* dst_ctx = dst; 92 93 SkRasterPipeline p; 94 p.append(SkRasterPipeline::load_8888, &dst_ctx); 95 p.append(SkRasterPipeline::move_src_dst); 96 p.append(SkRasterPipeline::load_8888, &src_ctx); 97 p.append(SkRasterPipeline::srcover); 98 p.append(SkRasterPipeline::store_8888, &dst_ctx); 99 100 if (kCompiled) { 101 auto compiled = p.compile(); 102 while (loops --> 0) { 103 compiled(0,0, N); 104 } 105 } else { 106 while (loops --> 0) { 107 p.run(0,0, N); 108 } 109 } 110 } 111}; 112DEF_BENCH( return (new SkRasterPipelineLegacyBench< true>); ) 113DEF_BENCH( return (new SkRasterPipelineLegacyBench<false>); ) 114