aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/ccpr/GrCCCubicShader.cpp
diff options
context:
space:
mode:
authorGravatar Chris Dalton <csmartdalton@google.com>2018-03-21 17:20:21 -0600
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-03-26 20:25:44 +0000
commit21ba551f13b2cd15c0cfc2743c6ea3b83976f1b6 (patch)
tree531c5dc7e166879aaf421e41c1d91c6143a14b58 /src/gpu/ccpr/GrCCCubicShader.cpp
parent4ccf49c1bf312558f57d9b0339529c0cc6b235a1 (diff)
ccpr: Replace curve corner MSAA with analytic attenuation
Begins using the new triangle corner algorithm on curves as well. Updates the vertex backend to render curves in a single pass. Simplifies the cubic and quadratic shaders. Removes all code related to sample locations. Bug: skia: Change-Id: I96c6c401be765e96a8fe087deb7f84760e68dcf0 Reviewed-on: https://skia-review.googlesource.com/115746 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Chris Dalton <csmartdalton@google.com>
Diffstat (limited to 'src/gpu/ccpr/GrCCCubicShader.cpp')
-rw-r--r--src/gpu/ccpr/GrCCCubicShader.cpp120
1 files changed, 33 insertions, 87 deletions
diff --git a/src/gpu/ccpr/GrCCCubicShader.cpp b/src/gpu/ccpr/GrCCCubicShader.cpp
index 4dc100b892..edff5ff563 100644
--- a/src/gpu/ccpr/GrCCCubicShader.cpp
+++ b/src/gpu/ccpr/GrCCCubicShader.cpp
@@ -13,8 +13,7 @@
using Shader = GrCCCoverageProcessor::Shader;
void GrCCCubicShader::emitSetupCode(GrGLSLVertexGeoBuilder* s, const char* pts,
- const char* repetitionID, const char* wind,
- GeometryVars* vars) const {
+ const char* wind, const char** /*tighterHull*/) const {
// Find the cubic's power basis coefficients.
s->codeAppendf("float2x4 C = float4x4(-1, 3, -3, 1, "
" 3, -6, 3, 0, "
@@ -58,14 +57,12 @@ void GrCCCubicShader::emitSetupCode(GrGLSLVertexGeoBuilder* s, const char* pts,
// Evaluate the cubic at T=.5 for a mid-ish point.
s->codeAppendf("float2 midpoint = %s * float4(.125, .375, .375, .125);", pts);
- // Orient the KLM matrix so L & M have matching signs on the side of the curve we wish to fill.
- // We give L & M both the same sign as wind, in order to pass this value to the fragment shader.
- // (Cubics are pre-chopped such that L & M do not change sign within any individual segment).
+ // Orient the KLM matrix so L & M are both positive on the side of the curve we wish to fill.
s->codeAppendf("float2 orientation = sign(float3(midpoint, 1) * float2x3(%s[1], %s[2]));",
fKLMMatrix.c_str(), fKLMMatrix.c_str());
s->codeAppendf("%s *= float3x3(orientation[0] * orientation[1], 0, 0, "
- "0, orientation[0] * %s, 0, "
- "0, 0, orientation[1] * %s);", fKLMMatrix.c_str(), wind, wind);
+ "0, orientation[0], 0, "
+ "0, 0, orientation[1]);", fKLMMatrix.c_str());
// Determine the amount of additional coverage to subtract out for the flat edge (P3 -> P0).
s->declareGlobal(fEdgeDistanceEquation);
@@ -73,105 +70,54 @@ void GrCCCubicShader::emitSetupCode(GrGLSLVertexGeoBuilder* s, const char* pts,
s->codeAppendf("float2 edgept0 = %s[edgeidx0];", pts);
s->codeAppendf("float2 edgept1 = %s[3 - edgeidx0];", pts);
Shader::EmitEdgeDistanceEquation(s, "edgept0", "edgept1", fEdgeDistanceEquation.c_str());
-
- this->onEmitSetupCode(s, pts, repetitionID, vars);
}
void GrCCCubicShader::onEmitVaryings(GrGLSLVaryingHandler* varyingHandler,
GrGLSLVarying::Scope scope, SkString* code,
const char* position, const char* coverage,
- const char* attenuatedCoverage, const char* /*wind*/) {
- SkASSERT(!coverage);
- SkASSERT(!attenuatedCoverage);
-
+ const char* attenuatedCoverage) {
fKLMD.reset(kFloat4_GrSLType, scope);
varyingHandler->addVarying("klmd", &fKLMD);
code->appendf("float3 klm = float3(%s, 1) * %s;", position, fKLMMatrix.c_str());
- code->appendf("float d = dot(float3(%s, 1), %s);", position, fEdgeDistanceEquation.c_str());
- code->appendf("%s = float4(klm, d);", OutName(fKLMD));
-
- this->onEmitVaryings(varyingHandler, scope, code);
-}
-
-void GrCCCubicShader::onEmitFragmentCode(GrGLSLFPFragmentBuilder* f,
- const char* outputCoverage) const {
- f->codeAppendf("float k = %s.x, l = %s.y, m = %s.z, d = %s.w;",
- fKLMD.fsIn(), fKLMD.fsIn(), fKLMD.fsIn(), fKLMD.fsIn());
-
- this->emitCoverage(f, outputCoverage);
-
- // Wind is the sign of both L and/or M. Take the sign of whichever has the larger magnitude.
- // (In reality, either would be fine because we chop cubics with more than a half pixel of
- // padding around the L & M lines, so neither should approach zero.)
- f->codeAppend ("half wind = sign(l + m);");
- f->codeAppendf("%s *= wind;", outputCoverage);
-}
+ // We give L & M both the same sign as wind, in order to pass this value to the fragment shader.
+ // (Cubics are pre-chopped such that L & M do not change sign within any individual segment.)
+ code->appendf("%s.xyz = klm * float3(1, %s, %s);",
+ OutName(fKLMD), coverage, coverage); // coverage == wind on curves.
+ code->appendf("%s.w = dot(float3(%s, 1), %s);", // Flat edge opposite the curve.
+ OutName(fKLMD), position, fEdgeDistanceEquation.c_str());
-void GrCCCubicHullShader::onEmitVaryings(GrGLSLVaryingHandler* varyingHandler,
- GrGLSLVarying::Scope scope, SkString* code) {
fGradMatrix.reset(kFloat2x2_GrSLType, scope);
varyingHandler->addVarying("grad_matrix", &fGradMatrix);
- // "klm" was just defined by the base class.
code->appendf("%s[0] = 2*bloat * 3 * klm[0] * %s[0].xy;",
OutName(fGradMatrix), fKLMMatrix.c_str());
code->appendf("%s[1] = -2*bloat * (klm[1] * %s[2].xy + klm[2] * %s[1].xy);",
- OutName(fGradMatrix), fKLMMatrix.c_str(), fKLMMatrix.c_str());
+ OutName(fGradMatrix), fKLMMatrix.c_str(), fKLMMatrix.c_str());
+
+ if (attenuatedCoverage) {
+ fCornerCoverage.reset(kHalf2_GrSLType, scope);
+ varyingHandler->addVarying("corner_coverage", &fCornerCoverage);
+ code->appendf("%s = %s;", // Attenuated corner coverage.
+ OutName(fCornerCoverage), attenuatedCoverage);
+ }
}
-void GrCCCubicHullShader::emitCoverage(GrGLSLFPFragmentBuilder* f,
- const char* outputCoverage) const {
- // k,l,m,d are defined by the base class.
+void GrCCCubicShader::onEmitFragmentCode(GrGLSLFPFragmentBuilder* f,
+ const char* outputCoverage) const {
+ f->codeAppendf("float k = %s.x, l = %s.y, m = %s.z;", fKLMD.fsIn(), fKLMD.fsIn(), fKLMD.fsIn());
f->codeAppend ("float f = k*k*k - l*m;");
f->codeAppendf("float2 grad_f = %s * float2(k, 1);", fGradMatrix.fsIn());
f->codeAppendf("%s = clamp(0.5 - f * inversesqrt(dot(grad_f, grad_f)), 0, 1);", outputCoverage);
- f->codeAppendf("%s += min(d, 0);", outputCoverage); // Flat edge opposite the curve.
-}
-
-void GrCCCubicCornerShader::onEmitSetupCode(GrGLSLVertexGeoBuilder* s, const char* pts,
- const char* repetitionID, GeometryVars* vars) const {
- s->codeAppendf("float2 corner = %s[%s * 3];", pts, repetitionID);
- vars->fCornerVars.fPoint = "corner";
-}
-
-void GrCCCubicCornerShader::onEmitVaryings(GrGLSLVaryingHandler* varyingHandler,
- GrGLSLVarying::Scope scope, SkString* code) {
- using Interpolation = GrGLSLVaryingHandler::Interpolation;
-
- fdKLMDdx.reset(kFloat4_GrSLType, scope);
- varyingHandler->addVarying("dklmddx", &fdKLMDdx, Interpolation::kCanBeFlat);
- code->appendf("%s = 2*bloat * float4(%s[0].x, %s[1].x, %s[2].x, %s.x);",
- OutName(fdKLMDdx), fKLMMatrix.c_str(), fKLMMatrix.c_str(),
- fKLMMatrix.c_str(), fEdgeDistanceEquation.c_str());
-
- fdKLMDdy.reset(kFloat4_GrSLType, scope);
- varyingHandler->addVarying("dklmddy", &fdKLMDdy, Interpolation::kCanBeFlat);
- code->appendf("%s = 2*bloat * float4(%s[0].y, %s[1].y, %s[2].y, %s.y);",
- OutName(fdKLMDdy), fKLMMatrix.c_str(), fKLMMatrix.c_str(),
- fKLMMatrix.c_str(), fEdgeDistanceEquation.c_str());
-}
-void GrCCCubicCornerShader::emitCoverage(GrGLSLFPFragmentBuilder* f,
- const char* outputCoverage) const {
- f->codeAppendf("float2x4 grad_klmd = float2x4(%s, %s);", fdKLMDdx.fsIn(), fdKLMDdy.fsIn());
+ f->codeAppendf("half d = min(%s.w, 0);", fKLMD.fsIn()); // Flat edge opposite the curve.
+ // Wind is the sign of both L and/or M. Take the sign of whichever has the larger magnitude.
+ // (In reality, either would be fine because we chop cubics with more than a half pixel of
+ // padding around the L & M lines, so neither should approach zero.)
+ f->codeAppend ("half wind = sign(l + m);");
+ f->codeAppendf("%s = (%s + d) * wind;", outputCoverage, outputCoverage);
- // Erase what the previous hull shader wrote. We don't worry about the two corners falling on
- // the same pixel because those cases should have been weeded out by this point.
- // k,l,m,d are defined by the base class.
- f->codeAppend ("float f = k*k*k - l*m;");
- f->codeAppend ("float2 grad_f = float3(3*k*k, -m, -l) * float2x3(grad_klmd);");
- f->codeAppendf("%s = -clamp(0.5 - f * inversesqrt(dot(grad_f, grad_f)), 0, 1);",
- outputCoverage);
- f->codeAppendf("%s -= d;", outputCoverage);
-
- // Use software msaa to estimate actual coverage at the corner pixels.
- const int sampleCount = Shader::DefineSoftSampleLocations(f, "samples");
- f->codeAppendf("float4 klmd_center = float4(%s.xyz, %s.w + 0.5);",
- fKLMD.fsIn(), fKLMD.fsIn());
- f->codeAppendf("for (int i = 0; i < %i; ++i) {", sampleCount);
- f->codeAppend ( "float4 klmd = grad_klmd * samples[i] + klmd_center;");
- f->codeAppend ( "half f = klmd.y * klmd.z - klmd.x * klmd.x * klmd.x;");
- f->codeAppendf( "%s += all(greaterThan(half4(f, klmd.y, klmd.z, klmd.w), "
- "half4(0))) ? %f : 0;",
- outputCoverage, 1.0 / sampleCount);
- f->codeAppend ("}");
+ if (fCornerCoverage.fsIn()) {
+ f->codeAppendf("%s = %s.x * %s.y + %s;", // Attenuated corner coverage.
+ outputCoverage, fCornerCoverage.fsIn(), fCornerCoverage.fsIn(),
+ outputCoverage);
+ }
}