65#define M(type) case StableKey::k##type : return "KnownRuntimeEffect_" #type;
67#define M2(type, initializer) case StableKey::k##type : return "KnownRuntimeEffect_" #type;
77std::string get_mangled_name(
const std::string& baseName,
int manglingSuffix) {
81std::string get_mangled_uniform_name(
const ShaderInfo& shaderInfo,
86 if (uniform.isPaintColor()) {
92 if (shaderInfo.ssboIndex()) {
98std::string get_mangled_sampler_name(
const TextureAndSampler& tex,
int manglingSuffix) {
99 return tex.name() + std::string(
"_") +
std::to_string(manglingSuffix);
103std::string emit_expression_for_entry(
const ShaderInfo& shaderInfo,
104 const ShaderNode* node,
105 ShaderSnippet::Args
args) {
106 return node->entry()->fExpressionGenerator(shaderInfo, node,
args);
112std::string emit_glue_code_for_entry(
const ShaderInfo& shaderInfo,
113 const ShaderNode* node,
114 const ShaderSnippet::Args&
args,
115 std::string* funcBody) {
116 std::string expr = emit_expression_for_entry(shaderInfo, node,
args);
117 std::string outputVar = get_mangled_name(
"outColor", node->keyIndex());
122 node->entry()->fName,
129void emit_preambles(
const ShaderInfo& shaderInfo,
131 std::string treeLabel,
132 std::string* preamble) {
133 for (
int i = 0; i < SkTo<int>(nodes.
size()); ++
i) {
134 const ShaderNode* node = nodes[
i];
136 std::string nextLabel = treeLabel.empty() ? nodeLabel
137 : (treeLabel +
"<-" + nodeLabel);
139 if (node->numChildren() > 0) {
140 emit_preambles(shaderInfo, node->children(), nextLabel, preamble);
143 std::string nodePreamble = node->entry()->fPreambleGenerator(shaderInfo, node);
144 if (!nodePreamble.empty()) {
148 node->keyIndex(), nextLabel.c_str(), node->entry()->fName,
149 nodePreamble.c_str());
190 const char* ssboIndex)
191 : fRuntimeEffectDictionary(rteDict)
192 , fSsboIndex(ssboIndex)
197 fRootNodes =
key.getRootNodes(dict, &fShaderNodeAlloc);
204 this->aggregateSnippetData(
root);
220 fBlendInfo = gBlendTable[
static_cast<int>(
fBlendMode)];
222 fSnippetRequirementFlags |=
root->requiredFlags();
227void ShaderInfo::aggregateSnippetData(
const ShaderNode* node) {
233 for (
const ShaderNode* child : node->
children()) {
234 this->aggregateSnippetData(child);
244 const char* outColor,
245 const char* inColor) {
246 switch (outputType) {
261 mainBody,
"%s = (1.0 - %s.a) * outputCoverage;", outColor, inColor);
265 mainBody,
"%s = (half4(1.0) - %s) * outputCoverage;", outColor, inColor);
284std::string ShaderInfo::toSkSL(
const Caps* caps,
286 bool useStorageBuffers,
287 int* numTexturesAndSamplersUsed,
288 int* numPaintUniforms,
289 int* renderStepUniformTotalBytes,
290 int* paintUniformsTotalBytes,
291 bool* hasGradientBuffer,
296 const bool useStepStorageBuffer = useStorageBuffers && hasStepUniforms;
297 const bool useShadingStorageBuffer = useStorageBuffers &&
step->performsShading();
298 const bool useGradientStorageBuffer = useStorageBuffers && (fSnippetRequirementFlags
301 const bool defineLocalCoordsVarying = this->needsLocalCoords();
304 useShadingStorageBuffer,
305 defineLocalCoordsVarying);
312 if (hasStepUniforms) {
313 if (useStepStorageBuffer) {
319 renderStepUniformTotalBytes);
323 bool wrotePaintColor =
false;
324 if (useShadingStorageBuffer) {
335 paintUniformsTotalBytes,
339 if (useGradientStorageBuffer) {
347 "layout (binding=%d) readonly buffer FSGradientBuffer {\n"
350 *hasGradientBuffer =
true;
356 if (
step->hasTextures()) {
357 preamble +=
step->texturesAndSamplersSkSL(bindingReqs, &binding);
361 if (numTexturesAndSamplersUsed) {
362 *numTexturesAndSamplersUsed = binding;
366 if (
step->emitsPrimitiveColor()) {
369 preamble +=
"half4 primitiveColor;";
375 emit_preambles(*
this, fRootNodes,
"", &preamble);
377 std::string mainBody =
"void main() {";
380 mainBody +=
"half4 initialColor = half4(0);";
382 if (useShadingStorageBuffer) {
389 if (
step->emitsPrimitiveColor()) {
390 mainBody +=
step->fragmentColorSkSL();
399 static constexpr char kUnusedDstColor[] =
"half4(1)";
400 static constexpr char kUnusedLocalCoords[] =
"float2(0)";
403 this->needsLocalCoords() ?
"localCoordsVar" : kUnusedLocalCoords};
407 clipShaderNode = node;
414 args.fPriorStageOutput = emit_glue_code_for_entry(*
this, node,
args, &mainBody);
420 args.fPriorStageOutput.c_str(),
424 const char* outColor =
args.fPriorStageOutput.c_str();
427 if (useStepStorageBuffer) {
429 "uint stepSsboIndex = %s.x;\n",
434 mainBody +=
"half4 outputCoverage = half4(1);";
435 mainBody +=
step->fragmentCoverageSkSL();
437 if (clipShaderNode) {
438 std::string clipShaderOutput =
439 emit_glue_code_for_entry(*
this, clipShaderNode,
args, &mainBody);
450 if (this->needsSurfaceColor()) {
465 "if (all(lessThanEqual(outputCoverage.rgb, half3(0)))) {"
473 "sk_FragColor = %s * outputCoverage + surfaceColor * (1.0 - outputCoverage);",
478 "half3 lerpRGB = mix(surfaceColor.aaa, %s.aaa, outputCoverage.rgb);"
479 "sk_FragColor.a = max(max(lerpRGB.r, lerpRGB.g), lerpRGB.b);",
484 fBlendInfo = {coverageBlendFormula.
equation(),
491 mainBody +=
"outputCoverage.a = max(max(outputCoverage.r, "
492 "outputCoverage.g), "
493 "outputCoverage.b);";
496 &mainBody, coverageBlendFormula.
primaryOutput(),
"sk_FragColor", outColor);
500 "sk_SecondaryFragColor",
510 return preamble +
"\n" + mainBody;
518 if (!keyView->isValid()) {
526 SkASSERT(fIDToPaintKey[(*existingEntry).asUInt()] == *keyView);
527 return *existingEntry;
534 fPaintKeyToID.set(
key, newID);
535 fIDToPaintKey.push_back(
key);
546 return fIDToPaintKey[codeID.
asUInt()];
550 return fBuiltInCodeSnippets[(
int)
id].fUniforms;
554 if (codeSnippetID < 0) {
559 return &fBuiltInCodeSnippets[codeSnippetID];
570 SkASSERT(fKnownRuntimeEffectCodeSnippets[knownRTECodeSnippetID].fPreambleGenerator);
571 return &fKnownRuntimeEffectCodeSnippets[knownRTECodeSnippetID];
578 if (userDefinedCodeSnippetID < SkTo<int>(fUserDefinedCodeSnippets.size())) {
579 return fUserDefinedCodeSnippets[userDefinedCodeSnippetID].get();
589std::string append_default_snippet_arguments(
const ShaderInfo& shaderInfo,
593 std::string
code =
"(";
595 const char* separator =
"";
634 for (
const std::string& childOutputVar : childOutputs) {
637 code += childOutputVar;
644std::string emit_helper_function(
const ShaderInfo& shaderInfo,
645 const ShaderNode* node) {
648 const ShaderSnippet* entry = node->entry();
649 std::string helperFnName = get_mangled_name(entry->fStaticFunctionName, node->keyIndex());
651 "half4 %s(half4 inColor, half4 destColor, float2 pos) {",
652 helperFnName.c_str());
654 const ShaderSnippet::Args
args = {
"inColor",
"destColor",
"pos"};
655 for (
const ShaderNode* child : node->children()) {
658 childOutputVarNames.
push_back(emit_glue_code_for_entry(shaderInfo, child,
args, &helperFn));
662 std::string snippetArgList = append_default_snippet_arguments(shaderInfo, node,
663 args, childOutputVarNames);
667 entry->fStaticFunctionName, snippetArgList.c_str());
678std::string GenerateDefaultExpression(
const ShaderInfo& shaderInfo,
679 const ShaderNode* node,
680 const ShaderSnippet::Args&
args) {
681 if (node->numChildren() == 0) {
683 return node->entry()->fStaticFunctionName +
684 append_default_snippet_arguments(shaderInfo, node,
args, {});
687 std::string helperFnName =
688 get_mangled_name(node->entry()->fStaticFunctionName, node->keyIndex());
690 "%s(%.*s, %.*s, %.*s)",
691 helperFnName.c_str(),
692 (
int)
args.fPriorStageOutput.size(),
args.fPriorStageOutput.data(),
693 (
int)
args.fBlenderDstColor.size(),
args.fBlenderDstColor.data(),
694 (
int)
args.fFragCoord.size(),
args.fFragCoord.data());
705std::string GenerateDefaultPreamble(
const ShaderInfo& shaderInfo,
706 const ShaderNode* node) {
707 if (node->numChildren() > 0) {
709 return emit_helper_function(shaderInfo, node);
717static constexpr Uniform kDstReadSampleUniforms[] = {
721static constexpr TextureAndSampler kDstReadSampleTexturesAndSamplers[] = {
725std::string GenerateDstReadSampleExpression(
const ShaderInfo& shaderInfo,
726 const ShaderNode* node,
727 const ShaderSnippet::Args&
args) {
728 const ShaderSnippet* entry = node->entry();
729 std::string sampler =
730 get_mangled_sampler_name(entry->fTexturesAndSamplers[0], node->keyIndex());
732 get_mangled_uniform_name(shaderInfo, entry->fUniforms[0], node->keyIndex());
733 std::string helperFnName = get_mangled_name(entry->fStaticFunctionName, node->keyIndex());
736 helperFnName.c_str(),
741std::string GenerateDstReadSamplePreamble(
const ShaderInfo& shaderInfo,
const ShaderNode* node) {
742 std::string helperFnName =
743 get_mangled_name(node->entry()->fStaticFunctionName, node->keyIndex());
746 "half4 surfaceColor;"
747 "half4 %s(float4 coords, sampler2D dstSampler) {"
748 "surfaceColor = sample(dstSampler, (sk_FragCoord.xy - coords.xy) * coords.zw);"
749 "return surfaceColor;"
751 helperFnName.c_str());
755std::string GenerateDstReadFetchExpression(
const ShaderInfo& shaderInfo,
756 const ShaderNode* node,
757 const ShaderSnippet::Args&
args) {
758 std::string helperFnName =
759 get_mangled_name(node->entry()->fStaticFunctionName, node->keyIndex());
764std::string GenerateDstReadFetchPreamble(
const ShaderInfo& shaderInfo,
const ShaderNode* node) {
765 std::string helperFnName =
766 get_mangled_name(node->entry()->fStaticFunctionName, node->keyIndex());
769 "half4 surfaceColor;"
771 "surfaceColor = sk_LastFragColor;"
772 "return surfaceColor;"
774 helperFnName.c_str());
778static constexpr int kNumClipShaderChildren = 1;
780std::string GenerateClipShaderExpression(
const ShaderInfo& shaderInfo,
781 const ShaderNode* node,
782 const ShaderSnippet::Args&
args) {
783 SkASSERT(node->numChildren() == kNumClipShaderChildren);
784 static constexpr char kUnusedSrcColor[] =
"half4(1)";
785 static constexpr char kUnusedDstColor[] =
"half4(1)";
786 return emit_expression_for_entry(
787 shaderInfo, node->child(0), {kUnusedSrcColor, kUnusedDstColor,
"sk_FragCoord.xy"});
790std::string GenerateClipShaderPreamble(
const ShaderInfo& shaderInfo,
const ShaderNode* node) {
796static constexpr int kFourStopGradient = 4;
797static constexpr int kEightStopGradient = 8;
799static constexpr Uniform kLinearGradientUniforms4[] = {
806static constexpr Uniform kLinearGradientUniforms8[] = {
813static constexpr Uniform kLinearGradientUniformsTexture[] = {
820static constexpr Uniform kLinearGradientUniformsBuffer[] = {
828static constexpr Uniform kRadialGradientUniforms4[] = {
835static constexpr Uniform kRadialGradientUniforms8[] = {
842static constexpr Uniform kRadialGradientUniformsTexture[] = {
848static constexpr Uniform kRadialGradientUniformsBuffer[] = {
856static constexpr Uniform kSweepGradientUniforms4[] = {
865static constexpr Uniform kSweepGradientUniforms8[] = {
874static constexpr Uniform kSweepGradientUniformsTexture[] = {
882static constexpr Uniform kSweepGradientUniformsBuffer[] = {
892static constexpr Uniform kConicalGradientUniforms4[] = {
903static constexpr Uniform kConicalGradientUniforms8[] = {
914static constexpr Uniform kConicalGradientUniformsTexture[] = {
924static constexpr Uniform kConicalGradientUniformsBuffer[] = {
936static constexpr TextureAndSampler kTextureGradientTexturesAndSamplers[] = {
937 {
"colorAndOffsetSampler"},
940static constexpr char kLinearGradient4Name[] =
"sk_linear_grad_4_shader";
941static constexpr char kLinearGradient8Name[] =
"sk_linear_grad_8_shader";
942static constexpr char kLinearGradientTextureName[] =
"sk_linear_grad_tex_shader";
943static constexpr char kLinearGradientBufferName[] =
"sk_linear_grad_buf_shader";
945static constexpr char kRadialGradient4Name[] =
"sk_radial_grad_4_shader";
946static constexpr char kRadialGradient8Name[] =
"sk_radial_grad_8_shader";
947static constexpr char kRadialGradientTextureName[] =
"sk_radial_grad_tex_shader";
948static constexpr char kRadialGradientBufferName[] =
"sk_radial_grad_buf_shader";
950static constexpr char kSweepGradient4Name[] =
"sk_sweep_grad_4_shader";
951static constexpr char kSweepGradient8Name[] =
"sk_sweep_grad_8_shader";
952static constexpr char kSweepGradientTextureName[] =
"sk_sweep_grad_tex_shader";
953static constexpr char kSweepGradientBufferName[] =
"sk_sweep_grad_buf_shader";
955static constexpr char kConicalGradient4Name[] =
"sk_conical_grad_4_shader";
956static constexpr char kConicalGradient8Name[] =
"sk_conical_grad_8_shader";
957static constexpr char kConicalGradientTextureName[] =
"sk_conical_grad_tex_shader";
958static constexpr char kConicalGradientBufferName[] =
"sk_conical_grad_buf_shader";
961static constexpr Uniform kSolidShaderUniforms[] = {
965static constexpr char kSolidShaderName[] =
"sk_solid_shader";
970static constexpr char kRGBPaintColorName[] =
"sk_rgb_opaque";
971static constexpr char kAlphaOnlyPaintColorName[] =
"sk_alpha_only";
974static constexpr Uniform kLocalMatrixShaderUniforms[] = {
978static constexpr int kNumLocalMatrixShaderChildren = 1;
980static constexpr char kLocalMatrixShaderName[] =
"LocalMatrix";
986std::string GenerateLocalMatrixPreamble(
const ShaderInfo& shaderInfo,
987 const ShaderNode* node) {
989 SkASSERT(node->numChildren() == kNumLocalMatrixShaderChildren);
992 static constexpr char kUnusedDestColor[] =
"half4(1)";
993 std::string childExpr = emit_expression_for_entry(shaderInfo, node->child(0),
994 {
"inColor", kUnusedDestColor,
"coords"});
995 std::string localMatrixUni =
996 get_mangled_uniform_name(shaderInfo, node->entry()->fUniforms[0], node->keyIndex());
998 std::string helperFnName =
999 get_mangled_name(node->entry()->fStaticFunctionName, node->keyIndex());
1001 "coords = (%s * coords.xy01).xy;"
1004 helperFnName.c_str(),
1005 localMatrixUni.c_str(),
1010static constexpr Uniform kImageShaderUniforms[] = {
1024static constexpr Uniform kCubicImageShaderUniforms[] = {
1038static constexpr Uniform kHWImageShaderUniforms[] = {
1048static constexpr TextureAndSampler kISTexturesAndSamplers[] = {
1052static_assert(0 ==
static_cast<int>(
SkTileMode::kClamp),
"ImageShader code depends on SkTileMode");
1053static_assert(1 ==
static_cast<int>(
SkTileMode::kRepeat),
"ImageShader code depends on SkTileMode");
1054static_assert(2 ==
static_cast<int>(
SkTileMode::kMirror),
"ImageShader code depends on SkTileMode");
1055static_assert(3 ==
static_cast<int>(
SkTileMode::kDecal),
"ImageShader code depends on SkTileMode");
1058 "ImageShader code depends on SkFilterMode");
1060 "ImageShader code depends on SkFilterMode");
1063 "ImageShader code depends on ReadSwizzle");
1065 "ImageShader code depends on ReadSwizzle");
1067 "ImageShader code depends on ReadSwizzle");
1069 "ImageShader code depends on ReadSwizzle");
1071 "ImageShader code depends on ReadSwizzle");
1073static constexpr char kImageShaderName[] =
"sk_image_shader";
1074static constexpr char kCubicImageShaderName[] =
"sk_cubic_image_shader";
1075static constexpr char kHWImageShaderName[] =
"sk_hw_image_shader";
1079static constexpr Uniform kYUVImageShaderUniforms[] = {
1096static constexpr Uniform kCubicYUVImageShaderUniforms[] = {
1111static constexpr Uniform kHWYUVImageShaderUniforms[] = {
1122static constexpr TextureAndSampler kYUVISTexturesAndSamplers[] = {
1129static constexpr char kYUVImageShaderName[] =
"sk_yuv_image_shader";
1130static constexpr char kCubicYUVImageShaderName[] =
"sk_cubic_yuv_image_shader";
1131static constexpr char kHWYUVImageShaderName[] =
"sk_hw_yuv_image_shader";
1134static constexpr Uniform kCoordClampShaderUniforms[] = {
1138static constexpr char kCoordClampShaderName[] =
"CoordClamp";
1140static constexpr int kNumCoordClampShaderChildren = 1;
1147std::string GenerateCoordClampPreamble(
const ShaderInfo& shaderInfo,
1148 const ShaderNode* node) {
1150 SkASSERT(node->numChildren() == kNumCoordClampShaderChildren);
1153 static constexpr char kUnusedDestColor[] =
"half4(1)";
1154 std::string childExpr = emit_expression_for_entry(shaderInfo, node->child(0),
1155 {
"inColor", kUnusedDestColor,
"coords"});
1157 std::string subsetUni =
1158 get_mangled_uniform_name(shaderInfo, node->entry()->fUniforms[0], node->keyIndex());
1160 std::string helperFnName =
1161 get_mangled_name(node->entry()->fStaticFunctionName, node->keyIndex());
1163 "coords = clamp(coords, %s.LT, %s.RB);"
1166 helperFnName.c_str(),
1174static constexpr Uniform kDitherShaderUniforms[] = {
1178static constexpr TextureAndSampler kDitherTexturesAndSamplers[] = {
1182static constexpr char kDitherShaderName[] =
"sk_dither_shader";
1185static constexpr Uniform kPerlinNoiseShaderUniforms[] = {
1193static constexpr TextureAndSampler kPerlinNoiseShaderTexturesAndSamplers[] = {
1194 {
"permutationsSampler" },
1198static constexpr char kPerlinNoiseShaderName[] =
"perlin_noise_shader";
1201static constexpr Uniform CoeffBlendderUniforms[] = {
1205static constexpr char kCoeffBlenderName[] =
"sk_coeff_blend";
1208static constexpr Uniform kBlendModeBlenderUniforms[] = {
1212static constexpr char kBlendModeBlenderName[] =
"sk_blend";
1215static constexpr int kNumBlendShaderChildren = 3;
1217std::string GenerateBlendShaderPreamble(
const ShaderInfo& shaderInfo,
1218 const ShaderNode* node) {
1220 SkASSERT(node->numChildren() == 3);
1225 "half4 %s(half4 inColor, half4 destColor, float2 pos) {",
1226 get_mangled_name(node->entry()->fStaticFunctionName, node->keyIndex()).c_str());
1229 const ShaderSnippet::Args
args = {
"inColor",
"destColor",
"pos"};
1230 std::string srcVar = emit_glue_code_for_entry(shaderInfo, node->child(0),
args, &helperFn);
1231 std::string dstVar = emit_glue_code_for_entry(shaderInfo, node->child(1),
args, &helperFn);
1234 static constexpr char kUnusedLocalCoords[] =
"float2(0)";
1236 std::string blendResultVar = emit_glue_code_for_entry(
1237 shaderInfo, node->child(2), {srcVar, dstVar, kUnusedLocalCoords}, &helperFn);
1242 blendResultVar.c_str());
1249 GraphitePipelineCallbacks(
const ShaderInfo& shaderInfo,
1250 const ShaderNode* node,
1251 std::string* preamble,
1253 : fShaderInfo(shaderInfo)
1255 , fPreamble(preamble)
1256 , fEffect(effect) {}
1259 std::string
result = get_mangled_name(std::string(decl->
var()->
name()), fNode->keyIndex());
1260 if (fShaderInfo.ssboIndex()) {
1266 void defineFunction(
const char* decl,
const char* body,
bool isMain)
override {
1270 "half4 %s(half4 inColor, half4 destColor, float2 coords) {"
1273 get_mangled_name(fNode->entry()->fName, fNode->keyIndex()).c_str(),
1280 void declareFunction(
const char* decl)
override {
1281 *fPreamble += std::string(decl);
1284 void defineStruct(
const char* definition)
override {
1285 *fPreamble += std::string(definition);
1288 void declareGlobal(
const char* declaration)
override {
1289 *fPreamble += std::string(declaration);
1292 std::string sampleShader(
int index, std::string coords)
override {
1293 return emit_expression_for_entry(fShaderInfo, fNode->child(index),
1294 {
"inColor",
"destColor", coords});
1297 std::string sampleColorFilter(
int index, std::string
color)
override {
1298 return emit_expression_for_entry(fShaderInfo, fNode->child(index),
1299 {color,
"destColor",
"coords"});
1302 std::string sampleBlender(
int index, std::string
src, std::string
dst)
override {
1303 return emit_expression_for_entry(fShaderInfo, fNode->child(index),
1304 {src, dst,
"coords"});
1307 std::string toLinearSrgb(std::string
color)
override {
1313 std::string helper = get_mangled_name(
"toLinearSRGB", fNode->keyIndex());
1321 std::string fromLinearSrgb(std::string
color)
override {
1327 std::string helper = get_mangled_name(
"fromLinearSRGB", fNode->keyIndex());
1334 std::string getMangledName(
const char*
name)
override {
1335 return get_mangled_name(
name, fNode->keyIndex());
1339 const ShaderInfo& fShaderInfo;
1340 const ShaderNode* fNode;
1341 std::string* fPreamble;
1345std::string GenerateRuntimeShaderPreamble(
const ShaderInfo& shaderInfo,
1346 const ShaderNode* node) {
1354 effect = shaderInfo.runtimeEffectDictionary()->find(node->codeSnippetId());
1360 std::string preamble;
1364 "half4 %s(half4 inColor) {"
1365 "return sk_color_space_transform(inColor, %s, %s, %s, %s, %s);"
1367 get_mangled_name(
"toLinearSRGB", node->keyIndex()).c_str(),
1369 node->keyIndex()).c_str(),
1371 node->keyIndex()).c_str(),
1373 node->keyIndex()).c_str(),
1375 node->keyIndex()).c_str(),
1377 node->keyIndex()).c_str());
1380 "half4 %s(half4 inColor) {"
1381 "return sk_color_space_transform(inColor, %s, %s, %s, %s, %s);"
1383 get_mangled_name(
"fromLinearSRGB", node->keyIndex()).c_str(),
1385 node->keyIndex()).c_str(),
1387 node->keyIndex()).c_str(),
1389 node->keyIndex()).c_str(),
1391 node->keyIndex()).c_str(),
1393 node->keyIndex()).c_str());
1396 GraphitePipelineCallbacks callbacks{shaderInfo, node, &preamble, effect};
1401std::string GenerateRuntimeShaderExpression(
const ShaderInfo& shaderInfo,
1402 const ShaderNode* node,
1403 const ShaderSnippet::Args&
args) {
1405 "%s(%.*s, %.*s, %.*s)",
1406 get_mangled_name(node->entry()->fName, node->keyIndex()).c_str(),
1407 (
int)
args.fPriorStageOutput.size(),
args.fPriorStageOutput.data(),
1408 (
int)
args.fBlenderDstColor.size(),
args.fBlenderDstColor.data(),
1409 (
int)
args.fFragCoord.size(),
args.fFragCoord.data());
1415static constexpr Uniform kMatrixColorFilterUniforms[] = {
1421static constexpr char kMatrixColorFilterName[] =
"sk_matrix_colorfilter";
1424static constexpr char kComposeName[] =
"Compose";
1426static constexpr int kNumComposeChildren = 2;
1429std::string GenerateNestedChildrenPreamble(
const ShaderInfo& shaderInfo,
1430 const ShaderNode* node) {
1431 SkASSERT(node->numChildren() == 2);
1434 static constexpr char kUnusedDestColor[] =
"half4(1)";
1435 std::string innerColor = emit_expression_for_entry(shaderInfo, node->child(0),
1436 {
"inColor", kUnusedDestColor,
"coords"});
1439 std::string outerColor = emit_expression_for_entry(shaderInfo, node->child(1),
1440 {innerColor, kUnusedDestColor,
"coords"});
1444 std::string helperFnName = get_mangled_name(node->entry()->fName, node->keyIndex());
1448 helperFnName.c_str(),
1449 outerColor.c_str());
1453static constexpr TextureAndSampler kTableColorFilterTexturesAndSamplers[] = {
1457static constexpr char kTableColorFilterName[] =
"sk_table_colorfilter";
1460static constexpr char kGaussianColorFilterName[] =
"sk_gaussian_colorfilter";
1463static constexpr Uniform kColorSpaceTransformUniforms[] = {
1472 "ColorSpaceTransform code depends on skcms_TFType");
1474 "ColorSpaceTransform code depends on skcms_TFType");
1476 "ColorSpaceTransform code depends on skcms_TFType");
1478 "ColorSpaceTransform code depends on skcms_TFType");
1480 "ColorSpaceTransform code depends on skcms_TFType");
1494static constexpr char kColorSpaceTransformName[] =
"sk_color_space_transform";
1497static constexpr char kErrorName[] =
"sk_error";
1500static constexpr char kPassthroughShaderName[] =
"sk_passthrough";
1504std::string GeneratePrimitiveColorExpression(
const ShaderInfo&,
1505 const ShaderNode* node,
1506 const ShaderSnippet::Args&) {
1507 return "primitiveColor";
1514#if defined(SK_DEBUG)
1515bool ShaderCodeDictionary::isValidID(
int snippetID)
const {
1516 if (snippetID < 0) {
1531 return userDefinedCodeSnippetID < SkTo<int>(fUserDefinedCodeSnippets.size());
1538 this->
lookup(
id).dump(
this,
id);
1542#if defined(GRAPHITE_TEST_UTILS)
1544int ShaderCodeDictionary::addRuntimeEffectSnippet(
const char* functionName) {
1547 fUserDefinedCodeSnippets.push_back(
1548 std::make_unique<ShaderSnippet>(
"UserDefined",
1553 GenerateDefaultExpression,
1554 GenerateDefaultPreamble,
1598const char* ShaderCodeDictionary::addTextToArena(std::string_view
text) {
1600 memcpy(textInArena,
text.data(),
text.size());
1601 textInArena[
text.size()] =
'\0';
1609 int numBaseUniforms = uniforms.
size();
1610 int xtraUniforms = 0;
1616 int numUniforms = numBaseUniforms + xtraUniforms;
1618 if (index >= numBaseUniforms) {
1622 const rteUniform* u;
1623 u = &uniforms[index];
1628 const char*
name = this->addTextToArena(u->name);
1632 return (u->flags & rteUniform::kArray_Flag) ?
Uniform(
name,
type, u->count)
1656 if (!fKnownRuntimeEffectCodeSnippets[index].fExpressionGenerator) {
1657 const char*
name = get_known_rte_name(
static_cast<StableKey>(stableKey));
1660 this->convertUniforms(effect),
1664 GenerateRuntimeShaderExpression,
1665 GenerateRuntimeShaderPreamble,
1675 RuntimeEffectKey
key;
1679 int32_t* existingCodeSnippetID = fRuntimeEffectMap.find(
key);
1680 if (existingCodeSnippetID) {
1681 return *existingCodeSnippetID;
1687 fUserDefinedCodeSnippets.push_back(
1688 std::make_unique<ShaderSnippet>(
"RuntimeEffect",
1689 this->convertUniforms(effect),
1693 GenerateRuntimeShaderExpression,
1694 GenerateRuntimeShaderPreamble,
1699 fRuntimeEffectMap.set(
key, newCodeSnippetID);
1700 return newCodeSnippetID;
1713 GenerateDefaultExpression,
1714 GenerateDefaultPreamble,
1718 "PassthroughShader",
1722 kPassthroughShaderName,
1723 GenerateDefaultExpression,
1724 GenerateDefaultPreamble,
1729 SkSpan(kSolidShaderUniforms),
1733 GenerateDefaultExpression,
1734 GenerateDefaultPreamble,
1739 SkSpan(kPaintColorUniforms),
1743 GenerateDefaultExpression,
1744 GenerateDefaultPreamble,
1748 "AlphaOnlyPaintColor",
1749 SkSpan(kPaintColorUniforms),
1752 kAlphaOnlyPaintColorName,
1753 GenerateDefaultExpression,
1754 GenerateDefaultPreamble,
1759 SkSpan(kLinearGradientUniforms4),
1762 kLinearGradient4Name,
1763 GenerateDefaultExpression,
1764 GenerateDefaultPreamble,
1769 SkSpan(kLinearGradientUniforms8),
1772 kLinearGradient8Name,
1773 GenerateDefaultExpression,
1774 GenerateDefaultPreamble,
1778 "LinearGradientTexture",
1779 SkSpan(kLinearGradientUniformsTexture),
1781 SkSpan(kTextureGradientTexturesAndSamplers),
1782 kLinearGradientTextureName,
1783 GenerateDefaultExpression,
1784 GenerateDefaultPreamble,
1788 "LinearGradientBuffer",
1789 SkSpan(kLinearGradientUniformsBuffer),
1792 kLinearGradientBufferName,
1793 GenerateDefaultExpression,
1794 GenerateDefaultPreamble,
1799 SkSpan(kRadialGradientUniforms4),
1802 kRadialGradient4Name,
1803 GenerateDefaultExpression,
1804 GenerateDefaultPreamble,
1809 SkSpan(kRadialGradientUniforms8),
1812 kRadialGradient8Name,
1813 GenerateDefaultExpression,
1814 GenerateDefaultPreamble,
1818 "RadialGradientTexture",
1819 SkSpan(kRadialGradientUniformsTexture),
1821 SkSpan(kTextureGradientTexturesAndSamplers),
1822 kRadialGradientTextureName,
1823 GenerateDefaultExpression,
1824 GenerateDefaultPreamble,
1828 "RadialGradientBuffer",
1829 SkSpan(kRadialGradientUniformsBuffer),
1832 kRadialGradientBufferName,
1833 GenerateDefaultExpression,
1834 GenerateDefaultPreamble,
1839 SkSpan(kSweepGradientUniforms4),
1842 kSweepGradient4Name,
1843 GenerateDefaultExpression,
1844 GenerateDefaultPreamble,
1849 SkSpan(kSweepGradientUniforms8),
1852 kSweepGradient8Name,
1853 GenerateDefaultExpression,
1854 GenerateDefaultPreamble,
1858 "SweepGradientTexture",
1859 SkSpan(kSweepGradientUniformsTexture),
1861 SkSpan(kTextureGradientTexturesAndSamplers),
1862 kSweepGradientTextureName,
1863 GenerateDefaultExpression,
1864 GenerateDefaultPreamble,
1868 "SweepGradientBuffer",
1869 SkSpan(kSweepGradientUniformsBuffer),
1872 kSweepGradientBufferName,
1873 GenerateDefaultExpression,
1874 GenerateDefaultPreamble,
1879 SkSpan(kConicalGradientUniforms4),
1882 kConicalGradient4Name,
1883 GenerateDefaultExpression,
1884 GenerateDefaultPreamble,
1889 SkSpan(kConicalGradientUniforms8),
1892 kConicalGradient8Name,
1893 GenerateDefaultExpression,
1894 GenerateDefaultPreamble,
1898 "ConicalGradientTexture",
1899 SkSpan(kConicalGradientUniformsTexture),
1901 SkSpan(kTextureGradientTexturesAndSamplers),
1902 kConicalGradientTextureName,
1903 GenerateDefaultExpression,
1904 GenerateDefaultPreamble,
1908 "ConicalGradientBuffer",
1909 SkSpan(kConicalGradientUniformsBuffer),
1912 kConicalGradientBufferName,
1913 GenerateDefaultExpression,
1914 GenerateDefaultPreamble,
1918 "LocalMatrixShader",
1919 SkSpan(kLocalMatrixShaderUniforms),
1922 kLocalMatrixShaderName,
1923 GenerateDefaultExpression,
1924 GenerateLocalMatrixPreamble,
1925 kNumLocalMatrixShaderChildren
1929 SkSpan(kImageShaderUniforms),
1931 SkSpan(kISTexturesAndSamplers),
1933 GenerateDefaultExpression,
1934 GenerateDefaultPreamble,
1939 SkSpan(kCubicImageShaderUniforms),
1941 SkSpan(kISTexturesAndSamplers),
1942 kCubicImageShaderName,
1943 GenerateDefaultExpression,
1944 GenerateDefaultPreamble,
1948 "HardwareImageShader",
1949 SkSpan(kHWImageShaderUniforms),
1951 SkSpan(kISTexturesAndSamplers),
1953 GenerateDefaultExpression,
1954 GenerateDefaultPreamble,
1959 SkSpan(kYUVImageShaderUniforms),
1961 SkSpan(kYUVISTexturesAndSamplers),
1962 kYUVImageShaderName,
1963 GenerateDefaultExpression,
1964 GenerateDefaultPreamble,
1968 "CubicYUVImageShader",
1969 SkSpan(kCubicYUVImageShaderUniforms),
1971 SkSpan(kYUVISTexturesAndSamplers),
1972 kCubicYUVImageShaderName,
1973 GenerateDefaultExpression,
1974 GenerateDefaultPreamble,
1979 SkSpan(kHWYUVImageShaderUniforms),
1981 SkSpan(kYUVISTexturesAndSamplers),
1982 kHWYUVImageShaderName,
1983 GenerateDefaultExpression,
1984 GenerateDefaultPreamble,
1989 SkSpan(kCoordClampShaderUniforms),
1992 kCoordClampShaderName,
1993 GenerateDefaultExpression,
1994 GenerateCoordClampPreamble,
1995 kNumCoordClampShaderChildren
1999 SkSpan(kDitherShaderUniforms),
2001 SkSpan(kDitherTexturesAndSamplers),
2003 GenerateDefaultExpression,
2004 GenerateDefaultPreamble,
2008 "PerlinNoiseShader",
2009 SkSpan(kPerlinNoiseShaderUniforms),
2011 SkSpan(kPerlinNoiseShaderTexturesAndSamplers),
2012 kPerlinNoiseShaderName,
2013 GenerateDefaultExpression,
2014 GenerateDefaultPreamble,
2019 "MatrixColorFilter",
2020 SkSpan(kMatrixColorFilterUniforms),
2023 kMatrixColorFilterName,
2024 GenerateDefaultExpression,
2025 GenerateDefaultPreamble,
2032 SkSpan(kTableColorFilterTexturesAndSamplers),
2033 kTableColorFilterName,
2034 GenerateDefaultExpression,
2035 GenerateDefaultPreamble,
2039 "GaussianColorFilter",
2043 kGaussianColorFilterName,
2044 GenerateDefaultExpression,
2045 GenerateDefaultPreamble,
2049 "ColorSpaceTransform",
2050 SkSpan(kColorSpaceTransformUniforms),
2053 kColorSpaceTransformName,
2054 GenerateDefaultExpression,
2055 GenerateDefaultPreamble,
2065 GenerateDefaultExpression,
2066 GenerateBlendShaderPreamble,
2067 kNumBlendShaderChildren
2071 SkSpan(CoeffBlendderUniforms),
2075 GenerateDefaultExpression,
2076 GenerateDefaultPreamble,
2081 SkSpan(kBlendModeBlenderUniforms),
2084 kBlendModeBlenderName,
2085 GenerateDefaultExpression,
2086 GenerateDefaultPreamble,
2096 GeneratePrimitiveColorExpression,
2097 GenerateDefaultPreamble,
2103 SkSpan(kDstReadSampleUniforms),
2105 SkSpan(kDstReadSampleTexturesAndSamplers),
2107 GenerateDstReadSampleExpression,
2108 GenerateDstReadSamplePreamble,
2117 GenerateDstReadFetchExpression,
2118 GenerateDstReadFetchPreamble,
2128 GenerateClipShaderExpression,
2129 GenerateClipShaderPreamble,
2130 kNumClipShaderChildren
2139 GenerateDefaultExpression,
2140 GenerateNestedChildrenPreamble,
2148 fBuiltInCodeSnippets[ffBlendModeID] = {
2155 GenerateDefaultExpression,
2156 GenerateDefaultPreamble,
static int step(int x, SkScalar min, SkScalar max)
#define SkDEBUGFAIL(message)
SK_API const char * SkBlendMode_Name(SkBlendMode blendMode)
@ kLastCoeffMode
last porter duff blend mode
@ kSrcOver
r = s + (1-sa)*d
@ kXor
r = s*(1-da) + d*(1-sa)
@ kSrcATop
r = s*da + d*(1-sa)
@ kDstATop
r = d*sa + s*(1-da)
@ kDstOver
r = d + (1-da)*s
constexpr SkPMColor4f SK_PMColor4fTRANSPARENT
#define SK_ALL_STABLEKEYS(M, M1, M2)
SkMeshSpecification::Uniform Uniform
SkSpan(Container &&) -> SkSpan< std::remove_pointer_t< decltype(std::data(std::declval< Container >()))> >
SkDEBUGCODE(SK_SPI) SkThreadID SkGetThreadID()
static void dump(const float m[20], SkYUVColorSpace cs, bool rgb2yuv)
T * makeArrayDefault(size_t count)
T * makeInitializedArray(size_t count, Initializer initializer)
static uint32_t StableKey(const SkRuntimeEffect &effect)
static uint32_t Hash(const SkRuntimeEffect &effect)
static const SkSL::Program & Program(const SkRuntimeEffect &effect)
static bool UsesColorTransform(const SkRuntimeEffect *effect)
size_t uniformSize() const
SkSpan< const Child > children() const
bool allowBlender() const
SkSpan< const Uniform > uniforms() const
std::string_view name() const
constexpr T * data() const
constexpr size_t size() const
const char * c_str() const
SkString asString() const
static constexpr Swizzle RGBA()
const ResourceBindingRequirements & resourceBindingRequirements() const
DstReadRequirement getDstReadRequirement() const
const SkSL::ShaderCaps * shaderCaps() const
bool storageBufferSupport() const
static constexpr PaintParamsKey Invalid()
static const char * ssboIndicesVarying()
PaintParamsKey lookup(UniquePaintParamsID) const SK_EXCLUDES(fSpinLock)
UniquePaintParamsID findOrCreate(PaintParamsKeyBuilder *) SK_EXCLUDES(fSpinLock)
int findOrCreateRuntimeEffectSnippet(const SkRuntimeEffect *effect)
SkSpan< const Uniform > getUniforms(BuiltInCodeSnippetID) const
const ShaderSnippet * getEntry(int codeSnippetID) const SK_EXCLUDES(fSpinLock)
const ShaderSnippet * entry() const
SkSpan< const ShaderNode * > children() const
SkEnumBitMask< SnippetRequirementFlags > requiredFlags() const
int32_t codeSnippetId() const
SkSpan< const uint32_t > data() const
static UniquePaintParamsID InvalidID()
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
const SkRuntimeEffect * GetKnownRuntimeEffect(StableKey stableKey)
static constexpr int kUnknownRuntimeEffectIDStart
static constexpr int kSkiaKnownRuntimeEffectsEnd
static constexpr int kSkiaBuiltInReservedCnt
static constexpr int kSkiaKnownRuntimeEffectsStart
static const int kStableKeyCnt
void ConvertProgram(const Program &program, const char *sampleCoords, const char *inputColor, const char *destColor, Callbacks *callbacks)
std::string printf(const char *fmt,...) SK_PRINTF_LIKE(1
std::string void appendf(std::string *str, const char *fmt,...) SK_PRINTF_LIKE(2
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
static constexpr int kFixedFunctionBlendModeIDOffset
std::string EmitPaintParamsUniforms(int bufferID, const Layout layout, SkSpan< const ShaderNode * > nodes, int *numUniforms, int *uniformsTotalBytes, bool *wrotePaintColor)
std::string EmitStorageBufferAccess(const char *bufferNamePrefix, const char *ssboIndex, const char *uniformName)
@ kFixedFunctionSrcATopBlendMode
@ kConicalGradientShader8
@ kConicalGradientShaderBuffer
@ kFixedFunctionDstATopBlendMode
@ kSweepGradientShaderTexture
@ kFixedFunctionSrcBlendMode
@ kFixedFunctionSrcOverBlendMode
@ kSweepGradientShaderBuffer
@ kConicalGradientShader4
@ kLinearGradientShaderTexture
@ kRadialGradientShaderBuffer
@ kFixedFunctionDstOverBlendMode
@ kFixedFunctionScreenBlendMode
@ kFixedFunctionDstBlendMode
@ kFixedFunctionDstOutBlendMode
@ kFixedFunctionSrcOutBlendMode
@ kFixedFunctionClearBlendMode
@ kFixedFunctionDstInBlendMode
@ kFixedFunctionSrcInBlendMode
@ kColorSpaceXformColorFilter
@ kConicalGradientShaderTexture
@ kFixedFunctionPlusBlendMode
@ kLinearGradientShaderBuffer
@ kFixedFunctionXorBlendMode
@ kRadialGradientShaderTexture
@ kFixedFunctionModulateBlendMode
static constexpr int kNoChildren
std::string EmitTexturesAndSamplers(const ResourceBindingRequirements &bindingReqs, SkSpan< const ShaderNode * > nodes, int *binding)
static constexpr Uniform kRuntimeEffectColorSpaceTransformUniforms[]
std::string EmitRenderStepStorageBuffer(int bufferID, SkSpan< const Uniform > uniforms)
std::string EmitRenderStepUniforms(int bufferID, const Layout layout, SkSpan< const Uniform > uniforms, int *renderStepUniformsTotalBytes)
std::string EmitVaryings(const RenderStep *step, const char *direction, bool emitSsboIndicesVarying, bool emitLocalCoordsVarying)
std::string EmitPaintParamsStorageBuffer(int bufferID, SkSpan< const ShaderNode * > nodes, int *numUniforms, bool *wrotePaintColor)
static constexpr char kRuntimeShaderName[]
static SkSLType uniform_type_to_sksl_type(const SkRuntimeEffect::Uniform &u)
void append_color_output(std::string *mainBody, BlendFormula::OutputType outputType, const char *outColor, const char *inColor)
std::string EmitUniformsFromStorageBuffer(const char *bufferNamePrefix, const char *ssboIndex, SkSpan< const Uniform > uniforms)
static constexpr int kBuiltInCodeSnippetIDCount
const char * BlendFuncName(SkBlendMode mode)
BlendFormula GetBlendFormula(bool isOpaque, bool hasCoverage, SkBlendMode xfermode)
BlendFormula GetLCDBlendFormula(SkBlendMode xfermode)
static constexpr bool BlendModifiesDst(BlendEquation equation, BlendCoeff srcCoeff, BlendCoeff dstCoeff)
static SkString to_string(int n)
const char * fFloatBufferArrayName
Layout fUniformBufferLayout
bool fSeparateTextureAndSamplerBinding
SkSpan< const Uniform > fUniforms
bool needsPriorStageOutput() const
bool needsBlenderDstColor() const
bool needsLocalCoords() const
SkSpan< const TextureAndSampler > fTexturesAndSamplers