Reland "Put top level FPs into their own functions"
This reverts commit a8486d10e0cc4daacc5420271305b35ca822ce64.
Reason for revert: several performance issues have been fixed
Original change's description:
> Revert "Revert "Revert "Put top level FPs into their own functions"""
>
> Flutter saw a substantial perf regression:
> https://github.com/flutter/flutter/issues/62447
>
> This reverts commit 7a96c2a6bb374b36ddf633b529c303e731e7467b.
>
> Change-Id: Ib7d73f2df429508d85f9681eb2f0afd84917772e
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/307782
> Reviewed-by: Michael Ludwig <michaelludwig@google.com>
> Commit-Queue: Brian Osman <brianosman@google.com>
Change-Id: Ie42ff7d5aff0a95f4533a31d60eac25c83b6defa
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/324376
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.cpp b/src/gpu/glsl/GrGLSLProgramBuilder.cpp
index 853028e..31e5408 100644
--- a/src/gpu/glsl/GrGLSLProgramBuilder.cpp
+++ b/src/gpu/glsl/GrGLSLProgramBuilder.cpp
@@ -173,54 +173,16 @@
this->uniformHandler(),
this->shaderCaps(),
fp,
- output.c_str(),
- input.c_str(),
+ "_output",
+ "_input",
"_coords",
coords,
/*forceInline=*/true);
+ auto name = fFS.writeProcessorFunction(&glslFP, args);
+ fFS.codeAppendf("%s = %s(%s);", output.c_str(), name.c_str(), input.c_str());
- if (fp.usesExplicitReturn()) {
- // FPs that explicitly return their output color must be in a helper function, but we inline
- // it if at all possible.
- args.fInputColor = "_input";
- args.fOutputColor = "_output";
- auto name = fFS.writeProcessorFunction(&glslFP, args);
- fFS.codeAppendf("%s = %s(%s);", output.c_str(), name.c_str(), input.c_str());
- } else {
- // Enclose custom code in a block to avoid namespace conflicts
- fFS.codeAppendf("{ // Stage %d, %s\n", fStageIndex, fp.name());
-
- 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);
-
- fFS.codeAppend("}");
- }
-
- // 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
+ // 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);)
return output;