Change how GPs configure attributes
Adds setVertexAttributes and setInstanceAttributes. These take a pointer
to the first attribute, and a count. The count is the total number of
possible attributes, though some may not be initialized. The base class
computes the number of initialized attributes, pre-computes the strides,
and only allows subsequent access to the initialized attributes.
The attributes need to be allocated contiguously. Some GPs place them in
an array, though most just place them as consecutive members, and pass
a pointer to the first one.
Indexed access would be possible, but now it makes more sense to iterate
over all attributes, so enable that, and use range-based for everywhere.
Completely remove the per-attribute offset helper (again - possible, but
not real helpful), and make the stride always available. In many ops,
just use the GP's computed stride, rather than re-computing it.
Bug: skia:
Change-Id: Ie4cccb7969a98ee5a10b373e714fbd702e875b3e
Reviewed-on: https://skia-review.googlesource.com/c/169241
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
diff --git a/src/gpu/ops/GrAAConvexPathRenderer.cpp b/src/gpu/ops/GrAAConvexPathRenderer.cpp
index fc1dfeb..1f2b703 100644
--- a/src/gpu/ops/GrAAConvexPathRenderer.cpp
+++ b/src/gpu/ops/GrAAConvexPathRenderer.cpp
@@ -577,21 +577,21 @@
GrGLSLVarying v(kHalf4_GrSLType);
varyingHandler->addVarying("QuadEdge", &v);
- vertBuilder->codeAppendf("%s = %s;", v.vsOut(), qe.kInQuadEdge.name());
+ vertBuilder->codeAppendf("%s = %s;", v.vsOut(), qe.fInQuadEdge.name());
// Setup pass through color
- varyingHandler->addPassThroughAttribute(qe.kInColor, args.fOutputColor);
+ varyingHandler->addPassThroughAttribute(qe.fInColor, args.fOutputColor);
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
// Setup position
- this->writeOutputPosition(vertBuilder, gpArgs, qe.kInPosition.name());
+ this->writeOutputPosition(vertBuilder, gpArgs, qe.fInPosition.name());
// emit transforms
this->emitTransforms(vertBuilder,
varyingHandler,
uniformHandler,
- qe.kInPosition.asShaderVar(),
+ qe.fInPosition.asShaderVar(),
qe.fLocalMatrix,
args.fFPCoordTransformHandler);
@@ -647,18 +647,16 @@
: INHERITED(kQuadEdgeEffect_ClassID)
, fLocalMatrix(localMatrix)
, fUsesLocalCoords(usesLocalCoords) {
- this->setVertexAttributeCnt(3);
+ fInPosition = {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
+ fInColor = {"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
+ fInQuadEdge = {"inQuadEdge", kFloat4_GrVertexAttribType, kHalf4_GrSLType};
+ this->setVertexAttributes(&fInPosition, 3);
}
- const Attribute& onVertexAttribute(int i) const override {
- return IthAttribute(i, kInPosition, kInColor, kInQuadEdge);
- }
- static constexpr Attribute kInPosition =
- {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
- static constexpr Attribute kInColor =
- {"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
- static constexpr Attribute kInQuadEdge =
- {"inQuadEdge", kFloat4_GrVertexAttribType, kHalf4_GrSLType};
+ Attribute fInPosition;
+ Attribute fInColor;
+ Attribute fInQuadEdge;
+
SkMatrix fLocalMatrix;
bool fUsesLocalCoords;
@@ -666,9 +664,6 @@
typedef GrGeometryProcessor INHERITED;
};
-constexpr GrPrimitiveProcessor::Attribute QuadEdgeEffect::kInPosition;
-constexpr GrPrimitiveProcessor::Attribute QuadEdgeEffect::kInColor;
-constexpr GrPrimitiveProcessor::Attribute QuadEdgeEffect::kInQuadEdge;
GR_DEFINE_GEOMETRY_PROCESSOR_TEST(QuadEdgeEffect);
@@ -799,11 +794,7 @@
return;
}
- size_t vertexStride = fHelper.compatibleWithAlphaAsCoverage()
- ? sizeof(GrDefaultGeoProcFactory::PositionColorAttr)
- : sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAttr);
- SkASSERT(vertexStride == gp->debugOnly_vertexStride());
-
+ size_t vertexStride = gp->vertexStride();
GrAAConvexTessellator tess;
int instanceCount = fPaths.count();
@@ -904,7 +895,7 @@
const GrBuffer* vertexBuffer;
int firstVertex;
- SkASSERT(sizeof(QuadVertex) == quadProcessor->debugOnly_vertexStride());
+ SkASSERT(sizeof(QuadVertex) == quadProcessor->vertexStride());
QuadVertex* verts = reinterpret_cast<QuadVertex*>(target->makeVertexSpace(
sizeof(QuadVertex), vertexCount, &vertexBuffer, &firstVertex));