Ethan Nicholas | 40679c3 | 2019-05-31 17:06:53 -0400 | [diff] [blame] | 1 | /* |
Ethan Nicholas | fc99416 | 2019-06-06 10:04:27 -0400 | [diff] [blame] | 2 | * Copyright 2019 Google LLC |
Ethan Nicholas | 40679c3 | 2019-05-31 17:06:53 -0400 | [diff] [blame] | 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 | #include "bench/Benchmark.h" |
Brian Osman | 68870aa | 2020-07-08 14:12:43 -0400 | [diff] [blame] | 8 | #include "bench/ResultsWriter.h" |
| 9 | #include "bench/SkSLBench.h" |
Ethan Nicholas | ba9a04f | 2020-11-06 09:28:04 -0500 | [diff] [blame] | 10 | #include "include/core/SkCanvas.h" |
| 11 | #include "src/gpu/GrCaps.h" |
| 12 | #include "src/gpu/GrRecordingContextPriv.h" |
| 13 | #include "src/gpu/mock/GrMockCaps.h" |
Ethan Nicholas | 40679c3 | 2019-05-31 17:06:53 -0400 | [diff] [blame] | 14 | #include "src/sksl/SkSLCompiler.h" |
Ethan Nicholas | dd2fdea | 2021-07-20 15:23:04 -0400 | [diff] [blame] | 15 | #include "src/sksl/SkSLDSLParser.h" |
Ethan Nicholas | ba9a04f | 2020-11-06 09:28:04 -0500 | [diff] [blame] | 16 | #include "src/sksl/SkSLIRGenerator.h" |
| 17 | #include "src/sksl/SkSLParser.h" |
Ethan Nicholas | 40679c3 | 2019-05-31 17:06:53 -0400 | [diff] [blame] | 18 | |
Brian Osman | 24c5d24 | 2020-09-29 15:08:55 -0400 | [diff] [blame] | 19 | class SkSLCompilerStartupBench : public Benchmark { |
| 20 | protected: |
| 21 | const char* onGetName() override { |
| 22 | return "sksl_compiler_startup"; |
| 23 | } |
| 24 | |
| 25 | bool isSuitableFor(Backend backend) override { |
| 26 | return backend == kNonRendering_Backend; |
| 27 | } |
| 28 | |
| 29 | void onDraw(int loops, SkCanvas*) override { |
Brian Osman | 0006ad0 | 2020-11-18 15:38:39 -0500 | [diff] [blame] | 30 | GrShaderCaps caps(GrContextOptions{}); |
Brian Osman | 24c5d24 | 2020-09-29 15:08:55 -0400 | [diff] [blame] | 31 | for (int i = 0; i < loops; i++) { |
Brian Osman | 0006ad0 | 2020-11-18 15:38:39 -0500 | [diff] [blame] | 32 | SkSL::Compiler compiler(&caps); |
Brian Osman | 24c5d24 | 2020-09-29 15:08:55 -0400 | [diff] [blame] | 33 | } |
| 34 | } |
| 35 | }; |
| 36 | |
| 37 | DEF_BENCH(return new SkSLCompilerStartupBench();) |
| 38 | |
Ethan Nicholas | ba9a04f | 2020-11-06 09:28:04 -0500 | [diff] [blame] | 39 | enum class Output { |
| 40 | kNone, |
| 41 | kGLSL, |
| 42 | kMetal, |
| 43 | kSPIRV |
| 44 | }; |
| 45 | |
| 46 | class SkSLCompileBench : public Benchmark { |
Ethan Nicholas | 40679c3 | 2019-05-31 17:06:53 -0400 | [diff] [blame] | 47 | public: |
Ethan Nicholas | ba9a04f | 2020-11-06 09:28:04 -0500 | [diff] [blame] | 48 | static const char* output_string(Output output) { |
| 49 | switch (output) { |
| 50 | case Output::kNone: return ""; |
| 51 | case Output::kGLSL: return "glsl_"; |
| 52 | case Output::kMetal: return "metal_"; |
| 53 | case Output::kSPIRV: return "spirv_"; |
| 54 | } |
| 55 | SkUNREACHABLE; |
| 56 | } |
| 57 | |
| 58 | SkSLCompileBench(SkSL::String name, const char* src, bool optimize, Output output) |
| 59 | : fName(SkSL::String("sksl_") + (optimize ? "" : "unoptimized_") + output_string(output) + |
| 60 | name) |
| 61 | , fSrc(src) |
| 62 | , fCaps(GrContextOptions(), GrMockOptions()) |
| 63 | , fCompiler(fCaps.shaderCaps()) |
| 64 | , fOutput(output) { |
| 65 | fSettings.fOptimize = optimize; |
Ethan Nicholas | dd2fdea | 2021-07-20 15:23:04 -0400 | [diff] [blame] | 66 | fSettings.fDSLMangling = false; |
Ethan Nicholas | ba9a04f | 2020-11-06 09:28:04 -0500 | [diff] [blame] | 67 | // The test programs we compile don't follow Vulkan rules and thus produce invalid |
| 68 | // SPIR-V. This is harmless, so long as we don't try to validate them. |
| 69 | fSettings.fValidateSPIRV = false; |
| 70 | } |
| 71 | |
| 72 | protected: |
| 73 | const char* onGetName() override { |
| 74 | return fName.c_str(); |
| 75 | } |
| 76 | |
| 77 | bool isSuitableFor(Backend backend) override { |
| 78 | return backend == kNonRendering_Backend; |
| 79 | } |
| 80 | |
| 81 | void onDraw(int loops, SkCanvas* canvas) override { |
| 82 | for (int i = 0; i < loops; i++) { |
Ethan Nicholas | dd2fdea | 2021-07-20 15:23:04 -0400 | [diff] [blame] | 83 | #if SKSL_DSL_PARSER |
| 84 | std::unique_ptr<SkSL::Program> program = SkSL::DSLParser(&fCompiler, |
| 85 | fSettings, |
| 86 | SkSL::ProgramKind::kFragment, |
| 87 | fSrc).program(); |
| 88 | #else |
Ethan Nicholas | ba9a04f | 2020-11-06 09:28:04 -0500 | [diff] [blame] | 89 | std::unique_ptr<SkSL::Program> program = fCompiler.convertProgram( |
John Stiles | dbd4e6f | 2021-02-16 13:29:15 -0500 | [diff] [blame] | 90 | SkSL::ProgramKind::kFragment, |
Ethan Nicholas | ba9a04f | 2020-11-06 09:28:04 -0500 | [diff] [blame] | 91 | fSrc, |
| 92 | fSettings); |
Ethan Nicholas | dd2fdea | 2021-07-20 15:23:04 -0400 | [diff] [blame] | 93 | #endif // SKSL_DSL_PARSER |
Ethan Nicholas | ba9a04f | 2020-11-06 09:28:04 -0500 | [diff] [blame] | 94 | if (fCompiler.errorCount()) { |
| 95 | SK_ABORT("shader compilation failed: %s\n", fCompiler.errorText().c_str()); |
| 96 | } |
| 97 | SkSL::String result; |
| 98 | switch (fOutput) { |
| 99 | case Output::kNone: break; |
| 100 | case Output::kGLSL: SkAssertResult(fCompiler.toGLSL(*program, &result)); break; |
| 101 | case Output::kMetal: SkAssertResult(fCompiler.toMetal(*program, &result)); break; |
| 102 | case Output::kSPIRV: SkAssertResult(fCompiler.toSPIRV(*program, &result)); break; |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | private: |
| 108 | SkSL::String fName; |
| 109 | SkSL::String fSrc; |
| 110 | GrMockCaps fCaps; |
| 111 | SkSL::Compiler fCompiler; |
| 112 | SkSL::Program::Settings fSettings; |
| 113 | Output fOutput; |
| 114 | |
| 115 | using INHERITED = Benchmark; |
| 116 | }; |
| 117 | |
| 118 | class SkSLParseBench : public Benchmark { |
| 119 | public: |
| 120 | SkSLParseBench(SkSL::String name, const char* src) |
| 121 | : fName("sksl_parse_" + name) |
Brian Osman | d7e7659 | 2020-11-02 12:26:22 -0500 | [diff] [blame] | 122 | , fSrc(src) |
Brian Osman | 0006ad0 | 2020-11-18 15:38:39 -0500 | [diff] [blame] | 123 | , fCaps(GrContextOptions()) |
| 124 | , fCompiler(&fCaps) {} |
Ethan Nicholas | 40679c3 | 2019-05-31 17:06:53 -0400 | [diff] [blame] | 125 | |
| 126 | protected: |
| 127 | const char* onGetName() override { |
| 128 | return fName.c_str(); |
| 129 | } |
| 130 | |
| 131 | bool isSuitableFor(Backend backend) override { |
| 132 | return backend == kNonRendering_Backend; |
| 133 | } |
| 134 | |
Ethan Nicholas | ba9a04f | 2020-11-06 09:28:04 -0500 | [diff] [blame] | 135 | void onDelayedSetup() override { |
John Stiles | dbd4e6f | 2021-02-16 13:29:15 -0500 | [diff] [blame] | 136 | SkSL::ParsedModule module = fCompiler.moduleForProgramKind(SkSL::ProgramKind::kFragment); |
Ethan Nicholas | ba9a04f | 2020-11-06 09:28:04 -0500 | [diff] [blame] | 137 | fCompiler.irGenerator().setSymbolTable(module.fSymbols); |
| 138 | } |
| 139 | |
Ethan Nicholas | 40679c3 | 2019-05-31 17:06:53 -0400 | [diff] [blame] | 140 | void onDraw(int loops, SkCanvas*) override { |
| 141 | for (int i = 0; i < loops; i++) { |
Ethan Nicholas | ba9a04f | 2020-11-06 09:28:04 -0500 | [diff] [blame] | 142 | fCompiler.irGenerator().pushSymbolTable(); |
Ethan Nicholas | 4a5e22a | 2021-08-13 17:29:51 -0400 | [diff] [blame] | 143 | SkSL::Parser parser(fSrc, *fCompiler.irGenerator().symbolTable(), |
| 144 | fCompiler.errorReporter()); |
Ethan Nicholas | ba9a04f | 2020-11-06 09:28:04 -0500 | [diff] [blame] | 145 | parser.compilationUnit(); |
| 146 | fCompiler.irGenerator().popSymbolTable(); |
Ethan Nicholas | 34b19c5 | 2020-09-14 11:33:47 -0400 | [diff] [blame] | 147 | if (fCompiler.errorCount()) { |
Ethan Nicholas | ba9a04f | 2020-11-06 09:28:04 -0500 | [diff] [blame] | 148 | SK_ABORT("shader compilation failed: %s\n", fCompiler.errorText().c_str()); |
Ethan Nicholas | 40679c3 | 2019-05-31 17:06:53 -0400 | [diff] [blame] | 149 | } |
| 150 | } |
| 151 | } |
| 152 | |
| 153 | private: |
| 154 | SkSL::String fName; |
| 155 | SkSL::String fSrc; |
Brian Osman | 0006ad0 | 2020-11-18 15:38:39 -0500 | [diff] [blame] | 156 | GrShaderCaps fCaps; |
Ethan Nicholas | 40679c3 | 2019-05-31 17:06:53 -0400 | [diff] [blame] | 157 | SkSL::Compiler fCompiler; |
Ethan Nicholas | 40679c3 | 2019-05-31 17:06:53 -0400 | [diff] [blame] | 158 | |
John Stiles | 7571f9e | 2020-09-02 22:42:33 -0400 | [diff] [blame] | 159 | using INHERITED = Benchmark; |
Ethan Nicholas | 40679c3 | 2019-05-31 17:06:53 -0400 | [diff] [blame] | 160 | }; |
| 161 | |
| 162 | /////////////////////////////////////////////////////////////////////////////// |
| 163 | |
Ethan Nicholas | ba9a04f | 2020-11-06 09:28:04 -0500 | [diff] [blame] | 164 | #define COMPILER_BENCH(name, text) \ |
| 165 | static constexpr char name ## _SRC[] = text; \ |
| 166 | DEF_BENCH(return new SkSLParseBench(#name, name ## _SRC);) \ |
| 167 | DEF_BENCH(return new SkSLCompileBench(#name, name ## _SRC, /*optimize=*/false, Output::kNone);) \ |
| 168 | DEF_BENCH(return new SkSLCompileBench(#name, name ## _SRC, /*optimize=*/true, Output::kNone);) \ |
| 169 | DEF_BENCH(return new SkSLCompileBench(#name, name ## _SRC, /*optimize=*/true, Output::kGLSL);) \ |
| 170 | DEF_BENCH(return new SkSLCompileBench(#name, name ## _SRC, /*optimize=*/true, Output::kMetal);) \ |
| 171 | DEF_BENCH(return new SkSLCompileBench(#name, name ## _SRC, /*optimize=*/true, Output::kSPIRV);) |
| 172 | |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 173 | // This fragment shader is from the third tile on the top row of GM_gradients_2pt_conical_outside. |
Ethan Nicholas | ba9a04f | 2020-11-06 09:28:04 -0500 | [diff] [blame] | 174 | COMPILER_BENCH(large, R"( |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 175 | layout(set=0, binding=0) uniform half urange_Stage1_c0; |
| 176 | layout(set=0, binding=0) uniform half4 uleftBorderColor_Stage1_c0_c0_c0; |
| 177 | layout(set=0, binding=0) uniform half4 urightBorderColor_Stage1_c0_c0_c0; |
| 178 | layout(set=0, binding=0) uniform float3x3 umatrix_Stage1_c0_c0_c0_c0; |
| 179 | layout(set=0, binding=0) uniform half2 ufocalParams_Stage1_c0_c0_c0_c0_c0; |
| 180 | layout(set=0, binding=0) uniform float4 uscale0_1_Stage1_c0_c0_c0_c1; |
| 181 | layout(set=0, binding=0) uniform float4 uscale2_3_Stage1_c0_c0_c0_c1; |
| 182 | layout(set=0, binding=0) uniform float4 uscale4_5_Stage1_c0_c0_c0_c1; |
| 183 | layout(set=0, binding=0) uniform float4 uscale6_7_Stage1_c0_c0_c0_c1; |
| 184 | layout(set=0, binding=0) uniform float4 ubias0_1_Stage1_c0_c0_c0_c1; |
| 185 | layout(set=0, binding=0) uniform float4 ubias2_3_Stage1_c0_c0_c0_c1; |
| 186 | layout(set=0, binding=0) uniform float4 ubias4_5_Stage1_c0_c0_c0_c1; |
| 187 | layout(set=0, binding=0) uniform float4 ubias6_7_Stage1_c0_c0_c0_c1; |
| 188 | layout(set=0, binding=0) uniform half4 uthresholds1_7_Stage1_c0_c0_c0_c1; |
| 189 | layout(set=0, binding=0) uniform half4 uthresholds9_13_Stage1_c0_c0_c0_c1; |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 190 | flat in half4 vcolor_Stage0; |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 191 | noperspective in float2 vTransformedCoords_0_Stage0; |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 192 | out half4 sk_FragColor; |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 193 | half4 TwoPointConicalGradientLayout_Stage1_c0_c0_c0_c0_c0(half4 _input) |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 194 | { |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 195 | float t = -1.0; |
| 196 | half v = 1.0; |
| 197 | @switch (2) |
| 198 | { |
| 199 | case 1: |
| 200 | { |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 201 | half r0_2 = ufocalParams_Stage1_c0_c0_c0_c0_c0.y; |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 202 | t = float(r0_2) - vTransformedCoords_0_Stage0.y * vTransformedCoords_0_Stage0.y; |
| 203 | if (t >= 0.0) |
| 204 | { |
| 205 | t = vTransformedCoords_0_Stage0.x + sqrt(t); |
| 206 | } |
| 207 | else |
| 208 | { |
| 209 | v = -1.0; |
| 210 | } |
| 211 | } |
| 212 | break; |
| 213 | case 0: |
| 214 | { |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 215 | half r0 = ufocalParams_Stage1_c0_c0_c0_c0_c0.x; |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 216 | @if (true) |
| 217 | { |
| 218 | t = length(vTransformedCoords_0_Stage0) - float(r0); |
| 219 | } |
| 220 | else |
| 221 | { |
| 222 | t = -length(vTransformedCoords_0_Stage0) - float(r0); |
| 223 | } |
| 224 | } |
| 225 | break; |
| 226 | case 2: |
| 227 | { |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 228 | half invR1 = ufocalParams_Stage1_c0_c0_c0_c0_c0.x; |
| 229 | half fx = ufocalParams_Stage1_c0_c0_c0_c0_c0.y; |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 230 | float x_t = -1.0; |
| 231 | @if (false) |
| 232 | { |
| 233 | x_t = dot(vTransformedCoords_0_Stage0, vTransformedCoords_0_Stage0) / vTransformedCoords_0_Stage0.x; |
| 234 | } |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 235 | else if (false) |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 236 | { |
| 237 | x_t = length(vTransformedCoords_0_Stage0) - vTransformedCoords_0_Stage0.x * float(invR1); |
| 238 | } |
| 239 | else |
| 240 | { |
| 241 | float temp = vTransformedCoords_0_Stage0.x * vTransformedCoords_0_Stage0.x - vTransformedCoords_0_Stage0.y * vTransformedCoords_0_Stage0.y; |
| 242 | if (temp >= 0.0) |
| 243 | { |
| 244 | @if (false || !true) |
| 245 | { |
| 246 | x_t = -sqrt(temp) - vTransformedCoords_0_Stage0.x * float(invR1); |
| 247 | } |
| 248 | else |
| 249 | { |
| 250 | x_t = sqrt(temp) - vTransformedCoords_0_Stage0.x * float(invR1); |
| 251 | } |
| 252 | } |
| 253 | } |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 254 | @if (!false) |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 255 | { |
| 256 | if (x_t <= 0.0) |
| 257 | { |
| 258 | v = -1.0; |
| 259 | } |
| 260 | } |
| 261 | @if (true) |
| 262 | { |
| 263 | @if (false) |
| 264 | { |
| 265 | t = x_t; |
| 266 | } |
| 267 | else |
| 268 | { |
| 269 | t = x_t + float(fx); |
| 270 | } |
| 271 | } |
| 272 | else |
| 273 | { |
| 274 | @if (false) |
| 275 | { |
| 276 | t = -x_t; |
| 277 | } |
| 278 | else |
| 279 | { |
| 280 | t = -x_t + float(fx); |
| 281 | } |
| 282 | } |
| 283 | @if (false) |
| 284 | { |
| 285 | t = 1.0 - t; |
| 286 | } |
| 287 | } |
| 288 | break; |
| 289 | } |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 290 | return half4(half(t), v, 0.0, 0.0); |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 291 | } |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 292 | half4 MatrixEffect_Stage1_c0_c0_c0_c0(half4 _input) |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 293 | { |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 294 | return TwoPointConicalGradientLayout_Stage1_c0_c0_c0_c0_c0(_input); |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 295 | } |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 296 | half4 UnrolledBinaryGradientColorizer_Stage1_c0_c0_c0_c1(half4 _input, float2 _coords) |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 297 | { |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 298 | half t = half(_coords.x); |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 299 | float4 scale; |
| 300 | float4 bias; |
| 301 | if (4 <= 4 || t < uthresholds1_7_Stage1_c0_c0_c0_c1.w) |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 302 | { |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 303 | if (4 <= 2 || t < uthresholds1_7_Stage1_c0_c0_c0_c1.y) |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 304 | { |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 305 | if (4 <= 1 || t < uthresholds1_7_Stage1_c0_c0_c0_c1.x) |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 306 | { |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 307 | scale = uscale0_1_Stage1_c0_c0_c0_c1; |
| 308 | bias = ubias0_1_Stage1_c0_c0_c0_c1; |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 309 | } |
| 310 | else |
| 311 | { |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 312 | scale = uscale2_3_Stage1_c0_c0_c0_c1; |
| 313 | bias = ubias2_3_Stage1_c0_c0_c0_c1; |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 314 | } |
| 315 | } |
| 316 | else |
| 317 | { |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 318 | if (4 <= 3 || t < uthresholds1_7_Stage1_c0_c0_c0_c1.z) |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 319 | { |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 320 | scale = uscale4_5_Stage1_c0_c0_c0_c1; |
| 321 | bias = ubias4_5_Stage1_c0_c0_c0_c1; |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 322 | } |
| 323 | else |
| 324 | { |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 325 | scale = uscale6_7_Stage1_c0_c0_c0_c1; |
| 326 | bias = ubias6_7_Stage1_c0_c0_c0_c1; |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 327 | } |
| 328 | } |
| 329 | } |
| 330 | else |
| 331 | { |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 332 | if (4 <= 6 || t < uthresholds9_13_Stage1_c0_c0_c0_c1.y) |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 333 | { |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 334 | if (4 <= 5 || t < uthresholds9_13_Stage1_c0_c0_c0_c1.x) |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 335 | { |
| 336 | scale = float4(0); |
| 337 | bias = float4(0); |
| 338 | } |
| 339 | else |
| 340 | { |
| 341 | scale = float4(0); |
| 342 | bias = float4(0); |
| 343 | } |
| 344 | } |
| 345 | else |
| 346 | { |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 347 | if (4 <= 7 || t < uthresholds9_13_Stage1_c0_c0_c0_c1.z) |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 348 | { |
| 349 | scale = float4(0); |
| 350 | bias = float4(0); |
| 351 | } |
| 352 | else |
| 353 | { |
| 354 | scale = float4(0); |
| 355 | bias = float4(0); |
| 356 | } |
| 357 | } |
| 358 | } |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 359 | return half4(float(t) * scale + bias); |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 360 | } |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 361 | half4 ClampedGradientEffect_Stage1_c0_c0_c0(half4 _input) |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 362 | { |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 363 | half4 t = MatrixEffect_Stage1_c0_c0_c0_c0(_input); |
| 364 | half4 outColor; |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 365 | if (!false && t.y < 0.0) |
| 366 | { |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 367 | outColor = half4(0.0); |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 368 | } |
| 369 | else if (t.x < 0.0) |
| 370 | { |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 371 | outColor = uleftBorderColor_Stage1_c0_c0_c0; |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 372 | } |
| 373 | else if (t.x > 1.0) |
| 374 | { |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 375 | outColor = urightBorderColor_Stage1_c0_c0_c0; |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 376 | } |
| 377 | else |
| 378 | { |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 379 | outColor = UnrolledBinaryGradientColorizer_Stage1_c0_c0_c0_c1(_input, float2(half2(t.x, 0.0))); |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 380 | } |
| 381 | @if (false) |
| 382 | { |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 383 | outColor.xyz *= outColor.w; |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 384 | } |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 385 | return outColor; |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 386 | } |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 387 | half4 OverrideInputFragmentProcessor_Stage1_c0_c0(half4 _input) |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 388 | { |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 389 | return ClampedGradientEffect_Stage1_c0_c0_c0(false ? half4(0) : half4(1.000000, 1.000000, 1.000000, 1.000000)); |
| 390 | } |
| 391 | half4 DitherEffect_Stage1_c0(half4 _input) |
| 392 | { |
| 393 | half4 color = OverrideInputFragmentProcessor_Stage1_c0_c0(_input); |
| 394 | half value; |
| 395 | @if (sk_Caps.integerSupport) |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 396 | { |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 397 | uint x = uint(sk_FragCoord.x); |
| 398 | uint y = uint(sk_FragCoord.y) ^ x; |
| 399 | uint m = (((((y & 1) << 5 | (x & 1) << 4) | (y & 2) << 2) | (x & 2) << 1) | (y & 4) >> 1) | (x & 4) >> 2; |
| 400 | value = half(m) / 64.0 - 0.4921875; |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 401 | } |
| 402 | else |
| 403 | { |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 404 | half4 bits = mod(half4(sk_FragCoord.yxyx), half4(2.0, 2.0, 4.0, 4.0)); |
| 405 | bits.zw = step(2.0, bits.zw); |
| 406 | bits.xz = abs(bits.xz - bits.yw); |
| 407 | value = dot(bits, half4(0.5, 0.25, 0.125, 0.0625)) - 0.46875; |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 408 | } |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 409 | return half4(clamp(color.xyz + value * urange_Stage1_c0, 0.0, color.w), color.w); |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 410 | } |
| 411 | void main() |
| 412 | { |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 413 | // Stage 0, QuadPerEdgeAAGeometryProcessor |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 414 | half4 outputColor_Stage0; |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 415 | outputColor_Stage0 = vcolor_Stage0; |
| 416 | const half4 outputCoverage_Stage0 = half4(1); |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 417 | half4 output_Stage1; |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 418 | output_Stage1 = DitherEffect_Stage1_c0(outputColor_Stage0); |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 419 | { |
| 420 | // Xfer Processor: Porter Duff |
| 421 | sk_FragColor = output_Stage1 * outputCoverage_Stage0; |
| 422 | } |
| 423 | } |
Ethan Nicholas | ba9a04f | 2020-11-06 09:28:04 -0500 | [diff] [blame] | 424 | )"); |
John Stiles | 7f88b72 | 2020-09-30 09:29:13 -0400 | [diff] [blame] | 425 | |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 426 | // This fragment shader is taken from GM_BlurDrawImage. |
Ethan Nicholas | ba9a04f | 2020-11-06 09:28:04 -0500 | [diff] [blame] | 427 | COMPILER_BENCH(medium, R"( |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 428 | layout(set=0, binding=0) uniform float3x3 umatrix_Stage1_c0_c0_c0; |
| 429 | layout(set=0, binding=0) uniform half4 urectH_Stage2_c1; |
| 430 | layout(set=0, binding=0) uniform float3x3 umatrix_Stage2_c1_c0; |
| 431 | layout(set=0, binding=0) uniform sampler2D uTextureSampler_0_Stage1; |
| 432 | layout(set=0, binding=0) uniform sampler2D uTextureSampler_0_Stage2; |
| 433 | flat in half4 vcolor_Stage0; |
| 434 | noperspective in float2 vTransformedCoords_0_Stage0; |
| 435 | out half4 sk_FragColor; |
| 436 | half4 TextureEffect_Stage1_c0_c0_c0_c0(half4 _input) |
| 437 | { |
| 438 | return sample(uTextureSampler_0_Stage1, vTransformedCoords_0_Stage0); |
| 439 | } |
| 440 | half4 MatrixEffect_Stage1_c0_c0_c0(half4 _input) |
| 441 | { |
| 442 | return TextureEffect_Stage1_c0_c0_c0_c0(_input); |
| 443 | } |
| 444 | half4 Blend_Stage1_c0_c0(half4 _input) |
| 445 | { |
| 446 | // Blend mode: SrcIn (Compose-One behavior) |
| 447 | return blend_src_in(MatrixEffect_Stage1_c0_c0_c0(half4(1)), _input); |
| 448 | } |
| 449 | half4 OverrideInputFragmentProcessor_Stage1_c0(half4 _input) |
| 450 | { |
| 451 | return Blend_Stage1_c0_c0(false ? half4(0) : half4(1.000000, 1.000000, 1.000000, 1.000000)); |
| 452 | } |
| 453 | half4 TextureEffect_Stage2_c1_c0_c0(half4 _input, float2 _coords) |
| 454 | { |
| 455 | return sample(uTextureSampler_0_Stage2, _coords).000r; |
| 456 | } |
| 457 | half4 MatrixEffect_Stage2_c1_c0(half4 _input, float2 _coords) |
| 458 | { |
| 459 | return TextureEffect_Stage2_c1_c0_c0(_input, ((umatrix_Stage2_c1_c0) * _coords.xy1).xy); |
| 460 | } |
| 461 | half4 RectBlurEffect_Stage2_c1(half4 _input) |
| 462 | { |
| 463 | /* key */ const bool highPrecision = false; |
| 464 | half xCoverage; |
| 465 | half yCoverage; |
| 466 | float2 pos = sk_FragCoord.xy; |
| 467 | @if (false) |
| 468 | { |
| 469 | pos = (float3x3(1) * float3(pos, 1.0)).xy; |
Ethan Nicholas | 40679c3 | 2019-05-31 17:06:53 -0400 | [diff] [blame] | 470 | } |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 471 | @if (true) |
| 472 | { |
| 473 | half2 xy; |
| 474 | @if (highPrecision) |
| 475 | { |
| 476 | xy = max(half2(float4(0).xy - pos), half2(pos - float4(0).zw)); |
Ethan Nicholas | 40679c3 | 2019-05-31 17:06:53 -0400 | [diff] [blame] | 477 | } |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 478 | else |
| 479 | { |
| 480 | xy = max(half2(float2(urectH_Stage2_c1.xy) - pos), half2(pos - float2(urectH_Stage2_c1.zw))); |
Ethan Nicholas | 40679c3 | 2019-05-31 17:06:53 -0400 | [diff] [blame] | 481 | } |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 482 | xCoverage = MatrixEffect_Stage2_c1_c0(_input, float2(half2(xy.x, 0.5))).w; |
| 483 | yCoverage = MatrixEffect_Stage2_c1_c0(_input, float2(half2(xy.y, 0.5))).w; |
Ethan Nicholas | 40679c3 | 2019-05-31 17:06:53 -0400 | [diff] [blame] | 484 | } |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 485 | else |
| 486 | { |
| 487 | half4 rect; |
| 488 | @if (highPrecision) |
| 489 | { |
| 490 | rect.xy = half2(float4(0).xy - pos); |
| 491 | rect.zw = half2(pos - float4(0).zw); |
Ethan Nicholas | 40679c3 | 2019-05-31 17:06:53 -0400 | [diff] [blame] | 492 | } |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 493 | else |
| 494 | { |
| 495 | rect.xy = half2(float2(urectH_Stage2_c1.xy) - pos); |
| 496 | rect.zw = half2(pos - float2(urectH_Stage2_c1.zw)); |
Ethan Nicholas | 40679c3 | 2019-05-31 17:06:53 -0400 | [diff] [blame] | 497 | } |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 498 | xCoverage = (1.0 - MatrixEffect_Stage2_c1_c0(_input, float2(half2(rect.x, 0.5))).w) - MatrixEffect_Stage2_c1_c0(_input, float2(half2(rect.z, 0.5))).w; |
| 499 | yCoverage = (1.0 - MatrixEffect_Stage2_c1_c0(_input, float2(half2(rect.y, 0.5))).w) - MatrixEffect_Stage2_c1_c0(_input, float2(half2(rect.w, 0.5))).w; |
Ethan Nicholas | 40679c3 | 2019-05-31 17:06:53 -0400 | [diff] [blame] | 500 | } |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 501 | return (_input * xCoverage) * yCoverage; |
| 502 | } |
| 503 | void main() |
| 504 | { |
| 505 | // Stage 0, QuadPerEdgeAAGeometryProcessor |
| 506 | half4 outputColor_Stage0; |
| 507 | outputColor_Stage0 = vcolor_Stage0; |
| 508 | const half4 outputCoverage_Stage0 = half4(1); |
| 509 | half4 output_Stage1; |
| 510 | output_Stage1 = OverrideInputFragmentProcessor_Stage1_c0(outputColor_Stage0); |
| 511 | half4 output_Stage2; |
| 512 | output_Stage2 = RectBlurEffect_Stage2_c1(outputCoverage_Stage0); |
| 513 | { |
| 514 | // Xfer Processor: Porter Duff |
| 515 | sk_FragColor = output_Stage1 * output_Stage2; |
| 516 | } |
| 517 | } |
Ethan Nicholas | ba9a04f | 2020-11-06 09:28:04 -0500 | [diff] [blame] | 518 | )"); |
Brian Osman | 68870aa | 2020-07-08 14:12:43 -0400 | [diff] [blame] | 519 | |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 520 | // This is the fragment shader used to blit the Viewer window when running the software rasterizer. |
Ethan Nicholas | ba9a04f | 2020-11-06 09:28:04 -0500 | [diff] [blame] | 521 | COMPILER_BENCH(small, R"( |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 522 | layout(set=0, binding=0) uniform float3x3 umatrix_Stage1_c0_c0; |
| 523 | layout(set=0, binding=0) uniform sampler2D uTextureSampler_0_Stage1; |
| 524 | noperspective in float2 vTransformedCoords_0_Stage0; |
| 525 | out half4 sk_FragColor; |
| 526 | half4 TextureEffect_Stage1_c0_c0_c0(half4 _input) |
| 527 | { |
| 528 | return sample(uTextureSampler_0_Stage1, vTransformedCoords_0_Stage0); |
| 529 | } |
| 530 | half4 MatrixEffect_Stage1_c0_c0(half4 _input) |
| 531 | { |
| 532 | return TextureEffect_Stage1_c0_c0_c0(_input); |
| 533 | } |
| 534 | half4 Blend_Stage1_c0(half4 _input) |
| 535 | { |
| 536 | // Blend mode: Modulate (Compose-One behavior) |
| 537 | return blend_modulate(MatrixEffect_Stage1_c0_c0(half4(1)), _input); |
| 538 | } |
| 539 | void main() |
| 540 | { |
| 541 | // Stage 0, QuadPerEdgeAAGeometryProcessor |
| 542 | half4 outputColor_Stage0 = half4(1); |
| 543 | const half4 outputCoverage_Stage0 = half4(1); |
| 544 | half4 output_Stage1; |
| 545 | output_Stage1 = Blend_Stage1_c0(outputColor_Stage0); |
John Stiles | 312535b | 2020-10-23 18:37:29 -0400 | [diff] [blame] | 546 | { |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 547 | // Xfer Processor: Porter Duff |
| 548 | sk_FragColor = output_Stage1 * outputCoverage_Stage0; |
John Stiles | 312535b | 2020-10-23 18:37:29 -0400 | [diff] [blame] | 549 | } |
John Stiles | d2702fa | 2021-03-15 18:04:05 -0400 | [diff] [blame] | 550 | } |
Ethan Nicholas | ba9a04f | 2020-11-06 09:28:04 -0500 | [diff] [blame] | 551 | )"); |
John Stiles | 312535b | 2020-10-23 18:37:29 -0400 | [diff] [blame] | 552 | |
Ethan Nicholas | ba9a04f | 2020-11-06 09:28:04 -0500 | [diff] [blame] | 553 | COMPILER_BENCH(tiny, "void main() { sk_FragColor = half4(1); }"); |
John Stiles | 312535b | 2020-10-23 18:37:29 -0400 | [diff] [blame] | 554 | |
Brian Osman | 24b8a8c | 2020-07-09 10:04:33 -0400 | [diff] [blame] | 555 | #if defined(SK_BUILD_FOR_UNIX) |
| 556 | |
| 557 | #include <malloc.h> |
| 558 | |
Brian Osman | 68870aa | 2020-07-08 14:12:43 -0400 | [diff] [blame] | 559 | // These benchmarks aren't timed, they produce memory usage statistics. They run standalone, and |
| 560 | // directly add their results to the nanobench log. |
| 561 | void RunSkSLMemoryBenchmarks(NanoJSONResultsWriter* log) { |
Brian Osman | 24b8a8c | 2020-07-09 10:04:33 -0400 | [diff] [blame] | 562 | auto heap_bytes_used = []() { return mallinfo().uordblks; }; |
| 563 | auto bench = [log](const char* name, int bytes) { |
Brian Osman | 68870aa | 2020-07-08 14:12:43 -0400 | [diff] [blame] | 564 | log->beginObject(name); // test |
| 565 | log->beginObject("meta"); // config |
Brian Osman | 24b8a8c | 2020-07-09 10:04:33 -0400 | [diff] [blame] | 566 | log->appendS32("bytes", bytes); // sub_result |
Brian Osman | 68870aa | 2020-07-08 14:12:43 -0400 | [diff] [blame] | 567 | log->endObject(); // config |
| 568 | log->endObject(); // test |
| 569 | }; |
| 570 | |
Brian Osman | 5626998 | 2020-11-20 12:38:07 -0500 | [diff] [blame] | 571 | // Heap used by a default compiler (with no modules loaded) |
Brian Osman | 68870aa | 2020-07-08 14:12:43 -0400 | [diff] [blame] | 572 | { |
Brian Osman | 24b8a8c | 2020-07-09 10:04:33 -0400 | [diff] [blame] | 573 | int before = heap_bytes_used(); |
Brian Osman | 0006ad0 | 2020-11-18 15:38:39 -0500 | [diff] [blame] | 574 | GrShaderCaps caps(GrContextOptions{}); |
| 575 | SkSL::Compiler compiler(&caps); |
Brian Osman | 24b8a8c | 2020-07-09 10:04:33 -0400 | [diff] [blame] | 576 | int after = heap_bytes_used(); |
| 577 | bench("sksl_compiler_baseline", after - before); |
Brian Osman | 68870aa | 2020-07-08 14:12:43 -0400 | [diff] [blame] | 578 | } |
Brian Osman | 5626998 | 2020-11-20 12:38:07 -0500 | [diff] [blame] | 579 | |
| 580 | // Heap used by a compiler with the two main GPU modules (fragment + vertex) loaded |
| 581 | { |
| 582 | int before = heap_bytes_used(); |
| 583 | GrShaderCaps caps(GrContextOptions{}); |
| 584 | SkSL::Compiler compiler(&caps); |
John Stiles | dbd4e6f | 2021-02-16 13:29:15 -0500 | [diff] [blame] | 585 | compiler.moduleForProgramKind(SkSL::ProgramKind::kVertex); |
| 586 | compiler.moduleForProgramKind(SkSL::ProgramKind::kFragment); |
Brian Osman | 5626998 | 2020-11-20 12:38:07 -0500 | [diff] [blame] | 587 | int after = heap_bytes_used(); |
| 588 | bench("sksl_compiler_gpu", after - before); |
| 589 | } |
| 590 | |
John Stiles | f7f36ae | 2021-06-08 14:06:22 -0400 | [diff] [blame] | 591 | // Heap used by a compiler with the runtime shader, color filter and blending modules loaded |
Brian Osman | 5626998 | 2020-11-20 12:38:07 -0500 | [diff] [blame] | 592 | { |
| 593 | int before = heap_bytes_used(); |
| 594 | GrShaderCaps caps(GrContextOptions{}); |
| 595 | SkSL::Compiler compiler(&caps); |
Brian Osman | cbb60bd | 2021-04-12 09:49:20 -0400 | [diff] [blame] | 596 | compiler.moduleForProgramKind(SkSL::ProgramKind::kRuntimeColorFilter); |
| 597 | compiler.moduleForProgramKind(SkSL::ProgramKind::kRuntimeShader); |
John Stiles | 2d8b835 | 2021-06-16 11:33:13 -0400 | [diff] [blame] | 598 | compiler.moduleForProgramKind(SkSL::ProgramKind::kRuntimeBlender); |
Brian Osman | 5626998 | 2020-11-20 12:38:07 -0500 | [diff] [blame] | 599 | int after = heap_bytes_used(); |
| 600 | bench("sksl_compiler_runtimeeffect", after - before); |
| 601 | } |
Brian Osman | 68870aa | 2020-07-08 14:12:43 -0400 | [diff] [blame] | 602 | } |
Brian Osman | 24b8a8c | 2020-07-09 10:04:33 -0400 | [diff] [blame] | 603 | |
| 604 | #else |
| 605 | |
| 606 | void RunSkSLMemoryBenchmarks(NanoJSONResultsWriter*) {} |
| 607 | |
| 608 | #endif |