30#include "src/sksl/generated/sksl_shared.minified.sksl"
31#include "src/sksl/generated/sksl_compute.minified.sksl"
32#include "src/sksl/generated/sksl_frag.minified.sksl"
33#include "src/sksl/generated/sksl_gpu.minified.sksl"
34#include "src/sksl/generated/sksl_public.minified.sksl"
35#include "src/sksl/generated/sksl_rt_shader.minified.sksl"
36#include "src/sksl/generated/sksl_vert.minified.sksl"
37#include "src/sksl/generated/sksl_graphite_frag.minified.sksl"
38#include "src/sksl/generated/sksl_graphite_vert.minified.sksl"
39#include "src/sksl/generated/sksl_graphite_frag_es2.minified.sksl"
40#include "src/sksl/generated/sksl_graphite_vert_es2.minified.sksl"
45 return "sksl_compiler_startup";
53 for (
int i = 0;
i < loops;
i++) {
87 : fName(
std::string(
"sksl_") + (
optimize ?
"" :
"unoptimized_") +
102 return fName.c_str();
106#if !defined(SK_GRAPHITE)
123 auto fixup = [
this](
const char* input,
const char* replacement) {
124 fSrc = std::regex_replace(fSrc,
std::regex(input), replacement);
131 fixup(R
"(void main\(\))", "half4 main(float2 xy)");
132 fixup(R
"(sk_FragColor =)", "return");
133 fixup(R
"(sk_FragCoord)", "_FragCoord");
134 fixup(R
"(sampler2D )", "uniform shader ");
135 fixup(R
"((flat |noperspective |)in )", "uniform ");
136 fixup(R
"(sample\(([A-Za-z0-9_]+), ([A-Za-z0-9_]+)\))", "$01.eval($02)");
137 fSrc =
"#version 300\nuniform float4 _FragCoord;\n" + fSrc;
150 for (
int i = 0;
i < loops;
i++) {
151 std::unique_ptr<SkSL::Program> program = fCompiler.
convertProgram(kind, fSrc,
193 program, *
main->definition(),
nullptr,
false);
200 float uniformBuffer[1024];
201 if (rasterProg->numUniforms() > (
int)
std::size(uniformBuffer)) {
208 rasterProg->appendStages(&pipeline,
211 SkSpan{uniformBuffer, rasterProg->numUniforms()});
228#define COMPILER_BENCH(name, text) \
229 static constexpr char name ## _SRC[] = text; \
230 DEF_BENCH(return new SkSLCompileBench(#name, name##_SRC, false, Output::kNone);) \
231 DEF_BENCH(return new SkSLCompileBench(#name, name##_SRC, true, Output::kNone);) \
232 DEF_BENCH(return new SkSLCompileBench(#name, name##_SRC, true, Output::kGLSL);) \
233 DEF_BENCH(return new SkSLCompileBench(#name, name##_SRC, true, Output::kMetal);) \
234 DEF_BENCH(return new SkSLCompileBench(#name, name##_SRC, true, Output::kSPIRV);) \
235 DEF_BENCH(return new SkSLCompileBench(#name, name##_SRC, true, Output::kSkRP);)
240uniform half4 uthresholds1_7_S1_c0_c0_c0;
241uniform half4 uthresholds9_13_S1_c0_c0_c0;
242uniform float4 uscale_S1_c0_c0_c0[4];
243uniform float4 ubias_S1_c0_c0_c0[4];
244uniform half uinvR1_S1_c0_c0_c1_c0;
245uniform half ufx_S1_c0_c0_c1_c0;
246uniform float3x3 umatrix_S1_c0_c0_c1;
247uniform half4 uleftBorderColor_S1_c0_c0;
248uniform half4 urightBorderColor_S1_c0_c0;
249uniform float3x3 umatrix_S1_c1;
250uniform half urange_S1;
251sampler2D uTextureSampler_0_S1;
252flat in half4 vcolor_S0;
253noperspective in float2 vTransformedCoords_6_S0;
254half4 UnrolledBinaryColorizer_S1_c0_c0_c0(half4 _input, float2 _coords)
256 half4 _tmp_0_inColor = _input;
257 float2 _tmp_1_coords = _coords;
258 half t = half(_tmp_1_coords.x);
262 if (t < uthresholds1_7_S1_c0_c0_c0.y)
264 if (t < uthresholds1_7_S1_c0_c0_c0.x)
266 s = uscale_S1_c0_c0_c0[0];
267 b = ubias_S1_c0_c0_c0[0];
271 s = uscale_S1_c0_c0_c0[1];
272 b = ubias_S1_c0_c0_c0[1];
277 if (t < uthresholds1_7_S1_c0_c0_c0.z)
279 s = uscale_S1_c0_c0_c0[2];
280 b = ubias_S1_c0_c0_c0[2];
284 s = uscale_S1_c0_c0_c0[3];
285 b = ubias_S1_c0_c0_c0[3];
289 return half4(half4(float(t) * s + b));
291half4 TwoPointConicalFocalLayout_S1_c0_c0_c1_c0(half4 _input)
293 half4 _tmp_2_inColor = _input;
294 float2 _tmp_3_coords = vTransformedCoords_6_S0;
300 x_t = dot(_tmp_3_coords, _tmp_3_coords) / _tmp_3_coords.x;
302 else if (bool(int(0)))
304 x_t = length(_tmp_3_coords) - _tmp_3_coords.x * float(uinvR1_S1_c0_c0_c1_c0);
308 float temp = _tmp_3_coords.x * _tmp_3_coords.x - _tmp_3_coords.y * _tmp_3_coords.y;
311 if (bool(int(0)) || !bool(int(1)))
313 x_t = -sqrt(temp) - _tmp_3_coords.x * float(uinvR1_S1_c0_c0_c1_c0);
317 x_t = sqrt(temp) - _tmp_3_coords.x * float(uinvR1_S1_c0_c0_c1_c0);
336 t = x_t + float(ufx_S1_c0_c0_c1_c0);
347 t = -x_t + float(ufx_S1_c0_c0_c1_c0);
354 return half4(half4(half(t), v, 0.0, 0.0));
356half4 MatrixEffect_S1_c0_c0_c1(half4 _input)
358 return TwoPointConicalFocalLayout_S1_c0_c0_c1_c0(_input);
360half4 ClampedGradient_S1_c0_c0(half4 _input)
362 half4 _tmp_4_inColor = _input;
363 half4 t = MatrixEffect_S1_c0_c0_c1(_tmp_4_inColor);
365 if (!bool(int(0)) && t.y < 0.0)
367 outColor = half4(0.0);
371 outColor = uleftBorderColor_S1_c0_c0;
375 outColor = urightBorderColor_S1_c0_c0;
379 outColor = UnrolledBinaryColorizer_S1_c0_c0_c0(_tmp_4_inColor, float2(half2(t.x, 0.0)));
381 return half4(outColor);
383half4 DisableCoverageAsAlpha_S1_c0(half4 _input)
385 _input = ClampedGradient_S1_c0_c0(_input);
386 half4 _tmp_5_inColor = _input;
387 return half4(_input);
389half4 TextureEffect_S1_c1_c0(half4 _input, float2 _coords)
391 return sample(uTextureSampler_0_S1, _coords).000r;
393half4 MatrixEffect_S1_c1(half4 _input, float2 _coords)
395 return TextureEffect_S1_c1_c0(_input, float3x2(umatrix_S1_c1) * _coords.xy1);
397half4 Dither_S1(half4 _input)
399 half4 _tmp_6_inColor = _input;
400 half4 color = DisableCoverageAsAlpha_S1_c0(_tmp_6_inColor);
401 half value = MatrixEffect_S1_c1(_tmp_6_inColor, sk_FragCoord.xy).w - 0.5;
402 return half4(half4(clamp(color.xyz + value * urange_S1, 0.0, color.w), color.w));
406 // Stage 0, QuadPerEdgeAAGeometryProcessor
407 half4 outputColor_S0;
408 outputColor_S0 = vcolor_S0;
409 const half4 outputCoverage_S0 = half4(1);
411 output_S1 = Dither_S1(outputColor_S0);
413 // Xfer Processor: Porter Duff
414 sk_FragColor = output_S1 * outputCoverage_S0;
421uniform float3x3 umatrix_S1_c0;
422uniform float3x3 umatrix_S2_c0_c0;
423uniform float4 urect_S2_c0;
424sampler2D uTextureSampler_0_S1;
425sampler2D uTextureSampler_0_S2;
426flat in half4 vcolor_S0;
427noperspective in float2 vTransformedCoords_3_S0;
428half4 TextureEffect_S1_c0_c0(half4 _input)
430 return sample(uTextureSampler_0_S1, vTransformedCoords_3_S0);
432half4 MatrixEffect_S1_c0(half4 _input)
434 return TextureEffect_S1_c0_c0(_input);
436half4 DisableCoverageAsAlpha_S1(half4 _input)
438 _input = MatrixEffect_S1_c0(_input);
439 half4 _tmp_0_inColor = _input;
440 return half4(_input);
442half4 TextureEffect_S2_c0_c0_c0(half4 _input, float2 _coords)
444 return sample(uTextureSampler_0_S2, _coords).000r;
446half4 MatrixEffect_S2_c0_c0(half4 _input, float2 _coords)
448 return TextureEffect_S2_c0_c0_c0(_input, float3x2(umatrix_S2_c0_c0) * _coords.xy1);
450half4 RectBlur_S2_c0(half4 _input, float2 _coords)
452 half4 _tmp_1_inColor = _input;
453 float2 _tmp_2_coords = _coords;
458 half2 xy = max(half2(urect_S2_c0.xy - _tmp_2_coords), half2(_tmp_2_coords - urect_S2_c0.zw));
459 xCoverage = MatrixEffect_S2_c0_c0(_tmp_1_inColor, float2(half2(xy.x, 0.5))).w;
460 yCoverage = MatrixEffect_S2_c0_c0(_tmp_1_inColor, float2(half2(xy.y, 0.5))).w;
464 half4 rect = half4(half2(urect_S2_c0.xy - _tmp_2_coords), half2(_tmp_2_coords - urect_S2_c0.zw));
465 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;
466 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;
468 return half4((_input * xCoverage) * yCoverage);
470half4 DeviceSpace_S2(half4 _input)
472 return RectBlur_S2_c0(_input, sk_FragCoord.xy);
476 // Stage 0, QuadPerEdgeAAGeometryProcessor
477 half4 outputColor_S0;
478 outputColor_S0 = vcolor_S0;
479 const half4 outputCoverage_S0 = half4(1);
481 output_S1 = DisableCoverageAsAlpha_S1(outputColor_S0);
483 output_S2 = DeviceSpace_S2(outputCoverage_S0);
485 // Xfer Processor: Porter Duff
486 sk_FragColor = output_S1 * output_S2;
493sampler2D uTextureSampler_0_S0;
494noperspective in float2 vTextureCoords_S0;
495flat in float vTexIndex_S0;
496noperspective in half4 vinColor_S0;
499 // Stage 0, BitmapText
500 half4 outputColor_S0;
501 outputColor_S0 = vinColor_S0;
504 texColor = sample(uTextureSampler_0_S0, vTextureCoords_S0).rrrr;
506 half4 outputCoverage_S0 = texColor;
508 // Xfer Processor: Porter Duff
509 sk_FragColor = outputColor_S0 * outputCoverage_S0;
516#define GRAPHITE_BENCH(name, text) \
517 static constexpr char name##_SRC[] = text; \
518 DEF_BENCH(return new SkSLCompileBench(#name, name##_SRC, true, Output::kGrMtl);) \
519 DEF_BENCH(return new SkSLCompileBench(#name, name##_SRC, true, Output::kGrWGSL);)
523layout(location=0) in flat int shadingSsboIndexVar;
524layout(location=1) in float2 localCoordsVar;
525layout(location=2) in float4 jacobian;
526layout(location=3) in float4 edgeDistances;
527layout(location=4) in float4 xRadii;
528layout(location=5) in float4 yRadii;
529layout(location=6) in float2 strokeParams;
530layout(location=7) in float2 perPixelControl;
533 // 0 - SolidColor uniforms
535 // 2 - ConicalGradient8 uniforms
545 // 3 - ColorSpaceTransform uniforms
548 half3x3 gamutTransform_3;
550 half4x4 csXformCoeffs_3;
551 // 4 - DitherShader uniforms
555layout (binding=2) buffer FSUniforms
557 FSUniformData fsUniformData[];
560// 4 - DitherShader samplers
561layout(binding=0) sampler2D sampler_4;
562// [1] 1: ColorFilterShader
563half4 ColorFilterShader_1(half4 inColor, half4 destColor, float2 coords)
565 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);
569 half4 initialColor = half4(0);
571 half4 outColor_0 = sk_solid_shader(fsUniformData[shadingSsboIndexVar].color_0);
572 // [1] ColorFilterShader
573 half4 outColor_1 = ColorFilterShader_1(outColor_0, half4(1), localCoordsVar);
575 half4 outColor_4 = sk_dither_shader(outColor_1, localCoordsVar, fsUniformData[shadingSsboIndexVar].range_4, sampler_4);
577 half4 outColor_5 = outColor_4;
578 half4 outputCoverage;
579 outputCoverage = analytic_rrect_coverage_fn(sk_FragCoord, jacobian, edgeDistances, xRadii, yRadii, strokeParams, perPixelControl);
580 sk_FragColor = outColor_5 * outputCoverage;
586layout(location=0) in flat int shadingSsboIndexVar;
587layout(location=1) in float2 textureCoords;
588layout(location=2) in half texIndex;
589layout(location=3) in half maskFormat;
590layout (binding=1) uniform StepUniforms
592 layout(offset=0) float4x4 subRunDeviceMatrix;
593 layout(offset=64) float4x4 deviceToLocal;
594 layout(offset=128) float2 atlasSizeInv;
599 // 0 - SolidColor uniforms
603layout (binding=2) buffer FSUniforms
605 FSUniformData fsUniformData[];
608layout(binding=0) sampler2D text_atlas_0;
609layout(binding=1) sampler2D text_atlas_1;
610layout(binding=2) sampler2D text_atlas_2;
611layout(binding=3) sampler2D text_atlas_3;
614 half4 initialColor = half4(0);
616 half4 outColor_0 = sk_solid_shader(fsUniformData[shadingSsboIndexVar].color_0);
618 half4 outColor_1 = outColor_0;
619 half4 outputCoverage;
620 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));
621 sk_FragColor = outColor_1 * outputCoverage;
625#if defined(SK_BUILD_FOR_UNIX)
629 return (int64_t)mallinfo().uordblks;
632#elif defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_FOR_IOS)
634#include <malloc/malloc.h>
636 malloc_statistics_t
stats;
637 malloc_zone_pressure_relief(malloc_default_zone(), 0);
638 malloc_zone_statistics(malloc_default_zone(), &
stats);
639 return (int64_t)
stats.size_in_use;
653 log->beginObject(
"meta");
654 log->appendS32(
"bytes", bytes);
666 if (baselineBytes >= 0) {
667 baselineBytes = (baselineBytes - before);
668 bench(
log,
"sksl_compiler_baseline", baselineBytes);
684 gpuBytes = (gpuBytes - before) + baselineBytes;
685 bench(
log,
"sksl_compiler_gpu", gpuBytes);
688#if defined(SK_GRAPHITE)
694 if (graphiteBytes >= 0) {
695 graphiteBytes = (graphiteBytes - before) + gpuBytes;
696 bench(
log,
"sksl_compiler_graphite", graphiteBytes);
703 if (computeBytes >= 0) {
704 computeBytes = (computeBytes - before) + baselineBytes;
705 bench(
log,
"sksl_compiler_compute", computeBytes);
710 int compilerGPUBinarySize =
std::size(SKSL_MINIFIED_sksl_shared) +
716 bench(
log,
"sksl_binary_size_gpu", compilerGPUBinarySize);
718 int compilerGraphiteBinarySize =
std::size(SKSL_MINIFIED_sksl_graphite_frag) +
719 std::size(SKSL_MINIFIED_sksl_graphite_vert);
720 bench(
log,
"sksl_binary_size_graphite", compilerGraphiteBinarySize);
722 int compilerGraphiteES2BinarySize =
std::size(SKSL_MINIFIED_sksl_graphite_frag_es2) +
723 std::size(SKSL_MINIFIED_sksl_graphite_vert_es2);
724 bench(
log,
"sksl_binary_size_graphite_es2", compilerGraphiteES2BinarySize);
726 int compilerComputeBinarySize =
std::size(SKSL_MINIFIED_sksl_compute);
727 bench(
log,
"sksl_binary_size_compute", compilerComputeBinarySize);
755 compiler.moduleForProgramKind(kind);
SkAssertResult(font.textToGlyphs("Hello", 5, SkTextEncoding::kUTF8, glyphs, std::size(glyphs))==count)
#define SK_ABORT(message,...)
void SK_SPI SkDebugf(const char format[],...) SK_PRINTF_LIKE(1
static SkTileMode optimize(SkTileMode tm, int dimension)
void RunSkSLModuleBenchmarks(NanoJSONResultsWriter *log)
static int64_t heap_bytes_used()
#define GRAPHITE_BENCH(name, text)
DEF_BENCH(return new SkSLModuleLoaderBench("sksl_module_loader_ganesh", { SkSL::ProgramKind::kVertex, SkSL::ProgramKind::kFragment, SkSL::ProgramKind::kRuntimeColorFilter, SkSL::ProgramKind::kRuntimeShader, SkSL::ProgramKind::kRuntimeBlender, SkSL::ProgramKind::kPrivateRuntimeColorFilter, SkSL::ProgramKind::kPrivateRuntimeShader, SkSL::ProgramKind::kPrivateRuntimeBlender, SkSL::ProgramKind::kCompute, });) DEF_BENCH(return new SkSLModuleLoaderBench("sksl_module_loader_graphite"
static void bench(NanoJSONResultsWriter *log, const char *name, int bytes)
#define COMPILER_BENCH(name, text)
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
const GrShaderCaps * shaderCaps() const
static const char * output_string(Output output)
SkSLCompileBench(std::string name, const char *src, bool optimize, Output output)
bool usesGraphite() const
void onDraw(int loops, SkCanvas *canvas) override
static bool CompileToSkRP(const SkSL::Program &program)
const char * onGetName() override
bool isSuitableFor(Backend backend) override
bool usesRuntimeShader() const
const char * onGetName() override
void onDraw(int loops, SkCanvas *) override
bool isSuitableFor(Backend backend) override
void onDraw(int loops, SkCanvas *) override
bool shouldLoop() const override
SkSLModuleLoaderBench(const char *name, std::vector< SkSL::ProgramKind > moduleList)
void onPreDraw(SkCanvas *) override
const char * onGetName() override
bool isSuitableFor(Backend backend) override
std::vector< SkSL::ProgramKind > fModuleList
std::string errorText(bool showCount=true)
std::unique_ptr< Program > convertProgram(ProgramKind kind, std::string programSource, const ProgramSettings &settings)
static ModuleLoader Get()
bool ToSPIRV(Program &program, const ShaderCaps *caps, OutputStream &out)
bool ToWGSL(Program &program, const ShaderCaps *caps, OutputStream &out)
bool ToGLSL(Program &program, const ShaderCaps *caps, OutputStream &out)
bool ToMetal(Program &program, const ShaderCaps *caps, OutputStream &out)
@ kPrivateRuntimeColorFilter
std::unique_ptr< RP::Program > MakeRasterPipelineProgram(const SkSL::Program &program, const FunctionDefinition &function, DebugTracePriv *debugTrace, bool writeTraceOps)
DEF_SWITCHES_START aot vmservice shared library name
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
const FunctionDeclaration * getFunction(const char *functionName) const