Re-land of "eliminated GrGLSLExpr".
This change is exactly the same as the last time it was landed; I believe the
underlying optimizer bug that was causing this to cause problems has been
fixed by a prior CL.
Bug: skia:
Change-Id: I5436422f094ea758caa3cd69e9338db31b1f93fa
Reviewed-on: https://skia-review.googlesource.com/15768
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.cpp b/src/gpu/glsl/GrGLSLProgramBuilder.cpp
index 7a8cbad..5c3bee1 100644
--- a/src/gpu/glsl/GrGLSLProgramBuilder.cpp
+++ b/src/gpu/glsl/GrGLSLProgramBuilder.cpp
@@ -53,24 +53,24 @@
}
}
-bool GrGLSLProgramBuilder::emitAndInstallProcs(GrGLSLExpr4* inputColor,
- GrGLSLExpr4* inputCoverage) {
+bool GrGLSLProgramBuilder::emitAndInstallProcs() {
// First we loop over all of the installed processors and collect coord transforms. These will
// be sent to the GrGLSLPrimitiveProcessor in its emitCode function
const GrPrimitiveProcessor& primProc = this->primitiveProcessor();
- this->emitAndInstallPrimProc(primProc, inputColor, inputCoverage);
-
- this->emitAndInstallFragProcs(inputColor, inputCoverage);
- this->emitAndInstallXferProc(*inputColor, *inputCoverage);
+ SkString inputColor;
+ SkString inputCoverage;
+ this->emitAndInstallPrimProc(primProc, &inputColor, &inputCoverage);
+ this->emitAndInstallFragProcs(&inputColor, &inputCoverage);
+ this->emitAndInstallXferProc(inputColor, inputCoverage);
this->emitFSOutputSwizzle(this->pipeline().getXferProcessor().hasSecondaryOutput());
return this->checkSamplerCounts() && this->checkImageStorageCounts();
}
void GrGLSLProgramBuilder::emitAndInstallPrimProc(const GrPrimitiveProcessor& proc,
- GrGLSLExpr4* outputColor,
- GrGLSLExpr4* outputCoverage) {
+ SkString* outputColor,
+ SkString* outputCoverage) {
// Program builders have a bit of state we need to clear with each effect
AutoStageAdvance adv(this);
this->nameExpression(outputColor, "outputColor");
@@ -139,16 +139,16 @@
fFS.codeAppend("}");
}
-void GrGLSLProgramBuilder::emitAndInstallFragProcs(GrGLSLExpr4* color, GrGLSLExpr4* coverage) {
+void GrGLSLProgramBuilder::emitAndInstallFragProcs(SkString* color, SkString* coverage) {
int transformedCoordVarsIdx = 0;
- GrGLSLExpr4** inOut = &color;
+ SkString** inOut = &color;
for (int i = 0; i < this->pipeline().numFragmentProcessors(); ++i) {
if (i == this->pipeline().numColorFragmentProcessors()) {
inOut = &coverage;
}
- GrGLSLExpr4 output;
+ SkString output;
const GrFragmentProcessor& fp = this->pipeline().getFragmentProcessor(i);
- this->emitAndInstallFragProc(fp, i, transformedCoordVarsIdx, **inOut, &output);
+ output = this->emitAndInstallFragProc(fp, i, transformedCoordVarsIdx, **inOut, output);
GrFragmentProcessor::Iter iter(&fp);
while (const GrFragmentProcessor* fp = iter.next()) {
transformedCoordVarsIdx += fp->numCoordTransforms();
@@ -158,15 +158,16 @@
}
// TODO Processors cannot output zeros because an empty string is all 1s
-// the fix is to allow effects to take the GrGLSLExpr4 directly
-void GrGLSLProgramBuilder::emitAndInstallFragProc(const GrFragmentProcessor& fp,
- int index,
- int transformedCoordVarsIdx,
- const GrGLSLExpr4& input,
- GrGLSLExpr4* output) {
+// the fix is to allow effects to take the SkString directly
+SkString GrGLSLProgramBuilder::emitAndInstallFragProc(const GrFragmentProcessor& fp,
+ int index,
+ int transformedCoordVarsIdx,
+ const SkString& input,
+ SkString output) {
+ SkASSERT(input.size());
// Program builders have a bit of state we need to clear with each effect
AutoStageAdvance adv(this);
- this->nameExpression(output, "output");
+ this->nameExpression(&output, "output");
// Enclose custom code in a block to avoid namespace conflicts
SkString openBrace;
@@ -193,8 +194,8 @@
this->uniformHandler(),
this->shaderCaps(),
fp,
- output->c_str(),
- input.isOnes() ? nullptr : input.c_str(),
+ output.c_str(),
+ input.c_str(),
coords,
textureSamplers,
texelBuffers,
@@ -209,10 +210,11 @@
fFragmentProcessors.push_back(fragProc);
fFS.codeAppend("}");
+ return output;
}
-void GrGLSLProgramBuilder::emitAndInstallXferProc(const GrGLSLExpr4& colorIn,
- const GrGLSLExpr4& coverageIn) {
+void GrGLSLProgramBuilder::emitAndInstallXferProc(const SkString& colorIn,
+ const SkString& coverageIn) {
// Program builders have a bit of state we need to clear with each effect
AutoStageAdvance adv(this);
@@ -249,8 +251,8 @@
this->uniformHandler(),
this->shaderCaps(),
xp,
- colorIn.c_str(),
- coverageIn.c_str(),
+ colorIn.size() ? colorIn.c_str() : "vec4(1)",
+ coverageIn.size() ? coverageIn.c_str() : "vec4(1)",
fFS.getPrimaryColorOutputName(),
fFS.getSecondaryColorOutputName(),
dstTextureSamplerHandle,
@@ -455,12 +457,12 @@
}
}
-void GrGLSLProgramBuilder::nameExpression(GrGLSLExpr4* output, const char* baseName) {
+void GrGLSLProgramBuilder::nameExpression(SkString* output, const char* baseName) {
// create var to hold stage result. If we already have a valid output name, just use that
// otherwise create a new mangled one. This name is only valid if we are reordering stages
// and have to tell stage exactly where to put its output.
SkString outName;
- if (output->isValid()) {
+ if (output->size()) {
outName = output->c_str();
} else {
this->nameVariable(&outName, '\0', baseName);