Declare outputColor and outputCoverage inside emitCode.
This is useful because it allows the variables to be declared as `const`
when they are trivial values like `half4(1)`. This enables the constant
folder to simplify or eliminate them. In most cases, this is only a
small benefit, as you'd expect a competent GPU driver to do the same.
However, Mali-400 can benefit significantly from optimizing away the
multiplication against a constant half4(1) coverage in Porter-Duff.
Mali-400 performance is back to normal: http://screen/3cDxdaGkYE8oBcS
Change-Id: I21fd23f91f747079cd05b082f7b3444aeabafb93
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/382476
Auto-Submit: John Stiles <johnstiles@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
diff --git a/src/gpu/GrDefaultGeoProcFactory.cpp b/src/gpu/GrDefaultGeoProcFactory.cpp
index 2761ae5..7e8aa9f 100644
--- a/src/gpu/GrDefaultGeoProcFactory.cpp
+++ b/src/gpu/GrDefaultGeoProcFactory.cpp
@@ -77,6 +77,7 @@
SkASSERT(!tweakAlpha || gp.hasVertexCoverage());
// Setup pass through color
+ fragBuilder->codeAppendf("half4 %s;", args.fOutputColor);
if (gp.hasVertexColor() || tweakAlpha) {
GrGLSLVarying varying(kHalf4_GrSLType);
varyingHandler->addVarying("color", &varying);
@@ -127,9 +128,9 @@
if (gp.hasVertexCoverage() && !tweakAlpha) {
fragBuilder->codeAppendf("half alpha = 1.0;");
varyingHandler->addPassThroughAttribute(gp.fInCoverage, "alpha");
- fragBuilder->codeAppendf("%s = half4(alpha);", args.fOutputCoverage);
+ fragBuilder->codeAppendf("half4 %s = half4(alpha);", args.fOutputCoverage);
} else if (gp.coverage() == 0xff) {
- fragBuilder->codeAppendf("%s = half4(1);", args.fOutputCoverage);
+ fragBuilder->codeAppendf("const half4 %s = half4(1);", args.fOutputCoverage);
} else {
const char* fragCoverage;
fCoverageUniform = uniformHandler->addUniform(nullptr,
@@ -137,7 +138,8 @@
kHalf_GrSLType,
"Coverage",
&fragCoverage);
- fragBuilder->codeAppendf("%s = half4(%s);", args.fOutputCoverage, fragCoverage);
+ fragBuilder->codeAppendf("half4 %s = half4(%s);",
+ args.fOutputCoverage, fragCoverage);
}
}