blob: 68f2f9925c4e852a70d659d7e3255b8d9ca361d1 [file] [log] [blame]
Ethan Nicholas40679c32019-05-31 17:06:53 -04001/*
Ethan Nicholasfc994162019-06-06 10:04:27 -04002 * Copyright 2019 Google LLC
Ethan Nicholas40679c32019-05-31 17:06:53 -04003 *
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 Osman68870aa2020-07-08 14:12:43 -04008#include "bench/ResultsWriter.h"
9#include "bench/SkSLBench.h"
Ethan Nicholasba9a04f2020-11-06 09:28:04 -050010#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 Nicholas40679c32019-05-31 17:06:53 -040014#include "src/sksl/SkSLCompiler.h"
Ethan Nicholasdd2fdea2021-07-20 15:23:04 -040015#include "src/sksl/SkSLDSLParser.h"
Ethan Nicholasba9a04f2020-11-06 09:28:04 -050016#include "src/sksl/SkSLIRGenerator.h"
17#include "src/sksl/SkSLParser.h"
Ethan Nicholas40679c32019-05-31 17:06:53 -040018
Brian Osman24c5d242020-09-29 15:08:55 -040019class SkSLCompilerStartupBench : public Benchmark {
20protected:
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 Osman0006ad02020-11-18 15:38:39 -050030 GrShaderCaps caps(GrContextOptions{});
Brian Osman24c5d242020-09-29 15:08:55 -040031 for (int i = 0; i < loops; i++) {
Brian Osman0006ad02020-11-18 15:38:39 -050032 SkSL::Compiler compiler(&caps);
Brian Osman24c5d242020-09-29 15:08:55 -040033 }
34 }
35};
36
37DEF_BENCH(return new SkSLCompilerStartupBench();)
38
Ethan Nicholasba9a04f2020-11-06 09:28:04 -050039enum class Output {
40 kNone,
41 kGLSL,
42 kMetal,
43 kSPIRV
44};
45
46class SkSLCompileBench : public Benchmark {
Ethan Nicholas40679c32019-05-31 17:06:53 -040047public:
Ethan Nicholasba9a04f2020-11-06 09:28:04 -050048 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 Nicholasdd2fdea2021-07-20 15:23:04 -040066 fSettings.fDSLMangling = false;
Ethan Nicholasba9a04f2020-11-06 09:28:04 -050067 // 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
72protected:
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 Nicholasdd2fdea2021-07-20 15:23:04 -040083#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 Nicholasba9a04f2020-11-06 09:28:04 -050089 std::unique_ptr<SkSL::Program> program = fCompiler.convertProgram(
John Stilesdbd4e6f2021-02-16 13:29:15 -050090 SkSL::ProgramKind::kFragment,
Ethan Nicholasba9a04f2020-11-06 09:28:04 -050091 fSrc,
92 fSettings);
Ethan Nicholasdd2fdea2021-07-20 15:23:04 -040093#endif // SKSL_DSL_PARSER
Ethan Nicholasba9a04f2020-11-06 09:28:04 -050094 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
107private:
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
118class SkSLParseBench : public Benchmark {
119public:
120 SkSLParseBench(SkSL::String name, const char* src)
121 : fName("sksl_parse_" + name)
Brian Osmand7e76592020-11-02 12:26:22 -0500122 , fSrc(src)
Brian Osman0006ad02020-11-18 15:38:39 -0500123 , fCaps(GrContextOptions())
124 , fCompiler(&fCaps) {}
Ethan Nicholas40679c32019-05-31 17:06:53 -0400125
126protected:
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 Nicholasba9a04f2020-11-06 09:28:04 -0500135 void onDelayedSetup() override {
John Stilesdbd4e6f2021-02-16 13:29:15 -0500136 SkSL::ParsedModule module = fCompiler.moduleForProgramKind(SkSL::ProgramKind::kFragment);
Ethan Nicholasba9a04f2020-11-06 09:28:04 -0500137 fCompiler.irGenerator().setSymbolTable(module.fSymbols);
138 }
139
Ethan Nicholas40679c32019-05-31 17:06:53 -0400140 void onDraw(int loops, SkCanvas*) override {
141 for (int i = 0; i < loops; i++) {
Ethan Nicholasba9a04f2020-11-06 09:28:04 -0500142 fCompiler.irGenerator().pushSymbolTable();
Ethan Nicholas4a5e22a2021-08-13 17:29:51 -0400143 SkSL::Parser parser(fSrc, *fCompiler.irGenerator().symbolTable(),
144 fCompiler.errorReporter());
Ethan Nicholasba9a04f2020-11-06 09:28:04 -0500145 parser.compilationUnit();
146 fCompiler.irGenerator().popSymbolTable();
Ethan Nicholas34b19c52020-09-14 11:33:47 -0400147 if (fCompiler.errorCount()) {
Ethan Nicholasba9a04f2020-11-06 09:28:04 -0500148 SK_ABORT("shader compilation failed: %s\n", fCompiler.errorText().c_str());
Ethan Nicholas40679c32019-05-31 17:06:53 -0400149 }
150 }
151 }
152
153private:
154 SkSL::String fName;
155 SkSL::String fSrc;
Brian Osman0006ad02020-11-18 15:38:39 -0500156 GrShaderCaps fCaps;
Ethan Nicholas40679c32019-05-31 17:06:53 -0400157 SkSL::Compiler fCompiler;
Ethan Nicholas40679c32019-05-31 17:06:53 -0400158
John Stiles7571f9e2020-09-02 22:42:33 -0400159 using INHERITED = Benchmark;
Ethan Nicholas40679c32019-05-31 17:06:53 -0400160};
161
162///////////////////////////////////////////////////////////////////////////////
163
Ethan Nicholasba9a04f2020-11-06 09:28:04 -0500164#define COMPILER_BENCH(name, text) \
165static constexpr char name ## _SRC[] = text; \
166DEF_BENCH(return new SkSLParseBench(#name, name ## _SRC);) \
167DEF_BENCH(return new SkSLCompileBench(#name, name ## _SRC, /*optimize=*/false, Output::kNone);) \
168DEF_BENCH(return new SkSLCompileBench(#name, name ## _SRC, /*optimize=*/true, Output::kNone);) \
169DEF_BENCH(return new SkSLCompileBench(#name, name ## _SRC, /*optimize=*/true, Output::kGLSL);) \
170DEF_BENCH(return new SkSLCompileBench(#name, name ## _SRC, /*optimize=*/true, Output::kMetal);) \
171DEF_BENCH(return new SkSLCompileBench(#name, name ## _SRC, /*optimize=*/true, Output::kSPIRV);)
172
John Stilesd2702fa2021-03-15 18:04:05 -0400173// This fragment shader is from the third tile on the top row of GM_gradients_2pt_conical_outside.
Ethan Nicholasba9a04f2020-11-06 09:28:04 -0500174COMPILER_BENCH(large, R"(
John Stilesd2702fa2021-03-15 18:04:05 -0400175layout(set=0, binding=0) uniform half urange_Stage1_c0;
176layout(set=0, binding=0) uniform half4 uleftBorderColor_Stage1_c0_c0_c0;
177layout(set=0, binding=0) uniform half4 urightBorderColor_Stage1_c0_c0_c0;
178layout(set=0, binding=0) uniform float3x3 umatrix_Stage1_c0_c0_c0_c0;
179layout(set=0, binding=0) uniform half2 ufocalParams_Stage1_c0_c0_c0_c0_c0;
180layout(set=0, binding=0) uniform float4 uscale0_1_Stage1_c0_c0_c0_c1;
181layout(set=0, binding=0) uniform float4 uscale2_3_Stage1_c0_c0_c0_c1;
182layout(set=0, binding=0) uniform float4 uscale4_5_Stage1_c0_c0_c0_c1;
183layout(set=0, binding=0) uniform float4 uscale6_7_Stage1_c0_c0_c0_c1;
184layout(set=0, binding=0) uniform float4 ubias0_1_Stage1_c0_c0_c0_c1;
185layout(set=0, binding=0) uniform float4 ubias2_3_Stage1_c0_c0_c0_c1;
186layout(set=0, binding=0) uniform float4 ubias4_5_Stage1_c0_c0_c0_c1;
187layout(set=0, binding=0) uniform float4 ubias6_7_Stage1_c0_c0_c0_c1;
188layout(set=0, binding=0) uniform half4 uthresholds1_7_Stage1_c0_c0_c0_c1;
189layout(set=0, binding=0) uniform half4 uthresholds9_13_Stage1_c0_c0_c0_c1;
John Stiles7f88b722020-09-30 09:29:13 -0400190flat in half4 vcolor_Stage0;
John Stilesd2702fa2021-03-15 18:04:05 -0400191noperspective in float2 vTransformedCoords_0_Stage0;
John Stiles7f88b722020-09-30 09:29:13 -0400192out half4 sk_FragColor;
John Stilesd2702fa2021-03-15 18:04:05 -0400193half4 TwoPointConicalGradientLayout_Stage1_c0_c0_c0_c0_c0(half4 _input)
John Stiles7f88b722020-09-30 09:29:13 -0400194{
John Stiles7f88b722020-09-30 09:29:13 -0400195 float t = -1.0;
196 half v = 1.0;
197 @switch (2)
198 {
199 case 1:
200 {
John Stilesd2702fa2021-03-15 18:04:05 -0400201 half r0_2 = ufocalParams_Stage1_c0_c0_c0_c0_c0.y;
John Stiles7f88b722020-09-30 09:29:13 -0400202 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 Stilesd2702fa2021-03-15 18:04:05 -0400215 half r0 = ufocalParams_Stage1_c0_c0_c0_c0_c0.x;
John Stiles7f88b722020-09-30 09:29:13 -0400216 @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 Stilesd2702fa2021-03-15 18:04:05 -0400228 half invR1 = ufocalParams_Stage1_c0_c0_c0_c0_c0.x;
229 half fx = ufocalParams_Stage1_c0_c0_c0_c0_c0.y;
John Stiles7f88b722020-09-30 09:29:13 -0400230 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 Stilesd2702fa2021-03-15 18:04:05 -0400235 else if (false)
John Stiles7f88b722020-09-30 09:29:13 -0400236 {
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 Stilesd2702fa2021-03-15 18:04:05 -0400254 @if (!false)
John Stiles7f88b722020-09-30 09:29:13 -0400255 {
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 Stilesd2702fa2021-03-15 18:04:05 -0400290 return half4(half(t), v, 0.0, 0.0);
John Stiles7f88b722020-09-30 09:29:13 -0400291}
John Stilesd2702fa2021-03-15 18:04:05 -0400292half4 MatrixEffect_Stage1_c0_c0_c0_c0(half4 _input)
John Stiles7f88b722020-09-30 09:29:13 -0400293{
John Stilesd2702fa2021-03-15 18:04:05 -0400294 return TwoPointConicalGradientLayout_Stage1_c0_c0_c0_c0_c0(_input);
John Stiles7f88b722020-09-30 09:29:13 -0400295}
John Stilesd2702fa2021-03-15 18:04:05 -0400296half4 UnrolledBinaryGradientColorizer_Stage1_c0_c0_c0_c1(half4 _input, float2 _coords)
John Stiles7f88b722020-09-30 09:29:13 -0400297{
John Stiles7f88b722020-09-30 09:29:13 -0400298 half t = half(_coords.x);
John Stilesd2702fa2021-03-15 18:04:05 -0400299 float4 scale;
300 float4 bias;
301 if (4 <= 4 || t < uthresholds1_7_Stage1_c0_c0_c0_c1.w)
John Stiles7f88b722020-09-30 09:29:13 -0400302 {
John Stilesd2702fa2021-03-15 18:04:05 -0400303 if (4 <= 2 || t < uthresholds1_7_Stage1_c0_c0_c0_c1.y)
John Stiles7f88b722020-09-30 09:29:13 -0400304 {
John Stilesd2702fa2021-03-15 18:04:05 -0400305 if (4 <= 1 || t < uthresholds1_7_Stage1_c0_c0_c0_c1.x)
John Stiles7f88b722020-09-30 09:29:13 -0400306 {
John Stilesd2702fa2021-03-15 18:04:05 -0400307 scale = uscale0_1_Stage1_c0_c0_c0_c1;
308 bias = ubias0_1_Stage1_c0_c0_c0_c1;
John Stiles7f88b722020-09-30 09:29:13 -0400309 }
310 else
311 {
John Stilesd2702fa2021-03-15 18:04:05 -0400312 scale = uscale2_3_Stage1_c0_c0_c0_c1;
313 bias = ubias2_3_Stage1_c0_c0_c0_c1;
John Stiles7f88b722020-09-30 09:29:13 -0400314 }
315 }
316 else
317 {
John Stilesd2702fa2021-03-15 18:04:05 -0400318 if (4 <= 3 || t < uthresholds1_7_Stage1_c0_c0_c0_c1.z)
John Stiles7f88b722020-09-30 09:29:13 -0400319 {
John Stilesd2702fa2021-03-15 18:04:05 -0400320 scale = uscale4_5_Stage1_c0_c0_c0_c1;
321 bias = ubias4_5_Stage1_c0_c0_c0_c1;
John Stiles7f88b722020-09-30 09:29:13 -0400322 }
323 else
324 {
John Stilesd2702fa2021-03-15 18:04:05 -0400325 scale = uscale6_7_Stage1_c0_c0_c0_c1;
326 bias = ubias6_7_Stage1_c0_c0_c0_c1;
John Stiles7f88b722020-09-30 09:29:13 -0400327 }
328 }
329 }
330 else
331 {
John Stilesd2702fa2021-03-15 18:04:05 -0400332 if (4 <= 6 || t < uthresholds9_13_Stage1_c0_c0_c0_c1.y)
John Stiles7f88b722020-09-30 09:29:13 -0400333 {
John Stilesd2702fa2021-03-15 18:04:05 -0400334 if (4 <= 5 || t < uthresholds9_13_Stage1_c0_c0_c0_c1.x)
John Stiles7f88b722020-09-30 09:29:13 -0400335 {
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 Stilesd2702fa2021-03-15 18:04:05 -0400347 if (4 <= 7 || t < uthresholds9_13_Stage1_c0_c0_c0_c1.z)
John Stiles7f88b722020-09-30 09:29:13 -0400348 {
349 scale = float4(0);
350 bias = float4(0);
351 }
352 else
353 {
354 scale = float4(0);
355 bias = float4(0);
356 }
357 }
358 }
John Stilesd2702fa2021-03-15 18:04:05 -0400359 return half4(float(t) * scale + bias);
John Stiles7f88b722020-09-30 09:29:13 -0400360}
John Stilesd2702fa2021-03-15 18:04:05 -0400361half4 ClampedGradientEffect_Stage1_c0_c0_c0(half4 _input)
John Stiles7f88b722020-09-30 09:29:13 -0400362{
John Stilesd2702fa2021-03-15 18:04:05 -0400363 half4 t = MatrixEffect_Stage1_c0_c0_c0_c0(_input);
364 half4 outColor;
John Stiles7f88b722020-09-30 09:29:13 -0400365 if (!false && t.y < 0.0)
366 {
John Stilesd2702fa2021-03-15 18:04:05 -0400367 outColor = half4(0.0);
John Stiles7f88b722020-09-30 09:29:13 -0400368 }
369 else if (t.x < 0.0)
370 {
John Stilesd2702fa2021-03-15 18:04:05 -0400371 outColor = uleftBorderColor_Stage1_c0_c0_c0;
John Stiles7f88b722020-09-30 09:29:13 -0400372 }
373 else if (t.x > 1.0)
374 {
John Stilesd2702fa2021-03-15 18:04:05 -0400375 outColor = urightBorderColor_Stage1_c0_c0_c0;
John Stiles7f88b722020-09-30 09:29:13 -0400376 }
377 else
378 {
John Stilesd2702fa2021-03-15 18:04:05 -0400379 outColor = UnrolledBinaryGradientColorizer_Stage1_c0_c0_c0_c1(_input, float2(half2(t.x, 0.0)));
John Stiles7f88b722020-09-30 09:29:13 -0400380 }
381 @if (false)
382 {
John Stilesd2702fa2021-03-15 18:04:05 -0400383 outColor.xyz *= outColor.w;
John Stiles7f88b722020-09-30 09:29:13 -0400384 }
John Stilesd2702fa2021-03-15 18:04:05 -0400385 return outColor;
John Stiles7f88b722020-09-30 09:29:13 -0400386}
John Stilesd2702fa2021-03-15 18:04:05 -0400387half4 OverrideInputFragmentProcessor_Stage1_c0_c0(half4 _input)
John Stiles7f88b722020-09-30 09:29:13 -0400388{
John Stilesd2702fa2021-03-15 18:04:05 -0400389 return ClampedGradientEffect_Stage1_c0_c0_c0(false ? half4(0) : half4(1.000000, 1.000000, 1.000000, 1.000000));
390}
391half4 DitherEffect_Stage1_c0(half4 _input)
392{
393 half4 color = OverrideInputFragmentProcessor_Stage1_c0_c0(_input);
394 half value;
395 @if (sk_Caps.integerSupport)
John Stiles7f88b722020-09-30 09:29:13 -0400396 {
John Stilesd2702fa2021-03-15 18:04:05 -0400397 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 Stiles7f88b722020-09-30 09:29:13 -0400401 }
402 else
403 {
John Stilesd2702fa2021-03-15 18:04:05 -0400404 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 Stiles7f88b722020-09-30 09:29:13 -0400408 }
John Stilesd2702fa2021-03-15 18:04:05 -0400409 return half4(clamp(color.xyz + value * urange_Stage1_c0, 0.0, color.w), color.w);
John Stiles7f88b722020-09-30 09:29:13 -0400410}
411void main()
412{
John Stilesd2702fa2021-03-15 18:04:05 -0400413 // Stage 0, QuadPerEdgeAAGeometryProcessor
John Stiles7f88b722020-09-30 09:29:13 -0400414 half4 outputColor_Stage0;
John Stilesd2702fa2021-03-15 18:04:05 -0400415 outputColor_Stage0 = vcolor_Stage0;
416 const half4 outputCoverage_Stage0 = half4(1);
John Stiles7f88b722020-09-30 09:29:13 -0400417 half4 output_Stage1;
John Stilesd2702fa2021-03-15 18:04:05 -0400418 output_Stage1 = DitherEffect_Stage1_c0(outputColor_Stage0);
John Stiles7f88b722020-09-30 09:29:13 -0400419 {
420 // Xfer Processor: Porter Duff
421 sk_FragColor = output_Stage1 * outputCoverage_Stage0;
422 }
423}
Ethan Nicholasba9a04f2020-11-06 09:28:04 -0500424)");
John Stiles7f88b722020-09-30 09:29:13 -0400425
John Stilesd2702fa2021-03-15 18:04:05 -0400426// This fragment shader is taken from GM_BlurDrawImage.
Ethan Nicholasba9a04f2020-11-06 09:28:04 -0500427COMPILER_BENCH(medium, R"(
John Stilesd2702fa2021-03-15 18:04:05 -0400428layout(set=0, binding=0) uniform float3x3 umatrix_Stage1_c0_c0_c0;
429layout(set=0, binding=0) uniform half4 urectH_Stage2_c1;
430layout(set=0, binding=0) uniform float3x3 umatrix_Stage2_c1_c0;
431layout(set=0, binding=0) uniform sampler2D uTextureSampler_0_Stage1;
432layout(set=0, binding=0) uniform sampler2D uTextureSampler_0_Stage2;
433flat in half4 vcolor_Stage0;
434noperspective in float2 vTransformedCoords_0_Stage0;
435out half4 sk_FragColor;
436half4 TextureEffect_Stage1_c0_c0_c0_c0(half4 _input)
437{
438 return sample(uTextureSampler_0_Stage1, vTransformedCoords_0_Stage0);
439}
440half4 MatrixEffect_Stage1_c0_c0_c0(half4 _input)
441{
442 return TextureEffect_Stage1_c0_c0_c0_c0(_input);
443}
444half4 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}
449half4 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}
453half4 TextureEffect_Stage2_c1_c0_c0(half4 _input, float2 _coords)
454{
455 return sample(uTextureSampler_0_Stage2, _coords).000r;
456}
457half4 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}
461half4 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 Nicholas40679c32019-05-31 17:06:53 -0400470 }
John Stilesd2702fa2021-03-15 18:04:05 -0400471 @if (true)
472 {
473 half2 xy;
474 @if (highPrecision)
475 {
476 xy = max(half2(float4(0).xy - pos), half2(pos - float4(0).zw));
Ethan Nicholas40679c32019-05-31 17:06:53 -0400477 }
John Stilesd2702fa2021-03-15 18:04:05 -0400478 else
479 {
480 xy = max(half2(float2(urectH_Stage2_c1.xy) - pos), half2(pos - float2(urectH_Stage2_c1.zw)));
Ethan Nicholas40679c32019-05-31 17:06:53 -0400481 }
John Stilesd2702fa2021-03-15 18:04:05 -0400482 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 Nicholas40679c32019-05-31 17:06:53 -0400484 }
John Stilesd2702fa2021-03-15 18:04:05 -0400485 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 Nicholas40679c32019-05-31 17:06:53 -0400492 }
John Stilesd2702fa2021-03-15 18:04:05 -0400493 else
494 {
495 rect.xy = half2(float2(urectH_Stage2_c1.xy) - pos);
496 rect.zw = half2(pos - float2(urectH_Stage2_c1.zw));
Ethan Nicholas40679c32019-05-31 17:06:53 -0400497 }
John Stilesd2702fa2021-03-15 18:04:05 -0400498 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 Nicholas40679c32019-05-31 17:06:53 -0400500 }
John Stilesd2702fa2021-03-15 18:04:05 -0400501 return (_input * xCoverage) * yCoverage;
502}
503void 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 Nicholasba9a04f2020-11-06 09:28:04 -0500518)");
Brian Osman68870aa2020-07-08 14:12:43 -0400519
John Stilesd2702fa2021-03-15 18:04:05 -0400520// This is the fragment shader used to blit the Viewer window when running the software rasterizer.
Ethan Nicholasba9a04f2020-11-06 09:28:04 -0500521COMPILER_BENCH(small, R"(
John Stilesd2702fa2021-03-15 18:04:05 -0400522layout(set=0, binding=0) uniform float3x3 umatrix_Stage1_c0_c0;
523layout(set=0, binding=0) uniform sampler2D uTextureSampler_0_Stage1;
524noperspective in float2 vTransformedCoords_0_Stage0;
525out half4 sk_FragColor;
526half4 TextureEffect_Stage1_c0_c0_c0(half4 _input)
527{
528 return sample(uTextureSampler_0_Stage1, vTransformedCoords_0_Stage0);
529}
530half4 MatrixEffect_Stage1_c0_c0(half4 _input)
531{
532 return TextureEffect_Stage1_c0_c0_c0(_input);
533}
534half4 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}
539void 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 Stiles312535b2020-10-23 18:37:29 -0400546 {
John Stilesd2702fa2021-03-15 18:04:05 -0400547 // Xfer Processor: Porter Duff
548 sk_FragColor = output_Stage1 * outputCoverage_Stage0;
John Stiles312535b2020-10-23 18:37:29 -0400549 }
John Stilesd2702fa2021-03-15 18:04:05 -0400550}
Ethan Nicholasba9a04f2020-11-06 09:28:04 -0500551)");
John Stiles312535b2020-10-23 18:37:29 -0400552
Ethan Nicholasba9a04f2020-11-06 09:28:04 -0500553COMPILER_BENCH(tiny, "void main() { sk_FragColor = half4(1); }");
John Stiles312535b2020-10-23 18:37:29 -0400554
Brian Osman24b8a8c2020-07-09 10:04:33 -0400555#if defined(SK_BUILD_FOR_UNIX)
556
557#include <malloc.h>
558
Brian Osman68870aa2020-07-08 14:12:43 -0400559// These benchmarks aren't timed, they produce memory usage statistics. They run standalone, and
560// directly add their results to the nanobench log.
561void RunSkSLMemoryBenchmarks(NanoJSONResultsWriter* log) {
Brian Osman24b8a8c2020-07-09 10:04:33 -0400562 auto heap_bytes_used = []() { return mallinfo().uordblks; };
563 auto bench = [log](const char* name, int bytes) {
Brian Osman68870aa2020-07-08 14:12:43 -0400564 log->beginObject(name); // test
565 log->beginObject("meta"); // config
Brian Osman24b8a8c2020-07-09 10:04:33 -0400566 log->appendS32("bytes", bytes); // sub_result
Brian Osman68870aa2020-07-08 14:12:43 -0400567 log->endObject(); // config
568 log->endObject(); // test
569 };
570
Brian Osman56269982020-11-20 12:38:07 -0500571 // Heap used by a default compiler (with no modules loaded)
Brian Osman68870aa2020-07-08 14:12:43 -0400572 {
Brian Osman24b8a8c2020-07-09 10:04:33 -0400573 int before = heap_bytes_used();
Brian Osman0006ad02020-11-18 15:38:39 -0500574 GrShaderCaps caps(GrContextOptions{});
575 SkSL::Compiler compiler(&caps);
Brian Osman24b8a8c2020-07-09 10:04:33 -0400576 int after = heap_bytes_used();
577 bench("sksl_compiler_baseline", after - before);
Brian Osman68870aa2020-07-08 14:12:43 -0400578 }
Brian Osman56269982020-11-20 12:38:07 -0500579
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 Stilesdbd4e6f2021-02-16 13:29:15 -0500585 compiler.moduleForProgramKind(SkSL::ProgramKind::kVertex);
586 compiler.moduleForProgramKind(SkSL::ProgramKind::kFragment);
Brian Osman56269982020-11-20 12:38:07 -0500587 int after = heap_bytes_used();
588 bench("sksl_compiler_gpu", after - before);
589 }
590
John Stilesf7f36ae2021-06-08 14:06:22 -0400591 // Heap used by a compiler with the runtime shader, color filter and blending modules loaded
Brian Osman56269982020-11-20 12:38:07 -0500592 {
593 int before = heap_bytes_used();
594 GrShaderCaps caps(GrContextOptions{});
595 SkSL::Compiler compiler(&caps);
Brian Osmancbb60bd2021-04-12 09:49:20 -0400596 compiler.moduleForProgramKind(SkSL::ProgramKind::kRuntimeColorFilter);
597 compiler.moduleForProgramKind(SkSL::ProgramKind::kRuntimeShader);
John Stiles2d8b8352021-06-16 11:33:13 -0400598 compiler.moduleForProgramKind(SkSL::ProgramKind::kRuntimeBlender);
Brian Osman56269982020-11-20 12:38:07 -0500599 int after = heap_bytes_used();
600 bench("sksl_compiler_runtimeeffect", after - before);
601 }
Brian Osman68870aa2020-07-08 14:12:43 -0400602}
Brian Osman24b8a8c2020-07-09 10:04:33 -0400603
604#else
605
606void RunSkSLMemoryBenchmarks(NanoJSONResultsWriter*) {}
607
608#endif