aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/glsl
diff options
context:
space:
mode:
authorGravatar Brian Salomon <bsalomon@google.com>2017-05-02 21:07:25 +0000
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-05-02 21:07:32 +0000
commit5e550ab57e0204bfadd2cb69c47d2a85e38d6a4c (patch)
treea1787bf7363e13f1420a66db2d730644592c8dde /src/gpu/glsl
parent733340a6997762dc2fe5048cfe5af33bf8293d93 (diff)
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>
Diffstat (limited to 'src/gpu/glsl')
-rw-r--r--src/gpu/glsl/GrGLSL.cpp12
-rw-r--r--src/gpu/glsl/GrGLSLFragmentProcessor.cpp2
-rw-r--r--src/gpu/glsl/GrGLSLFragmentProcessor.h8
-rw-r--r--src/gpu/glsl/GrGLSLProgramBuilder.cpp56
-rw-r--r--src/gpu/glsl/GrGLSLProgramBuilder.h25
-rw-r--r--src/gpu/glsl/GrGLSLShaderBuilder.cpp12
6 files changed, 55 insertions, 60 deletions
diff --git a/src/gpu/glsl/GrGLSL.cpp b/src/gpu/glsl/GrGLSL.cpp
index 76ffb826a7..d54ddee0d6 100644
--- a/src/gpu/glsl/GrGLSL.cpp
+++ b/src/gpu/glsl/GrGLSL.cpp
@@ -45,3 +45,15 @@ void GrGLSLAppendDefaultFloatPrecisionDeclaration(GrSLPrecision p,
}
}
}
+
+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 4000b18f8c..a779accab2 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,
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::emitChild(int childIndex, const char* inputColor,
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 05b3c06f78..1cf0d1d000 100644
--- a/src/gpu/glsl/GrGLSLFragmentProcessor.h
+++ b/src/gpu/glsl/GrGLSLFragmentProcessor.h
@@ -156,10 +156,6 @@ public:
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 @@ public:
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 3094f194ec..12e7ca2c1d 100644
--- a/src/gpu/glsl/GrGLSLProgramBuilder.cpp
+++ b/src/gpu/glsl/GrGLSLProgramBuilder.cpp
@@ -53,24 +53,24 @@ void GrGLSLProgramBuilder::addFeature(GrShaderFlags shaders,
}
}
-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 @@ void GrGLSLProgramBuilder::emitAndInstallPrimProc(const GrPrimitiveProcessor& pr
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 @@ void GrGLSLProgramBuilder::emitAndInstallFragProcs(SkString* color, SkString* co
}
// 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 @@ SkString GrGLSLProgramBuilder::emitAndInstallFragProc(const GrFragmentProcessor&
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 @@ SkString GrGLSLProgramBuilder::emitAndInstallFragProc(const GrFragmentProcessor&
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 @@ void GrGLSLProgramBuilder::emitAndInstallXferProc(const SkString& colorIn,
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::nameVariable(SkString* out, char prefix, const char*
}
}
-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 4b1957eb2a..147eb98c98 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 @@ protected:
void addFeature(GrShaderFlags shaders, uint32_t featureBit, const char* extensionName);
- bool emitAndInstallProcs();
+ bool emitAndInstallProcs(GrGLSLExpr4* inputColor, GrGLSLExpr4* inputCoverage);
void cleanupFragmentProcessors();
@@ -140,18 +140,19 @@ private:
};
// 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 1a681b56a3..2c7e5e476d 100644
--- a/src/gpu/glsl/GrGLSLShaderBuilder.cpp
+++ b/src/gpu/glsl/GrGLSLShaderBuilder.cpp
@@ -101,17 +101,9 @@ void GrGLSLShaderBuilder::appendTextureLookupAndModulate(
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());
}
}