diff options
author | Brian Salomon <bsalomon@google.com> | 2017-08-17 11:07:59 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-08-17 15:08:17 +0000 |
commit | 1d816b92bb7cf2258007f3f74ffd143b89f25d01 (patch) | |
tree | 07fb1e8e2631208eb007a4abdfe130db91e6cfc2 /src/gpu/ccpr | |
parent | 23f92277b916a4bdf11c320799ac9248af60a62e (diff) |
Revert "Switched highp float to highfloat and mediump float to half."
This reverts commit 88d99c63878c2d3d340120f0321676f72afcb4f0.
Reason for revert: Believed to be causing unit test failures in Chrome roll:
https://build.chromium.org/p/tryserver.chromium.android/builders/linux_android_rel_ng/builds/364433
https://luci-logdog.appspot.com/v/?s=chromium%2Fbb%2Ftryserver.chromium.android%2Flinux_android_rel_ng%2F364433%2F%2B%2Frecipes%2Fsteps%2Fcontent_browsertests__with_patch__on_Android%2F0%2Flogs%2FWebRtcCaptureFromElementBrowserTest.VerifyCanvasWebGLCaptureColor%2F0
Original change's description:
> Switched highp float to highfloat and mediump float to half.
>
> The ultimate goal is to end up with "float" and "half", but this
> intermediate step uses "highfloat" so that it is clear if I missed a
> "float" somewhere. Once this lands, a subsequent CL will switch all
> "highfloats" back to "floats".
>
> Bug: skia:
> Change-Id: Ia13225c7a0a0a2901e07665891c473d2500ddcca
> Reviewed-on: https://skia-review.googlesource.com/31000
> Commit-Queue: Ethan Nicholas <ethannicholas@google.com>
> Reviewed-by: Brian Salomon <bsalomon@google.com>
TBR=bsalomon@google.com,csmartdalton@google.com,ethannicholas@google.com
Change-Id: I8bfa97547ac3920d433665f161d27df3f15c83aa
No-Presubmit: true
No-Tree-Checks: true
No-Try: true
Bug: skia:
Reviewed-on: https://skia-review.googlesource.com/35705
Commit-Queue: Brian Salomon <bsalomon@google.com>
Reviewed-by: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/gpu/ccpr')
-rw-r--r-- | src/gpu/ccpr/GrCCPRCoverageProcessor.cpp | 108 | ||||
-rw-r--r-- | src/gpu/ccpr/GrCCPRCoverageProcessor.h | 6 | ||||
-rw-r--r-- | src/gpu/ccpr/GrCCPRCubicProcessor.cpp | 173 | ||||
-rw-r--r-- | src/gpu/ccpr/GrCCPRCubicProcessor.h | 33 | ||||
-rw-r--r-- | src/gpu/ccpr/GrCCPRPathProcessor.cpp | 36 | ||||
-rw-r--r-- | src/gpu/ccpr/GrCCPRQuadraticProcessor.cpp | 78 | ||||
-rw-r--r-- | src/gpu/ccpr/GrCCPRQuadraticProcessor.h | 23 | ||||
-rw-r--r-- | src/gpu/ccpr/GrCCPRTriangleProcessor.cpp | 62 | ||||
-rw-r--r-- | src/gpu/ccpr/GrCCPRTriangleProcessor.h | 10 |
9 files changed, 268 insertions, 261 deletions
diff --git a/src/gpu/ccpr/GrCCPRCoverageProcessor.cpp b/src/gpu/ccpr/GrCCPRCoverageProcessor.cpp index d192ff7430..e4e59ffa40 100644 --- a/src/gpu/ccpr/GrCCPRCoverageProcessor.cpp +++ b/src/gpu/ccpr/GrCCPRCoverageProcessor.cpp @@ -122,8 +122,8 @@ void PrimitiveProcessor::emitVertexShader(const GrCCPRCoverageProcessor& proc, const TexelBufferHandle& pointsBuffer, const char* rtAdjust, GrGPArgs* gpArgs) const { v->codeAppendf("int packedoffset = %s.w;", proc.instanceAttrib()); - v->codeAppend ("highfloat2 atlasoffset = highfloat2((packedoffset<<16) >> 16, " - "packedoffset >> 16);"); + v->codeAppend ("highp float2 atlasoffset = float2((packedoffset<<16) >> 16, " + "packedoffset >> 16);"); this->onEmitVertexShader(proc, v, pointsBuffer, "atlasoffset", rtAdjust, gpArgs); } @@ -135,10 +135,12 @@ void PrimitiveProcessor::emitGeometryShader(const GrCCPRCoverageProcessor& proc, SkString emitVertexFn; SkSTArray<2, GrShaderVar> emitArgs; - const char* position = emitArgs.emplace_back("position", kHighFloat2_GrSLType, - GrShaderVar::kNonArray).c_str(); - const char* coverage = emitArgs.emplace_back("coverage", kHighFloat_GrSLType, - GrShaderVar::kNonArray).c_str(); + const char* position = emitArgs.emplace_back("position", kVec2f_GrSLType, + GrShaderVar::kNonArray, + kHigh_GrSLPrecision).c_str(); + const char* coverage = emitArgs.emplace_back("coverage", kFloat_GrSLType, + GrShaderVar::kNonArray, + kHigh_GrSLPrecision).c_str(); g->emitFunction(kVoid_GrSLType, "emitVertex", emitArgs.count(), emitArgs.begin(), [&]() { SkString fnBody; this->emitPerVertexGeometryCode(&fnBody, position, coverage, fGeomWind.c_str()); @@ -149,12 +151,12 @@ void PrimitiveProcessor::emitGeometryShader(const GrCCPRCoverageProcessor& proc, fnBody.appendf("%s = %s * %s;", fFragCoverageTimesWind.gsOut(), coverage, fGeomWind.c_str()); } - fnBody.append ("gl_Position = highfloat4(position, 0, 1);"); + fnBody.append ("gl_Position = float4(position, 0, 1);"); fnBody.append ("EmitVertex();"); return fnBody; }().c_str(), &emitVertexFn); - g->codeAppendf("highfloat2 bloat = %f * abs(%s.xz);", kAABloatRadius, rtAdjust); + g->codeAppendf("highp float2 bloat = %f * abs(%s.xz);", kAABloatRadius, rtAdjust); #ifdef SK_DEBUG if (proc.debugVisualizations()) { @@ -171,7 +173,7 @@ int PrimitiveProcessor::emitHullGeometry(GrGLSLGeometryBuilder* g, const char* e SkASSERT(numSides >= 3); if (!insetPts) { - g->codeAppendf("highfloat2 centroidpt = %s * highfloat%i(%f);", + g->codeAppendf("highp float2 centroidpt = %s * float%i(%f);", polygonPts, numSides, 1.0 / numSides); } @@ -179,42 +181,42 @@ int PrimitiveProcessor::emitHullGeometry(GrGLSLGeometryBuilder* g, const char* e "nextidx = (%s + 1) %% %i;", wedgeIdx, numSides - 1, numSides, wedgeIdx, numSides); - g->codeAppendf("highfloat2 self = %s[%s];" - "int leftidx = %s > 0 ? previdx : nextidx;" - "int rightidx = %s > 0 ? nextidx : previdx;", + g->codeAppendf("highp float2 self = %s[%s];" + "highp int leftidx = %s > 0 ? previdx : nextidx;" + "highp int rightidx = %s > 0 ? nextidx : previdx;", polygonPts, wedgeIdx, fGeomWind.c_str(), fGeomWind.c_str()); // Which quadrant does the vector from self -> right fall into? - g->codeAppendf("highfloat2 right = %s[rightidx];", polygonPts); + g->codeAppendf("highp float2 right = %s[rightidx];", polygonPts); if (3 == numSides) { // TODO: evaluate perf gains. - g->codeAppend ("highfloat2 qsr = sign(right - self);"); + g->codeAppend ("highp float2 qsr = sign(right - self);"); } else { SkASSERT(4 == numSides); - g->codeAppendf("highfloat2 diag = %s[(%s + 2) %% 4];", polygonPts, wedgeIdx); - g->codeAppend ("highfloat2 qsr = sign((right != self ? right : diag) - self);"); + g->codeAppendf("highp float2 diag = %s[(%s + 2) %% 4];", polygonPts, wedgeIdx); + g->codeAppend ("highp float2 qsr = sign((right != self ? right : diag) - self);"); } // Which quadrant does the vector from left -> self fall into? - g->codeAppendf("highfloat2 qls = sign(self - %s[leftidx]);", polygonPts); + g->codeAppendf("highp float2 qls = sign(self - %s[leftidx]);", polygonPts); // d2 just helps us reduce triangle counts with orthogonal, axis-aligned lines. // TODO: evaluate perf gains. const char* dr2 = "dr"; if (3 == numSides) { // TODO: evaluate perf gains. - g->codeAppend ("highfloat2 dr = highfloat2(qsr.y != 0 ? +qsr.y : +qsr.x, " - "qsr.x != 0 ? -qsr.x : +qsr.y);"); - g->codeAppend ("highfloat2 dr2 = highfloat2(qsr.y != 0 ? +qsr.y : -qsr.x, " - "qsr.x != 0 ? -qsr.x : -qsr.y);"); - g->codeAppend ("highfloat2 dl = highfloat2(qls.y != 0 ? +qls.y : +qls.x, " - "qls.x != 0 ? -qls.x : +qls.y);"); + g->codeAppend ("highp float2 dr = float2(qsr.y != 0 ? +qsr.y : +qsr.x, " + "qsr.x != 0 ? -qsr.x : +qsr.y);"); + g->codeAppend ("highp float2 dr2 = float2(qsr.y != 0 ? +qsr.y : -qsr.x, " + "qsr.x != 0 ? -qsr.x : -qsr.y);"); + g->codeAppend ("highp float2 dl = float2(qls.y != 0 ? +qls.y : +qls.x, " + "qls.x != 0 ? -qls.x : +qls.y);"); dr2 = "dr2"; } else { - g->codeAppend ("highfloat2 dr = highfloat2(qsr.y != 0 ? +qsr.y : 1, " - "qsr.x != 0 ? -qsr.x : 1);"); - g->codeAppend ("highfloat2 dl = (qls == highfloat2(0)) ? dr : " - "highfloat2(qls.y != 0 ? +qls.y : 1, qls.x != 0 ? -qls.x : 1);"); + g->codeAppend ("highp float2 dr = float2(qsr.y != 0 ? +qsr.y : 1, " + "qsr.x != 0 ? -qsr.x : 1);"); + g->codeAppend ("highp float2 dl = (qls == float2(0)) ? dr : " + "float2(qls.y != 0 ? +qls.y : 1, qls.x != 0 ? -qls.x : 1);"); } g->codeAppendf("bool2 dnotequal = notEqual(%s, dl);", dr2); @@ -234,7 +236,7 @@ int PrimitiveProcessor::emitHullGeometry(GrGLSLGeometryBuilder* g, const char* e g->codeAppendf( "%s(self + bloat * dl, 1);", emitVertexFn); g->codeAppend ("}"); g->codeAppend ("if (all(dnotequal)) {"); - g->codeAppendf( "%s(self + bloat * highfloat2(-dl.y, dl.x), 1);", emitVertexFn); + g->codeAppendf( "%s(self + bloat * float2(-dl.y, dl.x), 1);", emitVertexFn); g->codeAppend ("}"); g->codeAppend ("EndPrimitive();"); @@ -245,18 +247,18 @@ int PrimitiveProcessor::emitEdgeGeometry(GrGLSLGeometryBuilder* g, const char* e const char* leftPt, const char* rightPt, const char* distanceEquation) const { if (!distanceEquation) { - this->emitEdgeDistanceEquation(g, leftPt, rightPt, "highfloat3 edge_distance_equation"); + this->emitEdgeDistanceEquation(g, leftPt, rightPt, "highp float3 edge_distance_equation"); distanceEquation = "edge_distance_equation"; } // qlr is defined in emitEdgeDistanceEquation. - g->codeAppendf("highfloat2x2 endpts = highfloat2x2(%s - bloat * qlr, %s + bloat * qlr);", + g->codeAppendf("highp float2x2 endpts = float2x2(%s - bloat * qlr, %s + bloat * qlr);", leftPt, rightPt); - g->codeAppendf("half2 endpts_coverage = %s.xy * endpts + %s.z;", + g->codeAppendf("mediump float2 endpts_coverage = %s.xy * endpts + %s.z;", distanceEquation, distanceEquation); // d1 is defined in emitEdgeDistanceEquation. - g->codeAppend ("highfloat2 d2 = d1;"); + g->codeAppend ("highp float2 d2 = d1;"); g->codeAppend ("bool aligned = qlr.x == 0 || qlr.y == 0;"); g->codeAppend ("if (aligned) {"); g->codeAppend ( "d1 -= qlr;"); @@ -285,25 +287,25 @@ void PrimitiveProcessor::emitEdgeDistanceEquation(GrGLSLGeometryBuilder* g, const char* leftPt, const char* rightPt, const char* outputDistanceEquation) const { // Which quadrant does the vector from left -> right fall into? - g->codeAppendf("highfloat2 qlr = sign(%s - %s);", rightPt, leftPt); - g->codeAppend ("highfloat2 d1 = highfloat2(qlr.y, -qlr.x);"); + g->codeAppendf("highp float2 qlr = sign(%s - %s);", rightPt, leftPt); + g->codeAppend ("highp float2 d1 = float2(qlr.y, -qlr.x);"); - g->codeAppendf("highfloat2 n = highfloat2(%s.y - %s.y, %s.x - %s.x);", + g->codeAppendf("highp float2 n = float2(%s.y - %s.y, %s.x - %s.x);", rightPt, leftPt, leftPt, rightPt); - g->codeAppendf("highfloat2 kk = n * highfloat2x2(%s + bloat * d1, %s - bloat * d1);", + g->codeAppendf("highp float2 kk = n * float2x2(%s + bloat * d1, %s - bloat * d1);", leftPt, leftPt); // Clamp for when n=0. wind=0 when n=0 so as long as we don't get Inf or NaN we are fine. - g->codeAppendf("highfloat scale = 1 / max(kk[0] - kk[1], 1e-30);"); + g->codeAppendf("highp float scale = 1 / max(kk[0] - kk[1], 1e-30);"); - g->codeAppendf("%s = half3(-n, kk[1]) * scale;", outputDistanceEquation); + g->codeAppendf("%s = float3(-n, kk[1]) * scale;", outputDistanceEquation); } int PrimitiveProcessor::emitCornerGeometry(GrGLSLGeometryBuilder* g, const char* emitVertexFn, const char* pt) const { - g->codeAppendf("%s(%s + highfloat2(-bloat.x, -bloat.y), 1);", emitVertexFn, pt); - g->codeAppendf("%s(%s + highfloat2(-bloat.x, +bloat.y), 1);", emitVertexFn, pt); - g->codeAppendf("%s(%s + highfloat2(+bloat.x, -bloat.y), 1);", emitVertexFn, pt); - g->codeAppendf("%s(%s + highfloat2(+bloat.x, +bloat.y), 1);", emitVertexFn, pt); + g->codeAppendf("%s(%s + float2(-bloat.x, -bloat.y), 1);", emitVertexFn, pt); + g->codeAppendf("%s(%s + float2(-bloat.x, +bloat.y), 1);", emitVertexFn, pt); + g->codeAppendf("%s(%s + float2(+bloat.x, -bloat.y), 1);", emitVertexFn, pt); + g->codeAppendf("%s(%s + float2(+bloat.x, +bloat.y), 1);", emitVertexFn, pt); g->codeAppend ("EndPrimitive();"); return 4; @@ -319,17 +321,17 @@ void PrimitiveProcessor::emitCoverage(const GrCCPRCoverageProcessor& proc, GrGLS f->codeAppendf("%s.a = %s;", outputColor, fFragCoverageTimesWind.fsIn()); break; case CoverageType::kShader: - f->codeAppendf("half coverage = 0;"); + f->codeAppendf("mediump float coverage = 0;"); this->emitShaderCoverage(f, "coverage"); f->codeAppendf("%s.a = coverage * %s;", outputColor, fFragWind.fsIn()); break; } - f->codeAppendf("%s = half4(1);", outputCoverage); + f->codeAppendf("%s = float4(1);", outputCoverage); #ifdef SK_DEBUG if (proc.debugVisualizations()) { - f->codeAppendf("%s = half4(-%s.a, %s.a, 0, 1);", outputColor, outputColor, outputColor); + f->codeAppendf("%s = float4(-%s.a, %s.a, 0, 1);", outputColor, outputColor, outputColor); } #endif } @@ -338,17 +340,17 @@ int PrimitiveProcessor::defineSoftSampleLocations(GrGLSLFragmentBuilder* f, const char* samplesName) const { // Standard DX11 sample locations. #if defined(SK_BUILD_FOR_ANDROID) || defined(SK_BUILD_FOR_IOS) - f->defineConstant("highfloat2[8]", samplesName, "highfloat2[8](" - "highfloat2(+1, -3)/16, highfloat2(-1, +3)/16, highfloat2(+5, +1)/16, highfloat2(-3, -5)/16, " - "highfloat2(-5, +5)/16, highfloat2(-7, -1)/16, highfloat2(+3, +7)/16, highfloat2(+7, -7)/16." + f->defineConstant("highp float2[8]", samplesName, "float2[8](" + "float2(+1, -3)/16, float2(-1, +3)/16, float2(+5, +1)/16, float2(-3, -5)/16, " + "float2(-5, +5)/16, float2(-7, -1)/16, float2(+3, +7)/16, float2(+7, -7)/16." ")"); return 8; #else - f->defineConstant("highfloat2[16]", samplesName, "highfloat2[16](" - "highfloat2(+1, +1)/16, highfloat2(-1, -3)/16, highfloat2(-3, +2)/16, highfloat2(+4, -1)/16, " - "highfloat2(-5, -2)/16, highfloat2(+2, +5)/16, highfloat2(+5, +3)/16, highfloat2(+3, -5)/16, " - "highfloat2(-2, +6)/16, highfloat2( 0, -7)/16, highfloat2(-4, -6)/16, highfloat2(-6, +4)/16, " - "highfloat2(-8, 0)/16, highfloat2(+7, -4)/16, highfloat2(+6, +7)/16, highfloat2(-7, -8)/16." + f->defineConstant("highp float2[16]", samplesName, "float2[16](" + "float2(+1, +1)/16, float2(-1, -3)/16, float2(-3, +2)/16, float2(+4, -1)/16, " + "float2(-5, -2)/16, float2(+2, +5)/16, float2(+5, +3)/16, float2(+3, -5)/16, " + "float2(-2, +6)/16, float2( 0, -7)/16, float2(-4, -6)/16, float2(-6, +4)/16, " + "float2(-8, 0)/16, float2(+7, -4)/16, float2(+6, +7)/16, float2(-7, -8)/16." ")"); return 16; #endif diff --git a/src/gpu/ccpr/GrCCPRCoverageProcessor.h b/src/gpu/ccpr/GrCCPRCoverageProcessor.h index ab6a3cb430..198956a00a 100644 --- a/src/gpu/ccpr/GrCCPRCoverageProcessor.h +++ b/src/gpu/ccpr/GrCCPRCoverageProcessor.h @@ -138,9 +138,9 @@ protected: PrimitiveProcessor(CoverageType coverageType) : fCoverageType(coverageType) - , fGeomWind("wind", kHalf_GrSLType, GrShaderVar::kNonArray, kLow_GrSLPrecision) - , fFragWind(kHalf_GrSLType) - , fFragCoverageTimesWind(kHalf_GrSLType) {} + , fGeomWind("wind", kFloat_GrSLType, GrShaderVar::kNonArray, kLow_GrSLPrecision) + , fFragWind(kFloat_GrSLType) + , fFragCoverageTimesWind(kFloat_GrSLType) {} // Called before generating shader code. Subclass should add its custom varyings to the handler // and update its corresponding internal member variables. diff --git a/src/gpu/ccpr/GrCCPRCubicProcessor.cpp b/src/gpu/ccpr/GrCCPRCubicProcessor.cpp index 161c1ed191..5f6f759c6d 100644 --- a/src/gpu/ccpr/GrCCPRCubicProcessor.cpp +++ b/src/gpu/ccpr/GrCCPRCubicProcessor.cpp @@ -27,7 +27,7 @@ void GrCCPRCubicProcessor::onEmitVertexShader(const GrCCPRCoverageProcessor& pro v->codeAppendf("int4 indices = int4(%s.y, %s.x, %s.x + 1, %s.y + 1);", proc.instanceAttrib(), proc.instanceAttrib(), proc.instanceAttrib(), proc.instanceAttrib()); - v->codeAppend ("highfloat4x2 bezierpts = highfloat4x2("); + v->codeAppend ("highp float4x2 bezierpts = float4x2("); v->appendTexelFetch(pointsBuffer, "indices[sk_VertexID]"); v->codeAppend (".xy, "); v->appendTexelFetch(pointsBuffer, "indices[(sk_VertexID + 1) % 4]"); @@ -38,24 +38,24 @@ void GrCCPRCubicProcessor::onEmitVertexShader(const GrCCPRCoverageProcessor& pro v->codeAppend (".xy);"); // Find the corner of the inset geometry that corresponds to this bezier vertex (bezierpts[0]). - v->codeAppend ("highfloat2x2 N = highfloat2x2(bezierpts[3].y - bezierpts[0].y, " - "bezierpts[0].x - bezierpts[3].x, " - "bezierpts[1].y - bezierpts[0].y, " - "bezierpts[0].x - bezierpts[1].x);"); - v->codeAppend ("highfloat2x2 P = highfloat2x2(bezierpts[3], bezierpts[1]);"); + v->codeAppend ("highp float2x2 N = float2x2(bezierpts[3].y - bezierpts[0].y, " + "bezierpts[0].x - bezierpts[3].x, " + "bezierpts[1].y - bezierpts[0].y, " + "bezierpts[0].x - bezierpts[1].x);"); + v->codeAppend ("highp float2x2 P = float2x2(bezierpts[3], bezierpts[1]);"); v->codeAppend ("if (abs(determinant(N)) < 2) {"); // Area of [pts[3], pts[0], pts[1]] < 1px. // The inset corner doesn't exist because we are effectively colinear with // both neighbor vertices. Just duplicate a neighbor's inset corner. v->codeAppend ( "int smallidx = (dot(N[0], N[0]) > dot(N[1], N[1])) ? 1 : 0;"); - v->codeAppend ( "N[smallidx] = highfloat2(bezierpts[2].y - bezierpts[3 - smallidx * 2].y, " - "bezierpts[3 - smallidx * 2].x - bezierpts[2].x);"); + v->codeAppend ( "N[smallidx] = float2(bezierpts[2].y - bezierpts[3 - smallidx * 2].y, " + "bezierpts[3 - smallidx * 2].x - bezierpts[2].x);"); v->codeAppend ( "P[smallidx] = bezierpts[2];"); v->codeAppend ("}"); v->codeAppend ("N[0] *= sign(dot(N[0], P[1] - P[0]));"); v->codeAppend ("N[1] *= sign(dot(N[1], P[0] - P[1]));"); - v->codeAppendf("highfloat2 K = highfloat2(dot(N[0], P[0] + %f * sign(N[0])), " - "dot(N[1], P[1] + %f * sign(N[1])));", inset, inset); + v->codeAppendf("highp float2 K = float2(dot(N[0], P[0] + %f * sign(N[0])), " + "dot(N[1], P[1] + %f * sign(N[1])));", inset, inset); v->codeAppendf("%s.xy = K * inverse(N) + %s;", fInset.vsOut(), atlasOffset); v->codeAppendf("%s.xy = %s.xy * %s.xz + %s.yw;", fInset.vsOut(), fInset.vsOut(), rtAdjust, rtAdjust); @@ -71,15 +71,15 @@ void GrCCPRCubicProcessor::onEmitVertexShader(const GrCCPRCoverageProcessor& pro v->codeAppend ("[sk_VertexID % 2];"); // Emit the vertex position. - v->codeAppendf("highfloat2 self = bezierpts[0] + %s;", atlasOffset); - gpArgs->fPositionVar.set(kHighFloat2_GrSLType, "self"); + v->codeAppendf("highp float2 self = bezierpts[0] + %s;", atlasOffset); + gpArgs->fPositionVar.set(kVec2f_GrSLType, "self"); } void GrCCPRCubicProcessor::emitWind(GrGLSLGeometryBuilder* g, const char* rtAdjust, const char* outputWind) const { // We will define bezierpts in onEmitGeometryShader. - g->codeAppend ("highfloat area_times_2 = " - "determinant(highfloat3x3(1, bezierpts[0], " + g->codeAppend ("highp float area_times_2 = " + "determinant(float3x3(1, bezierpts[0], " "1, bezierpts[2], " "0, bezierpts[3] - bezierpts[1]));"); // Drop curves that are nearly flat. The KLM math becomes unstable in this case. @@ -98,13 +98,13 @@ void GrCCPRCubicProcessor::emitWind(GrGLSLGeometryBuilder* g, const char* rtAdju void GrCCPRCubicProcessor::onEmitGeometryShader(GrGLSLGeometryBuilder* g, const char* emitVertexFn, const char* wind, const char* rtAdjust) const { // Prepend bezierpts at the start of the shader. - g->codePrependf("highfloat4x2 bezierpts = highfloat4x2(sk_in[0].gl_Position.xy, " - "sk_in[1].gl_Position.xy, " - "sk_in[2].gl_Position.xy, " - "sk_in[3].gl_Position.xy);"); + g->codePrependf("highp float4x2 bezierpts = float4x2(sk_in[0].gl_Position.xy, " + "sk_in[1].gl_Position.xy, " + "sk_in[2].gl_Position.xy, " + "sk_in[3].gl_Position.xy);"); // Evaluate the cubic at t=.5 for an approximate midpoint. - g->codeAppendf("highfloat2 midpoint = bezierpts * highfloat4(.125, .375, .375, .125);"); + g->codeAppendf("highp float2 midpoint = bezierpts * float4(.125, .375, .375, .125);"); // Finish finding the inset geometry we started in the vertex shader. The z component tells us // how "sharp" an inset corner is. And the vertex shader already skips one corner if it is @@ -112,9 +112,9 @@ void GrCCPRCubicProcessor::onEmitGeometryShader(GrGLSLGeometryBuilder* g, const // geometry is all empty (it should never be non-convex because the curve gets chopped into // convex segments ahead of time). g->codeAppendf("bool isempty = " - "any(lessThan(highfloat4(%s[0].z, %s[1].z, %s[2].z, %s[3].z) * %s, highfloat4(2)));", + "any(lessThan(float4(%s[0].z, %s[1].z, %s[2].z, %s[3].z) * %s, float4(2)));", fInset.gsIn(), fInset.gsIn(), fInset.gsIn(), fInset.gsIn(), wind); - g->codeAppendf("highfloat2 inset[4];"); + g->codeAppendf("highp float2 inset[4];"); g->codeAppend ("for (int i = 0; i < 4; ++i) {"); g->codeAppendf( "inset[i] = isempty ? midpoint : %s[i].xy;", fInset.gsIn()); g->codeAppend ("}"); @@ -124,30 +124,30 @@ void GrCCPRCubicProcessor::onEmitGeometryShader(GrGLSLGeometryBuilder* g, const // actually triangle with a vertex at the crossover point. If there are >1 backwards edges, the // inset geometry doesn't exist (i.e. the bezier quadrilateral isn't large enough) and we // degenerate to the midpoint. - g->codeAppend ("half backwards[4];"); - g->codeAppend ("short numbackwards = 0;"); + g->codeAppend ("lowp float backwards[4];"); + g->codeAppend ("lowp int numbackwards = 0;"); g->codeAppend ("for (int i = 0; i < 4; ++i) {"); - g->codeAppend ( "short j = (i + 1) % 4;"); - g->codeAppendf( "highfloat2 inner = inset[j] - inset[i];"); - g->codeAppendf( "highfloat2 outer = sk_in[j].gl_Position.xy - sk_in[i].gl_Position.xy;"); + g->codeAppend ( "lowp int j = (i + 1) % 4;"); + g->codeAppendf( "highp float2 inner = inset[j] - inset[i];"); + g->codeAppendf( "highp float2 outer = sk_in[j].gl_Position.xy - sk_in[i].gl_Position.xy;"); g->codeAppendf( "backwards[i] = sign(dot(outer, inner));"); g->codeAppendf( "numbackwards += backwards[i] < 0 ? 1 : 0;"); g->codeAppend ("}"); // Find the crossover point. If there actually isn't one, this math is meaningless and will get // dropped on the floor later. - g->codeAppend ("short x = (backwards[0] != backwards[2]) ? 1 : 0;"); - g->codeAppend ("short x3 = (x + 3) % 4;"); - g->codeAppend ("highfloat2x2 X = highfloat2x2(inset[x].y - inset[x+1].y, " - "inset[x+1].x - inset[x].x, " - "inset[x+2].y - inset[x3].y, " - "inset[x3].x - inset[x+2].x);"); - g->codeAppend ("highfloat2 KK = highfloat2(dot(X[0], inset[x]), dot(X[1], inset[x+2]));"); - g->codeAppend ("highfloat2 crossoverpoint = KK * inverse(X);"); + g->codeAppend ("lowp int x = (backwards[0] != backwards[2]) ? 1 : 0;"); + g->codeAppend ("lowp int x3 = (x + 3) % 4;"); + g->codeAppend ("highp float2x2 X = float2x2(inset[x].y - inset[x+1].y, " + "inset[x+1].x - inset[x].x, " + "inset[x+2].y - inset[x3].y, " + "inset[x3].x - inset[x+2].x);"); + g->codeAppend ("highp float2 KK = float2(dot(X[0], inset[x]), dot(X[1], inset[x+2]));"); + g->codeAppend ("highp float2 crossoverpoint = KK * inverse(X);"); // Determine what point backwards edges should collapse into. If there is one backwards edge, // it should collapse to the crossover point. If >1, they should all collapse to the midpoint. - g->codeAppend ("highfloat2 collapsepoint = numbackwards == 1 ? crossoverpoint : midpoint;"); + g->codeAppend ("highp float2 collapsepoint = numbackwards == 1 ? crossoverpoint : midpoint;"); // Collapse backwards egdes to the "collapse" point. g->codeAppend ("for (int i = 0; i < 4; ++i) {"); @@ -158,46 +158,46 @@ void GrCCPRCubicProcessor::onEmitGeometryShader(GrGLSLGeometryBuilder* g, const // Calculate the KLM matrix. g->declareGlobal(fKLMMatrix); - g->codeAppend ("highfloat4 K, L, M;"); + g->codeAppend ("highp float4 K, L, M;"); if (Type::kSerpentine == fType) { - g->codeAppend ("highfloat2 l,m;"); - g->codeAppendf("l.ts = highfloat2(%s[0], %s[1]);", fTS.gsIn(), fTS.gsIn()); - g->codeAppendf("m.ts = highfloat2(%s[2], %s[3]);", fTS.gsIn(), fTS.gsIn()); - g->codeAppend ("K = highfloat4(0, l.s * m.s, -l.t * m.s - m.t * l.s, l.t * m.t);"); - g->codeAppend ("L = highfloat4(-1,3,-3,1) * l.ssst * l.sstt * l.sttt;"); - g->codeAppend ("M = highfloat4(-1,3,-3,1) * m.ssst * m.sstt * m.sttt;"); + g->codeAppend ("highp float2 l,m;"); + g->codeAppendf("l.ts = float2(%s[0], %s[1]);", fTS.gsIn(), fTS.gsIn()); + g->codeAppendf("m.ts = float2(%s[2], %s[3]);", fTS.gsIn(), fTS.gsIn()); + g->codeAppend ("K = float4(0, l.s * m.s, -l.t * m.s - m.t * l.s, l.t * m.t);"); + g->codeAppend ("L = float4(-1,3,-3,1) * l.ssst * l.sstt * l.sttt;"); + g->codeAppend ("M = float4(-1,3,-3,1) * m.ssst * m.sstt * m.sttt;"); } else { - g->codeAppend ("highfloat2 d,e;"); - g->codeAppendf("d.ts = highfloat2(%s[0], %s[1]);", fTS.gsIn(), fTS.gsIn()); - g->codeAppendf("e.ts = highfloat2(%s[2], %s[3]);", fTS.gsIn(), fTS.gsIn()); - g->codeAppend ("highfloat4 dxe = highfloat4(d.s * e.s, d.s * e.t, d.t * e.s, d.t * e.t);"); - g->codeAppend ("K = highfloat4(0, dxe.x, -dxe.y - dxe.z, dxe.w);"); - g->codeAppend ("L = highfloat4(-1,1,-1,1) * d.sstt * (dxe.xyzw + highfloat4(0, 2*dxe.zy, 0));"); - g->codeAppend ("M = highfloat4(-1,1,-1,1) * e.sstt * (dxe.xzyw + highfloat4(0, 2*dxe.yz, 0));"); + g->codeAppend ("highp float2 d,e;"); + g->codeAppendf("d.ts = float2(%s[0], %s[1]);", fTS.gsIn(), fTS.gsIn()); + g->codeAppendf("e.ts = float2(%s[2], %s[3]);", fTS.gsIn(), fTS.gsIn()); + g->codeAppend ("highp float4 dxe = float4(d.s * e.s, d.s * e.t, d.t * e.s, d.t * e.t);"); + g->codeAppend ("K = float4(0, dxe.x, -dxe.y - dxe.z, dxe.w);"); + g->codeAppend ("L = float4(-1,1,-1,1) * d.sstt * (dxe.xyzw + float4(0, 2*dxe.zy, 0));"); + g->codeAppend ("M = float4(-1,1,-1,1) * e.sstt * (dxe.xzyw + float4(0, 2*dxe.yz, 0));"); } - g->codeAppend ("highfloat2x4 C = highfloat4x4(-1, 3, -3, 1, " - " 3, -6, 3, 0, " - "-3, 3, 0, 0, " - " 1, 0, 0, 0) * transpose(bezierpts);"); + g->codeAppend ("highp float2x4 C = float4x4(-1, 3, -3, 1, " + " 3, -6, 3, 0, " + "-3, 3, 0, 0, " + " 1, 0, 0, 0) * transpose(bezierpts);"); - g->codeAppend ("highfloat2 absdet = abs(C[0].xx * C[1].zy - C[1].xx * C[0].zy);"); + g->codeAppend ("highp float2 absdet = abs(C[0].xx * C[1].zy - C[1].xx * C[0].zy);"); g->codeAppend ("lowp int middlerow = absdet[0] > absdet[1] ? 2 : 1;"); - g->codeAppend ("highfloat3x3 CI = inverse(highfloat3x3(C[0][0], C[0][middlerow], C[0][3], " - "C[1][0], C[1][middlerow], C[1][3], " - " 0, 0, 1));"); - g->codeAppendf("%s = CI * highfloat3x3(K[0], K[middlerow], K[3], " - "L[0], L[middlerow], L[3], " - "M[0], M[middlerow], M[3]);", fKLMMatrix.c_str()); + g->codeAppend ("highp float3x3 CI = inverse(float3x3(C[0][0], C[0][middlerow], C[0][3], " + "C[1][0], C[1][middlerow], C[1][3], " + " 0, 0, 1));"); + g->codeAppendf("%s = CI * float3x3(K[0], K[middlerow], K[3], " + "L[0], L[middlerow], L[3], " + "M[0], M[middlerow], M[3]);", fKLMMatrix.c_str()); // Orient the KLM matrix so we fill the correct side of the curve. - g->codeAppendf("half2 orientation = sign(half3(midpoint, 1) * half2x3(%s[1], %s[2]));", + g->codeAppendf("lowp float2 orientation = sign(float3(midpoint, 1) * float2x3(%s[1], %s[2]));", fKLMMatrix.c_str(), fKLMMatrix.c_str()); - g->codeAppendf("%s *= highfloat3x3(orientation[0] * orientation[1], 0, 0, " - "0, orientation[0], 0, " - "0, 0, orientation[1]);", fKLMMatrix.c_str()); + g->codeAppendf("%s *= float3x3(orientation[0] * orientation[1], 0, 0, " + "0, orientation[0], 0, " + "0, 0, orientation[1]);", fKLMMatrix.c_str()); g->declareGlobal(fKLMDerivatives); g->codeAppendf("%s[0] = %s[0].xy * %s.xz;", @@ -228,7 +228,7 @@ void GrCCPRCubicInsetProcessor::emitCubicGeometry(GrGLSLGeometryBuilder* g, void GrCCPRCubicInsetProcessor::emitPerVertexGeometryCode(SkString* fnBody, const char* position, const char* /*coverage*/, const char* /*wind*/) const { - fnBody->appendf("highfloat3 klm = highfloat3(%s, 1) * %s;", position, fKLMMatrix.c_str()); + fnBody->appendf("highp float3 klm = float3(%s, 1) * %s;", position, fKLMMatrix.c_str()); fnBody->appendf("%s = klm;", fKLM.gsOut()); fnBody->appendf("%s[0] = 3 * klm[0] * %s[0];", fGradMatrix.gsOut(), fKLMDerivatives.c_str()); fnBody->appendf("%s[1] = -klm[1] * %s[2].xy - klm[2] * %s[1].xy;", @@ -237,11 +237,11 @@ void GrCCPRCubicInsetProcessor::emitPerVertexGeometryCode(SkString* fnBody, cons void GrCCPRCubicInsetProcessor::emitShaderCoverage(GrGLSLFragmentBuilder* f, const char* outputCoverage) const { - f->codeAppendf("highfloat k = %s.x, l = %s.y, m = %s.z;", + f->codeAppendf("highp float k = %s.x, l = %s.y, m = %s.z;", fKLM.fsIn(), fKLM.fsIn(), fKLM.fsIn()); - f->codeAppend ("highfloat f = k*k*k - l*m;"); - f->codeAppendf("highfloat2 grad = %s * highfloat2(k, 1);", fGradMatrix.fsIn()); - f->codeAppend ("highfloat d = f * inversesqrt(dot(grad, grad));"); + f->codeAppend ("highp float f = k*k*k - l*m;"); + f->codeAppendf("highp float2 grad = %s * float2(k, 1);", fGradMatrix.fsIn()); + f->codeAppend ("highp float d = f * inversesqrt(dot(grad, grad));"); f->codeAppendf("%s = clamp(0.5 - d, 0, 1);", outputCoverage); } @@ -251,8 +251,8 @@ void GrCCPRCubicBorderProcessor::emitCubicGeometry(GrGLSLGeometryBuilder* g, // We defined bezierpts in onEmitGeometryShader. g->declareGlobal(fEdgeDistanceEquation); g->codeAppendf("int edgeidx0 = %s > 0 ? 3 : 0;", wind); - g->codeAppendf("highfloat2 edgept0 = bezierpts[edgeidx0];"); - g->codeAppendf("highfloat2 edgept1 = bezierpts[3 - edgeidx0];"); + g->codeAppendf("highp float2 edgept0 = bezierpts[edgeidx0];"); + g->codeAppendf("highp float2 edgept1 = bezierpts[3 - edgeidx0];"); this->emitEdgeDistanceEquation(g, "edgept0", "edgept1", fEdgeDistanceEquation.c_str()); g->codeAppendf("%s.z += 0.5;", fEdgeDistanceEquation.c_str()); // outer = -.5, inner = .5 @@ -261,10 +261,9 @@ void GrCCPRCubicBorderProcessor::emitCubicGeometry(GrGLSLGeometryBuilder* g, fEdgeDistanceDerivatives.c_str(), fEdgeDistanceEquation.c_str(), rtAdjust); g->declareGlobal(fEdgeSpaceTransform); - g->codeAppend ("highfloat4 edgebbox = highfloat4(min(bezierpts[0], bezierpts[3]) - bloat, " - "max(bezierpts[0], bezierpts[3]) + bloat);"); - g->codeAppendf("%s.xy = 2 / highfloat2(edgebbox.zw - edgebbox.xy);", - fEdgeSpaceTransform.c_str()); + g->codeAppend ("highp float4 edgebbox = float4(min(bezierpts[0], bezierpts[3]) - bloat, " + "max(bezierpts[0], bezierpts[3]) + bloat);"); + g->codeAppendf("%s.xy = 2 / float2(edgebbox.zw - edgebbox.xy);", fEdgeSpaceTransform.c_str()); g->codeAppendf("%s.zw = -1 - %s.xy * edgebbox.xy;", fEdgeSpaceTransform.c_str(), fEdgeSpaceTransform.c_str()); @@ -279,14 +278,14 @@ void GrCCPRCubicBorderProcessor::emitCubicGeometry(GrGLSLGeometryBuilder* g, void GrCCPRCubicBorderProcessor::emitPerVertexGeometryCode(SkString* fnBody, const char* position, const char* /*coverage*/, const char* /*wind*/) const { - fnBody->appendf("highfloat3 klm = highfloat3(%s, 1) * %s;", position, fKLMMatrix.c_str()); - fnBody->appendf("highfloat d = dot(highfloat3(%s, 1), %s);", + fnBody->appendf("highp float3 klm = float3(%s, 1) * %s;", position, fKLMMatrix.c_str()); + fnBody->appendf("highp float d = dot(float3(%s, 1), %s);", position, fEdgeDistanceEquation.c_str()); - fnBody->appendf("%s = highfloat4(klm, d);", fKLMD.gsOut()); - fnBody->appendf("%s = highfloat4(%s[0].x, %s[1].x, %s[2].x, %s.x);", + fnBody->appendf("%s = float4(klm, d);", fKLMD.gsOut()); + fnBody->appendf("%s = float4(%s[0].x, %s[1].x, %s[2].x, %s.x);", fdKLMDdx.gsOut(), fKLMDerivatives.c_str(), fKLMDerivatives.c_str(), fKLMDerivatives.c_str(), fEdgeDistanceDerivatives.c_str()); - fnBody->appendf("%s = highfloat4(%s[0].y, %s[1].y, %s[2].y, %s.y);", + fnBody->appendf("%s = float4(%s[0].y, %s[1].y, %s[2].y, %s.y);", fdKLMDdy.gsOut(), fKLMDerivatives.c_str(), fKLMDerivatives.c_str(), fKLMDerivatives.c_str(), fEdgeDistanceDerivatives.c_str()); fnBody->appendf("%s = position * %s.xy + %s.zw;", fEdgeSpaceCoord.gsOut(), @@ -304,21 +303,21 @@ void GrCCPRCubicBorderProcessor::emitShaderCoverage(GrGLSLFragmentBuilder* f, // Along the shared edge, we start with distance-to-edge coverage, then subtract out the // remaining pixel coverage that is still inside the shared edge, but outside the curve. // Outside the shared edege, we just use standard msaa to count samples inside the curve. - f->codeAppendf("bool use_edge = all(lessThan(abs(%s), highfloat2(1)));", fEdgeSpaceCoord.fsIn()); + f->codeAppendf("bool use_edge = all(lessThan(abs(%s), float2(1)));", fEdgeSpaceCoord.fsIn()); f->codeAppendf("%s = (use_edge ? clamp(%s.w + 0.5, 0, 1) : 0) * %i;", outputCoverage, fKLMD.fsIn(), sampleCount); - f->codeAppendf("highfloat2x4 grad_klmd = highfloat2x4(%s, %s);", fdKLMDdx.fsIn(), + f->codeAppendf("highp float2x4 grad_klmd = float2x4(%s, %s);", fdKLMDdx.fsIn(), fdKLMDdy.fsIn()); f->codeAppendf("for (int i = 0; i < %i; ++i) {", sampleCount); - f->codeAppendf( "highfloat4 klmd = grad_klmd * samples[i] + %s;", fKLMD.fsIn()); - f->codeAppend ( "half f = klmd.y * klmd.z - klmd.x * klmd.x * klmd.x;"); + f->codeAppendf( "highp float4 klmd = grad_klmd * samples[i] + %s;", fKLMD.fsIn()); + f->codeAppend ( "lowp float f = klmd.y * klmd.z - klmd.x * klmd.x * klmd.x;"); // A sample is inside our cubic sub-section if it is inside the implicit AND L & M are both // positive. This works because the sections get chopped at the K/L and K/M intersections. - f->codeAppend ( "bool4 inside = greaterThan(highfloat4(f,klmd.yzw), highfloat4(0));"); - f->codeAppend ( "half in_curve = all(inside.xyz) ? 1 : 0;"); - f->codeAppend ( "half in_edge = inside.w ? 1 : 0;"); + f->codeAppend ( "bool4 inside = greaterThan(float4(f,klmd.yzw), float4(0));"); + f->codeAppend ( "lowp float in_curve = all(inside.xyz) ? 1 : 0;"); + f->codeAppend ( "lowp float in_edge = inside.w ? 1 : 0;"); f->codeAppendf( "%s += use_edge ? in_edge * (in_curve - 1) : in_curve;", outputCoverage); f->codeAppend ("}"); diff --git a/src/gpu/ccpr/GrCCPRCubicProcessor.h b/src/gpu/ccpr/GrCCPRCubicProcessor.h index 12a4ebcc6b..f31dad793e 100644 --- a/src/gpu/ccpr/GrCCPRCubicProcessor.h +++ b/src/gpu/ccpr/GrCCPRCubicProcessor.h @@ -46,10 +46,11 @@ public: GrCCPRCubicProcessor(Type type) : INHERITED(CoverageType::kShader) , fType(type) - , fInset(kHighFloat3_GrSLType) - , fTS(kHighFloat_GrSLType) - , fKLMMatrix("klm_matrix", kHighFloat3x3_GrSLType, GrShaderVar::kNonArray) - , fKLMDerivatives("klm_derivatives", kHighFloat2_GrSLType, 3) {} + , fInset(kVec3f_GrSLType) + , fTS(kFloat_GrSLType) + , fKLMMatrix("klm_matrix", kMat33f_GrSLType, GrShaderVar::kNonArray, + kHigh_GrSLPrecision) + , fKLMDerivatives("klm_derivatives", kVec2f_GrSLType, 3, kHigh_GrSLPrecision) {} void resetVaryings(GrGLSLVaryingHandler* varyingHandler) override { varyingHandler->addVarying("insets", &fInset, kHigh_GrSLPrecision); @@ -80,8 +81,8 @@ class GrCCPRCubicInsetProcessor : public GrCCPRCubicProcessor { public: GrCCPRCubicInsetProcessor(Type type) : INHERITED(type) - , fKLM(kHighFloat3_GrSLType) - , fGradMatrix(kHighFloat2x2_GrSLType) {} + , fKLM(kVec3f_GrSLType) + , fGradMatrix(kMat22f_GrSLType) {} void resetVaryings(GrGLSLVaryingHandler* varyingHandler) override { this->INHERITED::resetVaryings(varyingHandler); @@ -106,16 +107,16 @@ class GrCCPRCubicBorderProcessor : public GrCCPRCubicProcessor { public: GrCCPRCubicBorderProcessor(Type type) : INHERITED(type) - , fEdgeDistanceEquation("edge_distance_equation", kHighFloat3_GrSLType, - GrShaderVar::kNonArray) - , fEdgeDistanceDerivatives("edge_distance_derivatives", kHighFloat2_GrSLType, - GrShaderVar::kNonArray) - , fEdgeSpaceTransform("edge_space_transform", kHighFloat4_GrSLType, - GrShaderVar::kNonArray) - , fKLMD(kHighFloat4_GrSLType) - , fdKLMDdx(kHighFloat4_GrSLType) - , fdKLMDdy(kHighFloat4_GrSLType) - , fEdgeSpaceCoord(kHighFloat2_GrSLType) {} + , fEdgeDistanceEquation("edge_distance_equation", kVec3f_GrSLType, + GrShaderVar::kNonArray, kHigh_GrSLPrecision) + , fEdgeDistanceDerivatives("edge_distance_derivatives", kVec2f_GrSLType, + GrShaderVar::kNonArray, kHigh_GrSLPrecision) + , fEdgeSpaceTransform("edge_space_transform", kVec4f_GrSLType, GrShaderVar::kNonArray, + kHigh_GrSLPrecision) + , fKLMD(kVec4f_GrSLType) + , fdKLMDdx(kVec4f_GrSLType) + , fdKLMDdy(kVec4f_GrSLType) + , fEdgeSpaceCoord(kVec2f_GrSLType) {} void resetVaryings(GrGLSLVaryingHandler* varyingHandler) override { this->INHERITED::resetVaryings(varyingHandler); diff --git a/src/gpu/ccpr/GrCCPRPathProcessor.cpp b/src/gpu/ccpr/GrCCPRPathProcessor.cpp index 203a0ec1d4..1292553824 100644 --- a/src/gpu/ccpr/GrCCPRPathProcessor.cpp +++ b/src/gpu/ccpr/GrCCPRPathProcessor.cpp @@ -120,12 +120,12 @@ void GLSLPathProcessor::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { const char* atlasAdjust; fAtlasAdjustUniform = uniHandler->addUniform( kVertex_GrShaderFlag, - kHighFloat2_GrSLType, "atlas_adjust", &atlasAdjust); + kVec2f_GrSLType, kHigh_GrSLPrecision, "atlas_adjust", &atlasAdjust); varyingHandler->emitAttributes(proc); - GrGLSLVertToFrag texcoord(kHighFloat2_GrSLType); - GrGLSLVertToFrag color(kHalf4_GrSLType); + GrGLSLVertToFrag texcoord(kVec2f_GrSLType); + GrGLSLVertToFrag color(kVec4f_GrSLType); varyingHandler->addVarying("texcoord", &texcoord, kHigh_GrSLPrecision); varyingHandler->addFlatPassThroughAttribute(&proc.getInstanceAttrib(InstanceAttribs::kColor), args.fOutputColor, kLow_GrSLPrecision); @@ -136,41 +136,41 @@ void GLSLPathProcessor::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { // Find the intersections of (bloated) devBounds and devBounds45 in order to come up with an // octagon that circumscribes the (bloated) path. A vertex is the intersection of two lines: // one edge from the path's bounding box and one edge from its 45-degree bounding box. - v->codeAppendf("highfloat2x2 N = highfloat2x2(%s);", proc.getEdgeNormsAttrib().fName); + v->codeAppendf("highp float2x2 N = float2x2(%s);", proc.getEdgeNormsAttrib().fName); // N[0] is the normal for the edge we are intersecting from the regular bounding box, pointing // out of the octagon. - v->codeAppendf("highfloat2 refpt = (min(N[0].x, N[0].y) < 0) ? %s.xy : %s.zw;", + v->codeAppendf("highp float2 refpt = (min(N[0].x, N[0].y) < 0) ? %s.xy : %s.zw;", proc.getInstanceAttrib(InstanceAttribs::kDevBounds).fName, proc.getInstanceAttrib(InstanceAttribs::kDevBounds).fName); v->codeAppendf("refpt += N[0] * %f;", kAABloatRadius); // bloat for AA. // N[1] is the normal for the edge we are intersecting from the 45-degree bounding box, pointing // out of the octagon. - v->codeAppendf("highfloat2 refpt45 = (N[1].x < 0) ? %s.xy : %s.zw;", + v->codeAppendf("highp float2 refpt45 = (N[1].x < 0) ? %s.xy : %s.zw;", proc.getInstanceAttrib(InstanceAttribs::kDevBounds45).fName, proc.getInstanceAttrib(InstanceAttribs::kDevBounds45).fName); - v->codeAppendf("refpt45 *= highfloat2x2(.5,.5,-.5,.5);"); // transform back to device space. + v->codeAppendf("refpt45 *= float2x2(.5,.5,-.5,.5);"); // transform back to device space. v->codeAppendf("refpt45 += N[1] * %f;", kAABloatRadius); // bloat for AA. - v->codeAppend ("highfloat2 K = highfloat2(dot(N[0], refpt), dot(N[1], refpt45));"); - v->codeAppendf("highfloat2 octocoord = K * inverse(N);"); + v->codeAppend ("highp float2 K = float2(dot(N[0], refpt), dot(N[1], refpt45));"); + v->codeAppendf("highp float2 octocoord = K * inverse(N);"); - gpArgs->fPositionVar.set(kHighFloat2_GrSLType, "octocoord"); + gpArgs->fPositionVar.set(kVec2f_GrSLType, "octocoord"); // Convert to atlas coordinates in order to do our texture lookup. - v->codeAppendf("highfloat2 atlascoord = octocoord + highfloat2(%s);", + v->codeAppendf("highp float2 atlascoord = octocoord + float2(%s);", proc.getInstanceAttrib(InstanceAttribs::kAtlasOffset).fName); if (kTopLeft_GrSurfaceOrigin == proc.atlasProxy()->origin()) { v->codeAppendf("%s = atlascoord * %s;", texcoord.vsOut(), atlasAdjust); } else { SkASSERT(kBottomLeft_GrSurfaceOrigin == proc.atlasProxy()->origin()); - v->codeAppendf("%s = highfloat2(atlascoord.x * %s.x, 1 - atlascoord.y * %s.y);", + v->codeAppendf("%s = float2(atlascoord.x * %s.x, 1 - atlascoord.y * %s.y);", texcoord.vsOut(), atlasAdjust, atlasAdjust); } // Convert to (local) path cordinates. - v->codeAppendf("highfloat2 pathcoord = inverse(highfloat2x2(%s)) * (octocoord - %s);", + v->codeAppendf("highp float2 pathcoord = inverse(float2x2(%s)) * (octocoord - %s);", proc.getInstanceAttrib(InstanceAttribs::kViewMatrix).fName, proc.getInstanceAttrib(InstanceAttribs::kViewTranslate).fName); @@ -180,16 +180,16 @@ void GLSLPathProcessor::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { // Fragment shader. GrGLSLPPFragmentBuilder* f = args.fFragBuilder; - f->codeAppend ("half coverage_count = "); - f->appendTextureLookup(args.fTexSamplers[0], texcoord.fsIn(), kHighFloat2_GrSLType); + f->codeAppend ("mediump float coverage_count = "); + f->appendTextureLookup(args.fTexSamplers[0], texcoord.fsIn(), kVec2f_GrSLType); f->codeAppend (".a;"); if (SkPath::kWinding_FillType == proc.fillType()) { - f->codeAppendf("%s = half4(min(abs(coverage_count), 1));", args.fOutputCoverage); + f->codeAppendf("%s = float4(min(abs(coverage_count), 1));", args.fOutputCoverage); } else { SkASSERT(SkPath::kEvenOdd_FillType == proc.fillType()); - f->codeAppend ("half t = mod(abs(coverage_count), 2);"); - f->codeAppendf("%s = half4(1 - abs(t - 1));", args.fOutputCoverage); + f->codeAppend ("mediump float t = mod(abs(coverage_count), 2);"); + f->codeAppendf("%s = float4(1 - abs(t - 1));", args.fOutputCoverage); } } diff --git a/src/gpu/ccpr/GrCCPRQuadraticProcessor.cpp b/src/gpu/ccpr/GrCCPRQuadraticProcessor.cpp index 25cc5e4cc7..ed5f0f38d8 100644 --- a/src/gpu/ccpr/GrCCPRQuadraticProcessor.cpp +++ b/src/gpu/ccpr/GrCCPRQuadraticProcessor.cpp @@ -18,17 +18,17 @@ void GrCCPRQuadraticProcessor::onEmitVertexShader(const GrCCPRCoverageProcessor& GrGPArgs* gpArgs) const { v->codeAppendf("int3 indices = int3(%s.y, %s.x, %s.y + 1);", proc.instanceAttrib(), proc.instanceAttrib(), proc.instanceAttrib()); - v->codeAppend ("highfloat2 self = "); + v->codeAppend ("highp float2 self = "); v->appendTexelFetch(pointsBuffer, "indices[sk_VertexID]"); v->codeAppendf(".xy + %s;", atlasOffset); - gpArgs->fPositionVar.set(kHighFloat2_GrSLType, "self"); + gpArgs->fPositionVar.set(kVec2f_GrSLType, "self"); } void GrCCPRQuadraticProcessor::emitWind(GrGLSLGeometryBuilder* g, const char* rtAdjust, const char* outputWind) const { // We will define bezierpts in onEmitGeometryShader. - g->codeAppend ("highfloat area_times_2 = " - "determinant(highfloat2x2(bezierpts[1] - bezierpts[0], " + g->codeAppend ("highp float area_times_2 = " + "determinant(float2x2(bezierpts[1] - bezierpts[0], " "bezierpts[2] - bezierpts[0]));"); // Drop curves that are nearly flat, in favor of the higher quality triangle antialiasing. g->codeAppendf("if (2 * abs(area_times_2) < length((bezierpts[2] - bezierpts[0]) * %s.zx)) {", @@ -47,26 +47,26 @@ void GrCCPRQuadraticProcessor::onEmitGeometryShader(GrGLSLGeometryBuilder* g, const char* emitVertexFn, const char* wind, const char* rtAdjust) const { // Prepend bezierpts at the start of the shader. - g->codePrependf("highfloat3x2 bezierpts = highfloat3x2(sk_in[0].gl_Position.xy, " - "sk_in[1].gl_Position.xy, " - "sk_in[2].gl_Position.xy);"); + g->codePrependf("highp float3x2 bezierpts = float3x2(sk_in[0].gl_Position.xy, " + "sk_in[1].gl_Position.xy, " + "sk_in[2].gl_Position.xy);"); g->declareGlobal(fCanonicalMatrix); - g->codeAppendf("%s = highfloat3x3(0.0, 0, 1, " - "0.5, 0, 1, " - "1.0, 1, 1) * " - "inverse(highfloat3x3(bezierpts[0], 1, " - "bezierpts[1], 1, " - "bezierpts[2], 1));", + g->codeAppendf("%s = float3x3(0.0, 0, 1, " + "0.5, 0, 1, " + "1.0, 1, 1) * " + "inverse(float3x3(bezierpts[0], 1, " + "bezierpts[1], 1, " + "bezierpts[2], 1));", fCanonicalMatrix.c_str()); g->declareGlobal(fCanonicalDerivatives); - g->codeAppendf("%s = highfloat2x2(%s) * highfloat2x2(%s.x, 0, 0, %s.z);", + g->codeAppendf("%s = float2x2(%s) * float2x2(%s.x, 0, 0, %s.z);", fCanonicalDerivatives.c_str(), fCanonicalMatrix.c_str(), rtAdjust, rtAdjust); g->declareGlobal(fEdgeDistanceEquation); - g->codeAppendf("highfloat2 edgept0 = bezierpts[%s > 0 ? 2 : 0];", wind); - g->codeAppendf("highfloat2 edgept1 = bezierpts[%s > 0 ? 0 : 2];", wind); + g->codeAppendf("highp float2 edgept0 = bezierpts[%s > 0 ? 2 : 0];", wind); + g->codeAppendf("highp float2 edgept1 = bezierpts[%s > 0 ? 0 : 2];", wind); this->emitEdgeDistanceEquation(g, "edgept0", "edgept1", fEdgeDistanceEquation.c_str()); this->emitQuadraticGeometry(g, emitVertexFn, rtAdjust); @@ -75,7 +75,7 @@ void GrCCPRQuadraticProcessor::onEmitGeometryShader(GrGLSLGeometryBuilder* g, void GrCCPRQuadraticProcessor::emitPerVertexGeometryCode(SkString* fnBody, const char* position, const char* /*coverage*/, const char* /*wind*/) const { - fnBody->appendf("%s.xy = (%s * highfloat3(%s, 1)).xy;", + fnBody->appendf("%s.xy = (%s * float3(%s, 1)).xy;", fXYD.gsOut(), fCanonicalMatrix.c_str(), position); fnBody->appendf("%s.z = dot(%s.xy, %s) + %s.z;", fXYD.gsOut(), fEdgeDistanceEquation.c_str(), position, @@ -88,18 +88,18 @@ void GrCCPRQuadraticHullProcessor::emitQuadraticGeometry(GrGLSLGeometryBuilder* const char* /*rtAdjust*/) const { // Find the t value whose tangent is halfway between the tangents at the endpionts. // (We defined bezierpts in onEmitGeometryShader.) - g->codeAppend ("highfloat2 tan0 = bezierpts[1] - bezierpts[0];"); - g->codeAppend ("highfloat2 tan1 = bezierpts[2] - bezierpts[1];"); - g->codeAppend ("highfloat2 midnorm = normalize(tan0) - normalize(tan1);"); - g->codeAppend ("highfloat2 T = midnorm * highfloat2x2(tan0 - tan1, tan0);"); - g->codeAppend ("highfloat t = clamp(T.t / T.s, 0, 1);"); // T.s=0 is weeded out by this point. + g->codeAppend ("highp float2 tan0 = bezierpts[1] - bezierpts[0];"); + g->codeAppend ("highp float2 tan1 = bezierpts[2] - bezierpts[1];"); + g->codeAppend ("highp float2 midnorm = normalize(tan0) - normalize(tan1);"); + g->codeAppend ("highp float2 T = midnorm * float2x2(tan0 - tan1, tan0);"); + g->codeAppend ("highp float t = clamp(T.t / T.s, 0, 1);"); // T.s=0 is weeded out by this point. // Clip the bezier triangle by the tangent at our new t value. This is a simple application for // De Casteljau's algorithm. - g->codeAppendf("highfloat4x2 quadratic_hull = highfloat4x2(bezierpts[0], " - "bezierpts[0] + tan0 * t, " - "bezierpts[1] + tan1 * t, " - "bezierpts[2]);"); + g->codeAppendf("highp float4x2 quadratic_hull = float4x2(bezierpts[0], " + "bezierpts[0] + tan0 * t, " + "bezierpts[1] + tan1 * t, " + "bezierpts[2]);"); int maxVerts = this->emitHullGeometry(g, emitVertexFn, "quadratic_hull", 4, "sk_InvocationID"); @@ -109,13 +109,13 @@ void GrCCPRQuadraticHullProcessor::emitQuadraticGeometry(GrGLSLGeometryBuilder* } void GrCCPRQuadraticHullProcessor::onEmitPerVertexGeometryCode(SkString* fnBody) const { - fnBody->appendf("%s = highfloat2(2 * %s.x, -1) * %s;", + fnBody->appendf("%s = float2(2 * %s.x, -1) * %s;", fGradXY.gsOut(), fXYD.gsOut(), fCanonicalDerivatives.c_str()); } void GrCCPRQuadraticHullProcessor::emitShaderCoverage(GrGLSLFragmentBuilder* f, const char* outputCoverage) const { - f->codeAppendf("highfloat d = (%s.x * %s.x - %s.y) * inversesqrt(dot(%s, %s));", + f->codeAppendf("highp float d = (%s.x * %s.x - %s.y) * inversesqrt(dot(%s, %s));", fXYD.fsIn(), fXYD.fsIn(), fXYD.fsIn(), fGradXY.fsIn(), fGradXY.fsIn()); f->codeAppendf("%s = clamp(0.5 - d, 0, 1);", outputCoverage); f->codeAppendf("%s += min(%s.z, 0);", outputCoverage, fXYD.fsIn()); // Flat closing edge. @@ -128,7 +128,7 @@ void GrCCPRQuadraticCornerProcessor::emitQuadraticGeometry(GrGLSLGeometryBuilder g->codeAppendf("%s = %s.xy * %s.xz;", fEdgeDistanceDerivatives.c_str(), fEdgeDistanceEquation.c_str(), rtAdjust); - g->codeAppendf("highfloat2 corner = bezierpts[sk_InvocationID * 2];"); + g->codeAppendf("highp float2 corner = bezierpts[sk_InvocationID * 2];"); int numVertices = this->emitCornerGeometry(g, emitVertexFn, "corner"); g->configure(GrGLSLGeometryBuilder::InputType::kTriangles, @@ -136,35 +136,35 @@ void GrCCPRQuadraticCornerProcessor::emitQuadraticGeometry(GrGLSLGeometryBuilder } void GrCCPRQuadraticCornerProcessor::onEmitPerVertexGeometryCode(SkString* fnBody) const { - fnBody->appendf("%s = highfloat3(%s[0].x, %s[0].y, %s.x);", + fnBody->appendf("%s = float3(%s[0].x, %s[0].y, %s.x);", fdXYDdx.gsOut(), fCanonicalDerivatives.c_str(), fCanonicalDerivatives.c_str(), fEdgeDistanceDerivatives.c_str()); - fnBody->appendf("%s = highfloat3(%s[1].x, %s[1].y, %s.y);", + fnBody->appendf("%s = float3(%s[1].x, %s[1].y, %s.y);", fdXYDdy.gsOut(), fCanonicalDerivatives.c_str(), fCanonicalDerivatives.c_str(), fEdgeDistanceDerivatives.c_str()); } void GrCCPRQuadraticCornerProcessor::emitShaderCoverage(GrGLSLFragmentBuilder* f, const char* outputCoverage) const { - f->codeAppendf("highfloat x = %s.x, y = %s.y, d = %s.z;", + f->codeAppendf("highp float x = %s.x, y = %s.y, d = %s.z;", fXYD.fsIn(), fXYD.fsIn(), fXYD.fsIn()); - f->codeAppendf("highfloat2x3 grad_xyd = highfloat2x3(%s, %s);", fdXYDdx.fsIn(), fdXYDdy.fsIn()); + f->codeAppendf("highp float2x3 grad_xyd = float2x3(%s, %s);", fdXYDdx.fsIn(), fdXYDdy.fsIn()); // 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. - f->codeAppend ("highfloat f = x*x - y;"); - f->codeAppend ("highfloat2 grad_f = highfloat2(2*x, -1) * highfloat2x2(grad_xyd);"); + f->codeAppend ("highp float f = x*x - y;"); + f->codeAppend ("highp float2 grad_f = float2(2*x, -1) * float2x2(grad_xyd);"); f->codeAppendf("%s = -(0.5 - f * inversesqrt(dot(grad_f, grad_f)));", outputCoverage); f->codeAppendf("%s -= d;", outputCoverage); // Use software msaa to approximate coverage at the corner pixels. int sampleCount = this->defineSoftSampleLocations(f, "samples"); - f->codeAppendf("highfloat3 xyd_center = highfloat3(%s.xy, %s.z + 0.5);", + f->codeAppendf("highp float3 xyd_center = float3(%s.xy, %s.z + 0.5);", fXYD.fsIn(), fXYD.fsIn()); f->codeAppendf("for (int i = 0; i < %i; ++i) {", sampleCount); - f->codeAppend ( "highfloat3 xyd = grad_xyd * samples[i] + xyd_center;"); - f->codeAppend ( "half f = xyd.y - xyd.x * xyd.x;"); // f > 0 -> inside curve. - f->codeAppendf( "%s += all(greaterThan(highfloat2(f,xyd.z), highfloat2(0))) ? %f : 0;", + f->codeAppend ( "highp float3 xyd = grad_xyd * samples[i] + xyd_center;"); + f->codeAppend ( "lowp float f = xyd.y - xyd.x * xyd.x;"); // f > 0 -> inside curve. + f->codeAppendf( "%s += all(greaterThan(float2(f,xyd.z), float2(0))) ? %f : 0;", outputCoverage, 1.0 / sampleCount); f->codeAppendf("}"); } diff --git a/src/gpu/ccpr/GrCCPRQuadraticProcessor.h b/src/gpu/ccpr/GrCCPRQuadraticProcessor.h index 5b8a854ec8..1eda255bb2 100644 --- a/src/gpu/ccpr/GrCCPRQuadraticProcessor.h +++ b/src/gpu/ccpr/GrCCPRQuadraticProcessor.h @@ -24,12 +24,13 @@ class GrCCPRQuadraticProcessor : public GrCCPRCoverageProcessor::PrimitiveProces public: GrCCPRQuadraticProcessor() : INHERITED(CoverageType::kShader) - , fCanonicalMatrix("canonical_matrix", kHighFloat3x3_GrSLType, GrShaderVar::kNonArray) - , fCanonicalDerivatives("canonical_derivatives", kHighFloat2x2_GrSLType, - GrShaderVar::kNonArray) - , fEdgeDistanceEquation("edge_distance_equation", kHighFloat3_GrSLType, - GrShaderVar::kNonArray) - , fXYD(kHighFloat3_GrSLType) {} + , fCanonicalMatrix("canonical_matrix", kMat33f_GrSLType, GrShaderVar::kNonArray, + kHigh_GrSLPrecision) + , fCanonicalDerivatives("canonical_derivatives", kMat22f_GrSLType, + GrShaderVar::kNonArray, kHigh_GrSLPrecision) + , fEdgeDistanceEquation("edge_distance_equation", kVec3f_GrSLType, + GrShaderVar::kNonArray, kHigh_GrSLPrecision) + , fXYD(kVec3f_GrSLType) {} void resetVaryings(GrGLSLVaryingHandler* varyingHandler) override { varyingHandler->addVarying("xyd", &fXYD, kHigh_GrSLPrecision); @@ -66,7 +67,7 @@ protected: class GrCCPRQuadraticHullProcessor : public GrCCPRQuadraticProcessor { public: GrCCPRQuadraticHullProcessor() - : fGradXY(kHighFloat2_GrSLType) {} + : fGradXY(kVec2f_GrSLType) {} void resetVaryings(GrGLSLVaryingHandler* varyingHandler) override { this->INHERITED::resetVaryings(varyingHandler); @@ -90,10 +91,10 @@ private: class GrCCPRQuadraticCornerProcessor : public GrCCPRQuadraticProcessor { public: GrCCPRQuadraticCornerProcessor() - : fEdgeDistanceDerivatives("edge_distance_derivatives", kHighFloat2_GrSLType, - GrShaderVar::kNonArray) - , fdXYDdx(kHighFloat3_GrSLType) - , fdXYDdy(kHighFloat3_GrSLType) {} + : fEdgeDistanceDerivatives("edge_distance_derivatives", kVec2f_GrSLType, + GrShaderVar::kNonArray, kHigh_GrSLPrecision) + , fdXYDdx(kVec3f_GrSLType) + , fdXYDdy(kVec3f_GrSLType) {} void resetVaryings(GrGLSLVaryingHandler* varyingHandler) override { this->INHERITED::resetVaryings(varyingHandler); diff --git a/src/gpu/ccpr/GrCCPRTriangleProcessor.cpp b/src/gpu/ccpr/GrCCPRTriangleProcessor.cpp index ee25851497..bb2ad1b4ba 100644 --- a/src/gpu/ccpr/GrCCPRTriangleProcessor.cpp +++ b/src/gpu/ccpr/GrCCPRTriangleProcessor.cpp @@ -16,16 +16,16 @@ void GrCCPRTriangleProcessor::onEmitVertexShader(const GrCCPRCoverageProcessor& const TexelBufferHandle& pointsBuffer, const char* atlasOffset, const char* rtAdjust, GrGPArgs* gpArgs) const { - v->codeAppend ("highfloat2 self = "); + v->codeAppend ("highp float2 self = "); v->appendTexelFetch(pointsBuffer, SkStringPrintf("%s[sk_VertexID]", proc.instanceAttrib()).c_str()); v->codeAppendf(".xy + %s;", atlasOffset); - gpArgs->fPositionVar.set(kHighFloat2_GrSLType, "self"); + gpArgs->fPositionVar.set(kVec2f_GrSLType, "self"); } void GrCCPRTriangleProcessor::defineInputVertices(GrGLSLGeometryBuilder* g) const { // Prepend in_vertices at the start of the shader. - g->codePrependf("highfloat3x2 in_vertices = highfloat3x2(sk_in[0].gl_Position.xy, " + g->codePrependf("highp float3x2 in_vertices = float3x2(sk_in[0].gl_Position.xy, " "sk_in[1].gl_Position.xy, " "sk_in[2].gl_Position.xy);"); } @@ -33,8 +33,8 @@ void GrCCPRTriangleProcessor::defineInputVertices(GrGLSLGeometryBuilder* g) cons void GrCCPRTriangleProcessor::emitWind(GrGLSLGeometryBuilder* g, const char* /*rtAdjust*/, const char* outputWind) const { // We will define in_vertices in defineInputVertices. - g->codeAppendf("%s = sign(determinant(highfloat2x2(in_vertices[1] - in_vertices[0], " - "in_vertices[2] - in_vertices[0])));", + g->codeAppendf("%s = sign(determinant(float2x2(in_vertices[1] - in_vertices[0], " + "in_vertices[2] - in_vertices[0])));", outputWind); } @@ -53,8 +53,8 @@ void GrCCPRTriangleHullAndEdgeProcessor::onEmitGeometryShader(GrGLSLGeometryBuil if (GeometryType::kHulls != fGeometryType) { g->codeAppend ("int edgeidx0 = sk_InvocationID, " "edgeidx1 = (edgeidx0 + 1) % 3;"); - g->codeAppendf("highfloat2 edgept0 = in_vertices[%s > 0 ? edgeidx0 : edgeidx1];", wind); - g->codeAppendf("highfloat2 edgept1 = in_vertices[%s > 0 ? edgeidx1 : edgeidx0];", wind); + g->codeAppendf("highp float2 edgept0 = in_vertices[%s > 0 ? edgeidx0 : edgeidx1];", wind); + g->codeAppendf("highp float2 edgept1 = in_vertices[%s > 0 ? edgeidx1 : edgeidx0];", wind); maxOutputVertices += this->emitEdgeGeometry(g, emitVertexFn, "edgept0", "edgept1"); } @@ -73,15 +73,15 @@ void GrCCPRTriangleCornerProcessor::onEmitVertexShader(const GrCCPRCoverageProce this->INHERITED::onEmitVertexShader(proc, v, pointsBuffer, atlasOffset, rtAdjust, gpArgs); // Fetch and transform the next point in the triangle. - v->codeAppend ("highfloat2 next = "); + v->codeAppend ("highp float2 next = "); v->appendTexelFetch(pointsBuffer, SkStringPrintf("%s[(sk_VertexID+1) %% 3]", proc.instanceAttrib()).c_str()); v->codeAppendf(".xy + %s;", atlasOffset); // Find the plane that gives distance from the [self -> next] edge, normalized to its AA // bloat width. - v->codeAppend ("highfloat2 n = highfloat2(next.y - self.y, self.x - next.x);"); - v->codeAppendf("highfloat2 d = n * highfloat2x2(self + %f * sign(n), " + v->codeAppend ("highp float2 n = float2(next.y - self.y, self.x - next.x);"); + v->codeAppendf("highp float2 d = n * float2x2(self + %f * sign(n), " "self - %f * sign(n));", kAABloatRadius, kAABloatRadius); @@ -98,7 +98,7 @@ void GrCCPRTriangleCornerProcessor::onEmitGeometryShader(GrGLSLGeometryBuilder* const char* rtAdjust) const { this->defineInputVertices(g); - g->codeAppend ("highfloat2 self = in_vertices[sk_InvocationID];"); + g->codeAppend ("highp float2 self = in_vertices[sk_InvocationID];"); int numVertices = this->emitCornerGeometry(g, emitVertexFn, "self"); g->configure(GrGLSLGeometryBuilder::InputType::kTriangles, @@ -114,7 +114,7 @@ void GrCCPRTriangleCornerProcessor::emitPerVertexGeometryCode(SkString* fnBody, fNeighbors.gsOut(), fDevCoord.gsIn()); fnBody->appendf("%s.zw = %s[(sk_InvocationID + 2) %% 3];", fNeighbors.gsOut(), fDevCoord.gsIn()); - fnBody->appendf("%s = highfloat3x3(%s[(sk_InvocationID + 2) %% 3], " + fnBody->appendf("%s = float3x3(%s[(sk_InvocationID + 2) %% 3], " "%s[sk_InvocationID], " "%s[(sk_InvocationID + 1) %% 3]) * %s;", fEdgeDistances.gsOut(), fEdgeDistance.gsIn(), fEdgeDistance.gsIn(), @@ -129,28 +129,32 @@ void GrCCPRTriangleCornerProcessor::emitPerVertexGeometryCode(SkString* fnBody, void GrCCPRTriangleCornerProcessor::emitShaderCoverage(GrGLSLFragmentBuilder* f, const char* outputCoverage) const { // FIXME: Adreno breaks if we don't put the frag coord in an intermediate highp variable. - f->codeAppendf("highfloat2 fragcoord = sk_FragCoord.xy;"); + f->codeAppendf("highp float2 fragcoord = sk_FragCoord.xy;"); // Approximate coverage by tracking where 4 horizontal lines enter and leave the triangle. - GrShaderVar samples("samples", kHighFloat4_GrSLType, GrShaderVar::kNonArray); + GrShaderVar samples("samples", kVec4f_GrSLType, GrShaderVar::kNonArray, + kHigh_GrSLPrecision); f->declareGlobal(samples); - f->codeAppendf("%s = fragcoord.y + highfloat4(-0.375, -0.125, 0.125, 0.375);", samples.c_str()); + f->codeAppendf("%s = fragcoord.y + float4(-0.375, -0.125, 0.125, 0.375);", samples.c_str()); - GrShaderVar leftedge("leftedge", kHighFloat4_GrSLType, GrShaderVar::kNonArray); + GrShaderVar leftedge("leftedge", kVec4f_GrSLType, GrShaderVar::kNonArray, + kHigh_GrSLPrecision); f->declareGlobal(leftedge); - f->codeAppendf("%s = highfloat4(fragcoord.x - 0.5);", leftedge.c_str()); + f->codeAppendf("%s = float4(fragcoord.x - 0.5);", leftedge.c_str()); - GrShaderVar rightedge("rightedge", kHighFloat4_GrSLType, GrShaderVar::kNonArray); + GrShaderVar rightedge("rightedge", kVec4f_GrSLType, GrShaderVar::kNonArray, + kHigh_GrSLPrecision); f->declareGlobal(rightedge); - f->codeAppendf("%s = highfloat4(fragcoord.x + 0.5);", rightedge.c_str()); + f->codeAppendf("%s = float4(fragcoord.x + 0.5);", rightedge.c_str()); SkString sampleEdgeFn; - GrShaderVar edgeArg("edge_distance", kHighFloat3_GrSLType, GrShaderVar::kNonArray); + GrShaderVar edgeArg("edge_distance", kVec3f_GrSLType, GrShaderVar::kNonArray, + kHigh_GrSLPrecision); f->emitFunction(kVoid_GrSLType, "sampleEdge", 1, &edgeArg, [&]() { SkString b; - b.appendf("highfloat m = abs(%s.x) < 1e-3 ? 1e18 : -1 / %s.x;", + b.appendf("highp float m = abs(%s.x) < 1e-3 ? 1e18 : -1 / %s.x;", edgeArg.c_str(), edgeArg.c_str()); - b.appendf("highfloat4 edge = m * (%s.y * samples + %s.z);", + b.appendf("highp float4 edge = m * (%s.y * samples + %s.z);", edgeArg.c_str(), edgeArg.c_str()); b.appendf("if (%s.x <= 1e-3 || (abs(%s.x) < 1e-3 && %s.y > 0)) {", edgeArg.c_str(), edgeArg.c_str(), edgeArg.c_str()); @@ -162,10 +166,10 @@ void GrCCPRTriangleCornerProcessor::emitShaderCoverage(GrGLSLFragmentBuilder* f, }().c_str(), &sampleEdgeFn); // See if the previous neighbor already handled this pixel. - f->codeAppendf("if (all(lessThan(abs(fragcoord - %s.zw), highfloat2(%f)))) {", + f->codeAppendf("if (all(lessThan(abs(fragcoord - %s.zw), float2(%f)))) {", fNeighbors.fsIn(), kAABloatRadius); // Handle the case where all 3 corners defer to the previous neighbor. - f->codeAppendf( "if (%s != 0 || !all(lessThan(abs(fragcoord - %s.xy), highfloat2(%f)))) {", + f->codeAppendf( "if (%s != 0 || !all(lessThan(abs(fragcoord - %s.xy), float2(%f)))) {", fCornerIdx.fsIn(), fNeighbors.fsIn(), kAABloatRadius); f->codeAppend ( "discard;"); f->codeAppend ( "}"); @@ -173,7 +177,7 @@ void GrCCPRTriangleCornerProcessor::emitShaderCoverage(GrGLSLFragmentBuilder* f, // Erase what the hull and two edges wrote at this corner in previous shaders (the two .5's // for the edges and the -1 for the hull cancel each other out). - f->codeAppendf("%s = dot(highfloat3(fragcoord, 1) * highfloat2x3(%s), highfloat2(1));", + f->codeAppendf("%s = dot(float3(fragcoord, 1) * float2x3(%s), float2(1));", outputCoverage, fEdgeDistances.fsIn()); // Sample the two edges at this corner. @@ -181,15 +185,15 @@ void GrCCPRTriangleCornerProcessor::emitShaderCoverage(GrGLSLFragmentBuilder* f, f->codeAppendf("%s(%s[1]);", sampleEdgeFn.c_str(), fEdgeDistances.fsIn()); // Handle the opposite edge if the next neighbor will defer to us. - f->codeAppendf("if (all(lessThan(abs(fragcoord - %s.xy), highfloat2(%f)))) {", + f->codeAppendf("if (all(lessThan(abs(fragcoord - %s.xy), float2(%f)))) {", fNeighbors.fsIn(), kAABloatRadius); // Erase the coverage the opposite edge wrote to this corner. - f->codeAppendf( "%s += dot(%s[2], highfloat3(fragcoord, 1)) + 0.5;", + f->codeAppendf( "%s += dot(%s[2], float3(fragcoord, 1)) + 0.5;", outputCoverage, fEdgeDistances.fsIn()); // Sample the opposite edge. f->codeAppendf( "%s(%s[2]);", sampleEdgeFn.c_str(), fEdgeDistances.fsIn()); f->codeAppend ("}"); - f->codeAppendf("highfloat4 widths = max(%s - %s, 0);", rightedge.c_str(), leftedge.c_str()); - f->codeAppendf("%s += dot(widths, highfloat4(0.25));", outputCoverage); + f->codeAppendf("highp float4 widths = max(%s - %s, 0);", rightedge.c_str(), leftedge.c_str()); + f->codeAppendf("%s += dot(widths, float4(0.25));", outputCoverage); } diff --git a/src/gpu/ccpr/GrCCPRTriangleProcessor.h b/src/gpu/ccpr/GrCCPRTriangleProcessor.h index 9ac76521bf..1e52d51a45 100644 --- a/src/gpu/ccpr/GrCCPRTriangleProcessor.h +++ b/src/gpu/ccpr/GrCCPRTriangleProcessor.h @@ -72,11 +72,11 @@ class GrCCPRTriangleCornerProcessor : public GrCCPRTriangleProcessor { public: GrCCPRTriangleCornerProcessor() : INHERITED(CoverageType::kShader) - , fEdgeDistance(kHighFloat3_GrSLType) - , fDevCoord(kHighFloat2_GrSLType) - , fNeighbors(kHighFloat4_GrSLType) - , fEdgeDistances(kHighFloat3x3_GrSLType) - , fCornerIdx(kShort_GrSLType) {} + , fEdgeDistance(kVec3f_GrSLType) + , fDevCoord(kVec2f_GrSLType) + , fNeighbors(kVec4f_GrSLType) + , fEdgeDistances(kMat33f_GrSLType) + , fCornerIdx(kInt_GrSLType) {} void resetVaryings(GrGLSLVaryingHandler* varyingHandler) override { this->INHERITED::resetVaryings(varyingHandler); |