[graphite] Remove custom glue code for local matrix and blend shaders
We now pass the child output variable names into the snippet code after all the uniforms. This leaves the following 3 custom glue code generators: GenerateImageShaderGlueCode -- sampler GenerateFixedFunctionBlenderGlueCode -- prior stage's output GenerateShaderBasedBlenderGlueCode -- dst read & prior stage's output Bug: skia:12701 Change-Id: I9185d8f292cc45d351218b95fa6d7d70d639e2f6 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/536098 Commit-Queue: Robert Phillips <robertphillips@google.com> Reviewed-by: Michael Ludwig <michaelludwig@google.com>
This commit is contained in:
parent
33fe2f5609
commit
6cd730f8f2
@ -286,17 +286,19 @@ namespace {
|
||||
using DataPayloadField = SkPaintParamsKey::DataPayloadField;
|
||||
|
||||
// The default glue code just calls a helper function with the signature:
|
||||
// half4 fStaticFunctionName(/* all uniforms as parameters */);
|
||||
// half4 fStaticFunctionName(/* all uniforms as parameters */,
|
||||
// /* all child output variable names as parameters */);
|
||||
// and stores the result in a variable named "resultName".
|
||||
std::string GenerateDefaultGlueCode(const std::string& resultName,
|
||||
int entryIndex,
|
||||
const SkPaintParamsKey::BlockReader& reader,
|
||||
const std::string& priorStageOutputName,
|
||||
const std::vector<std::string>& childNames,
|
||||
const std::vector<std::string>& childOutputVarNames,
|
||||
int indent) {
|
||||
SkASSERT(childNames.empty());
|
||||
|
||||
const SkShaderSnippet* entry = reader.entry();
|
||||
|
||||
SkASSERT((int)childOutputVarNames.size() == entry->numExpectedChildren());
|
||||
|
||||
if (entry->needsLocalCoords()) {
|
||||
// Every snippet that requests local coordinates must have a localMatrix as its first
|
||||
// uniform
|
||||
@ -320,7 +322,13 @@ std::string GenerateDefaultGlueCode(const std::string& resultName,
|
||||
} else {
|
||||
result += entry->getMangledUniformName(i, entryIndex);
|
||||
}
|
||||
if (i+1 < entry->fUniforms.size()) {
|
||||
if (i+1 < entry->fUniforms.size() + childOutputVarNames.size()) {
|
||||
result += ", ";
|
||||
}
|
||||
}
|
||||
for (size_t i = 0; i < childOutputVarNames.size(); ++i) {
|
||||
result += childOutputVarNames[i].c_str();
|
||||
if (i+1 < childOutputVarNames.size()) {
|
||||
result += ", ";
|
||||
}
|
||||
}
|
||||
@ -369,33 +377,6 @@ static constexpr int kNumLocalMatrixShaderChildren = 1;
|
||||
|
||||
static constexpr char kLocalMatrixShaderName[] = "sk_local_matrix_shader";
|
||||
|
||||
// This exists as custom glue code to handle passing the result of the child into the
|
||||
// static function. If children were, somehow, handled in the default glue code, we could remove
|
||||
// this.
|
||||
std::string GenerateLocalMatrixShaderGlueCode(const std::string& resultName,
|
||||
int entryIndex,
|
||||
const SkPaintParamsKey::BlockReader& reader,
|
||||
const std::string& priorStageOutputName,
|
||||
const std::vector<std::string>& childOutputVarNames,
|
||||
int indent) {
|
||||
SkASSERT(childOutputVarNames.size() == kNumLocalMatrixShaderChildren);
|
||||
|
||||
const SkShaderSnippet* entry = reader.entry();
|
||||
|
||||
std::string localMatrixName = entry->getMangledUniformName(0, entryIndex);
|
||||
|
||||
std::string result;
|
||||
|
||||
add_indent(&result, indent);
|
||||
SkSL::String::appendf(&result,
|
||||
"%s = %s(%s, %s);\n",
|
||||
resultName.c_str(),
|
||||
entry->fStaticFunctionName,
|
||||
localMatrixName.c_str(),
|
||||
childOutputVarNames[0].c_str());
|
||||
return result;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
static constexpr int kNumImageShaderUniforms = 6;
|
||||
static constexpr SkUniform kImageShaderUniforms[kNumImageShaderUniforms] = {
|
||||
@ -475,33 +456,7 @@ static constexpr SkUniform kBlendShaderUniforms[kNumBlendShaderUniforms] = {
|
||||
|
||||
static constexpr int kNumBlendShaderChildren = 2;
|
||||
|
||||
static constexpr char kBlendHelperName[] = "sk_blend";
|
||||
|
||||
// This exists as custom glue code to handle passing the result of the children into the
|
||||
// static function. If this were, somehow, handled in the default glue code, we could remove this.
|
||||
std::string GenerateBlendShaderGlueCode(const std::string& resultName,
|
||||
int entryIndex,
|
||||
const SkPaintParamsKey::BlockReader& reader,
|
||||
const std::string& priorStageOutputName,
|
||||
const std::vector<std::string>& childNames,
|
||||
int indent) {
|
||||
SkASSERT(childNames.size() == kNumBlendShaderChildren);
|
||||
SkASSERT(reader.entry()->fUniforms.size() == 4); // actual blend uniform + 3 padding int
|
||||
|
||||
std::string blendModeUniformName = reader.entry()->getMangledUniformName(0, entryIndex);
|
||||
|
||||
std::string result;
|
||||
|
||||
add_indent(&result, indent);
|
||||
SkSL::String::appendf(&result, "%s = %s(%s, %s, %s);\n",
|
||||
resultName.c_str(),
|
||||
reader.entry()->fStaticFunctionName,
|
||||
blendModeUniformName.c_str(),
|
||||
childNames[1].c_str(),
|
||||
childNames[0].c_str());
|
||||
|
||||
return result;
|
||||
}
|
||||
static constexpr char kBlendShaderName[] = "sk_blend_shader";
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
static constexpr char kErrorName[] = "sk_error";
|
||||
@ -540,6 +495,8 @@ static constexpr SkUniform kShaderBasedBlenderUniforms[kNumShaderBasedBlenderUni
|
||||
{ "padding3", SkSLType::kInt },
|
||||
};
|
||||
|
||||
static constexpr char kBlendHelperName[] = "sk_blend";
|
||||
|
||||
// This method generates the glue code for the case where the SkBlendMode-based blending must occur
|
||||
// in the shader (i.e., fixed function blending isn't possible).
|
||||
// It exists as custom glue code so that we can deal with the dest reads. If that can be
|
||||
@ -682,7 +639,7 @@ SkShaderCodeDictionary::SkShaderCodeDictionary() {
|
||||
SnippetRequirementFlags::kLocalCoords,
|
||||
{ }, // no samplers
|
||||
kLocalMatrixShaderName,
|
||||
GenerateLocalMatrixShaderGlueCode,
|
||||
GenerateDefaultGlueCode,
|
||||
kNumLocalMatrixShaderChildren,
|
||||
{ }
|
||||
};
|
||||
@ -701,8 +658,8 @@ SkShaderCodeDictionary::SkShaderCodeDictionary() {
|
||||
{ kBlendShaderUniforms, kNumBlendShaderUniforms },
|
||||
SnippetRequirementFlags::kNone,
|
||||
{ }, // no samplers
|
||||
kBlendHelperName,
|
||||
GenerateBlendShaderGlueCode,
|
||||
kBlendShaderName,
|
||||
GenerateDefaultGlueCode,
|
||||
kNumBlendShaderChildren,
|
||||
{ }
|
||||
};
|
||||
|
@ -71,6 +71,8 @@ struct SkShaderSnippet {
|
||||
return fSnippetRequirementFlags & SnippetRequirementFlags::kLocalCoords;
|
||||
}
|
||||
|
||||
int numExpectedChildren() const { return fNumChildren; }
|
||||
|
||||
const char* fName = nullptr;
|
||||
SkSpan<const SkUniform> fUniforms;
|
||||
SnippetRequirementFlags fSnippetRequirementFlags;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -73,7 +73,7 @@ half4 sk_linear_grad_4_shader(float4x4 dev2Local,
|
||||
return half4(result);
|
||||
}
|
||||
|
||||
half4 sk_blend(int mode, half4 src, half4 dst) {
|
||||
half4 sk_blend(int blendMode, half4 src, half4 dst) {
|
||||
const int kClear = 0;
|
||||
const int kSrc = 1;
|
||||
const int kDst = 2;
|
||||
@ -104,7 +104,7 @@ half4 sk_blend(int mode, half4 src, half4 dst) {
|
||||
const int kColor = 27;
|
||||
const int kLuminosity = 28;
|
||||
|
||||
switch (mode) {
|
||||
switch (blendMode) {
|
||||
case kClear: { return blend_clear(src, dst); }
|
||||
case kSrc: { return blend_src(src, dst); }
|
||||
case kDst: { return blend_dst(src, dst); }
|
||||
@ -137,3 +137,7 @@ half4 sk_blend(int mode, half4 src, half4 dst) {
|
||||
default: return half4(0); // Avoids 'blend can exit without returning a value' error
|
||||
}
|
||||
}
|
||||
|
||||
half4 sk_blend_shader(int blendMode, int pad0, int pad1, int pad2, half4 child0, half4 child1) {
|
||||
return sk_blend(blendMode, child1, child0);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user