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