diff options
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 | 128 | ||||
-rw-r--r-- | src/gpu/ccpr/GrCCPRCubicProcessor.h | 16 | ||||
-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, 230 insertions, 237 deletions
diff --git a/src/gpu/ccpr/GrCCPRCoverageProcessor.cpp b/src/gpu/ccpr/GrCCPRCoverageProcessor.cpp index 079f240231..4aac3d3d02 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[%i];", proc.instanceAttrib(), proc.atlasOffsetIdx()); - v->codeAppend ("highp float2 atlasoffset = float2((packedoffset<<16) >> 16, " - "packedoffset >> 16);"); + v->codeAppend ("highfloat2 atlasoffset = highfloat2((packedoffset<<16) >> 16, " + "packedoffset >> 16);"); this->onEmitVertexShader(proc, v, pointsBuffer, "atlasoffset", rtAdjust, gpArgs); } @@ -135,12 +135,10 @@ void PrimitiveProcessor::emitGeometryShader(const GrCCPRCoverageProcessor& proc, SkString emitVertexFn; SkSTArray<2, GrShaderVar> emitArgs; - 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(); + 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(); g->emitFunction(kVoid_GrSLType, "emitVertex", emitArgs.count(), emitArgs.begin(), [&]() { SkString fnBody; this->emitPerVertexGeometryCode(&fnBody, position, coverage, fGeomWind.c_str()); @@ -151,12 +149,12 @@ void PrimitiveProcessor::emitGeometryShader(const GrCCPRCoverageProcessor& proc, fnBody.appendf("%s = %s * %s;", fFragCoverageTimesWind.gsOut(), coverage, fGeomWind.c_str()); } - fnBody.append ("gl_Position = float4(position, 0, 1);"); + fnBody.append ("gl_Position = highfloat4(position, 0, 1);"); fnBody.append ("EmitVertex();"); return fnBody; }().c_str(), &emitVertexFn); - g->codeAppendf("highp float2 bloat = %f * abs(%s.xz);", kAABloatRadius, rtAdjust); + g->codeAppendf("highfloat2 bloat = %f * abs(%s.xz);", kAABloatRadius, rtAdjust); #ifdef SK_DEBUG if (proc.debugVisualizationsEnabled()) { @@ -173,7 +171,7 @@ int PrimitiveProcessor::emitHullGeometry(GrGLSLGeometryBuilder* g, const char* e SkASSERT(numSides >= 3); if (!midpoint) { - g->codeAppendf("highp float2 midpoint = %s * float%i(%f);", + g->codeAppendf("highfloat2 midpoint = %s * highfloat%i(%f);", polygonPts, numSides, 1.0 / numSides); midpoint = "midpoint"; } @@ -182,42 +180,42 @@ int PrimitiveProcessor::emitHullGeometry(GrGLSLGeometryBuilder* g, const char* e "nextidx = (%s + 1) %% %i;", wedgeIdx, numSides - 1, numSides, wedgeIdx, numSides); - g->codeAppendf("highp float2 self = %s[%s];" - "highp int leftidx = %s > 0 ? previdx : nextidx;" - "highp int rightidx = %s > 0 ? nextidx : previdx;", + g->codeAppendf("highfloat2 self = %s[%s];" + "int leftidx = %s > 0 ? previdx : nextidx;" + "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("highp float2 right = %s[rightidx];", polygonPts); + g->codeAppendf("highfloat2 right = %s[rightidx];", polygonPts); if (3 == numSides) { // TODO: evaluate perf gains. - g->codeAppend ("highp float2 qsr = sign(right - self);"); + g->codeAppend ("highfloat2 qsr = sign(right - self);"); } else { SkASSERT(4 == numSides); - g->codeAppendf("highp float2 diag = %s[(%s + 2) %% 4];", polygonPts, wedgeIdx); - g->codeAppend ("highp float2 qsr = sign((right != self ? right : diag) - self);"); + g->codeAppendf("highfloat2 diag = %s[(%s + 2) %% 4];", polygonPts, wedgeIdx); + g->codeAppend ("highfloat2 qsr = sign((right != self ? right : diag) - self);"); } // Which quadrant does the vector from left -> self fall into? - g->codeAppendf("highp float2 qls = sign(self - %s[leftidx]);", polygonPts); + g->codeAppendf("highfloat2 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 ("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);"); + 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);"); dr2 = "dr2"; } else { - 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->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->codeAppendf("bool2 dnotequal = notEqual(%s, dl);", dr2); @@ -230,7 +228,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 * float2(-dl.y, dl.x), 1);", emitVertexFn); + g->codeAppendf( "%s(self + bloat * highfloat2(-dl.y, dl.x), 1);", emitVertexFn); g->codeAppend ("}"); g->codeAppend ("EndPrimitive();"); @@ -241,18 +239,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, "highp float3 edge_distance_equation"); + this->emitEdgeDistanceEquation(g, leftPt, rightPt, "highfloat3 edge_distance_equation"); distanceEquation = "edge_distance_equation"; } // qlr is defined in emitEdgeDistanceEquation. - g->codeAppendf("highp float2x2 endpts = float2x2(%s - bloat * qlr, %s + bloat * qlr);", + g->codeAppendf("highfloat2x2 endpts = highfloat2x2(%s - bloat * qlr, %s + bloat * qlr);", leftPt, rightPt); - g->codeAppendf("mediump float2 endpts_coverage = %s.xy * endpts + %s.z;", + g->codeAppendf("half2 endpts_coverage = %s.xy * endpts + %s.z;", distanceEquation, distanceEquation); // d1 is defined in emitEdgeDistanceEquation. - g->codeAppend ("highp float2 d2 = d1;"); + g->codeAppend ("highfloat2 d2 = d1;"); g->codeAppend ("bool aligned = qlr.x == 0 || qlr.y == 0;"); g->codeAppend ("if (aligned) {"); g->codeAppend ( "d1 -= qlr;"); @@ -281,25 +279,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("highp float2 qlr = sign(%s - %s);", rightPt, leftPt); - g->codeAppend ("highp float2 d1 = float2(qlr.y, -qlr.x);"); + g->codeAppendf("highfloat2 qlr = sign(%s - %s);", rightPt, leftPt); + g->codeAppend ("highfloat2 d1 = highfloat2(qlr.y, -qlr.x);"); - g->codeAppendf("highp float2 n = float2(%s.y - %s.y, %s.x - %s.x);", + g->codeAppendf("highfloat2 n = highfloat2(%s.y - %s.y, %s.x - %s.x);", rightPt, leftPt, leftPt, rightPt); - g->codeAppendf("highp float2 kk = n * float2x2(%s + bloat * d1, %s - bloat * d1);", + g->codeAppendf("highfloat2 kk = n * highfloat2x2(%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("highp float scale = 1 / max(kk[0] - kk[1], 1e-30);"); + g->codeAppendf("highfloat scale = 1 / max(kk[0] - kk[1], 1e-30);"); - g->codeAppendf("%s = float3(-n, kk[1]) * scale;", outputDistanceEquation); + g->codeAppendf("%s = half3(-n, kk[1]) * scale;", outputDistanceEquation); } int PrimitiveProcessor::emitCornerGeometry(GrGLSLGeometryBuilder* g, const char* emitVertexFn, const char* pt) const { - 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->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->codeAppend ("EndPrimitive();"); return 4; @@ -315,17 +313,17 @@ void PrimitiveProcessor::emitCoverage(const GrCCPRCoverageProcessor& proc, GrGLS f->codeAppendf("%s.a = %s;", outputColor, fFragCoverageTimesWind.fsIn()); break; case CoverageType::kShader: - f->codeAppendf("mediump float coverage = 0;"); + f->codeAppendf("half coverage = 0;"); this->emitShaderCoverage(f, "coverage"); f->codeAppendf("%s.a = coverage * %s;", outputColor, fFragWind.fsIn()); break; } - f->codeAppendf("%s = float4(1);", outputCoverage); + f->codeAppendf("%s = half4(1);", outputCoverage); #ifdef SK_DEBUG if (proc.debugVisualizationsEnabled()) { - f->codeAppendf("%s = float4(-%s.a, %s.a, 0, 1);", outputColor, outputColor, outputColor); + f->codeAppendf("%s = half4(-%s.a, %s.a, 0, 1);", outputColor, outputColor, outputColor); } #endif } @@ -334,17 +332,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("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." + 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." ")"); return 8; #else - 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." + 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." ")"); return 16; #endif diff --git a/src/gpu/ccpr/GrCCPRCoverageProcessor.h b/src/gpu/ccpr/GrCCPRCoverageProcessor.h index b8032d9ec2..8120136fad 100644 --- a/src/gpu/ccpr/GrCCPRCoverageProcessor.h +++ b/src/gpu/ccpr/GrCCPRCoverageProcessor.h @@ -133,9 +133,9 @@ protected: PrimitiveProcessor(CoverageType coverageType) : fCoverageType(coverageType) - , fGeomWind("wind", kFloat_GrSLType, GrShaderVar::kNonArray, kLow_GrSLPrecision) - , fFragWind(kFloat_GrSLType) - , fFragCoverageTimesWind(kFloat_GrSLType) {} + , fGeomWind("wind", kHalf_GrSLType, GrShaderVar::kNonArray, kLow_GrSLPrecision) + , fFragWind(kHalf_GrSLType) + , fFragCoverageTimesWind(kHalf_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 0ac4517d5f..1fc2a29342 100644 --- a/src/gpu/ccpr/GrCCPRCubicProcessor.cpp +++ b/src/gpu/ccpr/GrCCPRCubicProcessor.cpp @@ -16,18 +16,18 @@ void GrCCPRCubicProcessor::onEmitVertexShader(const GrCCPRCoverageProcessor& pro const TexelBufferHandle& pointsBuffer, const char* atlasOffset, const char* rtAdjust, GrGPArgs* gpArgs) const { - v->codeAppend ("highp float2 self = "); + v->codeAppend ("highfloat2 self = "); v->appendTexelFetch(pointsBuffer, SkStringPrintf("%s.x + sk_VertexID", proc.instanceAttrib()).c_str()); v->codeAppendf(".xy + %s;", atlasOffset); - gpArgs->fPositionVar.set(kVec2f_GrSLType, "self"); + gpArgs->fPositionVar.set(kHighFloat2_GrSLType, "self"); } void GrCCPRCubicProcessor::emitWind(GrGLSLGeometryBuilder* g, const char* rtAdjust, const char* outputWind) const { // We will define bezierpts in onEmitGeometryShader. - g->codeAppend ("highp float area_times_2 = " - "determinant(float3x3(1, bezierpts[0], " + g->codeAppend ("highfloat area_times_2 = " + "determinant(highfloat3x3(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. @@ -46,61 +46,61 @@ 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("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);"); + 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);"); // Evaluate the cubic at T=.5 for an mid-ish point. - g->codeAppendf("highp float2 midpoint = bezierpts * float4(.125, .375, .375, .125);"); + g->codeAppendf("highfloat2 midpoint = bezierpts * highfloat4(.125, .375, .375, .125);"); // Find the cubic's power basis coefficients. - 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 ("highfloat2x4 C = highfloat4x4(-1, 3, -3, 1, " + " 3, -6, 3, 0, " + "-3, 3, 0, 0, " + " 1, 0, 0, 0) * transpose(bezierpts);"); // Find the cubic's inflection function. - g->codeAppend ("highp float D3 = +determinant(float2x2(C[0].yz, C[1].yz));"); - g->codeAppend ("highp float D2 = -determinant(float2x2(C[0].xz, C[1].xz));"); - g->codeAppend ("highp float D1 = +determinant(float2x2(C));"); + g->codeAppend ("highfloat D3 = +determinant(highfloat2x2(C[0].yz, C[1].yz));"); + g->codeAppend ("highfloat D2 = -determinant(highfloat2x2(C[0].xz, C[1].xz));"); + g->codeAppend ("highfloat D1 = +determinant(highfloat2x2(C));"); // Calculate the KLM matrix. g->declareGlobal(fKLMMatrix); - g->codeAppend ("highp float4 K, L, M;"); - g->codeAppend ("highp float2 l, m;"); - g->codeAppend ("highp float discr = 3*D2*D2 - 4*D1*D3;"); + g->codeAppend ("highfloat4 K, L, M;"); + g->codeAppend ("highfloat2 l, m;"); + g->codeAppend ("highfloat discr = 3*D2*D2 - 4*D1*D3;"); if (CubicType::kSerpentine == fCubicType) { // This math also works out for the "cusp" and "cusp at infinity" cases. - g->codeAppend ("highp float q = 3*D2 + sign(D2) * sqrt(max(3*discr, 0));"); - g->codeAppend ("l.ts = normalize(float2(q, 6*D1));"); - g->codeAppend ("m.ts = discr <= 0 ? l.ts : normalize(float2(2*D3, q));"); - 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;"); + g->codeAppend ("highfloat q = 3*D2 + sign(D2) * sqrt(max(3*discr, 0));"); + g->codeAppend ("l.ts = normalize(highfloat2(q, 6*D1));"); + g->codeAppend ("m.ts = discr <= 0 ? l.ts : normalize(highfloat2(2*D3, q));"); + 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;"); } else { - g->codeAppend ("highp float q = D2 + sign(D2) * sqrt(max(-discr, 0));"); - g->codeAppend ("l.ts = normalize(float2(q, 2*D1));"); - g->codeAppend ("m.ts = discr >= 0 ? l.ts : normalize(float2(2 * (D2*D2 - D3*D1), D1*q));"); - g->codeAppend ("highp float4 lxm = float4(l.s * m.s, l.s * m.t, l.t * m.s, l.t * m.t);"); - g->codeAppend ("K = float4(0, lxm.x, -lxm.y - lxm.z, lxm.w);"); - g->codeAppend ("L = float4(-1,1,-1,1) * l.sstt * (lxm.xyzw + float4(0, 2*lxm.zy, 0));"); - g->codeAppend ("M = float4(-1,1,-1,1) * m.sstt * (lxm.xzyw + float4(0, 2*lxm.yz, 0));"); + g->codeAppend ("highfloat q = D2 + sign(D2) * sqrt(max(-discr, 0));"); + g->codeAppend ("l.ts = normalize(highfloat2(q, 2*D1));"); + g->codeAppend ("m.ts = discr >= 0 ? l.ts : normalize(highfloat2(2 * (D2*D2 - D3*D1), D1*q));"); + g->codeAppend ("highfloat4 lxm = highfloat4(l.s * m.s, l.s * m.t, l.t * m.s, l.t * m.t);"); + g->codeAppend ("K = highfloat4(0, lxm.x, -lxm.y - lxm.z, lxm.w);"); + g->codeAppend ("L = highfloat4(-1,1,-1,1) * l.sstt * (lxm.xyzw + highfloat4(0, 2*lxm.zy, 0));"); + g->codeAppend ("M = highfloat4(-1,1,-1,1) * m.sstt * (lxm.xzyw + highfloat4(0, 2*lxm.yz, 0));"); } - g->codeAppend ("lowp int middlerow = abs(D2) > abs(D1) ? 2 : 1;"); - 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()); + g->codeAppend ("short middlerow = abs(D2) > abs(D1) ? 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()); // Orient the KLM matrix so we fill the correct side of the curve. - g->codeAppendf("lowp float2 orientation = sign(float3(midpoint, 1) * float2x3(%s[1], %s[2]));", + g->codeAppendf("half2 orientation = sign(half3(midpoint, 1) * half2x3(%s[1], %s[2]));", fKLMMatrix.c_str(), 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->codeAppendf("%s *= highfloat3x3(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;", @@ -112,9 +112,9 @@ void GrCCPRCubicProcessor::onEmitGeometryShader(GrGLSLGeometryBuilder* g, const // Determine the amount of additional coverage to subtract out for the flat edge (P3 -> P0). g->declareGlobal(fEdgeDistanceEquation); - g->codeAppendf("int edgeidx0 = %s > 0 ? 3 : 0;", wind); - g->codeAppendf("highp float2 edgept0 = bezierpts[edgeidx0];"); - g->codeAppendf("highp float2 edgept1 = bezierpts[3 - edgeidx0];"); + g->codeAppendf("short edgeidx0 = %s > 0 ? 3 : 0;", wind); + g->codeAppendf("highfloat2 edgept0 = bezierpts[edgeidx0];"); + g->codeAppendf("highfloat2 edgept1 = bezierpts[3 - edgeidx0];"); this->emitEdgeDistanceEquation(g, "edgept0", "edgept1", fEdgeDistanceEquation.c_str()); this->emitCubicGeometry(g, emitVertexFn, wind, rtAdjust); @@ -123,10 +123,10 @@ void GrCCPRCubicProcessor::onEmitGeometryShader(GrGLSLGeometryBuilder* g, const void GrCCPRCubicProcessor::emitPerVertexGeometryCode(SkString* fnBody, const char* position, const char* /*coverage*/, const char* /*wind*/) const { - fnBody->appendf("highp float3 klm = float3(%s, 1) * %s;", position, fKLMMatrix.c_str()); - fnBody->appendf("highp float d = dot(float3(%s, 1), %s);", + fnBody->appendf("highfloat3 klm = highfloat3(%s, 1) * %s;", position, fKLMMatrix.c_str()); + fnBody->appendf("highfloat d = dot(highfloat3(%s, 1), %s);", position, fEdgeDistanceEquation.c_str()); - fnBody->appendf("%s = float4(klm, d);", fKLMD.gsOut()); + fnBody->appendf("%s = highfloat4(klm, d);", fKLMD.gsOut()); this->onEmitPerVertexGeometryCode(fnBody); } @@ -150,10 +150,10 @@ void GrCCPRCubicHullProcessor::onEmitPerVertexGeometryCode(SkString* fnBody) con void GrCCPRCubicHullProcessor::emitShaderCoverage(GrGLSLFragmentBuilder* f, const char* outputCoverage) const { - f->codeAppendf("highp float k = %s.x, l = %s.y, m = %s.z, d = %s.w;", + f->codeAppendf("highfloat k = %s.x, l = %s.y, m = %s.z, d = %s.w;", fKLMD.fsIn(), fKLMD.fsIn(), fKLMD.fsIn(), fKLMD.fsIn()); - f->codeAppend ("highp float f = k*k*k - l*m;"); - f->codeAppendf("highp float2 grad_f = %s * float2(k, 1);", fGradMatrix.fsIn()); + f->codeAppend ("highfloat f = k*k*k - l*m;"); + f->codeAppendf("highfloat2 grad_f = %s * highfloat2(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 closing edge. } @@ -166,7 +166,7 @@ void GrCCPRCubicCornerProcessor::emitCubicGeometry(GrGLSLGeometryBuilder* g, g->codeAppendf("%s = %s.xy * %s.xz;", fEdgeDistanceDerivatives.c_str(), fEdgeDistanceEquation.c_str(), rtAdjust); - g->codeAppendf("highp float2 corner = bezierpts[sk_InvocationID * 3];"); + g->codeAppendf("highfloat2 corner = bezierpts[sk_InvocationID * 3];"); int numVertices = this->emitCornerGeometry(g, emitVertexFn, "corner"); g->configure(GrGLSLGeometryBuilder::InputType::kLinesAdjacency, @@ -174,10 +174,10 @@ void GrCCPRCubicCornerProcessor::emitCubicGeometry(GrGLSLGeometryBuilder* g, } void GrCCPRCubicCornerProcessor::onEmitPerVertexGeometryCode(SkString* fnBody) const { - fnBody->appendf("%s = float4(%s[0].x, %s[1].x, %s[2].x, %s.x);", + fnBody->appendf("%s = highfloat4(%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 = float4(%s[0].y, %s[1].y, %s[2].y, %s.y);", + fnBody->appendf("%s = highfloat4(%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()); @@ -187,28 +187,28 @@ void GrCCPRCubicCornerProcessor::onEmitPerVertexGeometryCode(SkString* fnBody) c void GrCCPRCubicCornerProcessor::emitShaderCoverage(GrGLSLFragmentBuilder* f, const char* outputCoverage) const { - f->codeAppendf("highp float2x4 grad_klmd = float2x4(%s, %s);", + f->codeAppendf("highfloat2x4 grad_klmd = highfloat2x4(%s, %s);", fdKLMDdx.fsIn(), fdKLMDdy.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->codeAppendf("highp float k = %s.x, l = %s.y, m = %s.z, d = %s.w;", + f->codeAppendf("highfloat k = %s.x, l = %s.y, m = %s.z, d = %s.w;", fKLMD.fsIn(), fKLMD.fsIn(), fKLMD.fsIn(), fKLMD.fsIn()); - f->codeAppend ("highp float f = k*k*k - l*m;"); - f->codeAppend ("highp float2 grad_f = float3(3*k*k, -m, -l) * float2x3(grad_klmd);"); + f->codeAppend ("highfloat f = k*k*k - l*m;"); + f->codeAppend ("highfloat2 grad_f = highfloat3(3*k*k, -m, -l) * highfloat2x3(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 = this->defineSoftSampleLocations(f, "samples"); - f->codeAppendf("highp float4 klmd_center = float4(%s.xyz, %s.w + 0.5);", + f->codeAppendf("highfloat4 klmd_center = highfloat4(%s.xyz, %s.w + 0.5);", fKLMD.fsIn(), fKLMD.fsIn()); f->codeAppendf("for (int i = 0; i < %i; ++i) {", sampleCount); - f->codeAppend ( "highp float4 klmd = grad_klmd * samples[i] + klmd_center;"); - f->codeAppend ( "lowp float f = klmd.y * klmd.z - klmd.x * klmd.x * klmd.x;"); - f->codeAppendf( "%s += all(greaterThan(float4(f, klmd.y, klmd.z, klmd.w), " - "float4(0))) ? %f : 0;", + f->codeAppend ( "highfloat4 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 ("}"); } diff --git a/src/gpu/ccpr/GrCCPRCubicProcessor.h b/src/gpu/ccpr/GrCCPRCubicProcessor.h index cfee7bfac1..20ca3f2547 100644 --- a/src/gpu/ccpr/GrCCPRCubicProcessor.h +++ b/src/gpu/ccpr/GrCCPRCubicProcessor.h @@ -33,12 +33,12 @@ public: GrCCPRCubicProcessor(CubicType cubicType) : INHERITED(CoverageType::kShader) , fCubicType(cubicType) - , fKLMMatrix("klm_matrix", kMat33f_GrSLType, GrShaderVar::kNonArray, + , fKLMMatrix("klm_matrix", kHighFloat3x3_GrSLType, GrShaderVar::kNonArray, kHigh_GrSLPrecision) - , fKLMDerivatives("klm_derivatives", kVec2f_GrSLType, 3, kHigh_GrSLPrecision) - , fEdgeDistanceEquation("edge_distance_equation", kVec3f_GrSLType, + , fKLMDerivatives("klm_derivatives", kHighFloat2_GrSLType, 3, kHigh_GrSLPrecision) + , fEdgeDistanceEquation("edge_distance_equation", kHighFloat3_GrSLType, GrShaderVar::kNonArray, kHigh_GrSLPrecision) - , fKLMD(kVec4f_GrSLType) {} + , fKLMD(kHighFloat4_GrSLType) {} void resetVaryings(GrGLSLVaryingHandler* varyingHandler) override { varyingHandler->addVarying("klmd", &fKLMD, kHigh_GrSLPrecision); @@ -71,7 +71,7 @@ class GrCCPRCubicHullProcessor : public GrCCPRCubicProcessor { public: GrCCPRCubicHullProcessor(CubicType cubicType) : INHERITED(cubicType) - , fGradMatrix(kMat22f_GrSLType) {} + , fGradMatrix(kHighFloat2x2_GrSLType) {} void resetVaryings(GrGLSLVaryingHandler* varyingHandler) override { this->INHERITED::resetVaryings(varyingHandler); @@ -93,10 +93,10 @@ class GrCCPRCubicCornerProcessor : public GrCCPRCubicProcessor { public: GrCCPRCubicCornerProcessor(CubicType cubicType) : INHERITED(cubicType) - , fEdgeDistanceDerivatives("edge_distance_derivatives", kVec2f_GrSLType, + , fEdgeDistanceDerivatives("edge_distance_derivatives", kHighFloat2_GrSLType, GrShaderVar::kNonArray, kHigh_GrSLPrecision) - , fdKLMDdx(kVec4f_GrSLType) - , fdKLMDdy(kVec4f_GrSLType) {} + , fdKLMDdx(kHighFloat4_GrSLType) + , fdKLMDdy(kHighFloat4_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 429767d3d0..bb0ecc9e22 100644 --- a/src/gpu/ccpr/GrCCPRPathProcessor.cpp +++ b/src/gpu/ccpr/GrCCPRPathProcessor.cpp @@ -121,12 +121,12 @@ void GLSLPathProcessor::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { const char* atlasAdjust; fAtlasAdjustUniform = uniHandler->addUniform( kVertex_GrShaderFlag, - kVec2f_GrSLType, kHigh_GrSLPrecision, "atlas_adjust", &atlasAdjust); + kHighFloat2_GrSLType, "atlas_adjust", &atlasAdjust); varyingHandler->emitAttributes(proc); - GrGLSLVertToFrag texcoord(kVec2f_GrSLType); - GrGLSLVertToFrag color(kVec4f_GrSLType); + GrGLSLVertToFrag texcoord(kHighFloat2_GrSLType); + GrGLSLVertToFrag color(kHalf4_GrSLType); varyingHandler->addVarying("texcoord", &texcoord, kHigh_GrSLPrecision); varyingHandler->addFlatPassThroughAttribute(&proc.getInstanceAttrib(InstanceAttribs::kColor), args.fOutputColor, kLow_GrSLPrecision); @@ -137,41 +137,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("highp float2x2 N = float2x2(%s);", proc.getEdgeNormsAttrib().fName); + v->codeAppendf("highfloat2x2 N = highfloat2x2(%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("highp float2 refpt = (min(N[0].x, N[0].y) < 0) ? %s.xy : %s.zw;", + v->codeAppendf("highfloat2 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("highp float2 refpt45 = (N[1].x < 0) ? %s.xy : %s.zw;", + v->codeAppendf("highfloat2 refpt45 = (N[1].x < 0) ? %s.xy : %s.zw;", proc.getInstanceAttrib(InstanceAttribs::kDevBounds45).fName, proc.getInstanceAttrib(InstanceAttribs::kDevBounds45).fName); - v->codeAppendf("refpt45 *= float2x2(.5,.5,-.5,.5);"); // transform back to device space. + v->codeAppendf("refpt45 *= highfloat2x2(.5,.5,-.5,.5);"); // transform back to device space. v->codeAppendf("refpt45 += N[1] * %f;", kAABloatRadius); // bloat for AA. - v->codeAppend ("highp float2 K = float2(dot(N[0], refpt), dot(N[1], refpt45));"); - v->codeAppendf("highp float2 octocoord = K * inverse(N);"); + v->codeAppend ("highfloat2 K = highfloat2(dot(N[0], refpt), dot(N[1], refpt45));"); + v->codeAppendf("highfloat2 octocoord = K * inverse(N);"); - gpArgs->fPositionVar.set(kVec2f_GrSLType, "octocoord"); + gpArgs->fPositionVar.set(kHighFloat2_GrSLType, "octocoord"); // Convert to atlas coordinates in order to do our texture lookup. - v->codeAppendf("highp float2 atlascoord = octocoord + float2(%s);", + v->codeAppendf("highfloat2 atlascoord = octocoord + highfloat2(%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 = float2(atlascoord.x * %s.x, 1 - atlascoord.y * %s.y);", + v->codeAppendf("%s = highfloat2(atlascoord.x * %s.x, 1 - atlascoord.y * %s.y);", texcoord.vsOut(), atlasAdjust, atlasAdjust); } // Convert to (local) path cordinates. - v->codeAppendf("highp float2 pathcoord = inverse(float2x2(%s)) * (octocoord - %s);", + v->codeAppendf("highfloat2 pathcoord = inverse(highfloat2x2(%s)) * (octocoord - %s);", proc.getInstanceAttrib(InstanceAttribs::kViewMatrix).fName, proc.getInstanceAttrib(InstanceAttribs::kViewTranslate).fName); @@ -181,16 +181,16 @@ void GLSLPathProcessor::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) { // Fragment shader. GrGLSLPPFragmentBuilder* f = args.fFragBuilder; - f->codeAppend ("mediump float coverage_count = "); - f->appendTextureLookup(args.fTexSamplers[0], texcoord.fsIn(), kVec2f_GrSLType); + f->codeAppend ("half coverage_count = "); + f->appendTextureLookup(args.fTexSamplers[0], texcoord.fsIn(), kHighFloat2_GrSLType); f->codeAppend (".a;"); if (SkPath::kWinding_FillType == proc.fillType()) { - f->codeAppendf("%s = float4(min(abs(coverage_count), 1));", args.fOutputCoverage); + f->codeAppendf("%s = half4(min(abs(coverage_count), 1));", args.fOutputCoverage); } else { SkASSERT(SkPath::kEvenOdd_FillType == proc.fillType()); - f->codeAppend ("mediump float t = mod(abs(coverage_count), 2);"); - f->codeAppendf("%s = float4(1 - abs(t - 1));", args.fOutputCoverage); + f->codeAppend ("half t = mod(abs(coverage_count), 2);"); + f->codeAppendf("%s = half4(1 - abs(t - 1));", args.fOutputCoverage); } } diff --git a/src/gpu/ccpr/GrCCPRQuadraticProcessor.cpp b/src/gpu/ccpr/GrCCPRQuadraticProcessor.cpp index 73d0d1e3d0..ced5be1f70 100644 --- a/src/gpu/ccpr/GrCCPRQuadraticProcessor.cpp +++ b/src/gpu/ccpr/GrCCPRQuadraticProcessor.cpp @@ -16,18 +16,18 @@ void GrCCPRQuadraticProcessor::onEmitVertexShader(const GrCCPRCoverageProcessor& const TexelBufferHandle& pointsBuffer, const char* atlasOffset, const char* rtAdjust, GrGPArgs* gpArgs) const { - v->codeAppend ("highp float2 self = "); + v->codeAppend ("highfloat2 self = "); v->appendTexelFetch(pointsBuffer, SkStringPrintf("%s.x + sk_VertexID", proc.instanceAttrib()).c_str()); v->codeAppendf(".xy + %s;", atlasOffset); - gpArgs->fPositionVar.set(kVec2f_GrSLType, "self"); + gpArgs->fPositionVar.set(kHighFloat2_GrSLType, "self"); } void GrCCPRQuadraticProcessor::emitWind(GrGLSLGeometryBuilder* g, const char* rtAdjust, const char* outputWind) const { // We will define bezierpts in onEmitGeometryShader. - g->codeAppend ("highp float area_times_2 = " - "determinant(float2x2(bezierpts[1] - bezierpts[0], " + g->codeAppend ("highfloat area_times_2 = " + "determinant(highfloat2x2(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)) {", @@ -46,26 +46,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("highp float3x2 bezierpts = float3x2(sk_in[0].gl_Position.xy, " - "sk_in[1].gl_Position.xy, " - "sk_in[2].gl_Position.xy);"); + g->codePrependf("highfloat3x2 bezierpts = highfloat3x2(sk_in[0].gl_Position.xy, " + "sk_in[1].gl_Position.xy, " + "sk_in[2].gl_Position.xy);"); g->declareGlobal(fCanonicalMatrix); - 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));", + 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));", fCanonicalMatrix.c_str()); g->declareGlobal(fCanonicalDerivatives); - g->codeAppendf("%s = float2x2(%s) * float2x2(%s.x, 0, 0, %s.z);", + g->codeAppendf("%s = highfloat2x2(%s) * highfloat2x2(%s.x, 0, 0, %s.z);", fCanonicalDerivatives.c_str(), fCanonicalMatrix.c_str(), rtAdjust, rtAdjust); g->declareGlobal(fEdgeDistanceEquation); - g->codeAppendf("highp float2 edgept0 = bezierpts[%s > 0 ? 2 : 0];", wind); - g->codeAppendf("highp float2 edgept1 = bezierpts[%s > 0 ? 0 : 2];", wind); + g->codeAppendf("highfloat2 edgept0 = bezierpts[%s > 0 ? 2 : 0];", wind); + g->codeAppendf("highfloat2 edgept1 = bezierpts[%s > 0 ? 0 : 2];", wind); this->emitEdgeDistanceEquation(g, "edgept0", "edgept1", fEdgeDistanceEquation.c_str()); this->emitQuadraticGeometry(g, emitVertexFn, rtAdjust); @@ -74,7 +74,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 * float3(%s, 1)).xy;", + fnBody->appendf("%s.xy = (%s * highfloat3(%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, @@ -87,18 +87,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 ("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. + 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. // Clip the bezier triangle by the tangent at our new t value. This is a simple application for // De Casteljau's algorithm. - g->codeAppendf("highp float4x2 quadratic_hull = float4x2(bezierpts[0], " - "bezierpts[0] + tan0 * t, " - "bezierpts[1] + tan1 * t, " - "bezierpts[2]);"); + g->codeAppendf("highfloat4x2 quadratic_hull = highfloat4x2(bezierpts[0], " + "bezierpts[0] + tan0 * t, " + "bezierpts[1] + tan1 * t, " + "bezierpts[2]);"); int maxVerts = this->emitHullGeometry(g, emitVertexFn, "quadratic_hull", 4, "sk_InvocationID"); @@ -108,13 +108,13 @@ void GrCCPRQuadraticHullProcessor::emitQuadraticGeometry(GrGLSLGeometryBuilder* } void GrCCPRQuadraticHullProcessor::onEmitPerVertexGeometryCode(SkString* fnBody) const { - fnBody->appendf("%s = float2(2 * %s.x, -1) * %s;", + fnBody->appendf("%s = highfloat2(2 * %s.x, -1) * %s;", fGradXY.gsOut(), fXYD.gsOut(), fCanonicalDerivatives.c_str()); } void GrCCPRQuadraticHullProcessor::emitShaderCoverage(GrGLSLFragmentBuilder* f, const char* outputCoverage) const { - f->codeAppendf("highp float d = (%s.x * %s.x - %s.y) * inversesqrt(dot(%s, %s));", + f->codeAppendf("highfloat 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. @@ -127,7 +127,7 @@ void GrCCPRQuadraticCornerProcessor::emitQuadraticGeometry(GrGLSLGeometryBuilder g->codeAppendf("%s = %s.xy * %s.xz;", fEdgeDistanceDerivatives.c_str(), fEdgeDistanceEquation.c_str(), rtAdjust); - g->codeAppendf("highp float2 corner = bezierpts[sk_InvocationID * 2];"); + g->codeAppendf("highfloat2 corner = bezierpts[sk_InvocationID * 2];"); int numVertices = this->emitCornerGeometry(g, emitVertexFn, "corner"); g->configure(GrGLSLGeometryBuilder::InputType::kTriangles, @@ -135,35 +135,35 @@ void GrCCPRQuadraticCornerProcessor::emitQuadraticGeometry(GrGLSLGeometryBuilder } void GrCCPRQuadraticCornerProcessor::onEmitPerVertexGeometryCode(SkString* fnBody) const { - fnBody->appendf("%s = float3(%s[0].x, %s[0].y, %s.x);", + fnBody->appendf("%s = highfloat3(%s[0].x, %s[0].y, %s.x);", fdXYDdx.gsOut(), fCanonicalDerivatives.c_str(), fCanonicalDerivatives.c_str(), fEdgeDistanceDerivatives.c_str()); - fnBody->appendf("%s = float3(%s[1].x, %s[1].y, %s.y);", + fnBody->appendf("%s = highfloat3(%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("highp float x = %s.x, y = %s.y, d = %s.z;", + f->codeAppendf("highfloat x = %s.x, y = %s.y, d = %s.z;", fXYD.fsIn(), fXYD.fsIn(), fXYD.fsIn()); - f->codeAppendf("highp float2x3 grad_xyd = float2x3(%s, %s);", fdXYDdx.fsIn(), fdXYDdy.fsIn()); + f->codeAppendf("highfloat2x3 grad_xyd = highfloat2x3(%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 ("highp float f = x*x - y;"); - f->codeAppend ("highp float2 grad_f = float2(2*x, -1) * float2x2(grad_xyd);"); + f->codeAppend ("highfloat f = x*x - y;"); + f->codeAppend ("highfloat2 grad_f = highfloat2(2*x, -1) * highfloat2x2(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("highp float3 xyd_center = float3(%s.xy, %s.z + 0.5);", + f->codeAppendf("highfloat3 xyd_center = highfloat3(%s.xy, %s.z + 0.5);", fXYD.fsIn(), fXYD.fsIn()); f->codeAppendf("for (int i = 0; i < %i; ++i) {", sampleCount); - 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;", + 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;", outputCoverage, 1.0 / sampleCount); f->codeAppendf("}"); } diff --git a/src/gpu/ccpr/GrCCPRQuadraticProcessor.h b/src/gpu/ccpr/GrCCPRQuadraticProcessor.h index 85be23e962..80237b62b4 100644 --- a/src/gpu/ccpr/GrCCPRQuadraticProcessor.h +++ b/src/gpu/ccpr/GrCCPRQuadraticProcessor.h @@ -24,13 +24,12 @@ class GrCCPRQuadraticProcessor : public GrCCPRCoverageProcessor::PrimitiveProces public: GrCCPRQuadraticProcessor() : INHERITED(CoverageType::kShader) - , 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) {} + , 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) {} void resetVaryings(GrGLSLVaryingHandler* varyingHandler) override { varyingHandler->addVarying("xyd", &fXYD, kHigh_GrSLPrecision); @@ -67,7 +66,7 @@ protected: class GrCCPRQuadraticHullProcessor : public GrCCPRQuadraticProcessor { public: GrCCPRQuadraticHullProcessor() - : fGradXY(kVec2f_GrSLType) {} + : fGradXY(kHighFloat2_GrSLType) {} void resetVaryings(GrGLSLVaryingHandler* varyingHandler) override { this->INHERITED::resetVaryings(varyingHandler); @@ -91,10 +90,10 @@ private: class GrCCPRQuadraticCornerProcessor : public GrCCPRQuadraticProcessor { public: GrCCPRQuadraticCornerProcessor() - : fEdgeDistanceDerivatives("edge_distance_derivatives", kVec2f_GrSLType, - GrShaderVar::kNonArray, kHigh_GrSLPrecision) - , fdXYDdx(kVec3f_GrSLType) - , fdXYDdy(kVec3f_GrSLType) {} + : fEdgeDistanceDerivatives("edge_distance_derivatives", kHighFloat2_GrSLType, + GrShaderVar::kNonArray) + , fdXYDdx(kHighFloat3_GrSLType) + , fdXYDdy(kHighFloat3_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 bb2ad1b4ba..ee25851497 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 ("highp float2 self = "); + v->codeAppend ("highfloat2 self = "); v->appendTexelFetch(pointsBuffer, SkStringPrintf("%s[sk_VertexID]", proc.instanceAttrib()).c_str()); v->codeAppendf(".xy + %s;", atlasOffset); - gpArgs->fPositionVar.set(kVec2f_GrSLType, "self"); + gpArgs->fPositionVar.set(kHighFloat2_GrSLType, "self"); } void GrCCPRTriangleProcessor::defineInputVertices(GrGLSLGeometryBuilder* g) const { // Prepend in_vertices at the start of the shader. - g->codePrependf("highp float3x2 in_vertices = float3x2(sk_in[0].gl_Position.xy, " + g->codePrependf("highfloat3x2 in_vertices = highfloat3x2(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(float2x2(in_vertices[1] - in_vertices[0], " - "in_vertices[2] - in_vertices[0])));", + g->codeAppendf("%s = sign(determinant(highfloat2x2(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("highp float2 edgept0 = in_vertices[%s > 0 ? edgeidx0 : edgeidx1];", wind); - g->codeAppendf("highp float2 edgept1 = in_vertices[%s > 0 ? edgeidx1 : edgeidx0];", wind); + g->codeAppendf("highfloat2 edgept0 = in_vertices[%s > 0 ? edgeidx0 : edgeidx1];", wind); + g->codeAppendf("highfloat2 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 ("highp float2 next = "); + v->codeAppend ("highfloat2 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 ("highp float2 n = float2(next.y - self.y, self.x - next.x);"); - v->codeAppendf("highp float2 d = n * float2x2(self + %f * sign(n), " + v->codeAppend ("highfloat2 n = highfloat2(next.y - self.y, self.x - next.x);"); + v->codeAppendf("highfloat2 d = n * highfloat2x2(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 ("highp float2 self = in_vertices[sk_InvocationID];"); + g->codeAppend ("highfloat2 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 = float3x3(%s[(sk_InvocationID + 2) %% 3], " + fnBody->appendf("%s = highfloat3x3(%s[(sk_InvocationID + 2) %% 3], " "%s[sk_InvocationID], " "%s[(sk_InvocationID + 1) %% 3]) * %s;", fEdgeDistances.gsOut(), fEdgeDistance.gsIn(), fEdgeDistance.gsIn(), @@ -129,32 +129,28 @@ 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("highp float2 fragcoord = sk_FragCoord.xy;"); + f->codeAppendf("highfloat2 fragcoord = sk_FragCoord.xy;"); // Approximate coverage by tracking where 4 horizontal lines enter and leave the triangle. - GrShaderVar samples("samples", kVec4f_GrSLType, GrShaderVar::kNonArray, - kHigh_GrSLPrecision); + GrShaderVar samples("samples", kHighFloat4_GrSLType, GrShaderVar::kNonArray); f->declareGlobal(samples); - f->codeAppendf("%s = fragcoord.y + float4(-0.375, -0.125, 0.125, 0.375);", samples.c_str()); + f->codeAppendf("%s = fragcoord.y + highfloat4(-0.375, -0.125, 0.125, 0.375);", samples.c_str()); - GrShaderVar leftedge("leftedge", kVec4f_GrSLType, GrShaderVar::kNonArray, - kHigh_GrSLPrecision); + GrShaderVar leftedge("leftedge", kHighFloat4_GrSLType, GrShaderVar::kNonArray); f->declareGlobal(leftedge); - f->codeAppendf("%s = float4(fragcoord.x - 0.5);", leftedge.c_str()); + f->codeAppendf("%s = highfloat4(fragcoord.x - 0.5);", leftedge.c_str()); - GrShaderVar rightedge("rightedge", kVec4f_GrSLType, GrShaderVar::kNonArray, - kHigh_GrSLPrecision); + GrShaderVar rightedge("rightedge", kHighFloat4_GrSLType, GrShaderVar::kNonArray); f->declareGlobal(rightedge); - f->codeAppendf("%s = float4(fragcoord.x + 0.5);", rightedge.c_str()); + f->codeAppendf("%s = highfloat4(fragcoord.x + 0.5);", rightedge.c_str()); SkString sampleEdgeFn; - GrShaderVar edgeArg("edge_distance", kVec3f_GrSLType, GrShaderVar::kNonArray, - kHigh_GrSLPrecision); + GrShaderVar edgeArg("edge_distance", kHighFloat3_GrSLType, GrShaderVar::kNonArray); f->emitFunction(kVoid_GrSLType, "sampleEdge", 1, &edgeArg, [&]() { SkString b; - b.appendf("highp float m = abs(%s.x) < 1e-3 ? 1e18 : -1 / %s.x;", + b.appendf("highfloat m = abs(%s.x) < 1e-3 ? 1e18 : -1 / %s.x;", edgeArg.c_str(), edgeArg.c_str()); - b.appendf("highp float4 edge = m * (%s.y * samples + %s.z);", + b.appendf("highfloat4 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()); @@ -166,10 +162,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), float2(%f)))) {", + f->codeAppendf("if (all(lessThan(abs(fragcoord - %s.zw), highfloat2(%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), float2(%f)))) {", + f->codeAppendf( "if (%s != 0 || !all(lessThan(abs(fragcoord - %s.xy), highfloat2(%f)))) {", fCornerIdx.fsIn(), fNeighbors.fsIn(), kAABloatRadius); f->codeAppend ( "discard;"); f->codeAppend ( "}"); @@ -177,7 +173,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(float3(fragcoord, 1) * float2x3(%s), float2(1));", + f->codeAppendf("%s = dot(highfloat3(fragcoord, 1) * highfloat2x3(%s), highfloat2(1));", outputCoverage, fEdgeDistances.fsIn()); // Sample the two edges at this corner. @@ -185,15 +181,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), float2(%f)))) {", + f->codeAppendf("if (all(lessThan(abs(fragcoord - %s.xy), highfloat2(%f)))) {", fNeighbors.fsIn(), kAABloatRadius); // Erase the coverage the opposite edge wrote to this corner. - f->codeAppendf( "%s += dot(%s[2], float3(fragcoord, 1)) + 0.5;", + f->codeAppendf( "%s += dot(%s[2], highfloat3(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("highp float4 widths = max(%s - %s, 0);", rightedge.c_str(), leftedge.c_str()); - f->codeAppendf("%s += dot(widths, float4(0.25));", outputCoverage); + f->codeAppendf("highfloat4 widths = max(%s - %s, 0);", rightedge.c_str(), leftedge.c_str()); + f->codeAppendf("%s += dot(widths, highfloat4(0.25));", outputCoverage); } diff --git a/src/gpu/ccpr/GrCCPRTriangleProcessor.h b/src/gpu/ccpr/GrCCPRTriangleProcessor.h index 1e52d51a45..9ac76521bf 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(kVec3f_GrSLType) - , fDevCoord(kVec2f_GrSLType) - , fNeighbors(kVec4f_GrSLType) - , fEdgeDistances(kMat33f_GrSLType) - , fCornerIdx(kInt_GrSLType) {} + , fEdgeDistance(kHighFloat3_GrSLType) + , fDevCoord(kHighFloat2_GrSLType) + , fNeighbors(kHighFloat4_GrSLType) + , fEdgeDistances(kHighFloat3x3_GrSLType) + , fCornerIdx(kShort_GrSLType) {} void resetVaryings(GrGLSLVaryingHandler* varyingHandler) override { this->INHERITED::resetVaryings(varyingHandler); |