Revert "eliminated GrGLSLExpr"
This reverts commit 93f20f5629e52eed732d2b9d6dbbb351cc30b2cd.
Reason for revert: Mismerge readded deleted files.
Original change's description:
> eliminated GrGLSLExpr
>
> Now that skslc performs all of the optimizations (and then some) that
> GrGLSLExpr is responsible for, it's just extra work for no benefit.
>
> Bug: skia:
> Change-Id: I40b0629e00a33873ed9fc6c0a9f41d8350221f9a
> Reviewed-on: https://skia-review.googlesource.com/14560
> Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
> Reviewed-by: Brian Salomon <bsalomon@google.com>
>
TBR=bsalomon@google.com,ethannicholas@google.com
NOPRESUBMIT=true
NOTREECHECKS=true
NOTRY=true
Change-Id: Ia8b723594527afe34489fc78a4b49039081b6390
Reviewed-on: https://skia-review.googlesource.com/15154
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
diff --git a/src/gpu/GrFragmentProcessor.cpp b/src/gpu/GrFragmentProcessor.cpp
index 462766a..3529467 100644
--- a/src/gpu/GrFragmentProcessor.cpp
+++ b/src/gpu/GrFragmentProcessor.cpp
@@ -283,7 +283,7 @@
public:
void emitCode(EmitArgs& args) override {
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
- this->emitChild(0, args);
+ this->emitChild(0, nullptr, args);
fragBuilder->codeAppendf("%s.rgb *= %s.rgb;", args.fOutputColor,
args.fInputColor);
fragBuilder->codeAppendf("%s *= %s.a;", args.fOutputColor, args.fInputColor);
diff --git a/src/gpu/effects/GrBicubicEffect.cpp b/src/gpu/effects/GrBicubicEffect.cpp
index 70a0096..c60400e 100644
--- a/src/gpu/effects/GrBicubicEffect.cpp
+++ b/src/gpu/effects/GrBicubicEffect.cpp
@@ -112,8 +112,9 @@
fragBuilder->appendColorGamutXform(&xformedColor, bicubicColor.c_str(), &fColorSpaceHelper);
bicubicColor.swap(xformedColor);
}
- fragBuilder->codeAppendf("%s = %s * %s;", args.fOutputColor, bicubicColor.c_str(),
- args.fInputColor);
+ fragBuilder->codeAppendf("%s = %s;",
+ args.fOutputColor, (GrGLSLExpr4(bicubicColor.c_str()) *
+ GrGLSLExpr4(args.fInputColor)).c_str());
}
void GrGLBicubicEffect::onSetData(const GrGLSLProgramDataManager& pdman,
diff --git a/src/gpu/effects/GrConvexPolyEffect.cpp b/src/gpu/effects/GrConvexPolyEffect.cpp
index 4b9599e..312c038 100644
--- a/src/gpu/effects/GrConvexPolyEffect.cpp
+++ b/src/gpu/effects/GrConvexPolyEffect.cpp
@@ -132,7 +132,8 @@
if (GrProcessorEdgeTypeIsInverseFill(aare.getEdgeType())) {
fragBuilder->codeAppend("\t\talpha = 1.0 - alpha;\n");
}
- fragBuilder->codeAppendf("\t\t%s = %s * alpha;\n", args.fOutputColor, args.fInputColor);
+ fragBuilder->codeAppendf("\t\t%s = %s;\n", args.fOutputColor,
+ (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha")).c_str());
}
void GLAARectEffect::onSetData(const GrGLSLProgramDataManager& pdman,
@@ -211,7 +212,8 @@
if (GrProcessorEdgeTypeIsInverseFill(cpe.getEdgeType())) {
fragBuilder->codeAppend("\talpha = 1.0 - alpha;\n");
}
- fragBuilder->codeAppendf("\t%s = %s * alpha;\n", args.fOutputColor, args.fInputColor);
+ fragBuilder->codeAppendf("\t%s = %s;\n", args.fOutputColor,
+ (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha")).c_str());
}
void GrGLConvexPolyEffect::onSetData(const GrGLSLProgramDataManager& pdman,
diff --git a/src/gpu/effects/GrDitherEffect.cpp b/src/gpu/effects/GrDitherEffect.cpp
index 0686750..864a5d2 100644
--- a/src/gpu/effects/GrDitherEffect.cpp
+++ b/src/gpu/effects/GrDitherEffect.cpp
@@ -74,7 +74,7 @@
"fract(sin(dot(sk_FragCoord.xy, vec2(12.9898,78.233))) * "
"43758.5453);\n");
fragBuilder->codeAppendf("\t\t%s = clamp((1.0/255.0) * vec4(r, r, r, r) + %s, 0, 1);\n",
- args.fOutputColor, args.fInputColor);
+ args.fOutputColor, GrGLSLExpr4(args.fInputColor).c_str());
}
//////////////////////////////////////////////////////////////////////////////
diff --git a/src/gpu/effects/GrGaussianConvolutionFragmentProcessor.cpp b/src/gpu/effects/GrGaussianConvolutionFragmentProcessor.cpp
index 324c61e..b4f1314 100644
--- a/src/gpu/effects/GrGaussianConvolutionFragmentProcessor.cpp
+++ b/src/gpu/effects/GrGaussianConvolutionFragmentProcessor.cpp
@@ -91,7 +91,10 @@
}
fragBuilder->codeAppendf("coord += %s;\n", imgInc);
}
- fragBuilder->codeAppendf("%s *= %s;\n", args.fOutputColor, args.fInputColor);
+
+ SkString modulate;
+ GrGLSLMulVarBy4f(&modulate, args.fOutputColor, args.fInputColor);
+ fragBuilder->codeAppend(modulate.c_str());
}
void GrGLConvolutionEffect::onSetData(const GrGLSLProgramDataManager& pdman,
diff --git a/src/gpu/effects/GrMatrixConvolutionEffect.cpp b/src/gpu/effects/GrMatrixConvolutionEffect.cpp
index b3ea81a..03d90ea 100644
--- a/src/gpu/effects/GrMatrixConvolutionEffect.cpp
+++ b/src/gpu/effects/GrMatrixConvolutionEffect.cpp
@@ -114,7 +114,10 @@
fragBuilder->codeAppendf("%s.rgb = clamp(sum.rgb * %s + %s, 0, 1);", args.fOutputColor, gain, bias);
fragBuilder->codeAppendf("%s.rgb *= %s.a;", args.fOutputColor, args.fOutputColor);
}
- fragBuilder->codeAppendf("%s *= %s;\n", args.fOutputColor, args.fInputColor);
+
+ SkString modulate;
+ GrGLSLMulVarBy4f(&modulate, args.fOutputColor, args.fInputColor);
+ fragBuilder->codeAppend(modulate.c_str());
}
void GrGLMatrixConvolutionEffect::GenKey(const GrProcessor& processor,
diff --git a/src/gpu/effects/GrOvalEffect.cpp b/src/gpu/effects/GrOvalEffect.cpp
index 2eb1d85..672f5d8 100644
--- a/src/gpu/effects/GrOvalEffect.cpp
+++ b/src/gpu/effects/GrOvalEffect.cpp
@@ -140,7 +140,8 @@
fragBuilder->codeAppend("d = d > 0.5 ? 1.0 : 0.0;");
}
- fragBuilder->codeAppendf("%s = %s * d;", args.fOutputColor, args.fInputColor);
+ fragBuilder->codeAppendf("%s = %s;", args.fOutputColor,
+ (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("d")).c_str());
}
void GLCircleEffect::GenKey(const GrProcessor& processor, const GrShaderCaps&,
@@ -332,7 +333,8 @@
SkFAIL("Hairline not expected here.");
}
- fragBuilder->codeAppendf("%s = %s * alpha;", args.fOutputColor, args.fInputColor);
+ fragBuilder->codeAppendf("%s = %s;", args.fOutputColor,
+ (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha")).c_str());
}
void GLEllipseEffect::GenKey(const GrProcessor& effect, const GrShaderCaps&,
diff --git a/src/gpu/effects/GrRRectEffect.cpp b/src/gpu/effects/GrRRectEffect.cpp
index 8d18150..887bc00 100644
--- a/src/gpu/effects/GrRRectEffect.cpp
+++ b/src/gpu/effects/GrRRectEffect.cpp
@@ -279,7 +279,8 @@
fragBuilder->codeAppend("alpha = 1.0 - alpha;");
}
- fragBuilder->codeAppendf("%s = %s * alpha;", args.fOutputColor, args.fInputColor);
+ fragBuilder->codeAppendf("%s = %s;", args.fOutputColor,
+ (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha")).c_str());
}
void GLCircularRRectEffect::GenKey(const GrProcessor& processor, const GrShaderCaps&,
@@ -589,7 +590,8 @@
fragBuilder->codeAppend("float alpha = clamp(0.5 + approx_dist, 0.0, 1.0);");
}
- fragBuilder->codeAppendf("%s = %s * alpha;", args.fOutputColor, args.fInputColor);
+ fragBuilder->codeAppendf("%s = %s;", args.fOutputColor,
+ (GrGLSLExpr4(args.fInputColor) * GrGLSLExpr1("alpha")).c_str());
}
void GLEllipticalRRectEffect::GenKey(const GrProcessor& effect, const GrShaderCaps&,
diff --git a/src/gpu/effects/GrXfermodeFragmentProcessor.cpp b/src/gpu/effects/GrXfermodeFragmentProcessor.cpp
index aa79937..30a9faa 100644
--- a/src/gpu/effects/GrXfermodeFragmentProcessor.cpp
+++ b/src/gpu/effects/GrXfermodeFragmentProcessor.cpp
@@ -415,7 +415,7 @@
ComposeOneFragmentProcessor::Child child =
args.fFp.cast<ComposeOneFragmentProcessor>().child();
SkString childColor("child");
- this->emitChild(0, &childColor, args);
+ this->emitChild(0, nullptr, &childColor, args);
const char* inputColor = args.fInputColor;
// We don't try to optimize for this case at all
diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.cpp b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
index 0351819..9ddfa80 100644
--- a/src/gpu/gl/builders/GrGLProgramBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
@@ -40,7 +40,12 @@
// uniforms, varyings, textures, etc
GrGLProgramBuilder builder(gpu, pipeline, primProc, desc);
- if (!builder.emitAndInstallProcs()) {
+ // TODO: Once all stages can handle taking a float or vec4 and correctly handling them we can
+ // seed correctly here
+ GrGLSLExpr4 inputColor;
+ GrGLSLExpr4 inputCoverage;
+
+ if (!builder.emitAndInstallProcs(&inputColor, &inputCoverage)) {
builder.cleanupFragmentProcessors();
return nullptr;
}
diff --git a/src/gpu/glsl/GrGLSL.cpp b/src/gpu/glsl/GrGLSL.cpp
index 76ffb82..d54ddee 100644
--- a/src/gpu/glsl/GrGLSL.cpp
+++ b/src/gpu/glsl/GrGLSL.cpp
@@ -45,3 +45,15 @@
}
}
}
+
+void GrGLSLMulVarBy4f(SkString* outAppend, const char* vec4VarName, const GrGLSLExpr4& mulFactor) {
+ if (mulFactor.isOnes()) {
+ *outAppend = SkString();
+ }
+
+ if (mulFactor.isZeros()) {
+ outAppend->appendf("%s = vec4(0);", vec4VarName);
+ } else {
+ outAppend->appendf("%s *= %s;", vec4VarName, mulFactor.c_str());
+ }
+}
diff --git a/src/gpu/glsl/GrGLSLFragmentProcessor.cpp b/src/gpu/glsl/GrGLSLFragmentProcessor.cpp
index 4000b18..a779acc 100644
--- a/src/gpu/glsl/GrGLSLFragmentProcessor.cpp
+++ b/src/gpu/glsl/GrGLSLFragmentProcessor.cpp
@@ -26,6 +26,7 @@
void GrGLSLFragmentProcessor::emitChild(int childIndex, const char* inputColor,
SkString* outputColor, EmitArgs& args) {
+
SkASSERT(outputColor);
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
outputColor->append(fragBuilder->getMangleString());
@@ -35,7 +36,6 @@
void GrGLSLFragmentProcessor::internalEmitChild(int childIndex, const char* inputColor,
const char* outputColor, EmitArgs& args) {
- SkASSERT(inputColor);
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
fragBuilder->onBeforeChildProcEmitCode(); // call first so mangleString is updated
diff --git a/src/gpu/glsl/GrGLSLFragmentProcessor.h b/src/gpu/glsl/GrGLSLFragmentProcessor.h
index 05b3c06..1cf0d1d 100644
--- a/src/gpu/glsl/GrGLSLFragmentProcessor.h
+++ b/src/gpu/glsl/GrGLSLFragmentProcessor.h
@@ -156,10 +156,6 @@
return fChildProcessors[index];
}
- inline void emitChild(int childIndex, SkString* outputColor, EmitArgs& parentArgs) {
- this->emitChild(childIndex, "vec4(1.0)", outputColor, parentArgs);
- }
-
/** Will emit the code of a child proc in its own scope. Pass in the parent's EmitArgs and
* emitChild will automatically extract the coords and samplers of that child and pass them
* on to the child's emitCode(). Also, any uniforms or functions emitted by the child will
@@ -171,10 +167,6 @@
void emitChild(int childIndex, const char* inputColor, SkString* outputColor,
EmitArgs& parentArgs);
- inline void emitChild(int childIndex, EmitArgs& args) {
- this->emitChild(childIndex, "vec4(1.0)", args);
- }
-
/** Variation that uses the parent's output color variable to hold the child's output.*/
void emitChild(int childIndex, const char* inputColor, EmitArgs& parentArgs);
diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.cpp b/src/gpu/glsl/GrGLSLProgramBuilder.cpp
index 3094f19..12e7ca2 100644
--- a/src/gpu/glsl/GrGLSLProgramBuilder.cpp
+++ b/src/gpu/glsl/GrGLSLProgramBuilder.cpp
@@ -53,24 +53,24 @@
}
}
-bool GrGLSLProgramBuilder::emitAndInstallProcs() {
+bool GrGLSLProgramBuilder::emitAndInstallProcs(GrGLSLExpr4* inputColor,
+ GrGLSLExpr4* inputCoverage) {
// 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();
- SkString inputColor;
- SkString inputCoverage;
- this->emitAndInstallPrimProc(primProc, &inputColor, &inputCoverage);
- this->emitAndInstallFragProcs(&inputColor, &inputCoverage);
- this->emitAndInstallXferProc(inputColor, 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,
- SkString* outputColor,
- SkString* outputCoverage) {
+ GrGLSLExpr4* outputColor,
+ GrGLSLExpr4* 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(SkString* color, SkString* coverage) {
+void GrGLSLProgramBuilder::emitAndInstallFragProcs(GrGLSLExpr4* color, GrGLSLExpr4* coverage) {
int transformedCoordVarsIdx = 0;
- SkString** inOut = &color;
+ GrGLSLExpr4** inOut = &color;
for (int i = 0; i < this->pipeline().numFragmentProcessors(); ++i) {
if (i == this->pipeline().numColorFragmentProcessors()) {
inOut = &coverage;
}
- SkString output;
+ GrGLSLExpr4 output;
const GrFragmentProcessor& fp = this->pipeline().getFragmentProcessor(i);
- output = this->emitAndInstallFragProc(fp, i, transformedCoordVarsIdx, **inOut, output);
+ this->emitAndInstallFragProc(fp, i, transformedCoordVarsIdx, **inOut, &output);
GrFragmentProcessor::Iter iter(&fp);
while (const GrFragmentProcessor* fp = iter.next()) {
transformedCoordVarsIdx += fp->numCoordTransforms();
@@ -158,16 +158,15 @@
}
// TODO Processors cannot output zeros because an empty string is all 1s
-// 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());
+// 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) {
// 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;
@@ -194,8 +193,8 @@
this->uniformHandler(),
this->shaderCaps(),
fp,
- output.c_str(),
- input.c_str(),
+ output->c_str(),
+ input.isOnes() ? nullptr : input.c_str(),
coords,
textureSamplers,
bufferSamplers,
@@ -210,11 +209,10 @@
fFragmentProcessors.push_back(fragProc);
fFS.codeAppend("}");
- return output;
}
-void GrGLSLProgramBuilder::emitAndInstallXferProc(const SkString& colorIn,
- const SkString& coverageIn) {
+void GrGLSLProgramBuilder::emitAndInstallXferProc(const GrGLSLExpr4& colorIn,
+ const GrGLSLExpr4& coverageIn) {
// Program builders have a bit of state we need to clear with each effect
AutoStageAdvance adv(this);
@@ -251,8 +249,8 @@
this->uniformHandler(),
this->shaderCaps(),
xp,
- colorIn.size() ? colorIn.c_str() : "vec4(1)",
- coverageIn.size() ? coverageIn.c_str() : "vec4(1)",
+ colorIn.c_str(),
+ coverageIn.c_str(),
fFS.getPrimaryColorOutputName(),
fFS.getSecondaryColorOutputName(),
dstTextureSamplerHandle,
@@ -447,12 +445,12 @@
}
}
-void GrGLSLProgramBuilder::nameExpression(SkString* output, const char* baseName) {
+void GrGLSLProgramBuilder::nameExpression(GrGLSLExpr4* 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->size()) {
+ if (output->isValid()) {
outName = output->c_str();
} else {
this->nameVariable(&outName, '\0', baseName);
diff --git a/src/gpu/glsl/GrGLSLProgramBuilder.h b/src/gpu/glsl/GrGLSLProgramBuilder.h
index 4b1957e..147eb98 100644
--- a/src/gpu/glsl/GrGLSLProgramBuilder.h
+++ b/src/gpu/glsl/GrGLSLProgramBuilder.h
@@ -22,7 +22,7 @@
class GrShaderVar;
class GrGLSLVaryingHandler;
-class SkString;
+class GrGLSLExpr4;
class GrShaderCaps;
typedef SkSTArray<8, GrGLSLFragmentProcessor*, true> GrGLSLFragProcs;
@@ -110,7 +110,7 @@
void addFeature(GrShaderFlags shaders, uint32_t featureBit, const char* extensionName);
- bool emitAndInstallProcs();
+ bool emitAndInstallProcs(GrGLSLExpr4* inputColor, GrGLSLExpr4* inputCoverage);
void cleanupFragmentProcessors();
@@ -140,18 +140,19 @@
};
// Generates a possibly mangled name for a stage variable and writes it to the fragment shader.
- void nameExpression(SkString*, const char* baseName);
+ // If GrGLSLExpr4 has a valid name then it will use that instead
+ void nameExpression(GrGLSLExpr4*, const char* baseName);
void emitAndInstallPrimProc(const GrPrimitiveProcessor&,
- SkString* outputColor,
- SkString* outputCoverage);
- void emitAndInstallFragProcs(SkString* colorInOut, SkString* coverageInOut);
- SkString emitAndInstallFragProc(const GrFragmentProcessor&,
- int index,
- int transformedCoordVarsIdx,
- const SkString& input,
- SkString output);
- void emitAndInstallXferProc(const SkString& colorIn, const SkString& coverageIn);
+ GrGLSLExpr4* outputColor,
+ GrGLSLExpr4* outputCoverage);
+ void emitAndInstallFragProcs(GrGLSLExpr4* colorInOut, GrGLSLExpr4* coverageInOut);
+ void emitAndInstallFragProc(const GrFragmentProcessor&,
+ int index,
+ int transformedCoordVarsIdx,
+ const GrGLSLExpr4& input,
+ GrGLSLExpr4* output);
+ void emitAndInstallXferProc(const GrGLSLExpr4& colorIn, const GrGLSLExpr4& coverageIn);
void emitSamplersAndImageStorages(const GrResourceIOProcessor& processor,
SkTArray<SamplerHandle>* outTexSamplerHandles,
SkTArray<SamplerHandle>* outBufferSamplerHandles,
diff --git a/src/gpu/glsl/GrGLSLShaderBuilder.cpp b/src/gpu/glsl/GrGLSLShaderBuilder.cpp
index 1a681b5..2c7e5e4 100644
--- a/src/gpu/glsl/GrGLSLShaderBuilder.cpp
+++ b/src/gpu/glsl/GrGLSLShaderBuilder.cpp
@@ -101,17 +101,9 @@
if (colorXformHelper && colorXformHelper->isValid()) {
SkString xform;
this->appendColorGamutXform(&xform, lookup.c_str(), colorXformHelper);
- if (modulation) {
- this->codeAppendf("%s * %s", modulation, xform.c_str());
- } else {
- this->codeAppendf("%s", xform.c_str());
- }
+ this->codeAppend((GrGLSLExpr4(modulation) * GrGLSLExpr4(xform)).c_str());
} else {
- if (modulation) {
- this->codeAppendf("%s * %s", modulation, lookup.c_str());
- } else {
- this->codeAppendf("%s", lookup.c_str());
- }
+ this->codeAppend((GrGLSLExpr4(modulation) * GrGLSLExpr4(lookup)).c_str());
}
}
diff --git a/src/gpu/vk/GrVkPipelineStateBuilder.cpp b/src/gpu/vk/GrVkPipelineStateBuilder.cpp
index 2e81fc2..ea0aa75 100644
--- a/src/gpu/vk/GrVkPipelineStateBuilder.cpp
+++ b/src/gpu/vk/GrVkPipelineStateBuilder.cpp
@@ -25,7 +25,10 @@
// uniforms, varyings, textures, etc
GrVkPipelineStateBuilder builder(gpu, pipeline, primProc, desc);
- if (!builder.emitAndInstallProcs()) {
+ GrGLSLExpr4 inputColor;
+ GrGLSLExpr4 inputCoverage;
+
+ if (!builder.emitAndInstallProcs(&inputColor, &inputCoverage)) {
builder.cleanupFragmentProcessors();
return nullptr;
}