aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar egdaniel <egdaniel@google.com>2014-07-21 11:37:28 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-07-21 11:37:28 -0700
commit02cafcc1bf6e2968c2efdf459871167970da150e (patch)
tree6407fddf603d832732c775e450c6430e0d120e55 /src
parent5b7c7c4ed3baf24e10db8f1b647f7c711b4420fd (diff)
Remove gpu shader optimatization for solid white or trans black colors
Running test on the added bench which draws a grid of all white paths, all blue paths, or alternating checkered white/blue paths. With optimization in (ms): White Blue Checkered Linux ~80 ~80 ~160 N7 ~800 ~1100 ~1500 Moto-e ~830 ~1100 ~2500 Without optimization in (ms): White Blue Checkered Linux ~80 ~80 ~80 N7 ~1100 ~1100 ~1100 Moto-e ~1100 ~1100 ~1500 BUG=skia: Committed: https://skia.googlesource.com/skia/+/5f78d2251a440443c9eaa321dad058d7a32bfef7 R=bsalomon@google.com Author: egdaniel@google.com Review URL: https://codereview.chromium.org/375823005
Diffstat (limited to 'src')
-rw-r--r--src/gpu/GrDrawState.cpp9
-rw-r--r--src/gpu/GrDrawState.h6
-rw-r--r--src/gpu/gl/GrGLProgram.cpp11
-rw-r--r--src/gpu/gl/GrGLProgramDesc.cpp18
-rw-r--r--src/gpu/gl/GrGLProgramDesc.h1
-rw-r--r--src/gpu/gl/GrGLShaderBuilder.cpp6
-rw-r--r--src/gpu/gl/GrGpuGL_program.cpp4
7 files changed, 26 insertions, 29 deletions
diff --git a/src/gpu/GrDrawState.cpp b/src/gpu/GrDrawState.cpp
index 14ba6fad5d..02c7920f5d 100644
--- a/src/gpu/GrDrawState.cpp
+++ b/src/gpu/GrDrawState.cpp
@@ -409,6 +409,15 @@ GrDrawState::BlendOptFlags GrDrawState::calcBlendOpts(bool forceCoverage,
return kNone_BlendOpt;
}
+bool GrDrawState::canIgnoreColorAttribute() const {
+ if (fBlendOptFlags & kInvalid_BlendOptFlag) {
+ this->getBlendOpts();
+ }
+ return SkToBool(fBlendOptFlags & (GrDrawState::kEmitTransBlack_BlendOptFlag |
+ GrDrawState::kEmitCoverage_BlendOptFlag));
+}
+
+
////////////////////////////////////////////////////////////////////////////////
void GrDrawState::AutoViewMatrixRestore::restore() {
diff --git a/src/gpu/GrDrawState.h b/src/gpu/GrDrawState.h
index cef21af880..c1dd9dcd36 100644
--- a/src/gpu/GrDrawState.h
+++ b/src/gpu/GrDrawState.h
@@ -551,6 +551,12 @@ public:
}
/**
+ * We don't use suplied vertex color attributes if our blend mode is EmitCoverage or
+ * EmitTransBlack
+ */
+ bool canIgnoreColorAttribute() const;
+
+ /**
* Determines what optimizations can be applied based on the blend. The coefficients may have
* to be tweaked in order for the optimization to work. srcCoeff and dstCoeff are optional
* params that receive the tweaked coefficients. Normally the function looks at the current
diff --git a/src/gpu/gl/GrGLProgram.cpp b/src/gpu/gl/GrGLProgram.cpp
index 435d0cdb02..5bc7d0b277 100644
--- a/src/gpu/gl/GrGLProgram.cpp
+++ b/src/gpu/gl/GrGLProgram.cpp
@@ -154,7 +154,7 @@ void GrGLProgram::setColor(const GrDrawState& drawState,
GrColor color,
SharedGLState* sharedState) {
const GrGLProgramDesc::KeyHeader& header = fDesc.getHeader();
- if (!drawState.hasColorVertexAttribute()) {
+ if (!drawState.hasColorVertexAttribute() || drawState.canIgnoreColorAttribute()) {
switch (header.fColorInput) {
case GrGLProgramDesc::kAttribute_ColorInput:
SkASSERT(-1 != header.fColorAttributeIndex);
@@ -178,12 +178,8 @@ void GrGLProgram::setColor(const GrDrawState& drawState,
}
sharedState->fConstAttribColorIndex = -1;
break;
- case GrGLProgramDesc::kSolidWhite_ColorInput:
- case GrGLProgramDesc::kTransBlack_ColorInput:
- sharedState->fConstAttribColorIndex = -1;
- break;
default:
- SkFAIL("Unknown color type.");
+ SkFAIL("Unexpected color type.");
}
} else {
sharedState->fConstAttribColorIndex = -1;
@@ -218,11 +214,10 @@ void GrGLProgram::setCoverage(const GrDrawState& drawState,
sharedState->fConstAttribCoverageIndex = -1;
break;
case GrGLProgramDesc::kSolidWhite_ColorInput:
- case GrGLProgramDesc::kTransBlack_ColorInput:
sharedState->fConstAttribCoverageIndex = -1;
break;
default:
- SkFAIL("Unknown coverage type.");
+ SkFAIL("Unexpected coverage type.");
}
} else {
sharedState->fConstAttribCoverageIndex = -1;
diff --git a/src/gpu/gl/GrGLProgramDesc.cpp b/src/gpu/gl/GrGLProgramDesc.cpp
index 27a1fab1e0..e1a319104d 100644
--- a/src/gpu/gl/GrGLProgramDesc.cpp
+++ b/src/gpu/gl/GrGLProgramDesc.cpp
@@ -66,6 +66,7 @@ bool GrGLProgramDesc::Build(const GrDrawState& drawState,
bool skipColor = SkToBool(blendOpts & (GrDrawState::kEmitTransBlack_BlendOptFlag |
GrDrawState::kEmitCoverage_BlendOptFlag));
+
int firstEffectiveColorStage = 0;
bool inputColorIsUsed = true;
if (!skipColor) {
@@ -99,11 +100,6 @@ bool GrGLProgramDesc::Build(const GrDrawState& drawState,
bool requiresLocalCoordAttrib = !(skipCoverage && skipColor) &&
drawState.hasLocalCoordAttribute();
- bool colorIsTransBlack = SkToBool(blendOpts & GrDrawState::kEmitTransBlack_BlendOptFlag);
- bool colorIsSolidWhite = (blendOpts & GrDrawState::kEmitCoverage_BlendOptFlag) ||
- (!requiresColorAttrib && 0xffffffff == drawState.getColor()) ||
- (!inputColorIsUsed);
-
bool readsDst = false;
bool readFragPosition = false;
// We use vertexshader-less shader programs only when drawing paths.
@@ -192,11 +188,7 @@ bool GrGLProgramDesc::Build(const GrDrawState& drawState,
#endif
bool defaultToUniformInputs = GR_GL_NO_CONSTANT_ATTRIBUTES || gpu->caps()->pathRenderingSupport();
- if (colorIsTransBlack) {
- header->fColorInput = kTransBlack_ColorInput;
- } else if (colorIsSolidWhite) {
- header->fColorInput = kSolidWhite_ColorInput;
- } else if (defaultToUniformInputs && !requiresColorAttrib) {
+ if (defaultToUniformInputs && !requiresColorAttrib && inputColorIsUsed) {
header->fColorInput = kUniform_ColorInput;
} else {
header->fColorInput = kAttribute_ColorInput;
@@ -205,11 +197,9 @@ bool GrGLProgramDesc::Build(const GrDrawState& drawState,
bool covIsSolidWhite = !requiresCoverageAttrib && 0xffffffff == drawState.getCoverageColor();
- if (skipCoverage) {
- header->fCoverageInput = kTransBlack_ColorInput;
- } else if (covIsSolidWhite || !inputCoverageIsUsed) {
+ if ((covIsSolidWhite || !inputCoverageIsUsed) && !skipCoverage) {
header->fCoverageInput = kSolidWhite_ColorInput;
- } else if (defaultToUniformInputs && !requiresCoverageAttrib) {
+ } else if (defaultToUniformInputs && !requiresCoverageAttrib && inputCoverageIsUsed) {
header->fCoverageInput = kUniform_ColorInput;
} else {
header->fCoverageInput = kAttribute_ColorInput;
diff --git a/src/gpu/gl/GrGLProgramDesc.h b/src/gpu/gl/GrGLProgramDesc.h
index a8d27ab269..cccdee9ce2 100644
--- a/src/gpu/gl/GrGLProgramDesc.h
+++ b/src/gpu/gl/GrGLProgramDesc.h
@@ -100,7 +100,6 @@ private:
// Specifies where the initial color comes from before the stages are applied.
enum ColorInput {
kSolidWhite_ColorInput,
- kTransBlack_ColorInput,
kAttribute_ColorInput,
kUniform_ColorInput,
diff --git a/src/gpu/gl/GrGLShaderBuilder.cpp b/src/gpu/gl/GrGLShaderBuilder.cpp
index 7a57d8e32e..8d1e66be7c 100644
--- a/src/gpu/gl/GrGLShaderBuilder.cpp
+++ b/src/gpu/gl/GrGLShaderBuilder.cpp
@@ -164,10 +164,6 @@ bool GrGLShaderBuilder::genProgram(const GrEffectStage* colorStages[],
this->addUniform(GrGLShaderBuilder::kFragment_Visibility, kVec4f_GrSLType, "Color",
&name);
inputColor = GrGLSLExpr4(name);
- } else if (GrGLProgramDesc::kSolidWhite_ColorInput == header.fColorInput) {
- inputColor = GrGLSLExpr4(1);
- } else if (GrGLProgramDesc::kTransBlack_ColorInput == header.fColorInput) {
- inputColor = GrGLSLExpr4(0);
}
if (GrGLProgramDesc::kUniform_ColorInput == header.fCoverageInput) {
@@ -178,8 +174,6 @@ bool GrGLShaderBuilder::genProgram(const GrEffectStage* colorStages[],
inputCoverage = GrGLSLExpr4(name);
} else if (GrGLProgramDesc::kSolidWhite_ColorInput == header.fCoverageInput) {
inputCoverage = GrGLSLExpr4(1);
- } else if (GrGLProgramDesc::kTransBlack_ColorInput == header.fCoverageInput) {
- inputCoverage = GrGLSLExpr4(0);
}
if (k110_GrGLSLGeneration != fGpu->glslGeneration()) {
diff --git a/src/gpu/gl/GrGpuGL_program.cpp b/src/gpu/gl/GrGpuGL_program.cpp
index 9e1b6f5c2b..45181c25a8 100644
--- a/src/gpu/gl/GrGpuGL_program.cpp
+++ b/src/gpu/gl/GrGpuGL_program.cpp
@@ -353,9 +353,12 @@ void GrGpuGL::setupGeometry(const DrawInfo& info, size_t* indexOffsetInBytes) {
uint32_t usedAttribArraysMask = 0;
const GrVertexAttrib* vertexAttrib = this->getDrawState().getVertexAttribs();
+ bool canIgnoreColorAttrib = this->getDrawState().canIgnoreColorAttribute();
+
for (int vertexAttribIndex = 0; vertexAttribIndex < vertexAttribCount;
++vertexAttribIndex, ++vertexAttrib) {
+ if (kColor_GrVertexAttribBinding != vertexAttrib->fBinding || !canIgnoreColorAttrib) {
usedAttribArraysMask |= (1 << vertexAttribIndex);
GrVertexAttribType attribType = vertexAttrib->fType;
attribState->set(this,
@@ -367,6 +370,7 @@ void GrGpuGL::setupGeometry(const DrawInfo& info, size_t* indexOffsetInBytes) {
stride,
reinterpret_cast<GrGLvoid*>(
vertexOffsetInBytes + vertexAttrib->fOffset));
+ }
}
attribState->disableUnusedArrays(this, usedAttribArraysMask);
}