Index: src/gpu/instanced/InstanceProcessor.cpp |
diff --git a/src/gpu/instanced/InstanceProcessor.cpp b/src/gpu/instanced/InstanceProcessor.cpp |
index acad4c1e1b0e446d71de88e1411cd534759bef24..266c8b76355386cece75ebbd32d6ac02c4cb27bb 100644 |
--- a/src/gpu/instanced/InstanceProcessor.cpp |
+++ b/src/gpu/instanced/InstanceProcessor.cpp |
@@ -561,7 +561,7 @@ private: |
void GLSLInstanceProcessor::BackendNonAA::onInit(GrGLSLVaryingHandler* varyingHandler, |
GrGLSLVertexBuilder*) { |
if (kRect_ShapeFlag != fBatchInfo.fShapeTypes) { |
- varyingHandler->addFlatVarying("triangleIsArc", &fTriangleIsArc, kHigh_GrSLPrecision); |
+ varyingHandler->addFlatVarying("triangleIsArc", &fTriangleIsArc, kLow_GrSLPrecision); |
varyingHandler->addVarying("arcCoords", &fArcCoords, kMedium_GrSLPrecision); |
} |
} |
@@ -738,9 +738,9 @@ void GLSLInstanceProcessor::BackendCoverage::onInit(GrGLSLVaryingHandler* varyin |
v->codeAppend("float rectCoverage = 0.0;"); |
} |
if (kRect_ShapeFlag != fBatchInfo.fShapeTypes) { |
- varyingHandler->addFlatVarying("triangleIsArc", &fTriangleIsArc, kHigh_GrSLPrecision); |
+ varyingHandler->addFlatVarying("triangleIsArc", &fTriangleIsArc, kLow_GrSLPrecision); |
if (!fShapeIsCircle) { |
- varyingHandler->addVarying("ellipseCoords", &fEllipseCoords, kHigh_GrSLPrecision); |
+ varyingHandler->addVarying("ellipseCoords", &fEllipseCoords, kMedium_GrSLPrecision); |
varyingHandler->addFlatVarying("ellipseName", &fEllipseName, kHigh_GrSLPrecision); |
} else { |
varyingHandler->addVarying("circleCoords", &fEllipseCoords, kMedium_GrSLPrecision); |
@@ -845,18 +845,18 @@ void GLSLInstanceProcessor::BackendCoverage::onInitInnerShape(GrGLSLVaryingHandl |
if (kOval_ShapeFlag == fBatchInfo.fInnerShapeTypes) { |
varyingHandler->addVarying("innerEllipseCoords", &fInnerEllipseCoords, |
kMedium_GrSLPrecision); |
- varyingHandler->addFlatVarying("innerEllipseName", &fInnerEllipseName, |
- kMedium_GrSLPrecision); |
+ varyingHandler->addFlatVarying("innerEllipseName", &fInnerEllipseName, kHigh_GrSLPrecision); |
} else { |
varyingHandler->addVarying("distanceToInnerEdge", &fDistanceToInnerEdge, |
kMedium_GrSLPrecision); |
varyingHandler->addFlatVarying("innerShapeBloatedHalfSize", &fInnerShapeBloatedHalfSize, |
kMedium_GrSLPrecision); |
if (kRect_ShapeFlag != fBatchInfo.fInnerShapeTypes) { |
- varyingHandler->addVarying("innerShapeCoords", &fInnerShapeCoords, kHigh_GrSLPrecision); |
+ varyingHandler->addVarying("innerShapeCoords", &fInnerShapeCoords, |
+ kMedium_GrSLPrecision); |
varyingHandler->addFlatVarying("innerEllipseName", &fInnerEllipseName, |
- kMedium_GrSLPrecision); |
- varyingHandler->addFlatVarying("innerRRect", &fInnerRRect, kHigh_GrSLPrecision); |
+ kHigh_GrSLPrecision); |
+ varyingHandler->addFlatVarying("innerRRect", &fInnerRRect, kMedium_GrSLPrecision); |
} |
} |
} |
@@ -952,11 +952,13 @@ void GLSLInstanceProcessor::BackendCoverage::onEmitCode(GrGLSLVertexBuilder* v, |
this->emitInnerRect(f, innerCoverageDecl.c_str()); |
} else { |
f->codeAppendf("%s = 0.0;", innerCoverageDecl.c_str()); |
+ f->appendPrecisionModifier(kMedium_GrSLPrecision); |
f->codeAppendf("vec2 distanceToArcEdge = abs(%s) - %s.xy;", |
fInnerShapeCoords.fsIn(), fInnerRRect.fsIn()); |
f->codeAppend ("if (any(lessThan(distanceToArcEdge, vec2(1e-5)))) {"); |
this->emitInnerRect(f, "innerCoverage"); |
f->codeAppend ("} else {"); |
+ f->appendPrecisionModifier(kMedium_GrSLPrecision); |
f->codeAppendf( "vec2 ellipseCoords = distanceToArcEdge * %s.zw;", |
fInnerRRect.fsIn()); |
this->emitArc(f, "ellipseCoords", fInnerEllipseName.fsIn(), |
@@ -990,6 +992,7 @@ void GLSLInstanceProcessor::BackendCoverage::emitCircle(GrGLSLPPFragmentBuilder* |
const char* outCoverage) { |
// TODO: circleCoords = max(circleCoords, 0) if we decide to do this optimization on rrects. |
SkASSERT(!(kRRect_ShapesMask & fBatchInfo.fShapeTypes)); |
+ f->appendPrecisionModifier(kLow_GrSLPrecision); |
f->codeAppendf("float distanceToEdge = %s - length(%s);", |
fBloatedRadius.fsIn(), fEllipseCoords.fsIn()); |
f->codeAppendf("%s = clamp(distanceToEdge, 0.0, 1.0);", outCoverage); |
@@ -1006,6 +1009,7 @@ void GLSLInstanceProcessor::BackendCoverage::emitArc(GrGLSLPPFragmentBuilder* f, |
// This serves two purposes: |
// - To restrict the arcs of rounded rects to their positive quadrants. |
// - To avoid inversesqrt(0) in the ellipse formula. |
+ f->appendPrecisionModifier(kMedium_GrSLPrecision); |
if (ellipseCoordsMayBeNegative) { |
f->codeAppendf("vec2 ellipseClampedCoords = max(abs(%s), vec2(1e-4));", ellipseCoords); |
} else { |
@@ -1014,12 +1018,15 @@ void GLSLInstanceProcessor::BackendCoverage::emitArc(GrGLSLPPFragmentBuilder* f, |
ellipseCoords = "ellipseClampedCoords"; |
} |
// ellipseCoords are in pixel space and ellipseName is 1 / rx^2, 1 / ry^2. |
+ f->appendPrecisionModifier(kHigh_GrSLPrecision); |
f->codeAppendf("vec2 Z = %s * %s;", ellipseCoords, ellipseName); |
// implicit is the evaluation of (x/rx)^2 + (y/ry)^2 - 1. |
+ f->appendPrecisionModifier(kHigh_GrSLPrecision); |
f->codeAppendf("float implicit = dot(Z, %s) - 1.0;", ellipseCoords); |
// gradDot is the squared length of the gradient of the implicit. |
+ f->appendPrecisionModifier(kHigh_GrSLPrecision); |
f->codeAppendf("float gradDot = 4.0 * dot(Z, Z);"); |
- f->appendPrecisionModifier(kLow_GrSLPrecision); |
+ f->appendPrecisionModifier(kMedium_GrSLPrecision); |
f->codeAppend ("float approxDist = implicit * inversesqrt(gradDot);"); |
f->codeAppendf("%s = clamp(0.5 - approxDist, 0.0, 1.0);", outCoverage); |
} |
@@ -1112,8 +1119,7 @@ void GLSLInstanceProcessor::BackendMultisample::onInit(GrGLSLVaryingHandler* var |
GrGLSLVertexBuilder* v) { |
if (!this->isMixedSampled()) { |
if (kRect_ShapeFlag != fBatchInfo.fShapeTypes) { |
- varyingHandler->addFlatVarying("triangleIsArc", &fTriangleIsArc, |
- kHigh_GrSLPrecision); |
+ varyingHandler->addFlatVarying("triangleIsArc", &fTriangleIsArc, kLow_GrSLPrecision); |
varyingHandler->addVarying("arcCoords", &fArcCoords, kHigh_GrSLPrecision); |
if (!fBatchInfo.fHasPerspective) { |
varyingHandler->addFlatVarying("arcInverseMatrix", &fArcInverseMatrix, |
@@ -1147,7 +1153,7 @@ void GLSLInstanceProcessor::BackendMultisample::onInit(GrGLSLVaryingHandler* var |
fFragArcHalfSpan = fFragShapeHalfSpan; |
if (fBatchInfo.fShapeTypes & kRect_ShapeFlag) { |
varyingHandler->addFlatVarying("triangleIsArc", &fTriangleIsArc, |
- kHigh_GrSLPrecision); |
+ kLow_GrSLPrecision); |
} |
} |
if (kRect_ShapeFlag != fBatchInfo.fShapeTypes) { |