Add children to the key when creating a Runtime Shader.

They aren't called yet, but they are visible in the output SkSL.
A followup CL will invoke them when `eval` is called.

Change-Id: I8c28c332d718a9a773365c6a18e476da97bff9ad
Bug: skia:13508
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/559096
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Robert Phillips <robertphillips@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
This commit is contained in:
John Stiles 2022-07-15 14:34:47 -04:00 committed by SkCQ
parent b67b9c6158
commit 2cf696124c
2 changed files with 23 additions and 2 deletions

View File

@ -1186,6 +1186,22 @@ public:
SkPipelineDataGatherer* gatherer) const override {
RuntimeShaderBlock::BeginBlock(keyContext, builder, gatherer,
{fEffect, this->getLocalMatrix(), fUniforms});
for (const SkRuntimeEffect::ChildPtr& child : fChildren) {
std::optional<ChildType> type = child.type();
if (type == ChildType::kShader) {
as_SB(child.shader())->addToKey(keyContext, builder, gatherer);
} else if (type == ChildType::kColorFilter) {
as_CFB(child.colorFilter())->addToKey(keyContext, builder, gatherer);
} else if (type == ChildType::kBlender) {
as_BB(child.blender())->addToKey(keyContext, builder, gatherer);
} else {
// Patch in a "passthrough" child effect that returns the input color as-is.
PassthroughShaderBlock::BeginBlock(keyContext, builder, gatherer);
builder->endBlock();
}
}
builder->endBlock();
}

View File

@ -683,8 +683,13 @@ void GenerateRuntimeShaderPreamble(const SkShaderInfo& shaderInfo,
SkASSERT(std::string_view(entry->fName) == kRuntimeShaderName); // the callbacks assume this
SkSL::PipelineStage::ConvertProgram(program, "coords", "inColor", "half4(1)", &callbacks);
// We don't support children here yet.
// Advance over the parent entry.
*entryIndex += 1;
// Emit the preambles for all of our child effects (and advance the entry-index past them).
for (int j = 0; j < entry->fNumChildren; ++j) {
emit_preamble_for_entry(shaderInfo, entryIndex, preamble);
}
#endif // defined(SK_GRAPHITE_ENABLED) && defined(SK_ENABLE_SKSL)
}
@ -951,7 +956,7 @@ int SkShaderCodeDictionary::findOrCreateRuntimeEffectSnippet(const SkRuntimeEffe
kRuntimeShaderName,
GenerateRuntimeShaderExpression,
GenerateRuntimeShaderPreamble,
/*numChildren=*/0,
(int)effect->children().size(),
/*dataPayloadExpectations=*/{});
fRuntimeEffectMap.set(key, newCodeSnippetID);
return newCodeSnippetID;