blob: 175974ab3ac589f7d9a1730e71e0ea150e1337c2 [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 Nicholasba9a04f2020-11-06 09:28:04 -050015#include "src/sksl/SkSLIRGenerator.h"
16#include "src/sksl/SkSLParser.h"
Ethan Nicholas40679c32019-05-31 17:06:53 -040017
Brian Osman24c5d242020-09-29 15:08:55 -040018class SkSLCompilerStartupBench : public Benchmark {
19protected:
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 Osman0006ad02020-11-18 15:38:39 -050029 GrShaderCaps caps(GrContextOptions{});
Brian Osman24c5d242020-09-29 15:08:55 -040030 for (int i = 0; i < loops; i++) {
Brian Osman0006ad02020-11-18 15:38:39 -050031 SkSL::Compiler compiler(&caps);
Brian Osman24c5d242020-09-29 15:08:55 -040032 }
33 }
34};
35
36DEF_BENCH(return new SkSLCompilerStartupBench();)
37
Ethan Nicholasba9a04f2020-11-06 09:28:04 -050038enum class Output {
39 kNone,
40 kGLSL,
41 kMetal,
42 kSPIRV
43};
44
45class SkSLCompileBench : public Benchmark {
Ethan Nicholas40679c32019-05-31 17:06:53 -040046public:
Ethan Nicholasba9a04f2020-11-06 09:28:04 -050047 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
70protected:
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 Stilesdbd4e6f2021-02-16 13:29:15 -050082 SkSL::ProgramKind::kFragment,
Ethan Nicholasba9a04f2020-11-06 09:28:04 -050083 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
98private:
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
109class SkSLParseBench : public Benchmark {
110public:
111 SkSLParseBench(SkSL::String name, const char* src)
112 : fName("sksl_parse_" + name)
Brian Osmand7e76592020-11-02 12:26:22 -0500113 , fSrc(src)
Brian Osman0006ad02020-11-18 15:38:39 -0500114 , fCaps(GrContextOptions())
115 , fCompiler(&fCaps) {}
Ethan Nicholas40679c32019-05-31 17:06:53 -0400116
117protected:
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 Nicholasba9a04f2020-11-06 09:28:04 -0500126 void onDelayedSetup() override {
John Stilesdbd4e6f2021-02-16 13:29:15 -0500127 SkSL::ParsedModule module = fCompiler.moduleForProgramKind(SkSL::ProgramKind::kFragment);
Ethan Nicholasba9a04f2020-11-06 09:28:04 -0500128 fCompiler.irGenerator().setSymbolTable(module.fSymbols);
129 }
130
Ethan Nicholas40679c32019-05-31 17:06:53 -0400131 void onDraw(int loops, SkCanvas*) override {
132 for (int i = 0; i < loops; i++) {
Ethan Nicholasba9a04f2020-11-06 09:28:04 -0500133 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 Nicholas34b19c52020-09-14 11:33:47 -0400138 if (fCompiler.errorCount()) {
Ethan Nicholasba9a04f2020-11-06 09:28:04 -0500139 SK_ABORT("shader compilation failed: %s\n", fCompiler.errorText().c_str());
Ethan Nicholas40679c32019-05-31 17:06:53 -0400140 }
141 }
142 }
143
144private:
145 SkSL::String fName;
146 SkSL::String fSrc;
Brian Osman0006ad02020-11-18 15:38:39 -0500147 GrShaderCaps fCaps;
Ethan Nicholas40679c32019-05-31 17:06:53 -0400148 SkSL::Compiler fCompiler;
149 SkSL::Program::Settings fSettings;
150
John Stiles7571f9e2020-09-02 22:42:33 -0400151 using INHERITED = Benchmark;
Ethan Nicholas40679c32019-05-31 17:06:53 -0400152};
153
154///////////////////////////////////////////////////////////////////////////////
155
Ethan Nicholasba9a04f2020-11-06 09:28:04 -0500156#define COMPILER_BENCH(name, text) \
157static constexpr char name ## _SRC[] = text; \
158DEF_BENCH(return new SkSLParseBench(#name, name ## _SRC);) \
159DEF_BENCH(return new SkSLCompileBench(#name, name ## _SRC, /*optimize=*/false, Output::kNone);) \
160DEF_BENCH(return new SkSLCompileBench(#name, name ## _SRC, /*optimize=*/true, Output::kNone);) \
161DEF_BENCH(return new SkSLCompileBench(#name, name ## _SRC, /*optimize=*/true, Output::kGLSL);) \
162DEF_BENCH(return new SkSLCompileBench(#name, name ## _SRC, /*optimize=*/true, Output::kMetal);) \
163DEF_BENCH(return new SkSLCompileBench(#name, name ## _SRC, /*optimize=*/true, Output::kSPIRV);)
164
John Stilesd2702fa2021-03-15 18:04:05 -0400165// 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 -0500166COMPILER_BENCH(large, R"(
John Stilesd2702fa2021-03-15 18:04:05 -0400167layout(set=0, binding=0) uniform half urange_Stage1_c0;
168layout(set=0, binding=0) uniform half4 uleftBorderColor_Stage1_c0_c0_c0;
169layout(set=0, binding=0) uniform half4 urightBorderColor_Stage1_c0_c0_c0;
170layout(set=0, binding=0) uniform float3x3 umatrix_Stage1_c0_c0_c0_c0;
171layout(set=0, binding=0) uniform half2 ufocalParams_Stage1_c0_c0_c0_c0_c0;
172layout(set=0, binding=0) uniform float4 uscale0_1_Stage1_c0_c0_c0_c1;
173layout(set=0, binding=0) uniform float4 uscale2_3_Stage1_c0_c0_c0_c1;
174layout(set=0, binding=0) uniform float4 uscale4_5_Stage1_c0_c0_c0_c1;
175layout(set=0, binding=0) uniform float4 uscale6_7_Stage1_c0_c0_c0_c1;
176layout(set=0, binding=0) uniform float4 ubias0_1_Stage1_c0_c0_c0_c1;
177layout(set=0, binding=0) uniform float4 ubias2_3_Stage1_c0_c0_c0_c1;
178layout(set=0, binding=0) uniform float4 ubias4_5_Stage1_c0_c0_c0_c1;
179layout(set=0, binding=0) uniform float4 ubias6_7_Stage1_c0_c0_c0_c1;
180layout(set=0, binding=0) uniform half4 uthresholds1_7_Stage1_c0_c0_c0_c1;
181layout(set=0, binding=0) uniform half4 uthresholds9_13_Stage1_c0_c0_c0_c1;
John Stiles7f88b722020-09-30 09:29:13 -0400182flat in half4 vcolor_Stage0;
John Stilesd2702fa2021-03-15 18:04:05 -0400183noperspective in float2 vTransformedCoords_0_Stage0;
John Stiles7f88b722020-09-30 09:29:13 -0400184out half4 sk_FragColor;
John Stilesd2702fa2021-03-15 18:04:05 -0400185half4 TwoPointConicalGradientLayout_Stage1_c0_c0_c0_c0_c0(half4 _input)
John Stiles7f88b722020-09-30 09:29:13 -0400186{
John Stiles7f88b722020-09-30 09:29:13 -0400187 float t = -1.0;
188 half v = 1.0;
189 @switch (2)
190 {
191 case 1:
192 {
John Stilesd2702fa2021-03-15 18:04:05 -0400193 half r0_2 = ufocalParams_Stage1_c0_c0_c0_c0_c0.y;
John Stiles7f88b722020-09-30 09:29:13 -0400194 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 Stilesd2702fa2021-03-15 18:04:05 -0400207 half r0 = ufocalParams_Stage1_c0_c0_c0_c0_c0.x;
John Stiles7f88b722020-09-30 09:29:13 -0400208 @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 Stilesd2702fa2021-03-15 18:04:05 -0400220 half invR1 = ufocalParams_Stage1_c0_c0_c0_c0_c0.x;
221 half fx = ufocalParams_Stage1_c0_c0_c0_c0_c0.y;
John Stiles7f88b722020-09-30 09:29:13 -0400222 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 Stilesd2702fa2021-03-15 18:04:05 -0400227 else if (false)
John Stiles7f88b722020-09-30 09:29:13 -0400228 {
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 Stilesd2702fa2021-03-15 18:04:05 -0400246 @if (!false)
John Stiles7f88b722020-09-30 09:29:13 -0400247 {
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 Stilesd2702fa2021-03-15 18:04:05 -0400282 return half4(half(t), v, 0.0, 0.0);
John Stiles7f88b722020-09-30 09:29:13 -0400283}
John Stilesd2702fa2021-03-15 18:04:05 -0400284half4 MatrixEffect_Stage1_c0_c0_c0_c0(half4 _input)
John Stiles7f88b722020-09-30 09:29:13 -0400285{
John Stilesd2702fa2021-03-15 18:04:05 -0400286 return TwoPointConicalGradientLayout_Stage1_c0_c0_c0_c0_c0(_input);
John Stiles7f88b722020-09-30 09:29:13 -0400287}
John Stilesd2702fa2021-03-15 18:04:05 -0400288half4 UnrolledBinaryGradientColorizer_Stage1_c0_c0_c0_c1(half4 _input, float2 _coords)
John Stiles7f88b722020-09-30 09:29:13 -0400289{
John Stiles7f88b722020-09-30 09:29:13 -0400290 half t = half(_coords.x);
John Stilesd2702fa2021-03-15 18:04:05 -0400291 float4 scale;
292 float4 bias;
293 if (4 <= 4 || t < uthresholds1_7_Stage1_c0_c0_c0_c1.w)
John Stiles7f88b722020-09-30 09:29:13 -0400294 {
John Stilesd2702fa2021-03-15 18:04:05 -0400295 if (4 <= 2 || t < uthresholds1_7_Stage1_c0_c0_c0_c1.y)
John Stiles7f88b722020-09-30 09:29:13 -0400296 {
John Stilesd2702fa2021-03-15 18:04:05 -0400297 if (4 <= 1 || t < uthresholds1_7_Stage1_c0_c0_c0_c1.x)
John Stiles7f88b722020-09-30 09:29:13 -0400298 {
John Stilesd2702fa2021-03-15 18:04:05 -0400299 scale = uscale0_1_Stage1_c0_c0_c0_c1;
300 bias = ubias0_1_Stage1_c0_c0_c0_c1;
John Stiles7f88b722020-09-30 09:29:13 -0400301 }
302 else
303 {
John Stilesd2702fa2021-03-15 18:04:05 -0400304 scale = uscale2_3_Stage1_c0_c0_c0_c1;
305 bias = ubias2_3_Stage1_c0_c0_c0_c1;
John Stiles7f88b722020-09-30 09:29:13 -0400306 }
307 }
308 else
309 {
John Stilesd2702fa2021-03-15 18:04:05 -0400310 if (4 <= 3 || t < uthresholds1_7_Stage1_c0_c0_c0_c1.z)
John Stiles7f88b722020-09-30 09:29:13 -0400311 {
John Stilesd2702fa2021-03-15 18:04:05 -0400312 scale = uscale4_5_Stage1_c0_c0_c0_c1;
313 bias = ubias4_5_Stage1_c0_c0_c0_c1;
John Stiles7f88b722020-09-30 09:29:13 -0400314 }
315 else
316 {
John Stilesd2702fa2021-03-15 18:04:05 -0400317 scale = uscale6_7_Stage1_c0_c0_c0_c1;
318 bias = ubias6_7_Stage1_c0_c0_c0_c1;
John Stiles7f88b722020-09-30 09:29:13 -0400319 }
320 }
321 }
322 else
323 {
John Stilesd2702fa2021-03-15 18:04:05 -0400324 if (4 <= 6 || t < uthresholds9_13_Stage1_c0_c0_c0_c1.y)
John Stiles7f88b722020-09-30 09:29:13 -0400325 {
John Stilesd2702fa2021-03-15 18:04:05 -0400326 if (4 <= 5 || t < uthresholds9_13_Stage1_c0_c0_c0_c1.x)
John Stiles7f88b722020-09-30 09:29:13 -0400327 {
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 Stilesd2702fa2021-03-15 18:04:05 -0400339 if (4 <= 7 || t < uthresholds9_13_Stage1_c0_c0_c0_c1.z)
John Stiles7f88b722020-09-30 09:29:13 -0400340 {
341 scale = float4(0);
342 bias = float4(0);
343 }
344 else
345 {
346 scale = float4(0);
347 bias = float4(0);
348 }
349 }
350 }
John Stilesd2702fa2021-03-15 18:04:05 -0400351 return half4(float(t) * scale + bias);
John Stiles7f88b722020-09-30 09:29:13 -0400352}
John Stilesd2702fa2021-03-15 18:04:05 -0400353half4 ClampedGradientEffect_Stage1_c0_c0_c0(half4 _input)
John Stiles7f88b722020-09-30 09:29:13 -0400354{
John Stilesd2702fa2021-03-15 18:04:05 -0400355 half4 t = MatrixEffect_Stage1_c0_c0_c0_c0(_input);
356 half4 outColor;
John Stiles7f88b722020-09-30 09:29:13 -0400357 if (!false && t.y < 0.0)
358 {
John Stilesd2702fa2021-03-15 18:04:05 -0400359 outColor = half4(0.0);
John Stiles7f88b722020-09-30 09:29:13 -0400360 }
361 else if (t.x < 0.0)
362 {
John Stilesd2702fa2021-03-15 18:04:05 -0400363 outColor = uleftBorderColor_Stage1_c0_c0_c0;
John Stiles7f88b722020-09-30 09:29:13 -0400364 }
365 else if (t.x > 1.0)
366 {
John Stilesd2702fa2021-03-15 18:04:05 -0400367 outColor = urightBorderColor_Stage1_c0_c0_c0;
John Stiles7f88b722020-09-30 09:29:13 -0400368 }
369 else
370 {
John Stilesd2702fa2021-03-15 18:04:05 -0400371 outColor = UnrolledBinaryGradientColorizer_Stage1_c0_c0_c0_c1(_input, float2(half2(t.x, 0.0)));
John Stiles7f88b722020-09-30 09:29:13 -0400372 }
373 @if (false)
374 {
John Stilesd2702fa2021-03-15 18:04:05 -0400375 outColor.xyz *= outColor.w;
John Stiles7f88b722020-09-30 09:29:13 -0400376 }
John Stilesd2702fa2021-03-15 18:04:05 -0400377 return outColor;
John Stiles7f88b722020-09-30 09:29:13 -0400378}
John Stilesd2702fa2021-03-15 18:04:05 -0400379half4 OverrideInputFragmentProcessor_Stage1_c0_c0(half4 _input)
John Stiles7f88b722020-09-30 09:29:13 -0400380{
John Stilesd2702fa2021-03-15 18:04:05 -0400381 return ClampedGradientEffect_Stage1_c0_c0_c0(false ? half4(0) : half4(1.000000, 1.000000, 1.000000, 1.000000));
382}
383half4 DitherEffect_Stage1_c0(half4 _input)
384{
385 half4 color = OverrideInputFragmentProcessor_Stage1_c0_c0(_input);
386 half value;
387 @if (sk_Caps.integerSupport)
John Stiles7f88b722020-09-30 09:29:13 -0400388 {
John Stilesd2702fa2021-03-15 18:04:05 -0400389 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 Stiles7f88b722020-09-30 09:29:13 -0400393 }
394 else
395 {
John Stilesd2702fa2021-03-15 18:04:05 -0400396 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 Stiles7f88b722020-09-30 09:29:13 -0400400 }
John Stilesd2702fa2021-03-15 18:04:05 -0400401 return half4(clamp(color.xyz + value * urange_Stage1_c0, 0.0, color.w), color.w);
John Stiles7f88b722020-09-30 09:29:13 -0400402}
403void main()
404{
John Stilesd2702fa2021-03-15 18:04:05 -0400405 // Stage 0, QuadPerEdgeAAGeometryProcessor
John Stiles7f88b722020-09-30 09:29:13 -0400406 half4 outputColor_Stage0;
John Stilesd2702fa2021-03-15 18:04:05 -0400407 outputColor_Stage0 = vcolor_Stage0;
408 const half4 outputCoverage_Stage0 = half4(1);
John Stiles7f88b722020-09-30 09:29:13 -0400409 half4 output_Stage1;
John Stilesd2702fa2021-03-15 18:04:05 -0400410 output_Stage1 = DitherEffect_Stage1_c0(outputColor_Stage0);
John Stiles7f88b722020-09-30 09:29:13 -0400411 {
412 // Xfer Processor: Porter Duff
413 sk_FragColor = output_Stage1 * outputCoverage_Stage0;
414 }
415}
Ethan Nicholasba9a04f2020-11-06 09:28:04 -0500416)");
John Stiles7f88b722020-09-30 09:29:13 -0400417
John Stilesd2702fa2021-03-15 18:04:05 -0400418// This fragment shader is taken from GM_BlurDrawImage.
Ethan Nicholasba9a04f2020-11-06 09:28:04 -0500419COMPILER_BENCH(medium, R"(
John Stilesd2702fa2021-03-15 18:04:05 -0400420layout(set=0, binding=0) uniform float3x3 umatrix_Stage1_c0_c0_c0;
421layout(set=0, binding=0) uniform half4 urectH_Stage2_c1;
422layout(set=0, binding=0) uniform float3x3 umatrix_Stage2_c1_c0;
423layout(set=0, binding=0) uniform sampler2D uTextureSampler_0_Stage1;
424layout(set=0, binding=0) uniform sampler2D uTextureSampler_0_Stage2;
425flat in half4 vcolor_Stage0;
426noperspective in float2 vTransformedCoords_0_Stage0;
427out half4 sk_FragColor;
428half4 TextureEffect_Stage1_c0_c0_c0_c0(half4 _input)
429{
430 return sample(uTextureSampler_0_Stage1, vTransformedCoords_0_Stage0);
431}
432half4 MatrixEffect_Stage1_c0_c0_c0(half4 _input)
433{
434 return TextureEffect_Stage1_c0_c0_c0_c0(_input);
435}
436half4 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}
441half4 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}
445half4 TextureEffect_Stage2_c1_c0_c0(half4 _input, float2 _coords)
446{
447 return sample(uTextureSampler_0_Stage2, _coords).000r;
448}
449half4 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}
453half4 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 Nicholas40679c32019-05-31 17:06:53 -0400462 }
John Stilesd2702fa2021-03-15 18:04:05 -0400463 @if (true)
464 {
465 half2 xy;
466 @if (highPrecision)
467 {
468 xy = max(half2(float4(0).xy - pos), half2(pos - float4(0).zw));
Ethan Nicholas40679c32019-05-31 17:06:53 -0400469 }
John Stilesd2702fa2021-03-15 18:04:05 -0400470 else
471 {
472 xy = max(half2(float2(urectH_Stage2_c1.xy) - pos), half2(pos - float2(urectH_Stage2_c1.zw)));
Ethan Nicholas40679c32019-05-31 17:06:53 -0400473 }
John Stilesd2702fa2021-03-15 18:04:05 -0400474 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 Nicholas40679c32019-05-31 17:06:53 -0400476 }
John Stilesd2702fa2021-03-15 18:04:05 -0400477 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 Nicholas40679c32019-05-31 17:06:53 -0400484 }
John Stilesd2702fa2021-03-15 18:04:05 -0400485 else
486 {
487 rect.xy = half2(float2(urectH_Stage2_c1.xy) - pos);
488 rect.zw = half2(pos - float2(urectH_Stage2_c1.zw));
Ethan Nicholas40679c32019-05-31 17:06:53 -0400489 }
John Stilesd2702fa2021-03-15 18:04:05 -0400490 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 Nicholas40679c32019-05-31 17:06:53 -0400492 }
John Stilesd2702fa2021-03-15 18:04:05 -0400493 return (_input * xCoverage) * yCoverage;
494}
495void 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 Nicholasba9a04f2020-11-06 09:28:04 -0500510)");
Brian Osman68870aa2020-07-08 14:12:43 -0400511
John Stilesd2702fa2021-03-15 18:04:05 -0400512// This is the fragment shader used to blit the Viewer window when running the software rasterizer.
Ethan Nicholasba9a04f2020-11-06 09:28:04 -0500513COMPILER_BENCH(small, R"(
John Stilesd2702fa2021-03-15 18:04:05 -0400514layout(set=0, binding=0) uniform float3x3 umatrix_Stage1_c0_c0;
515layout(set=0, binding=0) uniform sampler2D uTextureSampler_0_Stage1;
516noperspective in float2 vTransformedCoords_0_Stage0;
517out half4 sk_FragColor;
518half4 TextureEffect_Stage1_c0_c0_c0(half4 _input)
519{
520 return sample(uTextureSampler_0_Stage1, vTransformedCoords_0_Stage0);
521}
522half4 MatrixEffect_Stage1_c0_c0(half4 _input)
523{
524 return TextureEffect_Stage1_c0_c0_c0(_input);
525}
526half4 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}
531void 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 Stiles312535b2020-10-23 18:37:29 -0400538 {
John Stilesd2702fa2021-03-15 18:04:05 -0400539 // Xfer Processor: Porter Duff
540 sk_FragColor = output_Stage1 * outputCoverage_Stage0;
John Stiles312535b2020-10-23 18:37:29 -0400541 }
John Stilesd2702fa2021-03-15 18:04:05 -0400542}
Ethan Nicholasba9a04f2020-11-06 09:28:04 -0500543)");
John Stiles312535b2020-10-23 18:37:29 -0400544
Ethan Nicholasba9a04f2020-11-06 09:28:04 -0500545COMPILER_BENCH(tiny, "void main() { sk_FragColor = half4(1); }");
John Stiles312535b2020-10-23 18:37:29 -0400546
Brian Osman24b8a8c2020-07-09 10:04:33 -0400547#if defined(SK_BUILD_FOR_UNIX)
548
549#include <malloc.h>
550
Brian Osman68870aa2020-07-08 14:12:43 -0400551// These benchmarks aren't timed, they produce memory usage statistics. They run standalone, and
552// directly add their results to the nanobench log.
553void RunSkSLMemoryBenchmarks(NanoJSONResultsWriter* log) {
Brian Osman24b8a8c2020-07-09 10:04:33 -0400554 auto heap_bytes_used = []() { return mallinfo().uordblks; };
555 auto bench = [log](const char* name, int bytes) {
Brian Osman68870aa2020-07-08 14:12:43 -0400556 log->beginObject(name); // test
557 log->beginObject("meta"); // config
Brian Osman24b8a8c2020-07-09 10:04:33 -0400558 log->appendS32("bytes", bytes); // sub_result
Brian Osman68870aa2020-07-08 14:12:43 -0400559 log->endObject(); // config
560 log->endObject(); // test
561 };
562
Brian Osman56269982020-11-20 12:38:07 -0500563 // Heap used by a default compiler (with no modules loaded)
Brian Osman68870aa2020-07-08 14:12:43 -0400564 {
Brian Osman24b8a8c2020-07-09 10:04:33 -0400565 int before = heap_bytes_used();
Brian Osman0006ad02020-11-18 15:38:39 -0500566 GrShaderCaps caps(GrContextOptions{});
567 SkSL::Compiler compiler(&caps);
Brian Osman24b8a8c2020-07-09 10:04:33 -0400568 int after = heap_bytes_used();
569 bench("sksl_compiler_baseline", after - before);
Brian Osman68870aa2020-07-08 14:12:43 -0400570 }
Brian Osman56269982020-11-20 12:38:07 -0500571
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 Stilesdbd4e6f2021-02-16 13:29:15 -0500577 compiler.moduleForProgramKind(SkSL::ProgramKind::kVertex);
578 compiler.moduleForProgramKind(SkSL::ProgramKind::kFragment);
Brian Osman56269982020-11-20 12:38:07 -0500579 int after = heap_bytes_used();
580 bench("sksl_compiler_gpu", after - before);
581 }
582
Brian Osmancbb60bd2021-04-12 09:49:20 -0400583 // Heap used by a compiler with the runtime shader & color filter modules loaded
Brian Osman56269982020-11-20 12:38:07 -0500584 {
585 int before = heap_bytes_used();
586 GrShaderCaps caps(GrContextOptions{});
587 SkSL::Compiler compiler(&caps);
Brian Osmancbb60bd2021-04-12 09:49:20 -0400588 compiler.moduleForProgramKind(SkSL::ProgramKind::kRuntimeColorFilter);
589 compiler.moduleForProgramKind(SkSL::ProgramKind::kRuntimeShader);
Brian Osman56269982020-11-20 12:38:07 -0500590 int after = heap_bytes_used();
591 bench("sksl_compiler_runtimeeffect", after - before);
592 }
Brian Osman68870aa2020-07-08 14:12:43 -0400593}
Brian Osman24b8a8c2020-07-09 10:04:33 -0400594
595#else
596
597void RunSkSLMemoryBenchmarks(NanoJSONResultsWriter*) {}
598
599#endif