From 19c1233c447f625c2522e7ecd0a0adecc629bb2f Mon Sep 17 00:00:00 2001 From: Brian Salomon Date: Mon, 18 Jun 2018 12:52:47 -0400 Subject: Change how vertex/instance attributes are handled in geometry processors. * No longer register vertex/instance attributes on base class, just counts * Separate instance and vertex attributes and remove InputRate and offset * Make attributes constexpr where possible Change-Id: I1f1d5e772fa177a96d2aeb805aab7b69f35bfae6 Reviewed-on: https://skia-review.googlesource.com/132405 Commit-Queue: Brian Salomon Reviewed-by: Chris Dalton --- src/gpu/ccpr/GrCCCoverageProcessor_VSImpl.cpp | 68 +++++++++++++-------------- 1 file changed, 32 insertions(+), 36 deletions(-) (limited to 'src/gpu/ccpr/GrCCCoverageProcessor_VSImpl.cpp') diff --git a/src/gpu/ccpr/GrCCCoverageProcessor_VSImpl.cpp b/src/gpu/ccpr/GrCCCoverageProcessor_VSImpl.cpp index 3c9fe89fbc..5c5120cf45 100644 --- a/src/gpu/ccpr/GrCCCoverageProcessor_VSImpl.cpp +++ b/src/gpu/ccpr/GrCCCoverageProcessor_VSImpl.cpp @@ -28,9 +28,8 @@ private: const int fNumSides; }; -static constexpr int kAttribIdx_X = 0; // Transposed X values of all input points. -static constexpr int kAttribIdx_Y = 1; // Transposed Y values of all input points. -static constexpr int kAttribIdx_VertexData = 2; +static constexpr int kInstanceAttribIdx_X = 0; // Transposed X values of all input points. +static constexpr int kInstanceAttribIdx_Y = 1; // Transposed Y values of all input points. // Vertex data tells the shader how to offset vertices for conservative raster, as well as how to // calculate coverage values for corners and edges. @@ -260,15 +259,16 @@ void GrCCCoverageProcessor::VSImpl::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) int inputWidth = (4 == numInputPoints || proc.hasInputWeight()) ? 4 : 3; const char* swizzle = (4 == inputWidth) ? "xyzw" : "xyz"; v->codeAppendf("float%ix2 pts = transpose(float2x%i(%s.%s, %s.%s));", inputWidth, inputWidth, - proc.getAttrib(kAttribIdx_X).name(), swizzle, - proc.getAttrib(kAttribIdx_Y).name(), swizzle); + proc.fInstanceAttributes[kInstanceAttribIdx_X].name(), swizzle, + proc.fInstanceAttributes[kInstanceAttribIdx_Y].name(), swizzle); v->codeAppend ("half wind;"); Shader::CalcWind(proc, v, "pts", "wind"); if (PrimitiveType::kWeightedTriangles == proc.fPrimitiveType) { SkASSERT(3 == numInputPoints); - SkASSERT(kFloat4_GrVertexAttribType == proc.getAttrib(kAttribIdx_X).type()); - v->codeAppendf("wind *= %s.w;", proc.getAttrib(kAttribIdx_X).name()); + SkASSERT(kFloat4_GrVertexAttribType == + proc.fInstanceAttributes[kInstanceAttribIdx_X].type()); + v->codeAppendf("wind *= %s.w;", proc.fInstanceAttributes[kInstanceAttribIdx_X].name()); } float bloat = kAABloatRadius; @@ -284,12 +284,12 @@ void GrCCCoverageProcessor::VSImpl::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) // Reverse all indices if the wind is counter-clockwise: [0, 1, 2] -> [2, 1, 0]. v->codeAppendf("int clockwise_indices = wind > 0 ? %s : 0x%x - %s;", - proc.getAttrib(kAttribIdx_VertexData).name(), + proc.fVertexAttribute.name(), ((fNumSides - 1) << kVertexData_LeftNeighborIdShift) | ((fNumSides - 1) << kVertexData_RightNeighborIdShift) | (((1 << kVertexData_RightNeighborIdShift) - 1) ^ 3) | (fNumSides - 1), - proc.getAttrib(kAttribIdx_VertexData).name()); + proc.fVertexAttribute.name()); // Here we generate conservative raster geometry for the input polygon. It is the convex // hull of N pixel-size boxes, one centered on each the input points. Each corner has three @@ -322,7 +322,7 @@ void GrCCCoverageProcessor::VSImpl::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) v->codeAppend ("rightdir = (float2(0) != rightdir) ? normalize(rightdir) : float2(1, 0);"); v->codeAppendf("if (0 != (%s & %i)) {", // Are we a corner? - proc.getAttrib(kAttribIdx_VertexData).name(), kVertexData_IsCornerBit); + proc.fVertexAttribute.name(), kVertexData_IsCornerBit); // In corner boxes, all 4 coverage values will not map linearly. // Therefore it is important to align the box so its diagonal shared @@ -341,7 +341,7 @@ void GrCCCoverageProcessor::VSImpl::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) // continue rotating 90 degrees clockwise until we reach the desired raster vertex for this // invocation. Corners with less than 3 corresponding raster vertices will result in // redundant vertices and degenerate triangles. - v->codeAppendf("int bloatidx = (%s >> %i) & 3;", proc.getAttrib(kAttribIdx_VertexData).name(), + v->codeAppendf("int bloatidx = (%s >> %i) & 3;", proc.fVertexAttribute.name(), kVertexData_BloatIdxShift); v->codeAppend ("switch (bloatidx) {"); v->codeAppend ( "case 3:"); @@ -376,12 +376,12 @@ void GrCCCoverageProcessor::VSImpl::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) v->codeAppend ("}"); v->codeAppendf("if (0 != (%s & %i)) {", // Are we an edge? - proc.getAttrib(kAttribIdx_VertexData).name(), kVertexData_IsEdgeBit); + proc.fVertexAttribute.name(), kVertexData_IsEdgeBit); v->codeAppend ( "coverage = left_coverage;"); v->codeAppend ("}"); v->codeAppendf("if (0 != (%s & %i)) {", // Invert coverage? - proc.getAttrib(kAttribIdx_VertexData).name(), + proc.fVertexAttribute.name(), kVertexData_InvertNegativeCoverageBit); v->codeAppend ( "coverage = -1 - coverage;"); v->codeAppend ("}"); @@ -391,7 +391,7 @@ void GrCCCoverageProcessor::VSImpl::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) v->codeAppend ("half2 corner_coverage = half2(0);"); v->codeAppendf("if (0 != (%s & %i)) {", // Are we a corner? - proc.getAttrib(kAttribIdx_VertexData).name(), kVertexData_IsCornerBit); + proc.fVertexAttribute.name(), kVertexData_IsCornerBit); // We use coverage=-1 to erase what the hull geometry wrote. // // In the context of curves, this effectively means "wind = -wind" and @@ -495,31 +495,27 @@ void GrCCCoverageProcessor::initVS(GrResourceProvider* rp) { } } + GrVertexAttribType xyAttribType; if (4 == this->numInputPoints() || this->hasInputWeight()) { - SkASSERT(kAttribIdx_X == this->numAttribs()); - this->addInstanceAttrib("X", kFloat4_GrVertexAttribType); - - SkASSERT(kAttribIdx_Y == this->numAttribs()); - this->addInstanceAttrib("Y", kFloat4_GrVertexAttribType); - - SkASSERT(offsetof(QuadPointInstance, fX) == this->getAttrib(kAttribIdx_X).offsetInRecord()); - SkASSERT(offsetof(QuadPointInstance, fY) == this->getAttrib(kAttribIdx_Y).offsetInRecord()); - SkASSERT(sizeof(QuadPointInstance) == this->getInstanceStride()); + GR_STATIC_ASSERT(offsetof(QuadPointInstance, fX) == 0); + GR_STATIC_ASSERT(sizeof(QuadPointInstance::fX) == + GrVertexAttribTypeSize(kFloat4_GrVertexAttribType)); + GR_STATIC_ASSERT(sizeof(QuadPointInstance::fY) == + GrVertexAttribTypeSize(kFloat4_GrVertexAttribType)); + xyAttribType = kFloat4_GrVertexAttribType; } else { - SkASSERT(kAttribIdx_X == this->numAttribs()); - this->addInstanceAttrib("X", kFloat3_GrVertexAttribType); - - SkASSERT(kAttribIdx_Y == this->numAttribs()); - this->addInstanceAttrib("Y", kFloat3_GrVertexAttribType); - - SkASSERT(offsetof(TriPointInstance, fX) == this->getAttrib(kAttribIdx_X).offsetInRecord()); - SkASSERT(offsetof(TriPointInstance, fY) == this->getAttrib(kAttribIdx_Y).offsetInRecord()); - SkASSERT(sizeof(TriPointInstance) == this->getInstanceStride()); + GR_STATIC_ASSERT(offsetof(TriPointInstance, fX) == 0); + GR_STATIC_ASSERT(sizeof(TriPointInstance::fX) == + GrVertexAttribTypeSize(kFloat3_GrVertexAttribType)); + GR_STATIC_ASSERT(sizeof(TriPointInstance::fY) == + GrVertexAttribTypeSize(kFloat3_GrVertexAttribType)); + xyAttribType = kFloat3_GrVertexAttribType; } - - SkASSERT(kAttribIdx_VertexData == this->numAttribs()); - this->addVertexAttrib("vertexdata", kInt_GrVertexAttribType); - SkASSERT(sizeof(int32_t) == this->getVertexStride()); + fInstanceAttributes[kInstanceAttribIdx_X] = {"X", xyAttribType}; + fInstanceAttributes[kInstanceAttribIdx_Y] = {"Y", xyAttribType}; + this->setInstanceAttributeCnt(2); + fVertexAttribute = {"vertexdata", kInt_GrVertexAttribType}; + this->setVertexAttributeCnt(1); if (caps.usePrimitiveRestart()) { fVSTriangleType = GrPrimitiveType::kTriangleStrip; -- cgit v1.2.3