Revert "Support combining per-vertex coverage with color in default GP vertex shader"
This reverts commit 8e13f69262eeb01e926df4eb79e89615cc741be5.
Reason for revert: Layout tests still failing.
Original change's description:
> Support combining per-vertex coverage with color in default GP vertex shader
>
> Leverage this in ops that use tessellation with per-vertex coverage, to
> move the (color * coverage) work into the vertex shader.
>
> For the tessellating path renderer, color is always uniform, but we were
> sending it per-vertex. Added support to the default GP for routing the
> uniform color to the vertex shader (when there is per-vertex coverage and
> coverage can be folded into alpha). The end result is that we do less work
> on the CPU, and send less data (for incompatible blend modes) or the same
> amount (for compatible blend modes).
>
> Finally, because color is never sent through a vertex attribute, this
> solves wide color (and avoids the vertex bloat that would have happened
> when using half-floats). For the linearizing convex path renderer, do the
> usual fix for wide color.
>
> PS6 is the "clean" version of this CL, later versions are guarded to
> rebaseline layout tests.
>
> Bug: skia:
> Change-Id: I7fa87219177d36db800463d4492b78f2cb14a1c3
> Reviewed-on: https://skia-review.googlesource.com/c/179996
> Reviewed-by: Brian Salomon <bsalomon@google.com>
> Reviewed-by: Jim Van Verth <jvanverth@google.com>
> Commit-Queue: Brian Osman <brianosman@google.com>
TBR=jvanverth@google.com,bsalomon@google.com,senorblanco@chromium.org,brianosman@google.com,senorblanco@google.com
Change-Id: Idf2b4c4b4d6bb6683bf6293d9e9a5ba097f38289
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/c/181762
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/src/gpu/GrDefaultGeoProcFactory.cpp b/src/gpu/GrDefaultGeoProcFactory.cpp
index 3a81a25..172b6d8 100644
--- a/src/gpu/GrDefaultGeoProcFactory.cpp
+++ b/src/gpu/GrDefaultGeoProcFactory.cpp
@@ -29,8 +29,7 @@
kColorAttributeIsWide_GPFlag = 0x4,
kLocalCoordAttribute_GPFlag = 0x8,
kCoverageAttribute_GPFlag = 0x10,
- kCoverageAttributeTweak_GPFlag = 0x20,
- kBonesAttribute_GPFlag = 0x40,
+ kBonesAttribute_GPFlag = 0x20,
};
static constexpr int kNumVec2sPerBone = 3; // Our bone matrices are 3x2 matrices passed in as
@@ -84,26 +83,13 @@
// emit attributes
varyingHandler->emitAttributes(gp);
- bool tweakAlpha = SkToBool(gp.fFlags & kCoverageAttributeTweak_GPFlag);
- SkASSERT(!tweakAlpha || gp.hasVertexCoverage());
-
// Setup pass through color
- if (gp.hasVertexColor() || tweakAlpha) {
+ if (gp.hasVertexColor()) {
GrGLSLVarying varying(kHalf4_GrSLType);
varyingHandler->addVarying("color", &varying);
- // There are several optional steps to process the color. Start with the attribute,
- // or with uniform color (in the case of folding coverage into a uniform color):
- if (gp.hasVertexColor()) {
- vertBuilder->codeAppendf("half4 color = %s;", gp.fInColor.name());
- } else {
- const char* colorUniformName;
- fColorUniform = uniformHandler->addUniform(kVertex_GrShaderFlag,
- kHalf4_GrSLType,
- "Color",
- &colorUniformName);
- vertBuilder->codeAppendf("half4 color = %s;", colorUniformName);
- }
+ // There are several optional steps to process the color. Start with the attribute:
+ vertBuilder->codeAppendf("half4 color = %s;", gp.fInColor.name());
// For SkColor, do a red/blue swap, possible color space conversion, and premul
if (gp.fFlags & kColorAttributeIsSkColor_GPFlag) {
@@ -121,10 +107,6 @@
vertBuilder->codeAppend("color = half4(color.rgb * color.a, color.a);");
}
- // Optionally fold coverage into alpha (color).
- if (tweakAlpha) {
- vertBuilder->codeAppendf("color = color * %s;", gp.fInCoverage.name());
- }
vertBuilder->codeAppendf("%s = color;\n", varying.vsOut());
fragBuilder->codeAppendf("%s = %s;", args.fOutputColor, varying.fsIn());
} else {
@@ -210,7 +192,7 @@
}
// Setup coverage as pass through
- if (gp.hasVertexCoverage() && !tweakAlpha) {
+ if (gp.hasVertexCoverage()) {
fragBuilder->codeAppendf("half alpha = 1.0;");
varyingHandler->addPassThroughAttribute(gp.fInCoverage, "alpha");
fragBuilder->codeAppendf("%s = half4(alpha);", args.fOutputCoverage);
@@ -231,8 +213,8 @@
GrProcessorKeyBuilder* b) {
const DefaultGeoProc& def = gp.cast<DefaultGeoProc>();
uint32_t key = def.fFlags;
- key |= (def.coverage() == 0xff) ? 0x80 : 0;
- key |= (def.localCoordsWillBeRead() && def.localMatrix().hasPerspective()) ? 0x100 : 0;
+ key |= (def.coverage() == 0xff) ? 0x40 : 0;
+ key |= (def.localCoordsWillBeRead() && def.localMatrix().hasPerspective()) ? 0x80 : 0x0;
key |= ComputePosKey(def.viewMatrix()) << 20;
b->add32(key);
b->add32(GrColorSpaceXform::XformKey(def.fColorSpaceXform.get()));
@@ -414,9 +396,6 @@
}
if (d->fRandom->nextBool()) {
flags |= kCoverageAttribute_GPFlag;
- if (d->fRandom->nextBool()) {
- flags |= kCoverageAttributeTweak_GPFlag;
- }
}
if (d->fRandom->nextBool()) {
flags |= kLocalCoordAttribute_GPFlag;
@@ -451,11 +430,7 @@
} else if (Color::kPremulWideColorAttribute_Type == color.fType) {
flags |= kColorAttribute_GPFlag | kColorAttributeIsWide_GPFlag;
}
- if (Coverage::kAttribute_Type == coverage.fType) {
- flags |= kCoverageAttribute_GPFlag;
- } else if (Coverage::kAttributeTweakAlpha_Type == coverage.fType) {
- flags |= kCoverageAttribute_GPFlag | kCoverageAttributeTweak_GPFlag;
- }
+ flags |= coverage.fType == Coverage::kAttribute_Type ? kCoverageAttribute_GPFlag : 0;
flags |= localCoords.fType == LocalCoords::kHasExplicit_Type ? kLocalCoordAttribute_GPFlag : 0;
uint8_t inCoverage = coverage.fCoverage;
@@ -509,11 +484,7 @@
} else if (Color::kPremulWideColorAttribute_Type == color.fType) {
flags |= kColorAttribute_GPFlag | kColorAttributeIsWide_GPFlag;
}
- if (Coverage::kAttribute_Type == coverage.fType) {
- flags |= kCoverageAttribute_GPFlag;
- } else if (Coverage::kAttributeTweakAlpha_Type == coverage.fType) {
- flags |= kCoverageAttribute_GPFlag | kCoverageAttributeTweak_GPFlag;
- }
+ flags |= coverage.fType == Coverage::kAttribute_Type ? kCoverageAttribute_GPFlag : 0;
flags |= localCoords.fType == LocalCoords::kHasExplicit_Type ? kLocalCoordAttribute_GPFlag : 0;
flags |= kBonesAttribute_GPFlag;
diff --git a/src/gpu/GrDefaultGeoProcFactory.h b/src/gpu/GrDefaultGeoProcFactory.h
index 96363f0..af33668 100644
--- a/src/gpu/GrDefaultGeoProcFactory.h
+++ b/src/gpu/GrDefaultGeoProcFactory.h
@@ -50,7 +50,6 @@
kSolid_Type,
kUniform_Type,
kAttribute_Type,
- kAttributeTweakAlpha_Type,
};
explicit Coverage(uint8_t coverage) : fType(kUniform_Type), fCoverage(coverage) {}
Coverage(Type type) : fType(type), fCoverage(0xff) {
diff --git a/src/gpu/GrTessellator.cpp b/src/gpu/GrTessellator.cpp
index b753707..19b859e 100644
--- a/src/gpu/GrTessellator.cpp
+++ b/src/gpu/GrTessellator.cpp
@@ -175,17 +175,10 @@
/***************************************************************************************/
-#ifdef SK_LEGACY_TESSELLATOR_CPU_COVERAGE
struct AAParams {
bool fTweakAlpha;
GrColor fColor;
};
-#define AA_PARAM const AAParams* aaParams
-#define AA_ARG aaParams
-#else
-#define AA_PARAM bool emitCoverage
-#define AA_ARG emitCoverage
-#endif
typedef bool (*CompareFunc)(const SkPoint& a, const SkPoint& b);
@@ -206,11 +199,10 @@
Direction fDirection;
};
-inline void* emit_vertex(Vertex* v, AA_PARAM, void* data) {
+inline void* emit_vertex(Vertex* v, const AAParams* aaParams, void* data) {
GrVertexWriter verts{data};
verts.write(v->fPoint);
-#ifdef SK_LEGACY_TESSELLATOR_CPU_COVERAGE
if (aaParams) {
if (aaParams->fTweakAlpha) {
verts.write(SkAlphaMulQ(aaParams->fColor, SkAlpha255To256(v->fAlpha)));
@@ -218,29 +210,24 @@
verts.write(aaParams->fColor, GrNormalizeByteToFloat(v->fAlpha));
}
}
-#else
- if (emitCoverage) {
- verts.write(GrNormalizeByteToFloat(v->fAlpha));
- }
-#endif
return verts.fPtr;
}
-void* emit_triangle(Vertex* v0, Vertex* v1, Vertex* v2, AA_PARAM, void* data) {
+void* emit_triangle(Vertex* v0, Vertex* v1, Vertex* v2, const AAParams* aaParams, void* data) {
LOG("emit_triangle %g (%g, %g) %d\n", v0->fID, v0->fPoint.fX, v0->fPoint.fY, v0->fAlpha);
LOG(" %g (%g, %g) %d\n", v1->fID, v1->fPoint.fX, v1->fPoint.fY, v1->fAlpha);
LOG(" %g (%g, %g) %d\n", v2->fID, v2->fPoint.fX, v2->fPoint.fY, v2->fAlpha);
#if TESSELLATOR_WIREFRAME
- data = emit_vertex(v0, AA_ARG, data);
- data = emit_vertex(v1, AA_ARG, data);
- data = emit_vertex(v1, AA_ARG, data);
- data = emit_vertex(v2, AA_ARG, data);
- data = emit_vertex(v2, AA_ARG, data);
- data = emit_vertex(v0, AA_ARG, data);
+ data = emit_vertex(v0, aaParams, data);
+ data = emit_vertex(v1, aaParams, data);
+ data = emit_vertex(v1, aaParams, data);
+ data = emit_vertex(v2, aaParams, data);
+ data = emit_vertex(v2, aaParams, data);
+ data = emit_vertex(v0, aaParams, data);
#else
- data = emit_vertex(v0, AA_ARG, data);
- data = emit_vertex(v1, AA_ARG, data);
- data = emit_vertex(v2, AA_ARG, data);
+ data = emit_vertex(v0, aaParams, data);
+ data = emit_vertex(v1, aaParams, data);
+ data = emit_vertex(v2, aaParams, data);
#endif
return data;
}
@@ -566,7 +553,7 @@
}
}
- void* emit(AA_PARAM, void* data) {
+ void* emit(const AAParams* aaParams, void* data) {
Edge* e = fFirstEdge;
VertexList vertices;
vertices.append(e->fTop);
@@ -589,14 +576,14 @@
Vertex* curr = v;
Vertex* next = v->fNext;
if (count == 3) {
- return emit_triangle(prev, curr, next, AA_ARG, data);
+ return emit_triangle(prev, curr, next, aaParams, data);
}
double ax = static_cast<double>(curr->fPoint.fX) - prev->fPoint.fX;
double ay = static_cast<double>(curr->fPoint.fY) - prev->fPoint.fY;
double bx = static_cast<double>(next->fPoint.fX) - curr->fPoint.fX;
double by = static_cast<double>(next->fPoint.fY) - curr->fPoint.fY;
if (ax * by - ay * bx >= 0.0) {
- data = emit_triangle(prev, curr, next, AA_ARG, data);
+ data = emit_triangle(prev, curr, next, aaParams, data);
v->fPrev->fNext = v->fNext;
v->fNext->fPrev = v->fPrev;
count--;
@@ -653,13 +640,13 @@
}
return poly;
}
- void* emit(AA_PARAM, void *data) {
+ void* emit(const AAParams* aaParams, void *data) {
if (fCount < 3) {
return data;
}
LOG("emit() %d, size %d\n", fID, fCount);
for (MonotonePoly* m = fHead; m != nullptr; m = m->fNext) {
- data = m->emit(AA_ARG, data);
+ data = m->emit(aaParams, data);
}
return data;
}
@@ -2179,10 +2166,11 @@
}
// Stage 6: Triangulate the monotone polygons into a vertex buffer.
-void* polys_to_triangles(Poly* polys, SkPath::FillType fillType, AA_PARAM, void* data) {
+void* polys_to_triangles(Poly* polys, SkPath::FillType fillType, const AAParams* aaParams,
+ void* data) {
for (Poly* poly = polys; poly; poly = poly->fNext) {
if (apply_fill_type(fillType, poly)) {
- data = poly->emit(AA_ARG, data);
+ data = poly->emit(aaParams, data);
}
}
return data;
@@ -2231,15 +2219,15 @@
return count;
}
-void* outer_mesh_to_triangles(const VertexList& outerMesh, AA_PARAM, void* data) {
+void* outer_mesh_to_triangles(const VertexList& outerMesh, const AAParams* aaParams, void* data) {
for (Vertex* v = outerMesh.fHead; v; v = v->fNext) {
for (Edge* e = v->fFirstEdgeBelow; e; e = e->fNextEdgeBelow) {
Vertex* v0 = e->fTop;
Vertex* v1 = e->fBottom;
Vertex* v2 = e->fBottom->fPartner;
Vertex* v3 = e->fTop->fPartner;
- data = emit_triangle(v0, v1, v2, AA_ARG, data);
- data = emit_triangle(v0, v2, v3, AA_ARG, data);
+ data = emit_triangle(v0, v1, v2, aaParams, data);
+ data = emit_triangle(v0, v2, v3, aaParams, data);
}
}
return data;
@@ -2252,11 +2240,8 @@
// Stage 6: Triangulate the monotone polygons into a vertex buffer.
int PathToTriangles(const SkPath& path, SkScalar tolerance, const SkRect& clipBounds,
- VertexAllocator* vertexAllocator, bool antialias,
-#ifdef SK_LEGACY_TESSELLATOR_CPU_COVERAGE
- const GrColor& color, bool canTweakAlphaForCoverage,
-#endif
- bool* isLinear) {
+ VertexAllocator* vertexAllocator, bool antialias, const GrColor& color,
+ bool canTweakAlphaForCoverage, bool* isLinear) {
int contourCnt = get_contour_count(path, tolerance);
if (contourCnt <= 0) {
*isLinear = true;
@@ -2283,17 +2268,12 @@
}
LOG("emitting %d verts\n", count);
-#ifdef SK_LEGACY_TESSELLATOR_CPU_COVERAGE
AAParams aaParams;
aaParams.fTweakAlpha = canTweakAlphaForCoverage;
aaParams.fColor = color;
+
void* end = polys_to_triangles(polys, fillType, antialias ? &aaParams : nullptr, verts);
end = outer_mesh_to_triangles(outerMesh, &aaParams, end);
-#else
- void* end = polys_to_triangles(polys, fillType, antialias, verts);
- end = outer_mesh_to_triangles(outerMesh, true, end);
-#endif
-
int actualCount = static_cast<int>((static_cast<uint8_t*>(end) - static_cast<uint8_t*>(verts))
/ vertexAllocator->stride());
SkASSERT(actualCount <= count);
@@ -2327,11 +2307,7 @@
for (Poly* poly = polys; poly; poly = poly->fNext) {
if (apply_fill_type(fillType, poly)) {
SkPoint* start = pointsEnd;
-#ifdef SK_LEGACY_TESSELLATOR_CPU_COVERAGE
pointsEnd = static_cast<SkPoint*>(poly->emit(nullptr, pointsEnd));
-#else
- pointsEnd = static_cast<SkPoint*>(poly->emit(false, pointsEnd));
-#endif
while (start != pointsEnd) {
vertsEnd->fPos = *start;
vertsEnd->fWinding = poly->fWinding;
diff --git a/src/gpu/GrTessellator.h b/src/gpu/GrTessellator.h
index 324a72c..4f82ea8 100644
--- a/src/gpu/GrTessellator.h
+++ b/src/gpu/GrTessellator.h
@@ -47,11 +47,8 @@
WindingVertex** verts);
int PathToTriangles(const SkPath& path, SkScalar tolerance, const SkRect& clipBounds,
- VertexAllocator*, bool antialias,
-#ifdef SK_LEGACY_TESSELLATOR_CPU_COVERAGE
- const GrColor& color, bool canTweakAlphaForCoverage,
-#endif
- bool *isLinear);
+ VertexAllocator*, bool antialias, const GrColor& color,
+ bool canTweakAlphaForCoverage, bool *isLinear);
}
#endif
diff --git a/src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp b/src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp
index b007245..52785eb 100644
--- a/src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp
+++ b/src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp
@@ -82,12 +82,22 @@
// extract the result vertices and indices from the GrAAConvexTessellator
static void extract_verts(const GrAAConvexTessellator& tess,
void* vertData,
- const GrVertexColor& color,
+ size_t vertexStride,
+ GrColor color,
uint16_t firstIndex,
- uint16_t* idxs) {
+ uint16_t* idxs,
+ bool tweakAlphaForCoverage) {
GrVertexWriter verts{vertData};
for (int i = 0; i < tess.numPts(); ++i) {
- verts.write(tess.point(i), color, tess.coverage(i));
+ verts.write(tess.point(i));
+ if (tweakAlphaForCoverage) {
+ SkASSERT(SkScalarRoundToInt(255.0f * tess.coverage(i)) <= 255);
+ unsigned scale = SkScalarRoundToInt(255.0f * tess.coverage(i));
+ GrColor scaledColor = (0xff == scale) ? color : SkAlphaMulQ(color, scale);
+ verts.write(scaledColor);
+ } else {
+ verts.write(color, tess.coverage(i));
+ }
}
for (int i = 0; i < tess.numIndices(); ++i) {
@@ -98,18 +108,22 @@
static sk_sp<GrGeometryProcessor> create_lines_only_gp(const GrShaderCaps* shaderCaps,
bool tweakAlphaForCoverage,
const SkMatrix& viewMatrix,
- bool usesLocalCoords,
- bool wideColor) {
+ bool usesLocalCoords) {
using namespace GrDefaultGeoProcFactory;
- Coverage::Type coverageType =
- tweakAlphaForCoverage ? Coverage::kAttributeTweakAlpha_Type : Coverage::kAttribute_Type;
+ Coverage::Type coverageType;
+ if (tweakAlphaForCoverage) {
+ coverageType = Coverage::kSolid_Type;
+ } else {
+ coverageType = Coverage::kAttribute_Type;
+ }
LocalCoords::Type localCoordsType =
- usesLocalCoords ? LocalCoords::kUsePosition_Type : LocalCoords::kUnused_Type;
- Color::Type colorType =
- wideColor ? Color::kPremulWideColorAttribute_Type : Color::kPremulGrColorAttribute_Type;
-
- return MakeForDeviceSpace(shaderCaps, colorType, coverageType, localCoordsType, viewMatrix);
+ usesLocalCoords ? LocalCoords::kUsePosition_Type : LocalCoords::kUnused_Type;
+ return MakeForDeviceSpace(shaderCaps,
+ Color::kPremulGrColorAttribute_Type,
+ coverageType,
+ localCoordsType,
+ viewMatrix);
}
namespace {
@@ -160,7 +174,6 @@
bounds.outset(w, w);
}
this->setTransformedBounds(bounds, viewMatrix, HasAABloat::kYes, IsZeroArea::kNo);
- fWideColor = !SkPMColor4fFitsInBytes(color);
}
const char* name() const override { return "AAFlatteningConvexPathOp"; }
@@ -230,8 +243,7 @@
sk_sp<GrGeometryProcessor> gp(create_lines_only_gp(target->caps().shaderCaps(),
fHelper.compatibleWithAlphaAsCoverage(),
this->viewMatrix(),
- fHelper.usesLocalCoords(),
- fWideColor));
+ fHelper.usesLocalCoords()));
if (!gp) {
SkDebugf("Couldn't create a GrGeometryProcessor\n");
return;
@@ -284,9 +296,10 @@
indices = (uint16_t*) sk_realloc_throw(indices, maxIndices * sizeof(uint16_t));
}
- extract_verts(tess, vertices + vertexStride * vertexCount,
- GrVertexColor(args.fColor, fWideColor), vertexCount,
- indices + indexCount);
+ // TODO4F: Preserve float colors
+ extract_verts(tess, vertices + vertexStride * vertexCount, vertexStride,
+ args.fColor.toBytes_RGBA(), vertexCount, indices + indexCount,
+ fHelper.compatibleWithAlphaAsCoverage());
vertexCount += currentVertices;
indexCount += currentIndices;
}
@@ -305,7 +318,6 @@
}
fPaths.push_back_n(that->fPaths.count(), that->fPaths.begin());
- fWideColor |= that->fWideColor;
return CombineResult::kMerged;
}
@@ -323,7 +335,6 @@
SkSTArray<1, PathData, true> fPaths;
Helper fHelper;
- bool fWideColor;
typedef GrMeshDrawOp INHERITED;
};
diff --git a/src/gpu/ops/GrTessellatingPathRenderer.cpp b/src/gpu/ops/GrTessellatingPathRenderer.cpp
index 28ad083..a59c161 100644
--- a/src/gpu/ops/GrTessellatingPathRenderer.cpp
+++ b/src/gpu/ops/GrTessellatingPathRenderer.cpp
@@ -277,11 +277,8 @@
bool isLinear;
bool canMapVB = GrCaps::kNone_MapFlags != target->caps().mapBufferFlags();
StaticVertexAllocator allocator(vertexStride, rp, canMapVB);
- int count = GrTessellator::PathToTriangles(getPath(), tol, clipBounds, &allocator, false,
-#ifdef SK_LEGACY_TESSELLATOR_CPU_COVERAGE
- GrColor(), false,
-#endif
- &isLinear);
+ int count = GrTessellator::PathToTriangles(getPath(), tol, clipBounds, &allocator,
+ false, GrColor(), false, &isLinear);
if (count == 0) {
return;
}
@@ -305,12 +302,11 @@
SkScalar tol = GrPathUtils::kDefaultTolerance;
bool isLinear;
DynamicVertexAllocator allocator(vertexStride, target);
- int count = GrTessellator::PathToTriangles(path, tol, clipBounds, &allocator, true,
-#ifdef SK_LEGACY_TESSELLATOR_CPU_COVERAGE
- fColor.toBytes_RGBA(),
- fHelper.compatibleWithAlphaAsCoverage(),
-#endif
- &isLinear);
+ // TODO4F: Preserve float colors
+ int count =
+ GrTessellator::PathToTriangles(path, tol, clipBounds, &allocator, true,
+ fColor.toBytes_RGBA(),
+ fHelper.compatibleWithAlphaAsCoverage(), &isLinear);
if (count == 0) {
return;
}
@@ -329,15 +325,9 @@
: LocalCoords::kUnused_Type;
Coverage::Type coverageType;
if (fAntiAlias) {
-#ifdef SK_LEGACY_TESSELLATOR_CPU_COVERAGE
color = Color(Color::kPremulGrColorAttribute_Type);
-#endif
if (fHelper.compatibleWithAlphaAsCoverage()) {
-#ifdef SK_LEGACY_TESSELLATOR_CPU_COVERAGE
coverageType = Coverage::kSolid_Type;
-#else
- coverageType = Coverage::kAttributeTweakAlpha_Type;
-#endif
} else {
coverageType = Coverage::kAttribute_Type;
}