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/bench/VertexColorSpaceBench.cpp b/bench/VertexColorSpaceBench.cpp
index ce826e1..b8f5472 100644
--- a/bench/VertexColorSpaceBench.cpp
+++ b/bench/VertexColorSpaceBench.cpp
@@ -52,7 +52,7 @@
fInColor = {"inColor", kHalf4_GrVertexAttribType, kHalf4_GrSLType};
break;
}
- this->setVertexAttributeCnt(2);
+ this->setVertexAttributes(&fInPosition, 2);
}
const char* name() const override { return "VertexColorXformGP"; }
@@ -109,10 +109,6 @@
}
private:
- const GrPrimitiveProcessor::Attribute& onVertexAttribute(int i) const override {
- return IthAttribute(i, fInPosition, fInColor);
- }
-
Mode fMode;
sk_sp<GrColorSpaceXform> fColorSpaceXform;
@@ -165,19 +161,7 @@
void onPrepareDraws(Target* target) override {
sk_sp<GrGeometryProcessor> gp(new GP(fMode, fColorSpaceXform));
- size_t vertexStride = sizeof(SkPoint);
- switch (fMode) {
- case kFloat_Mode:
- vertexStride += sizeof(SkColor4f);
- break;
- case kHalf_Mode:
- vertexStride += sizeof(uint64_t);
- break;
- default:
- vertexStride += sizeof(uint32_t);
- }
- SkASSERT(vertexStride == gp->debugOnly_vertexStride());
-
+ size_t vertexStride = gp->vertexStride();
const int kVertexCount = 1024;
const GrBuffer* vertexBuffer = nullptr;
int firstVertex = 0;
diff --git a/gm/beziereffects.cpp b/gm/beziereffects.cpp
index 9ef2860..41c24c3 100644
--- a/gm/beziereffects.cpp
+++ b/gm/beziereffects.cpp
@@ -100,7 +100,7 @@
};
void onPrepareDraws(Target* target) override {
- SkASSERT(this->gp()->debugOnly_vertexStride() == sizeof(Vertex));
+ SkASSERT(this->gp()->vertexStride() == sizeof(Vertex));
QuadHelper helper(target, sizeof(Vertex), 1);
Vertex* verts = reinterpret_cast<Vertex*>(helper.vertices());
if (!verts) {
@@ -322,7 +322,7 @@
};
void onPrepareDraws(Target* target) override {
- SkASSERT(this->gp()->debugOnly_vertexStride() == sizeof(Vertex));
+ SkASSERT(this->gp()->vertexStride() == sizeof(Vertex));
QuadHelper helper(target, sizeof(Vertex), 1);
Vertex* verts = reinterpret_cast<Vertex*>(helper.vertices());
if (!verts) {
diff --git a/gm/clockwise.cpp b/gm/clockwise.cpp
index 09ebb97..40b2abc 100644
--- a/gm/clockwise.cpp
+++ b/gm/clockwise.cpp
@@ -45,7 +45,7 @@
ClockwiseTestProcessor(bool readSkFragCoord)
: GrGeometryProcessor(kClockwiseTestProcessor_ClassID)
, fReadSkFragCoord(readSkFragCoord) {
- this->setVertexAttributeCnt(1);
+ this->setVertexAttributes(&gVertex, 1);
}
const char* name() const override { return "ClockwiseTestProcessor"; }
void getGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder* b) const final {
@@ -54,8 +54,6 @@
GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const final;
private:
- const Attribute& onVertexAttribute(int i) const override { return gVertex; }
-
const bool fReadSkFragCoord;
friend class GLSLClockwiseTestProcessor;
diff --git a/gm/convexpolyeffect.cpp b/gm/convexpolyeffect.cpp
index 5e7f993..22aa69d 100644
--- a/gm/convexpolyeffect.cpp
+++ b/gm/convexpolyeffect.cpp
@@ -85,7 +85,7 @@
LocalCoords::kUnused_Type,
SkMatrix::I()));
- SkASSERT(gp->debugOnly_vertexStride() == sizeof(SkPoint));
+ SkASSERT(gp->vertexStride() == sizeof(SkPoint));
QuadHelper helper(target, sizeof(SkPoint), 1);
SkPoint* verts = reinterpret_cast<SkPoint*>(helper.vertices());
if (!verts) {
diff --git a/src/gpu/GrDefaultGeoProcFactory.cpp b/src/gpu/GrDefaultGeoProcFactory.cpp
index 904021c..623bf81 100644
--- a/src/gpu/GrDefaultGeoProcFactory.cpp
+++ b/src/gpu/GrDefaultGeoProcFactory.cpp
@@ -322,19 +322,15 @@
, fBones(bones)
, fBoneCount(boneCount) {
fInPosition = {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
- int cnt = 1;
if (fFlags & kColorAttribute_GPFlag) {
fInColor = {"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
- ++cnt;
}
if (fFlags & kLocalCoordAttribute_GPFlag) {
fInLocalCoords = {"inLocalCoord", kFloat2_GrVertexAttribType,
kFloat2_GrSLType};
- ++cnt;
}
if (fFlags & kCoverageAttribute_GPFlag) {
fInCoverage = {"inCoverage", kFloat_GrVertexAttribType, kHalf_GrSLType};
- ++cnt;
}
if (fFlags & kBonesAttribute_GPFlag) {
SkASSERT(bones && (boneCount > 0));
@@ -346,22 +342,10 @@
indicesGPUType = kHalf4_GrSLType;
}
fInBoneIndices = {"inBoneIndices", indicesCPUType, indicesGPUType};
- ++cnt;
fInBoneWeights = {"inBoneWeights", kUByte4_norm_GrVertexAttribType,
kHalf4_GrSLType};
- ++cnt;
}
- this->setVertexAttributeCnt(cnt);
- }
-
- const Attribute& onVertexAttribute(int i) const override {
- return IthInitializedAttribute(i,
- fInPosition,
- fInColor,
- fInLocalCoords,
- fInCoverage,
- fInBoneIndices,
- fInBoneWeights);
+ this->setVertexAttributes(&fInPosition, 6);
}
Attribute fInPosition;
diff --git a/src/gpu/GrGeometryProcessor.h b/src/gpu/GrGeometryProcessor.h
index 5306a0f..a12ab00 100644
--- a/src/gpu/GrGeometryProcessor.h
+++ b/src/gpu/GrGeometryProcessor.h
@@ -39,36 +39,6 @@
fSampleShading = sampleShading;
}
- /**
- * Recursive helpers for implementing onVertexAttribute or onInstanceAttribute.
- */
-
- template <typename... Args>
- static const Attribute& IthAttribute(int i, const Attribute& attr0, const Args&... attrs) {
- SkASSERT(attr0.isInitialized());
- return (0 == i) ? attr0 : IthAttribute(i - 1, attrs...);
- }
-
- static const Attribute& IthAttribute(int i) {
- SK_ABORT("Illegal attribute Index");
- static constexpr Attribute kBogus;
- return kBogus;
- }
-
- template <typename... Args>
- static const Attribute& IthInitializedAttribute(int i, const Attribute& attr0,
- const Args&... attrs) {
- if (attr0.isInitialized()) {
- if (0 == i) {
- return attr0;
- }
- i -= 1;
- }
- return IthInitializedAttribute(i, attrs...);
- }
-
- static const Attribute& IthInitializedAttribute(int i) { return IthAttribute(i); }
-
private:
bool fWillUseGeoShader;
float fSampleShading;
diff --git a/src/gpu/GrPathProcessor.h b/src/gpu/GrPathProcessor.h
index 9bcddc5..accdb7d 100644
--- a/src/gpu/GrPathProcessor.h
+++ b/src/gpu/GrPathProcessor.h
@@ -38,18 +38,6 @@
virtual bool isPathRendering() const override { return true; }
private:
- const Attribute& onVertexAttribute(int i) const final {
- SK_ABORT("No vertex attributes");
- static constexpr Attribute kBogus;
- return kBogus;
- }
-
- const Attribute& onInstanceAttribute(int i) const final {
- SK_ABORT("No instanced attributes");
- static constexpr Attribute kBogus;
- return kBogus;
- }
-
GrPathProcessor(const SkPMColor4f&, const SkMatrix& viewMatrix, const SkMatrix& localMatrix);
SkPMColor4f fColor;
diff --git a/src/gpu/GrPrimitiveProcessor.cpp b/src/gpu/GrPrimitiveProcessor.cpp
index 9e0e161..b84af68 100644
--- a/src/gpu/GrPrimitiveProcessor.cpp
+++ b/src/gpu/GrPrimitiveProcessor.cpp
@@ -24,56 +24,6 @@
return this->onTextureSampler(i);
}
-const GrPrimitiveProcessor::Attribute& GrPrimitiveProcessor::vertexAttribute(int i) const {
- SkASSERT(i >= 0 && i < this->numVertexAttributes());
- const auto& result = this->onVertexAttribute(i);
- SkASSERT(result.isInitialized());
- return result;
-}
-
-const GrPrimitiveProcessor::Attribute& GrPrimitiveProcessor::instanceAttribute(int i) const {
- SkASSERT(i >= 0 && i < this->numInstanceAttributes());
- const auto& result = this->onInstanceAttribute(i);
- SkASSERT(result.isInitialized());
- return result;
-}
-
-#ifdef SK_DEBUG
-size_t GrPrimitiveProcessor::debugOnly_vertexStride() const {
- size_t stride = 0;
- for (int i = 0; i < fVertexAttributeCnt; ++i) {
- stride += this->vertexAttribute(i).sizeAlign4();
- }
- return stride;
-}
-
-size_t GrPrimitiveProcessor::debugOnly_instanceStride() const {
- size_t stride = 0;
- for (int i = 0; i < fInstanceAttributeCnt; ++i) {
- stride += this->instanceAttribute(i).sizeAlign4();
- }
- return stride;
-}
-
-size_t GrPrimitiveProcessor::debugOnly_vertexAttributeOffset(int i) const {
- SkASSERT(i >= 0 && i < fVertexAttributeCnt);
- size_t offset = 0;
- for (int j = 0; j < i; ++j) {
- offset += this->vertexAttribute(j).sizeAlign4();
- }
- return offset;
-}
-
-size_t GrPrimitiveProcessor::debugOnly_instanceAttributeOffset(int i) const {
- SkASSERT(i >= 0 && i < fInstanceAttributeCnt);
- size_t offset = 0;
- for (int j = 0; j < i; ++j) {
- offset += this->instanceAttribute(j).sizeAlign4();
- }
- return offset;
-}
-#endif
-
uint32_t
GrPrimitiveProcessor::getTransformKey(const SkTArray<const GrCoordTransform*, true>& coords,
int numCoords) const {
diff --git a/src/gpu/GrPrimitiveProcessor.h b/src/gpu/GrPrimitiveProcessor.h
index 2ae28dd..ffb7ac0 100644
--- a/src/gpu/GrPrimitiveProcessor.h
+++ b/src/gpu/GrPrimitiveProcessor.h
@@ -80,34 +80,88 @@
GrSLType fGPUType = kFloat_GrSLType;
};
+ class Iter {
+ public:
+ Iter() : fCurr(nullptr), fRemaining(0) {}
+ Iter(const Iter& iter) : fCurr(iter.fCurr), fRemaining(iter.fRemaining) {}
+ Iter& operator= (const Iter& iter) {
+ fCurr = iter.fCurr;
+ fRemaining = iter.fRemaining;
+ return *this;
+ }
+ Iter(const Attribute* attrs, int count) : fCurr(attrs), fRemaining(count) {
+ this->skipUninitialized();
+ }
+
+ bool operator!=(const Iter& that) const { return fCurr != that.fCurr; }
+ const Attribute& operator*() const { return *fCurr; }
+ void operator++() {
+ if (fRemaining) {
+ fRemaining--;
+ fCurr++;
+ this->skipUninitialized();
+ }
+ }
+
+ private:
+ void skipUninitialized() {
+ if (!fRemaining) {
+ fCurr = nullptr;
+ } else {
+ while (!fCurr->isInitialized()) {
+ ++fCurr;
+ }
+ }
+ }
+
+ const Attribute* fCurr;
+ int fRemaining;
+ };
+
+ class AttributeSet {
+ public:
+ Iter begin() const { return Iter(fAttributes, fCount); }
+ Iter end() const { return Iter(); }
+
+ private:
+ friend class GrPrimitiveProcessor;
+
+ void init(const Attribute* attrs, int count) {
+ fAttributes = attrs;
+ fCount = 0;
+ fStride = 0;
+ for (int i = 0; i < count; ++i) {
+ if (attrs[i].isInitialized()) {
+ fCount++;
+ fStride += attrs[i].sizeAlign4();
+ }
+ }
+ }
+
+ const Attribute* fAttributes = nullptr;
+ int fCount = 0;
+ size_t fStride = 0;
+ };
+
GrPrimitiveProcessor(ClassID);
int numTextureSamplers() const { return fTextureSamplerCnt; }
const TextureSampler& textureSampler(int index) const;
- int numVertexAttributes() const { return fVertexAttributeCnt; }
- const Attribute& vertexAttribute(int i) const;
- int numInstanceAttributes() const { return fInstanceAttributeCnt; }
- const Attribute& instanceAttribute(int i) const;
+ int numVertexAttributes() const { return fVertexAttributes.fCount; }
+ const AttributeSet& vertexAttributes() const { return fVertexAttributes; }
+ int numInstanceAttributes() const { return fInstanceAttributes.fCount; }
+ const AttributeSet& instanceAttributes() const { return fInstanceAttributes; }
- bool hasVertexAttributes() const { return SkToBool(fVertexAttributeCnt); }
- bool hasInstanceAttributes() const { return SkToBool(fInstanceAttributeCnt); }
+ bool hasVertexAttributes() const { return SkToBool(fVertexAttributes.fCount); }
+ bool hasInstanceAttributes() const { return SkToBool(fInstanceAttributes.fCount); }
-#ifdef SK_DEBUG
/**
* A common practice is to populate the the vertex/instance's memory using an implicit array of
* structs. In this case, it is best to assert that:
- * debugOnly_stride == sizeof(struct) and
- * offsetof(struct, field[i]) == debugOnly_AttributeOffset(i)
- * In general having Op subclasses assert that attribute offsets and strides agree with their
- * tessellation code's expectations is good practice.
- * However, these functions walk the attributes to compute offsets and call virtual functions
- * to access the attributes. Thus, they are only available in debug builds.
+ * stride == sizeof(struct)
*/
- size_t debugOnly_vertexStride() const;
- size_t debugOnly_instanceStride() const;
- size_t debugOnly_vertexAttributeOffset(int) const;
- size_t debugOnly_instanceAttributeOffset(int) const;
-#endif
+ size_t vertexStride() const { return fVertexAttributes.fStride; }
+ size_t instanceStride() const { return fInstanceAttributes.fStride; }
// Only the GrGeometryProcessor subclass actually has a geo shader or vertex attributes, but
// we put these calls on the base class to prevent having to cast
@@ -146,13 +200,12 @@
virtual float getSampleShading() const { return 0.0; }
protected:
- void setVertexAttributeCnt(int cnt) {
- SkASSERT(cnt >= 0);
- fVertexAttributeCnt = cnt;
+ void setVertexAttributes(const Attribute* attrs, int attrCount) {
+ fVertexAttributes.init(attrs, attrCount);
}
- void setInstanceAttributeCnt(int cnt) {
- SkASSERT(cnt >= 0);
- fInstanceAttributeCnt = cnt;
+ void setInstanceAttributes(const Attribute* attrs, int attrCount) {
+ SkASSERT(attrCount >= 0);
+ fInstanceAttributes.init(attrs, attrCount);
}
void setTextureSamplerCnt(int cnt) {
SkASSERT(cnt >= 0);
@@ -171,22 +224,11 @@
inline static const TextureSampler& IthTextureSampler(int i);
private:
- virtual const Attribute& onVertexAttribute(int) const {
- SK_ABORT("No vertex attributes");
- static constexpr Attribute kBogus;
- return kBogus;
- }
-
- virtual const Attribute& onInstanceAttribute(int i) const {
- SK_ABORT("No instanced attributes");
- static constexpr Attribute kBogus;
- return kBogus;
- }
-
virtual const TextureSampler& onTextureSampler(int) const { return IthTextureSampler(0); }
- int fVertexAttributeCnt = 0;
- int fInstanceAttributeCnt = 0;
+ AttributeSet fVertexAttributes;
+ AttributeSet fInstanceAttributes;
+
int fTextureSamplerCnt = 0;
typedef GrProcessor INHERITED;
};
diff --git a/src/gpu/ccpr/GrCCCoverageProcessor.h b/src/gpu/ccpr/GrCCCoverageProcessor.h
index 42effdd..7650a8c 100644
--- a/src/gpu/ccpr/GrCCCoverageProcessor.h
+++ b/src/gpu/ccpr/GrCCCoverageProcessor.h
@@ -250,13 +250,6 @@
void initGS();
void initVS(GrResourceProvider*);
- const Attribute& onVertexAttribute(int i) const override { return fVertexAttribute; }
-
- const Attribute& onInstanceAttribute(int i) const override {
- SkASSERT(fImpl == Impl::kVertexShader);
- return fInstanceAttributes[i];
- }
-
void appendGSMesh(GrBuffer* instanceBuffer, int instanceCount, int baseInstance,
SkTArray<GrMesh>* out) const;
void appendVSMesh(GrBuffer* instanceBuffer, int instanceCount, int baseInstance,
diff --git a/src/gpu/ccpr/GrCCCoverageProcessor_GSImpl.cpp b/src/gpu/ccpr/GrCCCoverageProcessor_GSImpl.cpp
index 8c2f507..e9dd398 100644
--- a/src/gpu/ccpr/GrCCCoverageProcessor_GSImpl.cpp
+++ b/src/gpu/ccpr/GrCCCoverageProcessor_GSImpl.cpp
@@ -395,7 +395,7 @@
GR_STATIC_ASSERT(offsetof(TriPointInstance, fY) ==
GrVertexAttribTypeSize(kFloat3_GrVertexAttribType));
}
- this->setVertexAttributeCnt(1);
+ this->setVertexAttributes(&fVertexAttribute, 1);
this->setWillUseGeoShader();
}
diff --git a/src/gpu/ccpr/GrCCCoverageProcessor_VSImpl.cpp b/src/gpu/ccpr/GrCCCoverageProcessor_VSImpl.cpp
index a6a05a7..7ec5aea 100644
--- a/src/gpu/ccpr/GrCCCoverageProcessor_VSImpl.cpp
+++ b/src/gpu/ccpr/GrCCCoverageProcessor_VSImpl.cpp
@@ -516,9 +516,9 @@
}
fInstanceAttributes[kInstanceAttribIdx_X] = {"X", xyAttribType, xySLType};
fInstanceAttributes[kInstanceAttribIdx_Y] = {"Y", xyAttribType, xySLType};
- this->setInstanceAttributeCnt(2);
+ this->setInstanceAttributes(fInstanceAttributes, 2);
fVertexAttribute = {"vertexdata", kInt_GrVertexAttribType, kInt_GrSLType};
- this->setVertexAttributeCnt(1);
+ this->setVertexAttributes(&fVertexAttribute, 1);
if (caps.usePrimitiveRestart()) {
fVSTriangleType = GrPrimitiveType::kTriangleStrip;
diff --git a/src/gpu/ccpr/GrCCPathProcessor.cpp b/src/gpu/ccpr/GrCCPathProcessor.cpp
index a2e0b2a..8ea06bd 100644
--- a/src/gpu/ccpr/GrCCPathProcessor.cpp
+++ b/src/gpu/ccpr/GrCCPathProcessor.cpp
@@ -83,19 +83,10 @@
, fAtlasSize(atlas->isize())
, fAtlasOrigin(atlas->origin()) {
// TODO: Can we just assert that atlas has GrCCAtlas::kTextureOrigin and remove fAtlasOrigin?
- this->setInstanceAttributeCnt(kNumInstanceAttribs);
- // Check that instance attributes exactly match Instance struct layout.
- SkASSERT(!strcmp(this->instanceAttribute(0).name(), "devbounds"));
- SkASSERT(!strcmp(this->instanceAttribute(1).name(), "devbounds45"));
- SkASSERT(!strcmp(this->instanceAttribute(2).name(), "dev_to_atlas_offset"));
- SkASSERT(!strcmp(this->instanceAttribute(3).name(), "color"));
- SkASSERT(this->debugOnly_instanceAttributeOffset(0) == offsetof(Instance, fDevBounds));
- SkASSERT(this->debugOnly_instanceAttributeOffset(1) == offsetof(Instance, fDevBounds45));
- SkASSERT(this->debugOnly_instanceAttributeOffset(2) == offsetof(Instance, fDevToAtlasOffset));
- SkASSERT(this->debugOnly_instanceAttributeOffset(3) == offsetof(Instance, fColor));
- SkASSERT(this->debugOnly_instanceStride() == sizeof(Instance));
+ this->setInstanceAttributes(kInstanceAttribs, kNumInstanceAttribs);
+ SkASSERT(this->instanceStride() == sizeof(Instance));
- this->setVertexAttributeCnt(1);
+ this->setVertexAttributes(&kEdgeNormsAttrib, 1);
this->setTextureSamplerCnt(1);
if (!viewMatrixIfUsingLocalCoords.invert(&fLocalMatrix)) {
diff --git a/src/gpu/ccpr/GrCCPathProcessor.h b/src/gpu/ccpr/GrCCPathProcessor.h
index 4eb319a..bd544bb 100644
--- a/src/gpu/ccpr/GrCCPathProcessor.h
+++ b/src/gpu/ccpr/GrCCPathProcessor.h
@@ -91,8 +91,6 @@
const SkRect& bounds) const;
private:
- const Attribute& onVertexAttribute(int i) const override { return kEdgeNormsAttrib; }
- const Attribute& onInstanceAttribute(int i) const override { return kInstanceAttribs[i]; }
const TextureSampler& onTextureSampler(int) const override { return fAtlasAccess; }
const TextureSampler fAtlasAccess;
diff --git a/src/gpu/ccpr/GrCCStroker.cpp b/src/gpu/ccpr/GrCCStroker.cpp
index 98f8cef..f836774 100644
--- a/src/gpu/ccpr/GrCCStroker.cpp
+++ b/src/gpu/ccpr/GrCCStroker.cpp
@@ -70,15 +70,10 @@
class LinearStrokeProcessor : public GrGeometryProcessor {
public:
LinearStrokeProcessor() : GrGeometryProcessor(kLinearStrokeProcessor_ClassID) {
- this->setInstanceAttributeCnt(2);
+ this->setInstanceAttributes(kInstanceAttribs, 2);
#ifdef SK_DEBUG
- // Check that instance attributes exactly match the LinearStrokeInstance struct layout.
using Instance = LinearStrokeInstance;
- SkASSERT(!strcmp(this->instanceAttribute(0).name(), "endpts"));
- SkASSERT(this->debugOnly_instanceAttributeOffset(0) == offsetof(Instance, fEndpoints));
- SkASSERT(!strcmp(this->instanceAttribute(1).name(), "stroke_radius"));
- SkASSERT(this->debugOnly_instanceAttributeOffset(1) == offsetof(Instance, fStrokeRadius));
- SkASSERT(this->debugOnly_instanceStride() == sizeof(Instance));
+ SkASSERT(this->instanceStride() == sizeof(Instance));
#endif
}
@@ -91,8 +86,6 @@
{"stroke_radius", kFloat_GrVertexAttribType, kFloat_GrSLType}
};
- const Attribute& onInstanceAttribute(int i) const override { return kInstanceAttribs[i]; }
-
class Impl : public GrGLSLGeometryProcessor {
void setData(const GrGLSLProgramDataManager&, const GrPrimitiveProcessor&,
FPCoordTransformIter&&) override {}
@@ -167,17 +160,10 @@
class CubicStrokeProcessor : public GrGeometryProcessor {
public:
CubicStrokeProcessor() : GrGeometryProcessor(kCubicStrokeProcessor_ClassID) {
- this->setInstanceAttributeCnt(3);
+ this->setInstanceAttributes(kInstanceAttribs, 3);
#ifdef SK_DEBUG
- // Check that instance attributes exactly match the CubicStrokeInstance struct layout.
using Instance = CubicStrokeInstance;
- SkASSERT(!strcmp(this->instanceAttribute(0).name(), "X"));
- SkASSERT(this->debugOnly_instanceAttributeOffset(0) == offsetof(Instance, fX));
- SkASSERT(!strcmp(this->instanceAttribute(1).name(), "Y"));
- SkASSERT(this->debugOnly_instanceAttributeOffset(1) == offsetof(Instance, fY));
- SkASSERT(!strcmp(this->instanceAttribute(2).name(), "stroke_info"));
- SkASSERT(this->debugOnly_instanceAttributeOffset(2) == offsetof(Instance, fStrokeRadius));
- SkASSERT(this->debugOnly_instanceStride() == sizeof(Instance));
+ SkASSERT(this->instanceStride() == sizeof(Instance));
#endif
}
@@ -191,8 +177,6 @@
{"stroke_info", kFloat2_GrVertexAttribType, kFloat2_GrSLType}
};
- const Attribute& onInstanceAttribute(int i) const override { return kInstanceAttribs[i]; }
-
class Impl : public GrGLSLGeometryProcessor {
void setData(const GrGLSLProgramDataManager&, const GrPrimitiveProcessor&,
FPCoordTransformIter&&) override {}
diff --git a/src/gpu/effects/GrBezierEffect.cpp b/src/gpu/effects/GrBezierEffect.cpp
index da7fca6..e42859b 100644
--- a/src/gpu/effects/GrBezierEffect.cpp
+++ b/src/gpu/effects/GrBezierEffect.cpp
@@ -240,7 +240,7 @@
, fUsesLocalCoords(usesLocalCoords)
, fCoverageScale(coverage)
, fEdgeType(edgeType) {
- this->setVertexAttributeCnt(2);
+ this->setVertexAttributes(kAttributes, SK_ARRAY_COUNT(kAttributes));
}
//////////////////////////////////////////////////////////////////////////////
@@ -440,7 +440,7 @@
, fUsesLocalCoords(usesLocalCoords)
, fCoverageScale(coverage)
, fEdgeType(edgeType) {
- this->setVertexAttributeCnt(2);
+ this->setVertexAttributes(kAttributes, SK_ARRAY_COUNT(kAttributes));
}
//////////////////////////////////////////////////////////////////////////////
diff --git a/src/gpu/effects/GrBezierEffect.h b/src/gpu/effects/GrBezierEffect.h
index 835901f..e0620ec 100644
--- a/src/gpu/effects/GrBezierEffect.h
+++ b/src/gpu/effects/GrBezierEffect.h
@@ -112,8 +112,6 @@
GrConicEffect(const SkPMColor4f&, const SkMatrix& viewMatrix, uint8_t coverage, GrClipEdgeType,
const SkMatrix& localMatrix, bool usesLocalCoords);
- const Attribute& onVertexAttribute(int i) const override { return kAttributes[i]; }
-
SkPMColor4f fColor;
SkMatrix fViewMatrix;
SkMatrix fLocalMatrix;
@@ -198,8 +196,6 @@
GrQuadEffect(const SkPMColor4f&, const SkMatrix& viewMatrix, uint8_t coverage, GrClipEdgeType,
const SkMatrix& localMatrix, bool usesLocalCoords);
- const Attribute& onVertexAttribute(int i) const override { return kAttributes[i]; }
-
SkPMColor4f fColor;
SkMatrix fViewMatrix;
SkMatrix fLocalMatrix;
diff --git a/src/gpu/effects/GrBitmapTextGeoProc.cpp b/src/gpu/effects/GrBitmapTextGeoProc.cpp
index 15df560..c59ae4a 100644
--- a/src/gpu/effects/GrBitmapTextGeoProc.cpp
+++ b/src/gpu/effects/GrBitmapTextGeoProc.cpp
@@ -138,18 +138,15 @@
fInPosition = {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
}
- fInTextureCoords = {"inTextureCoords", kUShort2_GrVertexAttribType,
- caps.integerSupport() ? kUShort2_GrSLType : kFloat2_GrSLType };
- int cnt = 2;
-
bool hasVertexColor = kA8_GrMaskFormat == fMaskFormat ||
kA565_GrMaskFormat == fMaskFormat;
if (hasVertexColor) {
fInColor = {"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
- ++cnt;
}
- this->setVertexAttributeCnt(cnt);
+ fInTextureCoords = {"inTextureCoords", kUShort2_GrVertexAttribType,
+ caps.integerSupport() ? kUShort2_GrSLType : kFloat2_GrSLType};
+ this->setVertexAttributes(&fInPosition, 3);
if (numActiveProxies) {
fAtlasSize = proxies[0]->isize();
@@ -162,10 +159,6 @@
this->setTextureSamplerCnt(numActiveProxies);
}
-const GrPrimitiveProcessor::Attribute& GrBitmapTextGeoProc::onVertexAttribute(int i) const {
- return IthInitializedAttribute(i, fInPosition, fInColor, fInTextureCoords);
-}
-
void GrBitmapTextGeoProc::addNewProxies(const sk_sp<GrTextureProxy>* proxies,
int numActiveProxies,
const GrSamplerState& params) {
diff --git a/src/gpu/effects/GrBitmapTextGeoProc.h b/src/gpu/effects/GrBitmapTextGeoProc.h
index 55e5925..ca9b796 100644
--- a/src/gpu/effects/GrBitmapTextGeoProc.h
+++ b/src/gpu/effects/GrBitmapTextGeoProc.h
@@ -59,7 +59,6 @@
const GrSamplerState& params, GrMaskFormat format,
const SkMatrix& localMatrix, bool usesW);
- const Attribute& onVertexAttribute(int i) const override;
const TextureSampler& onTextureSampler(int i) const override { return fTextureSamplers[i]; }
SkPMColor4f fColor;
diff --git a/src/gpu/effects/GrDistanceFieldGeoProc.cpp b/src/gpu/effects/GrDistanceFieldGeoProc.cpp
index 2ef7f9d..d6a5e84 100644
--- a/src/gpu/effects/GrDistanceFieldGeoProc.cpp
+++ b/src/gpu/effects/GrDistanceFieldGeoProc.cpp
@@ -206,8 +206,6 @@
///////////////////////////////////////////////////////////////////////////////
-constexpr GrPrimitiveProcessor::Attribute GrDistanceFieldA8TextGeoProc::kInColor;
-
GrDistanceFieldA8TextGeoProc::GrDistanceFieldA8TextGeoProc(const GrShaderCaps& caps,
const sk_sp<GrTextureProxy>* proxies,
int numProxies,
@@ -232,9 +230,10 @@
} else {
fInPosition = {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
}
+ fInColor = {"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType };
fInTextureCoords = {"inTextureCoords", kUShort2_GrVertexAttribType,
caps.integerSupport() ? kUShort2_GrSLType : kFloat2_GrSLType};
- this->setVertexAttributeCnt(3);
+ this->setVertexAttributes(&fInPosition, 3);
if (numProxies) {
fAtlasSize = proxies[0]->isize();
@@ -509,8 +508,6 @@
};
///////////////////////////////////////////////////////////////////////////////
-constexpr GrPrimitiveProcessor::Attribute GrDistanceFieldPathGeoProc::kInPosition;
-constexpr GrPrimitiveProcessor::Attribute GrDistanceFieldPathGeoProc::kInColor;
GrDistanceFieldPathGeoProc::GrDistanceFieldPathGeoProc(const GrShaderCaps& caps,
const SkMatrix& matrix,
@@ -524,9 +521,11 @@
SkASSERT(numProxies <= kMaxTextures);
SkASSERT(!(flags & ~kNonLCD_DistanceFieldEffectMask));
+ fInPosition = {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
+ fInColor = {"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
fInTextureCoords = {"inTextureCoords", kUShort2_GrVertexAttribType,
caps.integerSupport() ? kUShort2_GrSLType : kFloat2_GrSLType};
- this->setVertexAttributeCnt(3);
+ this->setVertexAttributes(&fInPosition, 3);
if (numProxies) {
fAtlasSize = proxies[0]->isize();
@@ -570,10 +569,6 @@
return new GrGLDistanceFieldPathGeoProc();
}
-const GrPrimitiveProcessor::Attribute& GrDistanceFieldPathGeoProc::onVertexAttribute(int i) const {
- return IthAttribute(i, kInPosition, kInColor, fInTextureCoords);
-}
-
///////////////////////////////////////////////////////////////////////////////
GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldPathGeoProc);
@@ -828,8 +823,6 @@
///////////////////////////////////////////////////////////////////////////////
-constexpr GrPrimitiveProcessor::Attribute GrDistanceFieldLCDTextGeoProc::kInColor;
-
GrDistanceFieldLCDTextGeoProc::GrDistanceFieldLCDTextGeoProc(const GrShaderCaps& caps,
const sk_sp<GrTextureProxy>* proxies,
int numProxies,
@@ -849,9 +842,10 @@
} else {
fInPosition = {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
}
+ fInColor = {"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
fInTextureCoords = {"inTextureCoords", kUShort2_GrVertexAttribType,
caps.integerSupport() ? kUShort2_GrSLType : kFloat2_GrSLType};
- this->setVertexAttributeCnt(3);
+ this->setVertexAttributes(&fInPosition, 3);
if (numProxies) {
fAtlasSize = proxies[0]->isize();
@@ -894,11 +888,6 @@
return new GrGLDistanceFieldLCDTextGeoProc();
}
-const GrPrimitiveProcessor::Attribute& GrDistanceFieldLCDTextGeoProc::onVertexAttribute(
- int i) const {
- return IthAttribute(i, fInPosition, kInColor, fInTextureCoords);
-}
-
///////////////////////////////////////////////////////////////////////////////
GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrDistanceFieldLCDTextGeoProc);
diff --git a/src/gpu/effects/GrDistanceFieldGeoProc.h b/src/gpu/effects/GrDistanceFieldGeoProc.h
index 2c449f6..3529fe0 100644
--- a/src/gpu/effects/GrDistanceFieldGeoProc.h
+++ b/src/gpu/effects/GrDistanceFieldGeoProc.h
@@ -81,7 +81,7 @@
const char* name() const override { return "DistanceFieldA8Text"; }
const Attribute& inPosition() const { return fInPosition; }
- const Attribute& inColor() const { return kInColor; }
+ const Attribute& inColor() const { return fInColor; }
const Attribute& inTextureCoords() const { return fInTextureCoords; }
const SkMatrix& localMatrix() const { return fLocalMatrix; }
#ifdef SK_GAMMA_APPLY_TO_A8
@@ -106,25 +106,19 @@
#endif
uint32_t flags, const SkMatrix& localMatrix);
- const Attribute& onVertexAttribute(int i) const override {
- return IthAttribute(i, fInPosition, kInColor, fInTextureCoords);
- }
-
const TextureSampler& onTextureSampler(int i) const override { return fTextureSamplers[i]; }
TextureSampler fTextureSamplers[kMaxTextures];
SkISize fAtlasSize; // size for all textures used with fTextureSamplers[].
SkMatrix fLocalMatrix;
Attribute fInPosition;
+ Attribute fInColor;
Attribute fInTextureCoords;
uint32_t fFlags;
#ifdef SK_GAMMA_APPLY_TO_A8
float fDistanceAdjust;
#endif
- static constexpr Attribute kInColor =
- {"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
-
GR_DECLARE_GEOMETRY_PROCESSOR_TEST
typedef GrGeometryProcessor INHERITED;
@@ -154,8 +148,8 @@
const char* name() const override { return "DistanceFieldPath"; }
- const Attribute& inPosition() const { return kInPosition; }
- const Attribute& inColor() const { return kInColor; }
+ const Attribute& inPosition() const { return fInPosition; }
+ const Attribute& inColor() const { return fInColor; }
const Attribute& inTextureCoords() const { return fInTextureCoords; }
const SkMatrix& matrix() const { return fMatrix; }
uint32_t getFlags() const { return fFlags; }
@@ -174,18 +168,15 @@
int numActiveProxies,
const GrSamplerState&, uint32_t flags);
- const Attribute& onVertexAttribute(int i) const override;
const TextureSampler& onTextureSampler(int i) const override { return fTextureSamplers[i]; }
SkMatrix fMatrix; // view matrix if perspective, local matrix otherwise
TextureSampler fTextureSamplers[kMaxTextures];
SkISize fAtlasSize; // size for all textures used with fTextureSamplers[].
+ Attribute fInPosition;
+ Attribute fInColor;
Attribute fInTextureCoords;
uint32_t fFlags;
- static constexpr Attribute kInPosition =
- {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
- static constexpr Attribute kInColor =
- {"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
GR_DECLARE_GEOMETRY_PROCESSOR_TEST
@@ -234,7 +225,7 @@
const char* name() const override { return "DistanceFieldLCDText"; }
const Attribute& inPosition() const { return fInPosition; }
- const Attribute& inColor() const { return kInColor; }
+ const Attribute& inColor() const { return fInColor; }
const Attribute& inTextureCoords() const { return fInTextureCoords; }
DistanceAdjust getDistanceAdjust() const { return fDistanceAdjust; }
uint32_t getFlags() const { return fFlags; }
@@ -252,7 +243,6 @@
int numActiveProxies, const GrSamplerState& params,
DistanceAdjust wa, uint32_t flags, const SkMatrix& localMatrix);
- const Attribute& onVertexAttribute(int) const override;
const TextureSampler& onTextureSampler(int i) const override { return fTextureSamplers[i]; }
TextureSampler fTextureSamplers[kMaxTextures];
@@ -260,12 +250,10 @@
const SkMatrix fLocalMatrix;
DistanceAdjust fDistanceAdjust;
Attribute fInPosition;
+ Attribute fInColor;
Attribute fInTextureCoords;
uint32_t fFlags;
- static constexpr Attribute kInColor =
- {"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
-
GR_DECLARE_GEOMETRY_PROCESSOR_TEST
typedef GrGeometryProcessor INHERITED;
diff --git a/src/gpu/effects/GrShadowGeoProc.cpp b/src/gpu/effects/GrShadowGeoProc.cpp
index c883597..ae14fa3 100644
--- a/src/gpu/effects/GrShadowGeoProc.cpp
+++ b/src/gpu/effects/GrShadowGeoProc.cpp
@@ -63,7 +63,10 @@
///////////////////////////////////////////////////////////////////////////////
GrRRectShadowGeoProc::GrRRectShadowGeoProc() : INHERITED(kGrRRectShadowGeoProc_ClassID) {
- this->setVertexAttributeCnt(3);
+ fInPosition = {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
+ fInColor = {"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
+ fInShadowParams = {"inShadowParams", kFloat3_GrVertexAttribType, kHalf3_GrSLType};
+ this->setVertexAttributes(&fInPosition, 3);
}
GrGLSLPrimitiveProcessor* GrRRectShadowGeoProc::createGLSLInstance(const GrShaderCaps&) const {
@@ -72,10 +75,6 @@
///////////////////////////////////////////////////////////////////////////////
-constexpr GrPrimitiveProcessor::Attribute GrRRectShadowGeoProc::kInPosition;
-constexpr GrPrimitiveProcessor::Attribute GrRRectShadowGeoProc::kInColor;
-constexpr GrPrimitiveProcessor::Attribute GrRRectShadowGeoProc::kInShadowParams;
-
GR_DEFINE_GEOMETRY_PROCESSOR_TEST(GrRRectShadowGeoProc);
#if GR_TEST_UTILS
diff --git a/src/gpu/effects/GrShadowGeoProc.h b/src/gpu/effects/GrShadowGeoProc.h
index 8380015..8b0727f 100644
--- a/src/gpu/effects/GrShadowGeoProc.h
+++ b/src/gpu/effects/GrShadowGeoProc.h
@@ -25,9 +25,9 @@
const char* name() const override { return "RRectShadow"; }
- const Attribute& inPosition() const { return kInPosition; }
- const Attribute& inColor() const { return kInColor; }
- const Attribute& inShadowParams() const { return kInShadowParams; }
+ const Attribute& inPosition() const { return fInPosition; }
+ const Attribute& inColor() const { return fInColor; }
+ const Attribute& inShadowParams() const { return fInShadowParams; }
GrColor color() const { return fColor; }
void getGLSLProcessorKey(const GrShaderCaps& caps, GrProcessorKeyBuilder* b) const override {}
@@ -37,18 +37,11 @@
private:
GrRRectShadowGeoProc();
- const Attribute& onVertexAttribute(int i) const override {
- return IthAttribute(i, kInPosition, kInColor, kInShadowParams);
- }
-
GrColor fColor;
- static constexpr Attribute kInPosition =
- {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
- static constexpr Attribute kInColor =
- {"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
- static constexpr Attribute kInShadowParams =
- {"inShadowParams", kFloat3_GrVertexAttribType, kHalf3_GrSLType};
+ Attribute fInPosition;
+ Attribute fInColor;
+ Attribute fInShadowParams;
GR_DECLARE_GEOMETRY_PROCESSOR_TEST
diff --git a/src/gpu/gl/builders/GrGLProgramBuilder.cpp b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
index 3904265..6c12738 100644
--- a/src/gpu/gl/builders/GrGLProgramBuilder.cpp
+++ b/src/gpu/gl/builders/GrGLProgramBuilder.cpp
@@ -147,17 +147,15 @@
};
fVertexStride = 0;
int i = 0;
- for (; i < fVertexAttributeCnt; i++) {
- addAttr(i, primProc.vertexAttribute(i), &fVertexStride);
- SkASSERT(fAttributes[i].fOffset == primProc.debugOnly_vertexAttributeOffset(i));
+ for (const auto& attr : primProc.vertexAttributes()) {
+ addAttr(i++, attr, &fVertexStride);
}
- SkASSERT(fVertexStride == primProc.debugOnly_vertexStride());
+ SkASSERT(fVertexStride == primProc.vertexStride());
fInstanceStride = 0;
- for (int j = 0; j < fInstanceAttributeCnt; j++, ++i) {
- addAttr(i, primProc.instanceAttribute(j), &fInstanceStride);
- SkASSERT(fAttributes[i].fOffset == primProc.debugOnly_instanceAttributeOffset(j));
+ for (const auto& attr : primProc.instanceAttributes()) {
+ addAttr(i++, attr, &fInstanceStride);
}
- SkASSERT(fInstanceStride == primProc.debugOnly_instanceStride());
+ SkASSERT(fInstanceStride == primProc.instanceStride());
}
void GrGLProgramBuilder::addInputVars(const SkSL::Program::Inputs& inputs) {
diff --git a/src/gpu/glsl/GrGLSLVarying.cpp b/src/gpu/glsl/GrGLSLVarying.cpp
index 42a5abd..a435f24 100644
--- a/src/gpu/glsl/GrGLSLVarying.cpp
+++ b/src/gpu/glsl/GrGLSLVarying.cpp
@@ -67,13 +67,11 @@
}
void GrGLSLVaryingHandler::emitAttributes(const GrGeometryProcessor& gp) {
- int vaCount = gp.numVertexAttributes();
- for (int i = 0; i < vaCount; i++) {
- this->addAttribute(gp.vertexAttribute(i).asShaderVar());
+ for (const auto& attr : gp.vertexAttributes()) {
+ this->addAttribute(attr.asShaderVar());
}
- int iaCount = gp.numInstanceAttributes();
- for (int i = 0; i < iaCount; i++) {
- this->addAttribute(gp.instanceAttribute(i).asShaderVar());
+ for (const auto& attr : gp.instanceAttributes()) {
+ this->addAttribute(attr.asShaderVar());
}
}
diff --git a/src/gpu/mtl/GrMtlPipelineStateBuilder.mm b/src/gpu/mtl/GrMtlPipelineStateBuilder.mm
index 8e08073..3512bec 100644
--- a/src/gpu/mtl/GrMtlPipelineStateBuilder.mm
+++ b/src/gpu/mtl/GrMtlPipelineStateBuilder.mm
@@ -161,18 +161,16 @@
int vertexAttributeCount = primProc.numVertexAttributes();
size_t vertexAttributeOffset = 0;
- for (int vertexIndex = 0; vertexIndex < vertexAttributeCount; vertexIndex++) {
- const GrGeometryProcessor::Attribute& attribute = primProc.vertexAttribute(vertexIndex);
+ for (const auto& attribute : primProc.vertexAttributes()) {
MTLVertexAttributeDescriptor* mtlAttribute = vertexDescriptor.attributes[attributeIndex];
mtlAttribute.format = attribute_type_to_mtlformat(attribute.cpuType());
mtlAttribute.offset = vertexAttributeOffset;
mtlAttribute.bufferIndex = vertexBinding;
- SkASSERT(mtlAttribute.offset == primProc.debugOnly_vertexAttributeOffset(vertexIndex));
vertexAttributeOffset += attribute.sizeAlign4();
attributeIndex++;
}
- SkASSERT(vertexAttributeOffset == primProc.debugOnly_vertexStride());
+ SkASSERT(vertexAttributeOffset == primProc.vertexStride());
if (vertexAttributeCount) {
MTLVertexBufferLayoutDescriptor* vertexBufferLayout =
@@ -184,18 +182,16 @@
int instanceAttributeCount = primProc.numInstanceAttributes();
size_t instanceAttributeOffset = 0;
- for (int instanceIndex = 0; instanceIndex < instanceAttributeCount; instanceIndex++) {
- const GrGeometryProcessor::Attribute& attribute = primProc.instanceAttribute(instanceIndex);
+ for (const auto& attribute : primProc.instanceAttributes()) {
MTLVertexAttributeDescriptor* mtlAttribute = vertexDescriptor.attributes[attributeIndex];
mtlAttribute.format = attribute_type_to_mtlformat(attribute.cpuType());
mtlAttribute.offset = instanceAttributeOffset;
mtlAttribute.bufferIndex = instanceBinding;
- SkASSERT(mtlAttribute.offset == primProc.debugOnly_instanceAttributeOffset(instanceIndex));
instanceAttributeOffset += attribute.sizeAlign4();
attributeIndex++;
}
- SkASSERT(instanceAttributeOffset == primProc.debugOnly_instanceStride());
+ SkASSERT(instanceAttributeOffset == primProc.instanceStride());
if (instanceAttributeCount) {
MTLVertexBufferLayoutDescriptor* instanceBufferLayout =
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));
diff --git a/src/gpu/ops/GrAAFillRectOp.cpp b/src/gpu/ops/GrAAFillRectOp.cpp
index 3a7cc05..3aa05bb 100644
--- a/src/gpu/ops/GrAAFillRectOp.cpp
+++ b/src/gpu/ops/GrAAFillRectOp.cpp
@@ -244,17 +244,14 @@
void onPrepareDraws(Target* target) override {
using namespace GrDefaultGeoProcFactory;
- size_t vertexStride = sizeof(SkPoint) + sizeof(GrColor);
Color color(Color::kPremulGrColorAttribute_Type);
Coverage::Type coverageType = Coverage::kSolid_Type;
if (!fHelper.compatibleWithAlphaAsCoverage()) {
coverageType = Coverage::kAttribute_Type;
- vertexStride += sizeof(float);
}
LocalCoords lc = LocalCoords::kUnused_Type;
if (fHelper.usesLocalCoords()) {
lc = LocalCoords::kHasExplicit_Type;
- vertexStride += sizeof(SkPoint);
}
sk_sp<GrGeometryProcessor> gp =
@@ -265,7 +262,7 @@
return;
}
- SkASSERT(vertexStride == gp->debugOnly_vertexStride());
+ size_t vertexStride = gp->vertexStride();
sk_sp<const GrBuffer> indexBuffer = get_index_buffer(target->resourceProvider());
PatternHelper helper(target, GrPrimitiveType::kTriangles, vertexStride, indexBuffer.get(),
diff --git a/src/gpu/ops/GrAAHairLinePathRenderer.cpp b/src/gpu/ops/GrAAHairLinePathRenderer.cpp
index 610bce1..d22c4f3 100644
--- a/src/gpu/ops/GrAAHairLinePathRenderer.cpp
+++ b/src/gpu/ops/GrAAHairLinePathRenderer.cpp
@@ -976,7 +976,7 @@
const GrBuffer* vertexBuffer;
int firstVertex;
- SkASSERT(sizeof(LineVertex) == lineGP->debugOnly_vertexStride());
+ SkASSERT(sizeof(LineVertex) == lineGP->vertexStride());
int vertexCount = kLineSegNumVertices * lineCount;
LineVertex* verts = reinterpret_cast<LineVertex*>(target->makeVertexSpace(
sizeof(LineVertex), vertexCount, &vertexBuffer, &firstVertex));
@@ -1019,8 +1019,8 @@
sk_sp<const GrBuffer> quadsIndexBuffer = get_quads_index_buffer(target->resourceProvider());
- SkASSERT(sizeof(BezierVertex) == quadGP->debugOnly_vertexStride());
- SkASSERT(sizeof(BezierVertex) == conicGP->debugOnly_vertexStride());
+ SkASSERT(sizeof(BezierVertex) == quadGP->vertexStride());
+ SkASSERT(sizeof(BezierVertex) == conicGP->vertexStride());
int vertexCount = kQuadNumVertices * quadAndConicCount;
void* vertices = target->makeVertexSpace(sizeof(BezierVertex), vertexCount, &vertexBuffer,
&firstVertex);
diff --git a/src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp b/src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp
index 74a9bc0..996fa33 100644
--- a/src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp
+++ b/src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp
@@ -247,11 +247,7 @@
return;
}
- size_t vertexStride = fHelper.compatibleWithAlphaAsCoverage()
- ? sizeof(GrDefaultGeoProcFactory::PositionColorAttr)
- : sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAttr);
- SkASSERT(vertexStride == gp->debugOnly_vertexStride());
-
+ size_t vertexStride = gp->vertexStride();
int instanceCount = fPaths.count();
int64_t vertexCount = 0;
diff --git a/src/gpu/ops/GrAAStrokeRectOp.cpp b/src/gpu/ops/GrAAStrokeRectOp.cpp
index f2be50a..c730c4d 100644
--- a/src/gpu/ops/GrAAStrokeRectOp.cpp
+++ b/src/gpu/ops/GrAAStrokeRectOp.cpp
@@ -274,11 +274,7 @@
return;
}
- size_t vertexStride = fHelper.compatibleWithAlphaAsCoverage()
- ? sizeof(GrDefaultGeoProcFactory::PositionColorAttr)
- : sizeof(GrDefaultGeoProcFactory::PositionColorCoverageAttr);
-
- SkASSERT(vertexStride == gp->debugOnly_vertexStride());
+ size_t vertexStride = gp->vertexStride();
int innerVertexNum = 4;
int outerVertexNum = this->miterStroke() ? 4 : 8;
int verticesPerInstance = (outerVertexNum + innerVertexNum) * 2;
diff --git a/src/gpu/ops/GrAtlasTextOp.cpp b/src/gpu/ops/GrAtlasTextOp.cpp
index d2aa33e..7263dfb 100644
--- a/src/gpu/ops/GrAtlasTextOp.cpp
+++ b/src/gpu/ops/GrAtlasTextOp.cpp
@@ -326,8 +326,7 @@
}
flushInfo.fGlyphsToFlush = 0;
- size_t vertexStride = GrTextBlob::GetVertexStride(maskFormat, vmPerspective);
- SkASSERT(vertexStride == flushInfo.fGeometryProcessor->debugOnly_vertexStride());
+ size_t vertexStride = flushInfo.fGeometryProcessor->vertexStride();
int glyphCount = this->numGlyphs();
const GrBuffer* vertexBuffer;
diff --git a/src/gpu/ops/GrDashOp.cpp b/src/gpu/ops/GrDashOp.cpp
index 220f49b..228c5ad 100644
--- a/src/gpu/ops/GrDashOp.cpp
+++ b/src/gpu/ops/GrDashOp.cpp
@@ -627,14 +627,7 @@
return;
}
- size_t vertexStride;
- if (fullDash) {
- vertexStride =
- SkPaint::kRound_Cap == fCap ? sizeof(DashCircleVertex) : sizeof(DashLineVertex);
- } else {
- vertexStride = sizeof(SkPoint);
- }
- SkASSERT(vertexStride == gp->debugOnly_vertexStride());
+ size_t vertexStride = gp->vertexStride();
QuadHelper helper(target, vertexStride, totalRectCount);
void* vertices = helper.vertices();
if (!vertices) {
@@ -859,30 +852,20 @@
DashingCircleEffect(const SkPMColor4f&, AAMode aaMode, const SkMatrix& localMatrix,
bool usesLocalCoords);
- const Attribute& onVertexAttribute(int i) const override {
- return IthAttribute(i, kInPosition, kInDashParams, kInCircleParams);
- }
-
SkPMColor4f fColor;
SkMatrix fLocalMatrix;
bool fUsesLocalCoords;
AAMode fAAMode;
- static constexpr Attribute kInPosition =
- {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
- static constexpr Attribute kInDashParams =
- {"inDashParams", kFloat3_GrVertexAttribType, kHalf3_GrSLType};
- static constexpr Attribute kInCircleParams =
- {"inCircleParams", kFloat2_GrVertexAttribType, kHalf2_GrSLType};
+ Attribute fInPosition;
+ Attribute fInDashParams;
+ Attribute fInCircleParams;
GR_DECLARE_GEOMETRY_PROCESSOR_TEST
friend class GLDashingCircleEffect;
typedef GrGeometryProcessor INHERITED;
};
-constexpr GrPrimitiveProcessor::Attribute DashingCircleEffect::kInPosition;
-constexpr GrPrimitiveProcessor::Attribute DashingCircleEffect::kInDashParams;
-constexpr GrPrimitiveProcessor::Attribute DashingCircleEffect::kInCircleParams;
//////////////////////////////////////////////////////////////////////////////
@@ -927,25 +910,25 @@
// XY are dashPos, Z is dashInterval
GrGLSLVarying dashParams(kHalf3_GrSLType);
varyingHandler->addVarying("DashParam", &dashParams);
- vertBuilder->codeAppendf("%s = %s;", dashParams.vsOut(), dce.kInDashParams.name());
+ vertBuilder->codeAppendf("%s = %s;", dashParams.vsOut(), dce.fInDashParams.name());
// x refers to circle radius - 0.5, y refers to cicle's center x coord
GrGLSLVarying circleParams(kHalf2_GrSLType);
varyingHandler->addVarying("CircleParams", &circleParams);
- vertBuilder->codeAppendf("%s = %s;", circleParams.vsOut(), dce.kInCircleParams.name());
+ vertBuilder->codeAppendf("%s = %s;", circleParams.vsOut(), dce.fInCircleParams.name());
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
// Setup pass through color
this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor, &fColorUniform);
// Setup position
- this->writeOutputPosition(vertBuilder, gpArgs, dce.kInPosition.name());
+ this->writeOutputPosition(vertBuilder, gpArgs, dce.fInPosition.name());
// emit transforms
this->emitTransforms(vertBuilder,
varyingHandler,
uniformHandler,
- dce.kInPosition.asShaderVar(),
+ dce.fInPosition.asShaderVar(),
dce.localMatrix(),
args.fFPCoordTransformHandler);
@@ -1016,7 +999,10 @@
, fLocalMatrix(localMatrix)
, fUsesLocalCoords(usesLocalCoords)
, fAAMode(aaMode) {
- this->setVertexAttributeCnt(3);
+ fInPosition = {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
+ fInDashParams = {"inDashParams", kFloat3_GrVertexAttribType, kHalf3_GrSLType};
+ fInCircleParams = {"inCircleParams", kFloat2_GrVertexAttribType, kHalf2_GrSLType};
+ this->setVertexAttributes(&fInPosition, 3);
}
GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DashingCircleEffect);
@@ -1070,21 +1056,14 @@
DashingLineEffect(const SkPMColor4f&, AAMode aaMode, const SkMatrix& localMatrix,
bool usesLocalCoords);
- const Attribute& onVertexAttribute(int i) const override {
- return IthAttribute(i, kInPosition, kInDashParams, kInRectParams);
- }
-
SkPMColor4f fColor;
SkMatrix fLocalMatrix;
bool fUsesLocalCoords;
AAMode fAAMode;
- static constexpr Attribute kInPosition =
- {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
- static constexpr Attribute kInDashParams =
- {"inDashParams", kFloat3_GrVertexAttribType, kHalf3_GrSLType};
- static constexpr Attribute kInRectParams =
- {"inRect", kFloat4_GrVertexAttribType, kHalf4_GrSLType};
+ Attribute fInPosition;
+ Attribute fInDashParams;
+ Attribute fInRect;
GR_DECLARE_GEOMETRY_PROCESSOR_TEST
@@ -1092,9 +1071,6 @@
typedef GrGeometryProcessor INHERITED;
};
-constexpr GrPrimitiveProcessor::Attribute DashingLineEffect::kInPosition;
-constexpr GrPrimitiveProcessor::Attribute DashingLineEffect::kInDashParams;
-constexpr GrPrimitiveProcessor::Attribute DashingLineEffect::kInRectParams;
//////////////////////////////////////////////////////////////////////////////
@@ -1132,26 +1108,26 @@
// XY refers to dashPos, Z is the dash interval length
GrGLSLVarying inDashParams(kFloat3_GrSLType);
varyingHandler->addVarying("DashParams", &inDashParams);
- vertBuilder->codeAppendf("%s = %s;", inDashParams.vsOut(), de.kInDashParams.name());
+ vertBuilder->codeAppendf("%s = %s;", inDashParams.vsOut(), de.fInDashParams.name());
// The rect uniform's xyzw refer to (left + 0.5, top + 0.5, right - 0.5, bottom - 0.5),
// respectively.
GrGLSLVarying inRectParams(kFloat4_GrSLType);
varyingHandler->addVarying("RectParams", &inRectParams);
- vertBuilder->codeAppendf("%s = %s;", inRectParams.vsOut(), de.kInRectParams.name());
+ vertBuilder->codeAppendf("%s = %s;", inRectParams.vsOut(), de.fInRect.name());
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
// Setup pass through color
this->setupUniformColor(fragBuilder, uniformHandler, args.fOutputColor, &fColorUniform);
// Setup position
- this->writeOutputPosition(vertBuilder, gpArgs, de.kInPosition.name());
+ this->writeOutputPosition(vertBuilder, gpArgs, de.fInPosition.name());
// emit transforms
this->emitTransforms(vertBuilder,
varyingHandler,
uniformHandler,
- de.kInPosition.asShaderVar(),
+ de.fInPosition.asShaderVar(),
de.localMatrix(),
args.fFPCoordTransformHandler);
@@ -1240,7 +1216,10 @@
, fLocalMatrix(localMatrix)
, fUsesLocalCoords(usesLocalCoords)
, fAAMode(aaMode) {
- this->setVertexAttributeCnt(3);
+ fInPosition = {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
+ fInDashParams = {"inDashParams", kFloat3_GrVertexAttribType, kHalf3_GrSLType};
+ fInRect = {"inRect", kFloat4_GrVertexAttribType, kHalf4_GrSLType};
+ this->setVertexAttributes(&fInPosition, 3);
}
GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DashingLineEffect);
diff --git a/src/gpu/ops/GrDefaultPathRenderer.cpp b/src/gpu/ops/GrDefaultPathRenderer.cpp
index 3e70847..a30fe3b 100644
--- a/src/gpu/ops/GrDefaultPathRenderer.cpp
+++ b/src/gpu/ops/GrDefaultPathRenderer.cpp
@@ -415,7 +415,7 @@
this->viewMatrix());
}
- SkASSERT(gp->debugOnly_vertexStride() == sizeof(SkPoint));
+ SkASSERT(gp->vertexStride() == sizeof(SkPoint));
int instanceCount = fPaths.count();
diff --git a/src/gpu/ops/GrDrawAtlasOp.cpp b/src/gpu/ops/GrDrawAtlasOp.cpp
index c242bfe..e19bdb6 100644
--- a/src/gpu/ops/GrDrawAtlasOp.cpp
+++ b/src/gpu/ops/GrDrawAtlasOp.cpp
@@ -130,9 +130,7 @@
this->viewMatrix()));
int instanceCount = fGeoData.count();
- size_t vertexStride =
- sizeof(SkPoint) + sizeof(SkPoint) + (this->hasColors() ? sizeof(GrColor) : 0);
- SkASSERT(vertexStride == gp->debugOnly_vertexStride());
+ size_t vertexStride = gp->vertexStride();
int numQuads = this->quadCount();
QuadHelper helper(target, vertexStride, numQuads);
diff --git a/src/gpu/ops/GrDrawVerticesOp.cpp b/src/gpu/ops/GrDrawVerticesOp.cpp
index ace2711..30ab521 100644
--- a/src/gpu/ops/GrDrawVerticesOp.cpp
+++ b/src/gpu/ops/GrDrawVerticesOp.cpp
@@ -226,14 +226,8 @@
&hasLocalCoordsAttribute,
&hasBoneAttribute);
- // Calculate the stride.
- size_t vertexStride = sizeof(SkPoint) +
- (hasColorAttribute ? sizeof(uint32_t) : 0) +
- (hasLocalCoordsAttribute ? sizeof(SkPoint) : 0) +
- (hasBoneAttribute ? 4 * (sizeof(int8_t) + sizeof(uint8_t)) : 0);
- SkASSERT(vertexStride == gp->debugOnly_vertexStride());
-
// Allocate buffers.
+ size_t vertexStride = gp->vertexStride();
const GrBuffer* vertexBuffer = nullptr;
int firstVertex = 0;
void* verts = target->makeVertexSpace(vertexStride, fVertexCount, &vertexBuffer, &firstVertex);
@@ -303,14 +297,8 @@
return;
}
- // Calculate the stride.
- size_t vertexStride = sizeof(SkPoint) +
- (hasColorAttribute ? sizeof(uint32_t) : 0) +
- (hasLocalCoordsAttribute ? sizeof(SkPoint) : 0) +
- (hasBoneAttribute ? 4 * (sizeof(int8_t) + sizeof(uint8_t)) : 0);
- SkASSERT(vertexStride == gp->debugOnly_vertexStride());
-
// Allocate vertex buffer.
+ size_t vertexStride = gp->vertexStride();
vertexBuffer.reset(rp->createBuffer(fVertexCount * vertexStride,
kVertex_GrBufferType,
kStatic_GrAccessPattern,
diff --git a/src/gpu/ops/GrLatticeOp.cpp b/src/gpu/ops/GrLatticeOp.cpp
index c089c34..ff48510 100644
--- a/src/gpu/ops/GrLatticeOp.cpp
+++ b/src/gpu/ops/GrLatticeOp.cpp
@@ -62,19 +62,20 @@
latticeGP.fColorSpaceXform.get());
args.fVaryingHandler->emitAttributes(latticeGP);
- this->writeOutputPosition(args.fVertBuilder, gpArgs, latticeGP.kPositions.name());
+ this->writeOutputPosition(args.fVertBuilder, gpArgs, latticeGP.fInPosition.name());
this->emitTransforms(args.fVertBuilder,
args.fVaryingHandler,
args.fUniformHandler,
- latticeGP.kTextureCoords.asShaderVar(),
+ latticeGP.fInTextureCoords.asShaderVar(),
args.fFPCoordTransformHandler);
args.fFragBuilder->codeAppend("float2 textureCoords;");
- args.fVaryingHandler->addPassThroughAttribute(latticeGP.kTextureCoords,
+ args.fVaryingHandler->addPassThroughAttribute(latticeGP.fInTextureCoords,
"textureCoords");
args.fFragBuilder->codeAppend("float4 textureDomain;");
args.fVaryingHandler->addPassThroughAttribute(
- latticeGP.kTextureDomain, "textureDomain", Interpolation::kCanBeFlat);
- args.fVaryingHandler->addPassThroughAttribute(latticeGP.kColors, args.fOutputColor,
+ latticeGP.fInTextureDomain, "textureDomain", Interpolation::kCanBeFlat);
+ args.fVaryingHandler->addPassThroughAttribute(latticeGP.fInColor,
+ args.fOutputColor,
Interpolation::kCanBeFlat);
args.fFragBuilder->codeAppendf("%s = ", args.fOutputColor);
args.fFragBuilder->appendTextureLookupAndModulate(
@@ -97,23 +98,19 @@
: INHERITED(kLatticeGP_ClassID), fColorSpaceXform(std::move(csxf)) {
fSampler.reset(proxy->textureType(), proxy->config(), filter);
this->setTextureSamplerCnt(1);
- this->setVertexAttributeCnt(4);
- }
-
- const Attribute& onVertexAttribute(int i) const override {
- return IthAttribute(i, kPositions, kTextureCoords, kTextureDomain, kColors);
+ fInPosition = {"position", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
+ fInTextureCoords = {"textureCoords", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
+ fInTextureDomain = {"textureDomain", kFloat4_GrVertexAttribType, kFloat4_GrSLType};
+ fInColor = {"color", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
+ this->setVertexAttributes(&fInPosition, 4);
}
const TextureSampler& onTextureSampler(int) const override { return fSampler; }
- static constexpr Attribute kPositions =
- {"position", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
- static constexpr Attribute kTextureCoords =
- {"textureCoords", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
- static constexpr Attribute kTextureDomain =
- {"textureDomain", kFloat4_GrVertexAttribType, kFloat4_GrSLType};
- static constexpr Attribute kColors =
- {"color", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
+ Attribute fInPosition;
+ Attribute fInTextureCoords;
+ Attribute fInTextureDomain;
+ Attribute fInColor;
sk_sp<GrColorSpaceXform> fColorSpaceXform;
TextureSampler fSampler;
@@ -121,11 +118,6 @@
typedef GrGeometryProcessor INHERITED;
};
-constexpr GrPrimitiveProcessor::Attribute LatticeGP::kPositions;
-constexpr GrPrimitiveProcessor::Attribute LatticeGP::kTextureCoords;
-constexpr GrPrimitiveProcessor::Attribute LatticeGP::kTextureDomain;
-constexpr GrPrimitiveProcessor::Attribute LatticeGP::kColors;
-
class NonAALatticeOp final : public GrMeshDrawOp {
private:
using Helper = GrSimpleMeshDrawOpHelper;
@@ -214,9 +206,7 @@
return;
}
- static constexpr size_t kVertexStide =
- sizeof(SkPoint) + sizeof(SkPoint) + sizeof(SkRect) + sizeof(uint32_t);
- SkASSERT(kVertexStide == gp->debugOnly_vertexStride());
+ size_t kVertexStride = gp->vertexStride();
int patchCnt = fPatches.count();
int numRects = 0;
@@ -229,7 +219,7 @@
}
sk_sp<const GrBuffer> indexBuffer = target->resourceProvider()->refQuadIndexBuffer();
- PatternHelper helper(target, GrPrimitiveType::kTriangles, kVertexStide, indexBuffer.get(),
+ PatternHelper helper(target, GrPrimitiveType::kTriangles, kVertexStride, indexBuffer.get(),
kVertsPerRect, kIndicesPerRect, numRects);
void* vertices = helper.vertices();
if (!vertices || !indexBuffer) {
@@ -260,7 +250,7 @@
static const Sk4f kFlipMuls(1.f, -1.f, 1.f, -1.f);
while (patch.fIter->next(&srcR, &dstR)) {
auto vertices = reinterpret_cast<LatticeGP::Vertex*>(verts);
- SkPointPriv::SetRectTriStrip(&vertices->fPosition, dstR, kVertexStide);
+ SkPointPriv::SetRectTriStrip(&vertices->fPosition, dstR, kVertexStride);
Sk4f coords(SkIntToScalar(srcR.fLeft), SkIntToScalar(srcR.fTop),
SkIntToScalar(srcR.fRight), SkIntToScalar(srcR.fBottom));
Sk4f domain = coords + kDomainOffsets;
@@ -271,7 +261,7 @@
domain = SkNx_shuffle<0, 3, 2, 1>(kFlipMuls * domain + kFlipOffsets);
}
SkPointPriv::SetRectTriStrip(&vertices->fTextureCoords, coords[0], coords[1],
- coords[2], coords[3], kVertexStide);
+ coords[2], coords[3], kVertexStride);
for (int j = 0; j < kVertsPerRect; ++j) {
vertices[j].fTextureDomain = {domain[0], domain[1], domain[2], domain[3]};
}
@@ -279,13 +269,13 @@
for (int j = 0; j < kVertsPerRect; ++j) {
vertices[j].fColor = patchColor;
}
- verts += kVertsPerRect * kVertexStide;
+ verts += kVertsPerRect * kVertexStride;
}
// If we didn't handle it above, apply the matrix here.
if (!isScaleTranslate) {
SkPoint* positions = reinterpret_cast<SkPoint*>(patchVerts);
- SkMatrixPriv::MapPointsWithStride(patch.fViewMatrix, positions, kVertexStide,
+ SkMatrixPriv::MapPointsWithStride(patch.fViewMatrix, positions, kVertexStride,
kVertsPerRect * patch.fIter->numRectsToDraw());
}
}
diff --git a/src/gpu/ops/GrNonAAFillRectOp.cpp b/src/gpu/ops/GrNonAAFillRectOp.cpp
index c30621c..ae0c9b7 100644
--- a/src/gpu/ops/GrNonAAFillRectOp.cpp
+++ b/src/gpu/ops/GrNonAAFillRectOp.cpp
@@ -188,10 +188,7 @@
return;
}
- static constexpr size_t kVertexStride =
- sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoordAttr);
- SkASSERT(kVertexStride == gp->debugOnly_vertexStride());
-
+ size_t kVertexStride = gp->vertexStride();
int rectCount = fRects.count();
sk_sp<const GrBuffer> indexBuffer = target->resourceProvider()->refQuadIndexBuffer();
@@ -322,11 +319,7 @@
SkDebugf("Couldn't create GrGeometryProcessor\n");
return;
}
- size_t vertexStride = fHasLocalRect
- ? sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoordAttr)
- : sizeof(GrDefaultGeoProcFactory::PositionColorAttr);
- SkASSERT(vertexStride == gp->debugOnly_vertexStride());
-
+ size_t vertexStride = gp->vertexStride();
int rectCount = fRects.count();
sk_sp<const GrBuffer> indexBuffer = target->resourceProvider()->refQuadIndexBuffer();
diff --git a/src/gpu/ops/GrNonAAStrokeRectOp.cpp b/src/gpu/ops/GrNonAAStrokeRectOp.cpp
index bd8b3e4..c2786ef 100644
--- a/src/gpu/ops/GrNonAAStrokeRectOp.cpp
+++ b/src/gpu/ops/GrNonAAStrokeRectOp.cpp
@@ -155,10 +155,7 @@
fViewMatrix);
}
- static constexpr size_t kVertexStride = sizeof(GrDefaultGeoProcFactory::PositionAttr);
-
- SkASSERT(kVertexStride == gp->debugOnly_vertexStride());
-
+ size_t kVertexStride = gp->vertexStride();
int vertexCount = kVertsPerHairlineRect;
if (fStrokeWidth > 0) {
vertexCount = kVertsPerStrokeRect;
diff --git a/src/gpu/ops/GrOvalOpFactory.cpp b/src/gpu/ops/GrOvalOpFactory.cpp
index e3ccbfc..5e73e1d 100644
--- a/src/gpu/ops/GrOvalOpFactory.cpp
+++ b/src/gpu/ops/GrOvalOpFactory.cpp
@@ -75,27 +75,26 @@
: INHERITED(kCircleGeometryProcessor_ClassID)
, fLocalMatrix(localMatrix)
, fStroke(stroke) {
- int cnt = 3;
+ fInPosition = {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
+ fInColor = {"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
+ fInCircleEdge = {"inCircleEdge", kFloat4_GrVertexAttribType, kFloat4_GrSLType};
+
if (clipPlane) {
fInClipPlane = {"inClipPlane", kFloat3_GrVertexAttribType, kHalf3_GrSLType};
- ++cnt;
}
if (isectPlane) {
fInIsectPlane = {"inIsectPlane", kFloat3_GrVertexAttribType, kHalf3_GrSLType};
- ++cnt;
}
if (unionPlane) {
fInUnionPlane = {"inUnionPlane", kFloat3_GrVertexAttribType, kHalf3_GrSLType};
- ++cnt;
}
if (roundCaps) {
SkASSERT(stroke);
SkASSERT(clipPlane);
fInRoundCapCenters =
{"inRoundCapCenters", kFloat4_GrVertexAttribType, kFloat4_GrSLType};
- ++cnt;
}
- this->setVertexAttributeCnt(cnt);
+ this->setVertexAttributes(&fInPosition, 7);
}
~CircleGeometryProcessor() override {}
@@ -125,7 +124,7 @@
// emit attributes
varyingHandler->emitAttributes(cgp);
fragBuilder->codeAppend("float4 circleEdge;");
- varyingHandler->addPassThroughAttribute(cgp.kInCircleEdge, "circleEdge");
+ varyingHandler->addPassThroughAttribute(cgp.fInCircleEdge, "circleEdge");
if (cgp.fInClipPlane.isInitialized()) {
fragBuilder->codeAppend("half3 clipPlane;");
varyingHandler->addPassThroughAttribute(cgp.fInClipPlane, "clipPlane");
@@ -148,20 +147,20 @@
// This is the cap radius in normalized space where the outer radius is 1 and
// circledEdge.w is the normalized inner radius.
vertBuilder->codeAppendf("%s = (1.0 - %s.w) / 2.0;", capRadius.vsOut(),
- cgp.kInCircleEdge.name());
+ cgp.fInCircleEdge.name());
}
// setup pass through color
- varyingHandler->addPassThroughAttribute(cgp.kInColor, args.fOutputColor);
+ varyingHandler->addPassThroughAttribute(cgp.fInColor, args.fOutputColor);
// Setup position
- this->writeOutputPosition(vertBuilder, gpArgs, cgp.kInPosition.name());
+ this->writeOutputPosition(vertBuilder, gpArgs, cgp.fInPosition.name());
// emit transforms
this->emitTransforms(vertBuilder,
varyingHandler,
uniformHandler,
- cgp.kInPosition.asShaderVar(),
+ cgp.fInPosition.asShaderVar(),
cgp.fLocalMatrix,
args.fFPCoordTransformHandler);
@@ -231,20 +230,11 @@
typedef GrGLSLGeometryProcessor INHERITED;
};
- const Attribute& onVertexAttribute(int i) const override {
- return IthInitializedAttribute(i, kInPosition, kInColor, kInCircleEdge, fInClipPlane,
- fInIsectPlane, fInUnionPlane, fInRoundCapCenters);
- }
-
SkMatrix fLocalMatrix;
- static constexpr Attribute kInPosition =
- {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
- static constexpr Attribute kInColor =
- {"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
- static constexpr Attribute kInCircleEdge =
- {"inCircleEdge", kFloat4_GrVertexAttribType, kFloat4_GrSLType};
-
+ Attribute fInPosition;
+ Attribute fInColor;
+ Attribute fInCircleEdge;
// Optional attributes.
Attribute fInClipPlane;
Attribute fInIsectPlane;
@@ -256,9 +246,6 @@
typedef GrGeometryProcessor INHERITED;
};
-constexpr GrPrimitiveProcessor::Attribute CircleGeometryProcessor::kInPosition;
-constexpr GrPrimitiveProcessor::Attribute CircleGeometryProcessor::kInColor;
-constexpr GrPrimitiveProcessor::Attribute CircleGeometryProcessor::kInCircleEdge;
GR_DEFINE_GEOMETRY_PROCESSOR_TEST(CircleGeometryProcessor);
@@ -279,7 +266,11 @@
public:
ButtCapDashedCircleGeometryProcessor(const SkMatrix& localMatrix)
: INHERITED(kButtCapStrokedCircleGeometryProcessor_ClassID), fLocalMatrix(localMatrix) {
- this->setVertexAttributeCnt(4);
+ fInPosition = {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
+ fInColor = {"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
+ fInCircleEdge = {"inCircleEdge", kFloat4_GrVertexAttribType, kFloat4_GrSLType};
+ fInDashParams = {"inDashParams", kFloat4_GrVertexAttribType, kFloat4_GrSLType};
+ this->setVertexAttributes(&fInPosition, 4);
}
~ButtCapDashedCircleGeometryProcessor() override {}
@@ -310,11 +301,11 @@
// emit attributes
varyingHandler->emitAttributes(bcscgp);
fragBuilder->codeAppend("float4 circleEdge;");
- varyingHandler->addPassThroughAttribute(bcscgp.kInCircleEdge, "circleEdge");
+ varyingHandler->addPassThroughAttribute(bcscgp.fInCircleEdge, "circleEdge");
fragBuilder->codeAppend("float4 dashParams;");
varyingHandler->addPassThroughAttribute(
- bcscgp.kInDashParams, "dashParams",
+ bcscgp.fInDashParams, "dashParams",
GrGLSLVaryingHandler::Interpolation::kCanBeFlat);
GrGLSLVarying wrapDashes(kHalf4_GrSLType);
varyingHandler->addVarying("wrapDashes", &wrapDashes,
@@ -322,7 +313,7 @@
GrGLSLVarying lastIntervalLength(kHalf_GrSLType);
varyingHandler->addVarying("lastIntervalLength", &lastIntervalLength,
GrGLSLVaryingHandler::Interpolation::kCanBeFlat);
- vertBuilder->codeAppendf("float4 dashParams = %s;", bcscgp.kInDashParams.name());
+ vertBuilder->codeAppendf("float4 dashParams = %s;", bcscgp.fInDashParams.name());
// Our fragment shader works in on/off intervals as specified by dashParams.xy:
// x = length of on interval, y = length of on + off.
// There are two other parameters in dashParams.zw:
@@ -384,17 +375,17 @@
// setup pass through color
varyingHandler->addPassThroughAttribute(
- bcscgp.kInColor, args.fOutputColor,
+ bcscgp.fInColor, args.fOutputColor,
GrGLSLVaryingHandler::Interpolation::kCanBeFlat);
// Setup position
- this->writeOutputPosition(vertBuilder, gpArgs, bcscgp.kInPosition.name());
+ this->writeOutputPosition(vertBuilder, gpArgs, bcscgp.fInPosition.name());
// emit transforms
this->emitTransforms(vertBuilder,
varyingHandler,
uniformHandler,
- bcscgp.kInPosition.asShaderVar(),
+ bcscgp.fInPosition.asShaderVar(),
bcscgp.fLocalMatrix,
args.fFPCoordTransformHandler);
GrShaderVar fnArgs[] = {
@@ -488,28 +479,16 @@
typedef GrGLSLGeometryProcessor INHERITED;
};
- const Attribute& onVertexAttribute(int i) const override {
- return IthAttribute(i, kInPosition, kInColor, kInCircleEdge, kInDashParams);
- }
-
SkMatrix fLocalMatrix;
- static constexpr Attribute kInPosition =
- {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
- static constexpr Attribute kInColor =
- {"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
- static constexpr Attribute kInCircleEdge =
- {"inCircleEdge", kFloat4_GrVertexAttribType, kFloat4_GrSLType};
- static constexpr Attribute kInDashParams =
- {"inDashParams", kFloat4_GrVertexAttribType, kFloat4_GrSLType};
+ Attribute fInPosition;
+ Attribute fInColor;
+ Attribute fInCircleEdge;
+ Attribute fInDashParams;
GR_DECLARE_GEOMETRY_PROCESSOR_TEST
typedef GrGeometryProcessor INHERITED;
};
-constexpr GrPrimitiveProcessor::Attribute ButtCapDashedCircleGeometryProcessor::kInPosition;
-constexpr GrPrimitiveProcessor::Attribute ButtCapDashedCircleGeometryProcessor::kInColor;
-constexpr GrPrimitiveProcessor::Attribute ButtCapDashedCircleGeometryProcessor::kInCircleEdge;
-constexpr GrPrimitiveProcessor::Attribute ButtCapDashedCircleGeometryProcessor::kInDashParams;
#if GR_TEST_UTILS
sk_sp<GrGeometryProcessor> ButtCapDashedCircleGeometryProcessor::TestCreate(GrProcessorTestData* d) {
@@ -533,7 +512,11 @@
EllipseGeometryProcessor(bool stroke, const SkMatrix& localMatrix)
: INHERITED(kEllipseGeometryProcessor_ClassID)
, fLocalMatrix(localMatrix) {
- this->setVertexAttributeCnt(4);
+ fInPosition = {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
+ fInColor = {"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
+ fInEllipseOffset = {"inEllipseOffset", kFloat2_GrVertexAttribType, kHalf2_GrSLType};
+ fInEllipseRadii = {"inEllipseRadii", kFloat4_GrVertexAttribType, kHalf4_GrSLType};
+ this->setVertexAttributes(&fInPosition, 4);
fStroke = stroke;
}
@@ -566,24 +549,24 @@
GrGLSLVarying ellipseOffsets(kHalf2_GrSLType);
varyingHandler->addVarying("EllipseOffsets", &ellipseOffsets);
vertBuilder->codeAppendf("%s = %s;", ellipseOffsets.vsOut(),
- egp.kInEllipseOffset.name());
+ egp.fInEllipseOffset.name());
GrGLSLVarying ellipseRadii(kHalf4_GrSLType);
varyingHandler->addVarying("EllipseRadii", &ellipseRadii);
- vertBuilder->codeAppendf("%s = %s;", ellipseRadii.vsOut(), egp.kInEllipseRadii.name());
+ vertBuilder->codeAppendf("%s = %s;", ellipseRadii.vsOut(), egp.fInEllipseRadii.name());
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
// setup pass through color
- varyingHandler->addPassThroughAttribute(egp.kInColor, args.fOutputColor);
+ varyingHandler->addPassThroughAttribute(egp.fInColor, args.fOutputColor);
// Setup position
- this->writeOutputPosition(vertBuilder, gpArgs, egp.kInPosition.name());
+ this->writeOutputPosition(vertBuilder, gpArgs, egp.fInPosition.name());
// emit transforms
this->emitTransforms(vertBuilder,
varyingHandler,
uniformHandler,
- egp.kInPosition.asShaderVar(),
+ egp.fInPosition.asShaderVar(),
egp.fLocalMatrix,
args.fFPCoordTransformHandler);
// For stroked ellipses, we use the full ellipse equation (x^2/a^2 + y^2/b^2 = 1)
@@ -639,18 +622,10 @@
typedef GrGLSLGeometryProcessor INHERITED;
};
- const Attribute& onVertexAttribute(int i) const override {
- return IthAttribute(i, kInPosition, kInColor, kInEllipseOffset, kInEllipseRadii);
- }
-
- static constexpr Attribute kInPosition =
- {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
- static constexpr Attribute kInColor =
- {"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
- static constexpr Attribute kInEllipseOffset =
- {"inEllipseOffset", kFloat2_GrVertexAttribType, kHalf2_GrSLType};
- static constexpr Attribute kInEllipseRadii =
- {"inEllipseRadii", kFloat4_GrVertexAttribType, kHalf4_GrSLType};
+ Attribute fInPosition;
+ Attribute fInColor;
+ Attribute fInEllipseOffset;
+ Attribute fInEllipseRadii;
SkMatrix fLocalMatrix;
bool fStroke;
@@ -659,10 +634,6 @@
typedef GrGeometryProcessor INHERITED;
};
-constexpr GrPrimitiveProcessor::Attribute EllipseGeometryProcessor::kInPosition;
-constexpr GrPrimitiveProcessor::Attribute EllipseGeometryProcessor::kInColor;
-constexpr GrPrimitiveProcessor::Attribute EllipseGeometryProcessor::kInEllipseOffset;
-constexpr GrPrimitiveProcessor::Attribute EllipseGeometryProcessor::kInEllipseRadii;
GR_DEFINE_GEOMETRY_PROCESSOR_TEST(EllipseGeometryProcessor);
@@ -692,7 +663,11 @@
: INHERITED(kDIEllipseGeometryProcessor_ClassID)
, fViewMatrix(viewMatrix) {
fStyle = style;
- this->setVertexAttributeCnt(4);
+ fInPosition = {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
+ fInColor = {"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
+ fInEllipseOffsets0 = {"inEllipseOffsets0", kFloat2_GrVertexAttribType, kHalf2_GrSLType};
+ fInEllipseOffsets1 = {"inEllipseOffsets1", kFloat2_GrVertexAttribType, kHalf2_GrSLType};
+ this->setVertexAttributes(&fInPosition, 4);
}
~DIEllipseGeometryProcessor() override {}
@@ -723,20 +698,20 @@
GrGLSLVarying offsets0(kHalf2_GrSLType);
varyingHandler->addVarying("EllipseOffsets0", &offsets0);
- vertBuilder->codeAppendf("%s = %s;", offsets0.vsOut(), diegp.kInEllipseOffsets0.name());
+ vertBuilder->codeAppendf("%s = %s;", offsets0.vsOut(), diegp.fInEllipseOffsets0.name());
GrGLSLVarying offsets1(kHalf2_GrSLType);
varyingHandler->addVarying("EllipseOffsets1", &offsets1);
- vertBuilder->codeAppendf("%s = %s;", offsets1.vsOut(), diegp.kInEllipseOffsets1.name());
+ vertBuilder->codeAppendf("%s = %s;", offsets1.vsOut(), diegp.fInEllipseOffsets1.name());
GrGLSLFPFragmentBuilder* fragBuilder = args.fFragBuilder;
- varyingHandler->addPassThroughAttribute(diegp.kInColor, args.fOutputColor);
+ varyingHandler->addPassThroughAttribute(diegp.fInColor, args.fOutputColor);
// Setup position
this->writeOutputPosition(vertBuilder,
uniformHandler,
gpArgs,
- diegp.kInPosition.name(),
+ diegp.fInPosition.name(),
diegp.fViewMatrix,
&fViewMatrixUniform);
@@ -744,7 +719,7 @@
this->emitTransforms(vertBuilder,
varyingHandler,
uniformHandler,
- diegp.kInPosition.asShaderVar(),
+ diegp.fInPosition.asShaderVar(),
args.fFPCoordTransformHandler);
// for outer curve
@@ -815,20 +790,11 @@
typedef GrGLSLGeometryProcessor INHERITED;
};
- const Attribute& onVertexAttribute(int i) const override {
- return IthAttribute(i, kInPosition, kInColor, kInEllipseOffsets0, kInEllipseOffsets1);
- }
- static constexpr Attribute kInPosition =
- {"inPosition", kFloat2_GrVertexAttribType, kFloat2_GrSLType};
- static constexpr Attribute kInColor =
- {"inColor", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
- static constexpr Attribute kInEllipseOffsets0 = {"inEllipseOffsets0",
- kFloat2_GrVertexAttribType,
- kHalf2_GrSLType};
- static constexpr Attribute kInEllipseOffsets1 = {"inEllipseOffsets1",
- kFloat2_GrVertexAttribType,
- kHalf2_GrSLType};
+ Attribute fInPosition;
+ Attribute fInColor;
+ Attribute fInEllipseOffsets0;
+ Attribute fInEllipseOffsets1;
SkMatrix fViewMatrix;
DIEllipseStyle fStyle;
@@ -837,10 +803,6 @@
typedef GrGeometryProcessor INHERITED;
};
-constexpr GrPrimitiveProcessor::Attribute DIEllipseGeometryProcessor::kInPosition;
-constexpr GrPrimitiveProcessor::Attribute DIEllipseGeometryProcessor::kInColor;
-constexpr GrPrimitiveProcessor::Attribute DIEllipseGeometryProcessor::kInEllipseOffsets0;
-constexpr GrPrimitiveProcessor::Attribute DIEllipseGeometryProcessor::kInEllipseOffsets1;
GR_DEFINE_GEOMETRY_PROCESSOR_TEST(DIEllipseGeometryProcessor);
@@ -1179,21 +1141,7 @@
sk_sp<GrGeometryProcessor> gp(new CircleGeometryProcessor(
!fAllFill, fClipPlane, fClipPlaneIsect, fClipPlaneUnion, fRoundCaps, localMatrix));
- struct CircleVertex {
- SkPoint fPos;
- GrColor fColor;
- SkPoint fOffset;
- SkScalar fOuterRadius;
- SkScalar fInnerRadius;
- // These planes may or may not be present in the vertex buffer.
- SkScalar fHalfPlanes[3][3];
- };
-
- size_t vertexStride = sizeof(CircleVertex) - (fClipPlane ? 0 : 3 * sizeof(SkScalar)) -
- (fClipPlaneIsect ? 0 : 3 * sizeof(SkScalar)) -
- (fClipPlaneUnion ? 0 : 3 * sizeof(SkScalar)) +
- (fRoundCaps ? 2 * sizeof(SkPoint) : 0);
- SkASSERT(vertexStride == gp->debugOnly_vertexStride());
+ size_t vertexStride = gp->vertexStride();
const GrBuffer* vertexBuffer;
int firstVertex;
@@ -1553,7 +1501,7 @@
};
static constexpr size_t kVertexStride = sizeof(CircleVertex);
- SkASSERT(kVertexStride == gp->debugOnly_vertexStride());
+ SkASSERT(kVertexStride == gp->vertexStride());
const GrBuffer* vertexBuffer;
int firstVertex;
@@ -1858,7 +1806,7 @@
// Setup geometry processor
sk_sp<GrGeometryProcessor> gp(new EllipseGeometryProcessor(fStroked, localMatrix));
- SkASSERT(sizeof(EllipseVertex) == gp->debugOnly_vertexStride());
+ SkASSERT(sizeof(EllipseVertex) == gp->vertexStride());
QuadHelper helper(target, sizeof(EllipseVertex), fEllipses.count());
EllipseVertex* verts = reinterpret_cast<EllipseVertex*>(helper.vertices());
if (!verts) {
@@ -2093,7 +2041,7 @@
sk_sp<GrGeometryProcessor> gp(
new DIEllipseGeometryProcessor(this->viewMatrix(), this->style()));
- SkASSERT(sizeof(DIEllipseVertex) == gp->debugOnly_vertexStride());
+ SkASSERT(sizeof(DIEllipseVertex) == gp->vertexStride());
QuadHelper helper(target, sizeof(DIEllipseVertex), fEllipses.count());
DIEllipseVertex* verts = reinterpret_cast<DIEllipseVertex*>(helper.vertices());
if (!verts) {
@@ -2510,7 +2458,7 @@
sk_sp<GrGeometryProcessor> gp(
new CircleGeometryProcessor(!fAllFill, false, false, false, false, localMatrix));
- SkASSERT(sizeof(CircleVertex) == gp->debugOnly_vertexStride());
+ SkASSERT(sizeof(CircleVertex) == gp->vertexStride());
const GrBuffer* vertexBuffer;
int firstVertex;
@@ -2800,7 +2748,7 @@
// Setup geometry processor
sk_sp<GrGeometryProcessor> gp(new EllipseGeometryProcessor(fStroked, localMatrix));
- SkASSERT(sizeof(EllipseVertex) == gp->debugOnly_vertexStride());
+ SkASSERT(sizeof(EllipseVertex) == gp->vertexStride());
// drop out the middle quad if we're stroked
int indicesPerInstance = fStroked ? kIndicesPerStrokeRRect : kIndicesPerFillRRect;
diff --git a/src/gpu/ops/GrQuadPerEdgeAA.cpp b/src/gpu/ops/GrQuadPerEdgeAA.cpp
index 2d5c3bb..8a3a1dd 100644
--- a/src/gpu/ops/GrQuadPerEdgeAA.cpp
+++ b/src/gpu/ops/GrQuadPerEdgeAA.cpp
@@ -412,12 +412,6 @@
return fPositions.cpuType() == kFloat3_GrVertexAttribType;
}
-int GrQuadPerEdgeAA::GPAttributes::vertexAttributeCount() const {
- // Always has position, hence 1+
- return (1 + this->hasLocalCoords() + this->hasVertexColors() + this->hasDomain() +
- 4 * this->usesCoverageAA());
-}
-
uint32_t GrQuadPerEdgeAA::GPAttributes::getKey() const {
// aa, color, domain are single bit flags
uint32_t x = this->usesCoverageAA() ? 0 : 1;
diff --git a/src/gpu/ops/GrQuadPerEdgeAA.h b/src/gpu/ops/GrQuadPerEdgeAA.h
index 9a70850..18f6335 100644
--- a/src/gpu/ops/GrQuadPerEdgeAA.h
+++ b/src/gpu/ops/GrQuadPerEdgeAA.h
@@ -72,7 +72,7 @@
// using the localCoords() attribute as the 4th argument; it must set the transform data helper
// to use the identity matrix; it must manage the color space transform for the quad's paint
// color; it should include getKey() in the geometry processor's key builder; and it should
- // return these managed attributes from its onVertexAttribute() function.
+ // add these attributes at construction time.
class GPAttributes {
public:
using Attribute = GrPrimitiveProcessor::Attribute;
@@ -95,7 +95,8 @@
bool needsPerspectiveInterpolation() const;
- int vertexAttributeCount() const;
+ const Attribute* attributes() const { return &fPositions; }
+ int attributeCount() const { return 8; }
uint32_t getKey() const;
diff --git a/src/gpu/ops/GrRegionOp.cpp b/src/gpu/ops/GrRegionOp.cpp
index a7040bf..5268582 100644
--- a/src/gpu/ops/GrRegionOp.cpp
+++ b/src/gpu/ops/GrRegionOp.cpp
@@ -119,8 +119,7 @@
SkDebugf("Couldn't create GrGeometryProcessor\n");
return;
}
- static constexpr size_t kVertexStride = sizeof(GrDefaultGeoProcFactory::PositionColorAttr);
- SkASSERT(kVertexStride == gp->debugOnly_vertexStride());
+ size_t kVertexStride = gp->vertexStride();
int numRegions = fRegions.count();
int numRects = 0;
diff --git a/src/gpu/ops/GrShadowRRectOp.cpp b/src/gpu/ops/GrShadowRRectOp.cpp
index 180d47e..f3444ef 100644
--- a/src/gpu/ops/GrShadowRRectOp.cpp
+++ b/src/gpu/ops/GrShadowRRectOp.cpp
@@ -541,7 +541,7 @@
sk_sp<GrGeometryProcessor> gp = GrRRectShadowGeoProc::Make();
int instanceCount = fGeoData.count();
- SkASSERT(sizeof(CircleVertex) == gp->debugOnly_vertexStride());
+ SkASSERT(sizeof(CircleVertex) == gp->vertexStride());
const GrBuffer* vertexBuffer;
int firstVertex;
diff --git a/src/gpu/ops/GrSmallPathRenderer.cpp b/src/gpu/ops/GrSmallPathRenderer.cpp
index cee4b75..215178c 100644
--- a/src/gpu/ops/GrSmallPathRenderer.cpp
+++ b/src/gpu/ops/GrSmallPathRenderer.cpp
@@ -367,9 +367,7 @@
}
// allocate vertices
- static constexpr size_t kVertexStride =
- sizeof(SkPoint) + sizeof(GrColor) + 2 * sizeof(uint16_t);
- SkASSERT(kVertexStride == flushInfo.fGeometryProcessor->debugOnly_vertexStride());
+ size_t kVertexStride = flushInfo.fGeometryProcessor->vertexStride();
const GrBuffer* vertexBuffer;
diff --git a/src/gpu/ops/GrTessellatingPathRenderer.cpp b/src/gpu/ops/GrTessellatingPathRenderer.cpp
index 342b870..a59c161 100644
--- a/src/gpu/ops/GrTessellatingPathRenderer.cpp
+++ b/src/gpu/ops/GrTessellatingPathRenderer.cpp
@@ -316,12 +316,9 @@
void onPrepareDraws(Target* target) override {
sk_sp<GrGeometryProcessor> gp;
- size_t vertexStride;
{
using namespace GrDefaultGeoProcFactory;
- vertexStride = sizeof(SkPoint); // position
-
Color color(fColor);
LocalCoords::Type localCoordsType = fHelper.usesLocalCoords()
? LocalCoords::kUsePosition_Type
@@ -329,12 +326,10 @@
Coverage::Type coverageType;
if (fAntiAlias) {
color = Color(Color::kPremulGrColorAttribute_Type);
- vertexStride += sizeof(uint32_t);
if (fHelper.compatibleWithAlphaAsCoverage()) {
coverageType = Coverage::kSolid_Type;
} else {
coverageType = Coverage::kAttribute_Type;
- vertexStride += 4;
}
} else {
coverageType = Coverage::kSolid_Type;
@@ -352,7 +347,7 @@
if (!gp.get()) {
return;
}
- SkASSERT(vertexStride == gp->debugOnly_vertexStride());
+ size_t vertexStride = gp->vertexStride();
if (fAntiAlias) {
this->drawAA(target, std::move(gp), vertexStride);
} else {
diff --git a/src/gpu/ops/GrTextureOp.cpp b/src/gpu/ops/GrTextureOp.cpp
index a013d94..d0d6c5f 100644
--- a/src/gpu/ops/GrTextureOp.cpp
+++ b/src/gpu/ops/GrTextureOp.cpp
@@ -125,13 +125,7 @@
, fPaintColorSpaceXform(std::move(paintColorSpaceXform))
, fSampler(textureType, textureConfig, filter) {
this->setTextureSamplerCnt(1);
- this->setVertexAttributeCnt(fAttrs.vertexAttributeCount());
- }
-
- const Attribute& onVertexAttribute(int i) const override {
- return IthInitializedAttribute(i, fAttrs.positions(), fAttrs.colors(), fAttrs.localCoords(),
- fAttrs.domain(), fAttrs.edges(0), fAttrs.edges(1),
- fAttrs.edges(2), fAttrs.edges(3));
+ this->setVertexAttributes(fAttrs.attributes(), fAttrs.attributeCount());
}
const TextureSampler& onTextureSampler(int) const override { return fSampler; }
@@ -412,7 +406,7 @@
int cnt) const {
TRACE_EVENT0("skia", TRACE_FUNC);
using Vertex = GrQuadPerEdgeAA::Vertex<PosDim, GrColor, 2, D, AA>;
- SkASSERT(gp->debugOnly_vertexStride() == sizeof(Vertex));
+ SkASSERT(gp->vertexStride() == sizeof(Vertex));
auto vertices = static_cast<Vertex*>(v);
auto origin = proxy->origin();
const auto* texture = proxy->peekTexture();
@@ -512,7 +506,7 @@
tessFnIdx |= hasPerspective ? 0x4 : 0x0;
size_t vertexSize = kTessFnsAndVertexSizes[tessFnIdx].fVertexSize;
- SkASSERT(vertexSize == gp->debugOnly_vertexStride());
+ SkASSERT(vertexSize == gp->vertexStride());
GrMesh* meshes = target->allocMeshes(numProxies);
const GrBuffer* vbuffer;
diff --git a/src/gpu/vk/GrVkPipeline.cpp b/src/gpu/vk/GrVkPipeline.cpp
index 2675e7a..1a47c85 100644
--- a/src/gpu/vk/GrVkPipeline.cpp
+++ b/src/gpu/vk/GrVkPipeline.cpp
@@ -94,31 +94,27 @@
int vaCount = primProc.numVertexAttributes();
int attribIndex = 0;
size_t vertexAttributeOffset = 0;
- for (; attribIndex < vaCount; attribIndex++) {
- const GrGeometryProcessor::Attribute& attrib = primProc.vertexAttribute(attribIndex);
+ for (const auto& attrib : primProc.vertexAttributes()) {
VkVertexInputAttributeDescription& vkAttrib = attributeDesc[attribIndex];
- vkAttrib.location = attribIndex; // for now assume location = attribIndex
+ vkAttrib.location = attribIndex++; // for now assume location = attribIndex
vkAttrib.binding = vertexBinding;
vkAttrib.format = attrib_type_to_vkformat(attrib.cpuType());
vkAttrib.offset = vertexAttributeOffset;
- SkASSERT(vkAttrib.offset == primProc.debugOnly_vertexAttributeOffset(attribIndex));
vertexAttributeOffset += attrib.sizeAlign4();
}
- SkASSERT(vertexAttributeOffset == primProc.debugOnly_vertexStride());
+ SkASSERT(vertexAttributeOffset == primProc.vertexStride());
int iaCount = primProc.numInstanceAttributes();
size_t instanceAttributeOffset = 0;
- for (int iaIndex = 0; iaIndex < iaCount; ++iaIndex, ++attribIndex) {
- const GrGeometryProcessor::Attribute& attrib = primProc.instanceAttribute(iaIndex);
+ for (const auto& attrib : primProc.instanceAttributes()) {
VkVertexInputAttributeDescription& vkAttrib = attributeDesc[attribIndex];
- vkAttrib.location = attribIndex; // for now assume location = attribIndex
+ vkAttrib.location = attribIndex++; // for now assume location = attribIndex
vkAttrib.binding = instanceBinding;
vkAttrib.format = attrib_type_to_vkformat(attrib.cpuType());
vkAttrib.offset = instanceAttributeOffset;
- SkASSERT(vkAttrib.offset == primProc.debugOnly_instanceAttributeOffset(iaIndex));
instanceAttributeOffset += attrib.sizeAlign4();
}
- SkASSERT(instanceAttributeOffset == primProc.debugOnly_instanceStride());
+ SkASSERT(instanceAttributeOffset == primProc.instanceStride());
if (primProc.hasVertexAttributes()) {
bindingDescs->push_back() = {
diff --git a/tests/GrMeshTest.cpp b/tests/GrMeshTest.cpp
index 163dec6..ec19d16 100644
--- a/tests/GrMeshTest.cpp
+++ b/tests/GrMeshTest.cpp
@@ -295,43 +295,38 @@
: INHERITED(kGrMeshTestProcessor_ClassID) {
if (instanced) {
fInstanceLocation = {"location", kFloat2_GrVertexAttribType, kHalf2_GrSLType};
- fColor = {"color", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
- this->setInstanceAttributeCnt(2);
+ fInstanceColor = {"color", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
+ this->setInstanceAttributes(&fInstanceLocation, 2);
if (hasVertexBuffer) {
- fVertex = {"vertex", kFloat2_GrVertexAttribType, kHalf2_GrSLType};
- this->setVertexAttributeCnt(1);
+ fVertexPosition = {"vertex", kFloat2_GrVertexAttribType, kHalf2_GrSLType};
+ this->setVertexAttributes(&fVertexPosition, 1);
}
} else {
- fVertex = {"vertex", kFloat2_GrVertexAttribType, kHalf2_GrSLType};
- fColor = {"color", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
- this->setVertexAttributeCnt(2);
+ fVertexPosition = {"vertex", kFloat2_GrVertexAttribType, kHalf2_GrSLType};
+ fVertexColor = {"color", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
+ this->setVertexAttributes(&fVertexPosition, 2);
}
}
const char* name() const override { return "GrMeshTest Processor"; }
+ const Attribute& inColor() const {
+ return fVertexColor.isInitialized() ? fVertexColor : fInstanceColor;
+ }
+
void getGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder* b) const final {
b->add32(fInstanceLocation.isInitialized());
- b->add32(fVertex.isInitialized());
+ b->add32(fVertexPosition.isInitialized());
}
GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const final;
private:
- const Attribute& onVertexAttribute(int i) const override {
- if (fInstanceLocation.isInitialized()) {
- return fVertex;
- }
- return IthAttribute(i, fVertex, fColor);
- }
-
- const Attribute& onInstanceAttribute(int i) const override {
- return IthAttribute(i, fInstanceLocation, fColor);
- }
+ Attribute fVertexPosition;
+ Attribute fVertexColor;
Attribute fInstanceLocation;
- Attribute fVertex;
- Attribute fColor;
+ Attribute fInstanceColor;
friend class GLSLMeshTestProcessor;
typedef GrGeometryProcessor INHERITED;
@@ -346,14 +341,14 @@
GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
varyingHandler->emitAttributes(mp);
- varyingHandler->addPassThroughAttribute(mp.fColor, args.fOutputColor);
+ varyingHandler->addPassThroughAttribute(mp.inColor(), args.fOutputColor);
GrGLSLVertexBuilder* v = args.fVertBuilder;
if (!mp.fInstanceLocation.isInitialized()) {
- v->codeAppendf("float2 vertex = %s;", mp.fVertex.name());
+ v->codeAppendf("float2 vertex = %s;", mp.fVertexPosition.name());
} else {
- if (mp.fVertex.isInitialized()) {
- v->codeAppendf("float2 offset = %s;", mp.fVertex.name());
+ if (mp.fVertexPosition.isInitialized()) {
+ v->codeAppendf("float2 offset = %s;", mp.fVertexPosition.name());
} else {
v->codeAppend ("float2 offset = float2(sk_VertexID / 2, sk_VertexID % 2);");
}
diff --git a/tests/GrPipelineDynamicStateTest.cpp b/tests/GrPipelineDynamicStateTest.cpp
index 6691afc..cae0b2b 100644
--- a/tests/GrPipelineDynamicStateTest.cpp
+++ b/tests/GrPipelineDynamicStateTest.cpp
@@ -57,7 +57,7 @@
public:
GrPipelineDynamicStateTestProcessor()
: INHERITED(kGrPipelineDynamicStateTestProcessor_ClassID) {
- this->setVertexAttributeCnt(2);
+ this->setVertexAttributes(kAttributes, SK_ARRAY_COUNT(kAttributes));
}
const char* name() const override { return "GrPipelineDynamicStateTest Processor"; }
@@ -66,21 +66,19 @@
GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const final;
-private:
- const Attribute& onVertexAttribute(int i) const override {
- return IthAttribute(i, kVertex, kColor);
- }
+ const Attribute& inVertex() const { return kAttributes[0]; }
+ const Attribute& inColor() const { return kAttributes[1]; }
- static constexpr Attribute kVertex =
- {"vertex", kFloat2_GrVertexAttribType, kHalf2_GrSLType};
- static constexpr Attribute kColor =
- {"color", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType};
+private:
+ static constexpr Attribute kAttributes[] = {
+ {"vertex", kFloat2_GrVertexAttribType, kHalf2_GrSLType},
+ {"color", kUByte4_norm_GrVertexAttribType, kHalf4_GrSLType},
+ };
friend class GLSLPipelineDynamicStateTestProcessor;
typedef GrGeometryProcessor INHERITED;
};
-constexpr GrPrimitiveProcessor::Attribute GrPipelineDynamicStateTestProcessor::kVertex;
-constexpr GrPrimitiveProcessor::Attribute GrPipelineDynamicStateTestProcessor::kColor;
+constexpr GrPrimitiveProcessor::Attribute GrPipelineDynamicStateTestProcessor::kAttributes[];
class GLSLPipelineDynamicStateTestProcessor : public GrGLSLGeometryProcessor {
void setData(const GrGLSLProgramDataManager& pdman, const GrPrimitiveProcessor&,
@@ -92,10 +90,10 @@
GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
varyingHandler->emitAttributes(mp);
- varyingHandler->addPassThroughAttribute(mp.kColor, args.fOutputColor);
+ varyingHandler->addPassThroughAttribute(mp.inColor(), args.fOutputColor);
GrGLSLVertexBuilder* v = args.fVertBuilder;
- v->codeAppendf("float2 vertex = %s;", mp.kVertex.name());
+ v->codeAppendf("float2 vertex = %s;", mp.inVertex().name());
gpArgs->fPositionVar.set(kFloat2_GrSLType, "vertex");
GrGLSLFPFragmentBuilder* f = args.fFragBuilder;
diff --git a/tests/OnFlushCallbackTest.cpp b/tests/OnFlushCallbackTest.cpp
index 3744b96..ac9805e 100644
--- a/tests/OnFlushCallbackTest.cpp
+++ b/tests/OnFlushCallbackTest.cpp
@@ -108,10 +108,7 @@
return;
}
- size_t vertexStride = fHasLocalRect
- ? sizeof(GrDefaultGeoProcFactory::PositionColorLocalCoordAttr)
- : sizeof(GrDefaultGeoProcFactory::PositionColorAttr);
- SkASSERT(vertexStride == gp->debugOnly_vertexStride());
+ size_t vertexStride = gp->vertexStride();
const GrBuffer* indexBuffer;
int firstIndex;
diff --git a/tests/PrimitiveProcessorTest.cpp b/tests/PrimitiveProcessorTest.cpp
index 39cd435..dea8d5c 100644
--- a/tests/PrimitiveProcessorTest.cpp
+++ b/tests/PrimitiveProcessorTest.cpp
@@ -65,7 +65,7 @@
fAttributes[i] = {fAttribNames[i].c_str(), kFloat2_GrVertexAttribType,
kFloat2_GrSLType};
}
- this->setVertexAttributeCnt(numAttribs);
+ this->setVertexAttributes(fAttributes.get(), numAttribs);
}
const char* name() const override { return "Dummy GP"; }
@@ -93,10 +93,6 @@
}
private:
- const GrPrimitiveProcessor::Attribute& onVertexAttribute(int i) const override {
- return fAttributes[i];
- }
-
int fNumAttribs;
std::unique_ptr<SkString[]> fAttribNames;
std::unique_ptr<Attribute[]> fAttributes;
@@ -104,8 +100,7 @@
typedef GrGeometryProcessor INHERITED;
};
sk_sp<GrGeometryProcessor> gp(new GP(fNumAttribs));
- size_t vertexStride = fNumAttribs * GrVertexAttribTypeSize(kFloat2_GrVertexAttribType);
- SkASSERT(vertexStride == gp->debugOnly_vertexStride());
+ size_t vertexStride = gp->vertexStride();
QuadHelper helper(target, vertexStride, 1);
SkPoint* vertices = reinterpret_cast<SkPoint*>(helper.vertices());
SkPointPriv::SetRectTriStrip(vertices, 0.f, 0.f, 1.f, 1.f, vertexStride);