254{
255 half4 _tmp_0_inColor = _input;
256 float2 _tmp_1_coords = _coords;
257 half t = half(_tmp_1_coords.x);
260 {
261 if (t < uthresholds1_7_S1_c0_c0_c0.y)
262 {
263 if (t < uthresholds1_7_S1_c0_c0_c0.x)
264 {
265 s = uscale_S1_c0_c0_c0[0];
266 b = ubias_S1_c0_c0_c0[0];
267 }
268 else
269 {
270 s = uscale_S1_c0_c0_c0[1];
271 b = ubias_S1_c0_c0_c0[1];
272 }
273 }
274 else
275 {
276 if (t < uthresholds1_7_S1_c0_c0_c0.z)
277 {
278 s = uscale_S1_c0_c0_c0[2];
279 b = ubias_S1_c0_c0_c0[2];
280 }
281 else
282 {
283 s = uscale_S1_c0_c0_c0[3];
284 b = ubias_S1_c0_c0_c0[3];
285 }
286 }
287 }
289}
290half4 TwoPointConicalFocalLayout_S1_c0_c0_c1_c0(half4 _input)
291{
292 half4 _tmp_2_inColor = _input;
293 float2 _tmp_3_coords = vTransformedCoords_6_S0;
294 float t = -1.0;
295 half v = 1.0;
296 float x_t = -1.0;
297 if (bool(int(0)))
298 {
299 x_t =
dot(_tmp_3_coords, _tmp_3_coords) / _tmp_3_coords.x;
300 }
301 else if (bool(int(0)))
302 {
303 x_t =
length(_tmp_3_coords) - _tmp_3_coords.x *
float(uinvR1_S1_c0_c0_c1_c0);
304 }
305 else
306 {
307 float temp = _tmp_3_coords.x * _tmp_3_coords.x - _tmp_3_coords.y * _tmp_3_coords.y;
308 if (temp >= 0.0)
309 {
310 if (bool(int(0)) || !bool(int(1)))
311 {
312 x_t = -
sqrt(temp) - _tmp_3_coords.x *
float(uinvR1_S1_c0_c0_c1_c0);
313 }
314 else
315 {
316 x_t =
sqrt(temp) - _tmp_3_coords.x *
float(uinvR1_S1_c0_c0_c1_c0);
317 }
318 }
319 }
320 if (!bool(int(0)))
321 {
322 if (x_t <= 0.0)
323 {
324 v = -1.0;
325 }
326 }
327 if (bool(int(1)))
328 {
329 if (bool(int(0)))
330 {
331 t = x_t;
332 }
333 else
334 {
335 t = x_t +
float(ufx_S1_c0_c0_c1_c0);
336 }
337 }
338 else
339 {
340 if (bool(int(0)))
341 {
342 t = -x_t;
343 }
344 else
345 {
346 t = -x_t +
float(ufx_S1_c0_c0_c1_c0);
347 }
348 }
349 if (bool(int(0)))
350 {
351 t = 1.0 - t;
352 }
354}
355half4 MatrixEffect_S1_c0_c0_c1(half4 _input)
356{
357 return TwoPointConicalFocalLayout_S1_c0_c0_c1_c0(_input);
358}
359half4 ClampedGradient_S1_c0_c0(half4 _input)
360{
361 half4 _tmp_4_inColor = _input;
362 half4 t = MatrixEffect_S1_c0_c0_c1(_tmp_4_inColor);
364 if (!bool(int(0)) && t.y < 0.0)
365 {
366 outColor =
half4(0.0);
367 }
368 else if (t.x < 0.0)
369 {
370 outColor = uleftBorderColor_S1_c0_c0;
371 }
372 else if (t.x > 1.0)
373 {
374 outColor = urightBorderColor_S1_c0_c0;
375 }
376 else
377 {
378 outColor = UnrolledBinaryColorizer_S1_c0_c0_c0(_tmp_4_inColor,
float2(
half2(t.x, 0.0)));
379 }
380 return half4(outColor);
381}
382half4 DisableCoverageAsAlpha_S1_c0(half4 _input)
383{
384 _input = ClampedGradient_S1_c0_c0(_input);
385 half4 _tmp_5_inColor = _input;
386 return half4(_input);
387}
388half4 TextureEffect_S1_c1_c0(half4 _input,
float2 _coords)
389{
390 return sample(uTextureSampler_0_S1, _coords).000r;
391}
392half4 MatrixEffect_S1_c1(half4 _input,
float2 _coords)
393{
394 return TextureEffect_S1_c1_c0(_input, float3x2(umatrix_S1_c1) * _coords.xy1);
395}
396half4 Dither_S1(half4 _input)
397{
398 half4 _tmp_6_inColor = _input;
399 half4 color = DisableCoverageAsAlpha_S1_c0(_tmp_6_inColor);
400 half
value = MatrixEffect_S1_c1(_tmp_6_inColor, sk_FragCoord.xy).w - 0.5;
402}
404{
405
406 half4 outputColor_S0;
407 outputColor_S0 = vcolor_S0;
410 output_S1 = Dither_S1(outputColor_S0);
411 {
412
413 sk_FragColor = output_S1 * outputCoverage_S0;
414 }
415}
416)");
417
418// This fragment shader is taken from GM_BlurDrawImage.
419COMPILER_BENCH(medium, R"(
420uniform float3x3 umatrix_S1_c0;
421uniform float3x3 umatrix_S2_c0_c0;
422uniform
float4 urect_S2_c0;
423sampler2D uTextureSampler_0_S1;
424sampler2D uTextureSampler_0_S2;
425flat in
half4 vcolor_S0;
426noperspective in
float2 vTransformedCoords_3_S0;
427half4 TextureEffect_S1_c0_c0(half4 _input)
428{
429 return sample(uTextureSampler_0_S1, vTransformedCoords_3_S0);
430}
431half4 MatrixEffect_S1_c0(half4 _input)
432{
433 return TextureEffect_S1_c0_c0(_input);
434}
435half4 DisableCoverageAsAlpha_S1(half4 _input)
436{
437 _input = MatrixEffect_S1_c0(_input);
438 half4 _tmp_0_inColor = _input;
439 return half4(_input);
440}
441half4 TextureEffect_S2_c0_c0_c0(half4 _input,
float2 _coords)
442{
443 return sample(uTextureSampler_0_S2, _coords).000r;
444}
445half4 MatrixEffect_S2_c0_c0(half4 _input,
float2 _coords)
446{
447 return TextureEffect_S2_c0_c0_c0(_input, float3x2(umatrix_S2_c0_c0) * _coords.xy1);
448}
450{
451 half4 _tmp_1_inColor = _input;
452 float2 _tmp_2_coords = _coords;
453 half xCoverage;
454 half yCoverage;
455 if (bool(int(1)))
456 {
457 half2 xy =
max(
half2(urect_S2_c0.xy - _tmp_2_coords),
half2(_tmp_2_coords - urect_S2_c0.zw));
458 xCoverage = MatrixEffect_S2_c0_c0(_tmp_1_inColor,
float2(
half2(xy.x, 0.5))).w;
459 yCoverage = MatrixEffect_S2_c0_c0(_tmp_1_inColor,
float2(
half2(xy.y, 0.5))).w;
460 }
461 else
462 {
464 xCoverage = (1.0 - MatrixEffect_S2_c0_c0(_tmp_1_inColor,
float2(
half2(
rect.x, 0.5))).w) - MatrixEffect_S2_c0_c0(_tmp_1_inColor,
float2(
half2(
rect.z, 0.5))).
w;
465 yCoverage = (1.0 - MatrixEffect_S2_c0_c0(_tmp_1_inColor,
float2(
half2(
rect.y, 0.5))).w) - MatrixEffect_S2_c0_c0(_tmp_1_inColor,
float2(
half2(
rect.w, 0.5))).
w;
466 }
467 return half4((_input * xCoverage) * yCoverage);
468}
469half4 DeviceSpace_S2(half4 _input)
470{
471 return RectBlur_S2_c0(_input, sk_FragCoord.xy);
472}
474{
475
476 half4 outputColor_S0;
477 outputColor_S0 = vcolor_S0;
480 output_S1 = DisableCoverageAsAlpha_S1(outputColor_S0);
482 output_S2 = DeviceSpace_S2(outputCoverage_S0);
483 {
484
485 sk_FragColor = output_S1 * output_S2;
486 }
487}
488)");
489
490// This fragment shader is taken from GM_lcdtext.
491COMPILER_BENCH(small, R"(
492sampler2D uTextureSampler_0_S0;
493noperspective in
float2 vTextureCoords_S0;
494flat in float vTexIndex_S0;
495noperspective in
half4 vinColor_S0;
497{
498
499 half4 outputColor_S0;
500 outputColor_S0 = vinColor_S0;
502 {
503 texColor = sample(uTextureSampler_0_S0, vTextureCoords_S0).rrrr;
504 }
505 half4 outputCoverage_S0 = texColor;
506 {
507
508 sk_FragColor = outputColor_S0 * outputCoverage_S0;
509 }
510}
511)");
512
513COMPILER_BENCH(tiny, "void main() { sk_FragColor =
half4(1); }
");
514
515#define GRAPHITE_BENCH(name, text) \
516 static constexpr char name##_SRC[] = text; \
517 DEF_BENCH(return new SkSLCompileBench(#name, name##_SRC, /*optimize=*/true, Output::kGrMtl);) \
518 DEF_BENCH(return new SkSLCompileBench(#name, name##_SRC, /*optimize=*/true, Output::kGrWGSL);)
519
520// This fragment shader is from the third tile on the top row of GM_gradients_2pt_conical_outside.
521GRAPHITE_BENCH(graphite_large, R"(
522layout(location=0) in flat int shadingSsboIndexVar;
523layout(location=1) in
float2 localCoordsVar;
524layout(location=2) in
float4 jacobian;
525layout(location=3) in
float4 edgeDistances;
526layout(location=4) in
float4 xRadii;
527layout(location=5) in
float4 yRadii;
528layout(location=6) in
float2 strokeParams;
529layout(location=7) in
float2 perPixelControl;
530struct FSUniformData
531{
532
534
539 float radius0_2;
540 float radius1_2;
541 int tilemode_2;
542 int colorSpace_2;
543 int doUnPremul_2;
544
545 int flags_3;
546 int srcKind_3;
547 half3x3 gamutTransform_3;
548 int dstKind_3;
549 half4x4 csXformCoeffs_3;
550
551 half range_4;
552}
553;
554layout (binding=2)
buffer FSUniforms
555{
556 FSUniformData fsUniformData[];
557}
558;
559
560layout(binding=0) sampler2D sampler_4;
561
562half4 ColorFilterShader_1(half4 inColor, half4 destColor,
float2 coords)
563{
564 return sk_color_space_transform(sk_conical_grad_8_shader(coords, fsUniformData[shadingSsboIndexVar].colors_2, fsUniformData[shadingSsboIndexVar].offsets_2, fsUniformData[shadingSsboIndexVar].point0_2, fsUniformData[shadingSsboIndexVar].point1_2, fsUniformData[shadingSsboIndexVar].radius0_2, fsUniformData[shadingSsboIndexVar].radius1_2, fsUniformData[shadingSsboIndexVar].tilemode_2, fsUniformData[shadingSsboIndexVar].colorSpace_2, fsUniformData[shadingSsboIndexVar].doUnPremul_2), fsUniformData[shadingSsboIndexVar].flags_3, fsUniformData[shadingSsboIndexVar].srcKind_3, fsUniformData[shadingSsboIndexVar].gamutTransform_3, fsUniformData[shadingSsboIndexVar].dstKind_3, fsUniformData[shadingSsboIndexVar].csXformCoeffs_3);
565}
567{
569
570 half4 outColor_0 = sk_solid_shader(fsUniformData[shadingSsboIndexVar].color_0);
571
572 half4 outColor_1 = ColorFilterShader_1(outColor_0,
half4(1), localCoordsVar);
573
574 half4 outColor_4 = sk_dither_shader(outColor_1, localCoordsVar, fsUniformData[shadingSsboIndexVar].range_4, sampler_4);
575
576 half4 outColor_5 = outColor_4;
577 half4 outputCoverage;
578 outputCoverage = analytic_rrect_coverage_fn(sk_FragCoord, jacobian, edgeDistances, xRadii, yRadii, strokeParams, perPixelControl);
579 sk_FragColor = outColor_5 * outputCoverage;
580}
581)");
582
583// This fragment shader is taken from GM_lcdtext.
584GRAPHITE_BENCH(graphite_small, R"(
585layout(location=0) in flat int shadingSsboIndexVar;
586layout(location=1) in
float2 textureCoords;
587layout(location=2) in half texIndex;
588layout(location=3) in half maskFormat;
589layout (binding=1) uniform StepUniforms
590{
591 layout(
offset=0) float4x4 subRunDeviceMatrix;
592 layout(
offset=64) float4x4 deviceToLocal;
594}
595;
596struct FSUniformData
597{
598
600}
601;
602layout (binding=2)
buffer FSUniforms
603{
604 FSUniformData fsUniformData[];
605}
606;
607layout(binding=0) sampler2D text_atlas_0;
608layout(binding=1) sampler2D text_atlas_1;
609layout(binding=2) sampler2D text_atlas_2;
610layout(binding=3) sampler2D text_atlas_3;
612{
614
615 half4 outColor_0 = sk_solid_shader(fsUniformData[shadingSsboIndexVar].color_0);
616
617 half4 outColor_1 = outColor_0;
618 half4 outputCoverage;
619 outputCoverage = bitmap_text_coverage_fn(sample_indexed_atlas(textureCoords, int(texIndex), text_atlas_0, text_atlas_1, text_atlas_2, text_atlas_3), int(maskFormat));
620 sk_FragColor = outColor_1 * outputCoverage;
621}
622)");
623
624#if defined(SK_BUILD_FOR_UNIX)
625
626#include <malloc.h>
627static int64_t heap_bytes_used() {
628 return (int64_t)mallinfo().uordblks;
629}
630
631#elif defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
632
633#include <malloc/malloc.h>
634static int64_t heap_bytes_used() {
635 malloc_statistics_t stats;
636 malloc_zone_pressure_relief(malloc_default_zone(), 0);
637 malloc_zone_statistics(malloc_default_zone(), &stats);
638 return (int64_t)stats.size_in_use;
639}
640
641#else
642
643static int64_t heap_bytes_used() {
644 return -1;
645}
646
647#endif
648
649static void bench(NanoJSONResultsWriter* log, const char* name, int bytes) {
650 SkDEBUGCODE(SkDebugf("%
s: %
d bytes\n
", name, bytes);)
651 log->beginObject(name); // test
652 log->beginObject("meta"); // config
653 log->appendS32("bytes", bytes); // sub_result
654 log->endObject(); // config
655 log->endObject(); // test
656}
657
658// These benchmarks aren't timed, they produce memory usage statistics. They run standalone, and
659// directly add their results to the nanobench log.
660void RunSkSLModuleBenchmarks(NanoJSONResultsWriter* log) {
661 // Heap used by a default compiler (with no modules loaded)
662 int64_t before = heap_bytes_used();
663 SkSL::Compiler compiler;
664 int baselineBytes = heap_bytes_used();
665 if (baselineBytes >= 0) {
666 baselineBytes = (baselineBytes - before);
667 bench(log, "sksl_compiler_baseline", baselineBytes);
668 }
669
670 // Heap used by a compiler with the two main GPU modules (fragment + vertex) and runtime effects
671 // (shader + color filter + blender) loaded. Ganesh will load all of these in regular usage.
672 before = heap_bytes_used();
673 compiler.moduleForProgramKind(SkSL::ProgramKind::kVertex);
674 compiler.moduleForProgramKind(SkSL::ProgramKind::kFragment);
675 compiler.moduleForProgramKind(SkSL::ProgramKind::kRuntimeColorFilter);
676 compiler.moduleForProgramKind(SkSL::ProgramKind::kRuntimeShader);
677 compiler.moduleForProgramKind(SkSL::ProgramKind::kRuntimeBlender);
678 compiler.moduleForProgramKind(SkSL::ProgramKind::kPrivateRuntimeColorFilter);
679 compiler.moduleForProgramKind(SkSL::ProgramKind::kPrivateRuntimeShader);
680 compiler.moduleForProgramKind(SkSL::ProgramKind::kPrivateRuntimeBlender);
681 int64_t gpuBytes = heap_bytes_used();
682 if (gpuBytes >= 0) {
683 gpuBytes = (gpuBytes - before) + baselineBytes;
684 bench(log, "sksl_compiler_gpu", gpuBytes);
685 }
686
687#if defined(SK_GRAPHITE)
688 // Heap used by a compiler with the Graphite modules loaded.
689 before = heap_bytes_used();
690 compiler.moduleForProgramKind(SkSL::ProgramKind::kGraphiteVertex);
691 compiler.moduleForProgramKind(SkSL::ProgramKind::kGraphiteFragment);
692 int64_t graphiteBytes = heap_bytes_used();
693 if (graphiteBytes >= 0) {
694 graphiteBytes = (graphiteBytes - before) + gpuBytes;
695 bench(log, "sksl_compiler_graphite", graphiteBytes);
696 }
697
698 // Heap used by a compiler with compute-shader support loaded.
699 before = heap_bytes_used();
700 compiler.moduleForProgramKind(SkSL::ProgramKind::kCompute);
701 int64_t computeBytes = heap_bytes_used();
702 if (computeBytes >= 0) {
703 computeBytes = (computeBytes - before) + baselineBytes;
704 bench(log, "sksl_compiler_compute", computeBytes);
705 }
706#endif
707
708 // Report the minified module sizes.
709 int compilerGPUBinarySize = std::size(SKSL_MINIFIED_sksl_shared) +
710 std::size(SKSL_MINIFIED_sksl_gpu) +
711 std::size(SKSL_MINIFIED_sksl_vert) +
712 std::size(SKSL_MINIFIED_sksl_frag) +
713 std::size(SKSL_MINIFIED_sksl_public) +
714 std::size(SKSL_MINIFIED_sksl_rt_shader);
715 bench(log, "sksl_binary_size_gpu", compilerGPUBinarySize);
716
717 int compilerGraphiteBinarySize = std::size(SKSL_MINIFIED_sksl_graphite_frag) +
718 std::size(SKSL_MINIFIED_sksl_graphite_vert);
719 bench(log, "sksl_binary_size_graphite", compilerGraphiteBinarySize);
720
721 int compilerGraphiteES2BinarySize = std::size(SKSL_MINIFIED_sksl_graphite_frag_es2) +
722 std::size(SKSL_MINIFIED_sksl_graphite_vert_es2);
723 bench(log, "sksl_binary_size_graphite_es2", compilerGraphiteES2BinarySize);
724
725 int compilerComputeBinarySize = std::size(SKSL_MINIFIED_sksl_compute);
726 bench(log, "sksl_binary_size_compute", compilerComputeBinarySize);
727}
728
729class SkSLModuleLoaderBench : public Benchmark {
730public:
731 SkSLModuleLoaderBench(const char* name, std::vector<SkSL::ProgramKind> moduleList)
732 : fName(name), fModuleList(std::move(moduleList)) {}
733
734 const char* onGetName() override {
735 return fName;
736 }
737
738 bool isSuitableFor(Backend backend) override {
739 return backend == Backend::kNonRendering;
740 }
741
742 bool shouldLoop() const override {
743 return false;
744 }
745
746 void onPreDraw(SkCanvas*) override {
747 SkSL::ModuleLoader::Get().unloadModules();
748 }
749
750 void onDraw(int loops, SkCanvas*) override {
751 SkASSERT(loops == 1);
752 SkSL::Compiler compiler;
753 for (SkSL::ProgramKind kind : fModuleList) {
754 compiler.moduleForProgramKind(kind);
755 }
756 }
757
758 const char* fName;
759 std::vector<SkSL::ProgramKind> fModuleList;
760};
761
762DEF_BENCH(return new SkSLModuleLoaderBench("sksl_module_loader_ganesh",
763 {
764 SkSL::ProgramKind::kVertex,
765 SkSL::ProgramKind::kFragment,
766 SkSL::ProgramKind::kRuntimeColorFilter,
767 SkSL::ProgramKind::kRuntimeShader,
768 SkSL::ProgramKind::kRuntimeBlender,
769 SkSL::ProgramKind::kPrivateRuntimeColorFilter,
770 SkSL::ProgramKind::kPrivateRuntimeShader,
771 SkSL::ProgramKind::kPrivateRuntimeBlender,
772 SkSL::ProgramKind::kCompute,
773 });)
774
775DEF_BENCH(return new SkSLModuleLoaderBench("sksl_module_loader_graphite",
776 {
777 SkSL::ProgramKind::kVertex,
778 SkSL::ProgramKind::kFragment,
779 SkSL::ProgramKind::kRuntimeColorFilter,
780 SkSL::ProgramKind::kRuntimeShader,
781 SkSL::ProgramKind::kRuntimeBlender,
782 SkSL::ProgramKind::kPrivateRuntimeColorFilter,
783 SkSL::ProgramKind::kPrivateRuntimeShader,
784 SkSL::ProgramKind::kPrivateRuntimeBlender,
785 SkSL::ProgramKind::kCompute,
786 SkSL::ProgramKind::kGraphiteVertex,
787 SkSL::ProgramKind::kGraphiteFragment,
788 });)
static unsigned clamp(SkFixed fx, int max)
VULKAN_HPP_DEFAULT_DISPATCH_LOADER_DYNAMIC_STORAGE auto & d
static const uint8_t buffer[]
static float max(float r, float g, float b)
sk_sp< SkBlender > blender SkRect rect
SINT T dot(const Vec< N, T > &a, const Vec< N, T > &b)
SIN Vec< N, float > sqrt(const Vec< N, float > &x)