Revert "Revert "Put top level FPs into their own functions""
Now that we have inlining this should be ok.
This reverts commit 24dcd207ea7f9c5f03121663963c75b74ec759cb.
Change-Id: I2aed6de6d962595cb0f3305bc26f340c99e0d1d2
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/301552
Reviewed-by: Michael Ludwig <michaelludwig@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.cpp b/src/gpu/glsl/GrGLSLProgramBuilder.cpp
index e8e5aaf..c4ec408 100644
--- a/src/gpu/glsl/GrGLSLProgramBuilder.cpp
+++ b/src/gpu/glsl/GrGLSLProgramBuilder.cpp
@@ -160,11 +160,6 @@
AutoStageAdvance adv(this);
this->nameExpression(&output, "output");
- // Enclose custom code in a block to avoid namespace conflicts
- SkString openBrace;
- openBrace.printf("{ // Stage %d, %s\n", fStageIndex, fp.name());
- fFS.codeAppend(openBrace.c_str());
-
int samplerIdx = 0;
for (auto [subFP, subGLSLFP] : GrGLSLFragmentProcessor::ParallelRange(fp, glslFP)) {
if (auto* te = subFP.asTextureEffect()) {
@@ -184,42 +179,17 @@
this->uniformHandler(),
this->shaderCaps(),
fp,
- output.c_str(),
- input.c_str(),
+ "_output",
+ "_input",
"_coords",
coords);
-
- if (fp.referencesSampleCoords()) {
- // The fp's generated code expects a _coords variable, but we're at the root so _coords
- // is just the local coordinates produced by the primitive processor.
- SkASSERT(fp.usesVaryingCoordsDirectly());
-
- const GrShaderVar& varying = coordVars[0];
- switch(varying.getType()) {
- case kFloat2_GrSLType:
- fFS.codeAppendf("float2 %s = %s.xy;\n",
- args.fSampleCoord, varying.getName().c_str());
- break;
- case kFloat3_GrSLType:
- fFS.codeAppendf("float2 %s = %s.xy / %s.z;\n",
- args.fSampleCoord,
- varying.getName().c_str(),
- varying.getName().c_str());
- break;
- default:
- SkDEBUGFAILF("Unexpected type for varying: %d named %s\n",
- (int) varying.getType(), varying.getName().c_str());
- break;
- }
- }
-
- glslFP.emitCode(args);
+ auto name = fFS.writeProcessorFunction(&glslFP, args);
+ fFS.codeAppendf("%s = %s(%s);", output.c_str(), name.c_str(), input.c_str());
// We have to check that effects and the code they emit are consistent, ie if an effect
// asks for dst color, then the emit code needs to follow suit
SkDEBUGCODE(verify(fp);)
- fFS.codeAppend("}");
return output;
}