aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/ccpr
diff options
context:
space:
mode:
authorGravatar Mike Klein <mtklein@google.com>2018-06-19 01:40:57 +0000
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-06-19 01:41:10 +0000
commit5045e501d2aec23e5f1e4b46346033ac3202c6b0 (patch)
treeb0179c300d6bc1822b0d945be812fff267bb414a /src/gpu/ccpr
parent63b3bfb711d7e3d4f9ad75681d77a69a3c454ab0 (diff)
Revert "Change how vertex/instance attributes are handled in geometry processors."
This reverts commit 19c1233c447f625c2522e7ecd0a0adecc629bb2f. Reason for revert: want to make sure Google3 can roll Original change's description: > Change how vertex/instance attributes are handled in geometry processors. > > * No longer register vertex/instance attributes on base class, just counts > > * Separate instance and vertex attributes and remove InputRate and offset > > * Make attributes constexpr where possible > > Change-Id: I1f1d5e772fa177a96d2aeb805aab7b69f35bfae6 > Reviewed-on: https://skia-review.googlesource.com/132405 > Commit-Queue: Brian Salomon <bsalomon@google.com> > Reviewed-by: Chris Dalton <csmartdalton@google.com> TBR=egdaniel@google.com,bsalomon@google.com,csmartdalton@google.com Change-Id: I4800632515e14fbf54af52826928ac915657b59f No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://skia-review.googlesource.com/135661 Reviewed-by: Mike Klein <mtklein@google.com> Commit-Queue: Mike Klein <mtklein@google.com>
Diffstat (limited to 'src/gpu/ccpr')
-rw-r--r--src/gpu/ccpr/GrCCCoverageProcessor.h10
-rw-r--r--src/gpu/ccpr/GrCCCoverageProcessor_GSImpl.cpp24
-rw-r--r--src/gpu/ccpr/GrCCCoverageProcessor_VSImpl.cpp68
-rw-r--r--src/gpu/ccpr/GrCCPathProcessor.cpp36
-rw-r--r--src/gpu/ccpr/GrCCPathProcessor.h23
5 files changed, 74 insertions, 87 deletions
diff --git a/src/gpu/ccpr/GrCCCoverageProcessor.h b/src/gpu/ccpr/GrCCCoverageProcessor.h
index 89890486d3..e3ea34f8dd 100644
--- a/src/gpu/ccpr/GrCCCoverageProcessor.h
+++ b/src/gpu/ccpr/GrCCCoverageProcessor.h
@@ -246,13 +246,6 @@ private:
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,
@@ -260,8 +253,6 @@ private:
GrGLSLPrimitiveProcessor* createGSImpl(std::unique_ptr<Shader>) const;
GrGLSLPrimitiveProcessor* createVSImpl(std::unique_ptr<Shader>) const;
- // The type and meaning of this attribute depends on whether we're using VSImpl or GSImpl.
- Attribute fVertexAttribute;
const PrimitiveType fPrimitiveType;
const Impl fImpl;
@@ -271,7 +262,6 @@ private:
const GSSubpass fGSSubpass = GSSubpass::kHulls;
// Used by VSImpl.
- Attribute fInstanceAttributes[2];
sk_sp<const GrBuffer> fVSVertexBuffer;
sk_sp<const GrBuffer> fVSIndexBuffer;
int fVSNumIndicesPerInstance;
diff --git a/src/gpu/ccpr/GrCCCoverageProcessor_GSImpl.cpp b/src/gpu/ccpr/GrCCCoverageProcessor_GSImpl.cpp
index 8134fbe89b..aa7a8db8a5 100644
--- a/src/gpu/ccpr/GrCCCoverageProcessor_GSImpl.cpp
+++ b/src/gpu/ccpr/GrCCCoverageProcessor_GSImpl.cpp
@@ -31,8 +31,9 @@ protected:
const GrCCCoverageProcessor& proc = args.fGP.cast<GrCCCoverageProcessor>();
// The vertex shader simply forwards transposed x or y values to the geometry shader.
- SkASSERT(1 == proc.numVertexAttributes());
- gpArgs->fPositionVar = proc.fVertexAttribute.asShaderVar();
+ SkASSERT(1 == proc.numAttribs());
+ gpArgs->fPositionVar.set(GrVertexAttribTypeToSLType(proc.getAttrib(0).type()),
+ proc.getAttrib(0).name());
// Geometry shader.
GrGLSLVaryingHandler* varyingHandler = args.fVaryingHandler;
@@ -61,7 +62,7 @@ protected:
Shader::CalcWind(proc, g, "pts", wind.c_str());
if (PrimitiveType::kWeightedTriangles == proc.fPrimitiveType) {
SkASSERT(3 == numInputPoints);
- SkASSERT(kFloat4_GrVertexAttribType == proc.fVertexAttribute.type());
+ SkASSERT(kFloat4_GrVertexAttribType == proc.getAttrib(0).type());
g->codeAppendf("%s *= sk_in[0].sk_Position.w;", wind.c_str());
}
@@ -381,19 +382,14 @@ public:
void GrCCCoverageProcessor::initGS() {
SkASSERT(Impl::kGeometryShader == fImpl);
if (4 == this->numInputPoints() || this->hasInputWeight()) {
- fVertexAttribute = {"x_or_y_values", kFloat4_GrVertexAttribType};
- GR_STATIC_ASSERT(sizeof(QuadPointInstance) ==
- 2 * GrVertexAttribTypeSize(kFloat4_GrVertexAttribType));
- GR_STATIC_ASSERT(offsetof(QuadPointInstance, fY) ==
- GrVertexAttribTypeSize(kFloat4_GrVertexAttribType));
+ this->addVertexAttrib("x_or_y_values", kFloat4_GrVertexAttribType);
+ SkASSERT(sizeof(QuadPointInstance) == this->getVertexStride() * 2);
+ SkASSERT(offsetof(QuadPointInstance, fY) == this->getVertexStride());
} else {
- fVertexAttribute = {"x_or_y_values", kFloat3_GrVertexAttribType};
- GR_STATIC_ASSERT(sizeof(TriPointInstance) ==
- 2 * GrVertexAttribTypeSize(kFloat3_GrVertexAttribType));
- GR_STATIC_ASSERT(offsetof(TriPointInstance, fY) ==
- GrVertexAttribTypeSize(kFloat3_GrVertexAttribType));
+ this->addVertexAttrib("x_or_y_values", kFloat3_GrVertexAttribType);
+ SkASSERT(sizeof(TriPointInstance) == this->getVertexStride() * 2);
+ SkASSERT(offsetof(TriPointInstance, fY) == this->getVertexStride());
}
- this->setVertexAttributeCnt(1);
this->setWillUseGeoShader();
}
diff --git a/src/gpu/ccpr/GrCCCoverageProcessor_VSImpl.cpp b/src/gpu/ccpr/GrCCCoverageProcessor_VSImpl.cpp
index 5c5120cf45..3c9fe89fbc 100644
--- a/src/gpu/ccpr/GrCCCoverageProcessor_VSImpl.cpp
+++ b/src/gpu/ccpr/GrCCCoverageProcessor_VSImpl.cpp
@@ -28,8 +28,9 @@ private:
const int fNumSides;
};
-static constexpr int kInstanceAttribIdx_X = 0; // Transposed X values of all input points.
-static constexpr int kInstanceAttribIdx_Y = 1; // Transposed Y values of all input points.
+static constexpr int kAttribIdx_X = 0; // Transposed X values of all input points.
+static constexpr int kAttribIdx_Y = 1; // Transposed Y values of all input points.
+static constexpr int kAttribIdx_VertexData = 2;
// Vertex data tells the shader how to offset vertices for conservative raster, as well as how to
// calculate coverage values for corners and edges.
@@ -259,16 +260,15 @@ void GrCCCoverageProcessor::VSImpl::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs)
int inputWidth = (4 == numInputPoints || proc.hasInputWeight()) ? 4 : 3;
const char* swizzle = (4 == inputWidth) ? "xyzw" : "xyz";
v->codeAppendf("float%ix2 pts = transpose(float2x%i(%s.%s, %s.%s));", inputWidth, inputWidth,
- proc.fInstanceAttributes[kInstanceAttribIdx_X].name(), swizzle,
- proc.fInstanceAttributes[kInstanceAttribIdx_Y].name(), swizzle);
+ proc.getAttrib(kAttribIdx_X).name(), swizzle,
+ proc.getAttrib(kAttribIdx_Y).name(), swizzle);
v->codeAppend ("half wind;");
Shader::CalcWind(proc, v, "pts", "wind");
if (PrimitiveType::kWeightedTriangles == proc.fPrimitiveType) {
SkASSERT(3 == numInputPoints);
- SkASSERT(kFloat4_GrVertexAttribType ==
- proc.fInstanceAttributes[kInstanceAttribIdx_X].type());
- v->codeAppendf("wind *= %s.w;", proc.fInstanceAttributes[kInstanceAttribIdx_X].name());
+ SkASSERT(kFloat4_GrVertexAttribType == proc.getAttrib(kAttribIdx_X).type());
+ v->codeAppendf("wind *= %s.w;", proc.getAttrib(kAttribIdx_X).name());
}
float bloat = kAABloatRadius;
@@ -284,12 +284,12 @@ void GrCCCoverageProcessor::VSImpl::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs)
// Reverse all indices if the wind is counter-clockwise: [0, 1, 2] -> [2, 1, 0].
v->codeAppendf("int clockwise_indices = wind > 0 ? %s : 0x%x - %s;",
- proc.fVertexAttribute.name(),
+ proc.getAttrib(kAttribIdx_VertexData).name(),
((fNumSides - 1) << kVertexData_LeftNeighborIdShift) |
((fNumSides - 1) << kVertexData_RightNeighborIdShift) |
(((1 << kVertexData_RightNeighborIdShift) - 1) ^ 3) |
(fNumSides - 1),
- proc.fVertexAttribute.name());
+ proc.getAttrib(kAttribIdx_VertexData).name());
// Here we generate conservative raster geometry for the input polygon. It is the convex
// hull of N pixel-size boxes, one centered on each the input points. Each corner has three
@@ -322,7 +322,7 @@ void GrCCCoverageProcessor::VSImpl::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs)
v->codeAppend ("rightdir = (float2(0) != rightdir) ? normalize(rightdir) : float2(1, 0);");
v->codeAppendf("if (0 != (%s & %i)) {", // Are we a corner?
- proc.fVertexAttribute.name(), kVertexData_IsCornerBit);
+ proc.getAttrib(kAttribIdx_VertexData).name(), kVertexData_IsCornerBit);
// In corner boxes, all 4 coverage values will not map linearly.
// Therefore it is important to align the box so its diagonal shared
@@ -341,7 +341,7 @@ void GrCCCoverageProcessor::VSImpl::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs)
// continue rotating 90 degrees clockwise until we reach the desired raster vertex for this
// invocation. Corners with less than 3 corresponding raster vertices will result in
// redundant vertices and degenerate triangles.
- v->codeAppendf("int bloatidx = (%s >> %i) & 3;", proc.fVertexAttribute.name(),
+ v->codeAppendf("int bloatidx = (%s >> %i) & 3;", proc.getAttrib(kAttribIdx_VertexData).name(),
kVertexData_BloatIdxShift);
v->codeAppend ("switch (bloatidx) {");
v->codeAppend ( "case 3:");
@@ -376,12 +376,12 @@ void GrCCCoverageProcessor::VSImpl::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs)
v->codeAppend ("}");
v->codeAppendf("if (0 != (%s & %i)) {", // Are we an edge?
- proc.fVertexAttribute.name(), kVertexData_IsEdgeBit);
+ proc.getAttrib(kAttribIdx_VertexData).name(), kVertexData_IsEdgeBit);
v->codeAppend ( "coverage = left_coverage;");
v->codeAppend ("}");
v->codeAppendf("if (0 != (%s & %i)) {", // Invert coverage?
- proc.fVertexAttribute.name(),
+ proc.getAttrib(kAttribIdx_VertexData).name(),
kVertexData_InvertNegativeCoverageBit);
v->codeAppend ( "coverage = -1 - coverage;");
v->codeAppend ("}");
@@ -391,7 +391,7 @@ void GrCCCoverageProcessor::VSImpl::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs)
v->codeAppend ("half2 corner_coverage = half2(0);");
v->codeAppendf("if (0 != (%s & %i)) {", // Are we a corner?
- proc.fVertexAttribute.name(), kVertexData_IsCornerBit);
+ proc.getAttrib(kAttribIdx_VertexData).name(), kVertexData_IsCornerBit);
// We use coverage=-1 to erase what the hull geometry wrote.
//
// In the context of curves, this effectively means "wind = -wind" and
@@ -495,27 +495,31 @@ void GrCCCoverageProcessor::initVS(GrResourceProvider* rp) {
}
}
- GrVertexAttribType xyAttribType;
if (4 == this->numInputPoints() || this->hasInputWeight()) {
- GR_STATIC_ASSERT(offsetof(QuadPointInstance, fX) == 0);
- GR_STATIC_ASSERT(sizeof(QuadPointInstance::fX) ==
- GrVertexAttribTypeSize(kFloat4_GrVertexAttribType));
- GR_STATIC_ASSERT(sizeof(QuadPointInstance::fY) ==
- GrVertexAttribTypeSize(kFloat4_GrVertexAttribType));
- xyAttribType = kFloat4_GrVertexAttribType;
+ SkASSERT(kAttribIdx_X == this->numAttribs());
+ this->addInstanceAttrib("X", kFloat4_GrVertexAttribType);
+
+ SkASSERT(kAttribIdx_Y == this->numAttribs());
+ this->addInstanceAttrib("Y", kFloat4_GrVertexAttribType);
+
+ SkASSERT(offsetof(QuadPointInstance, fX) == this->getAttrib(kAttribIdx_X).offsetInRecord());
+ SkASSERT(offsetof(QuadPointInstance, fY) == this->getAttrib(kAttribIdx_Y).offsetInRecord());
+ SkASSERT(sizeof(QuadPointInstance) == this->getInstanceStride());
} else {
- GR_STATIC_ASSERT(offsetof(TriPointInstance, fX) == 0);
- GR_STATIC_ASSERT(sizeof(TriPointInstance::fX) ==
- GrVertexAttribTypeSize(kFloat3_GrVertexAttribType));
- GR_STATIC_ASSERT(sizeof(TriPointInstance::fY) ==
- GrVertexAttribTypeSize(kFloat3_GrVertexAttribType));
- xyAttribType = kFloat3_GrVertexAttribType;
+ SkASSERT(kAttribIdx_X == this->numAttribs());
+ this->addInstanceAttrib("X", kFloat3_GrVertexAttribType);
+
+ SkASSERT(kAttribIdx_Y == this->numAttribs());
+ this->addInstanceAttrib("Y", kFloat3_GrVertexAttribType);
+
+ SkASSERT(offsetof(TriPointInstance, fX) == this->getAttrib(kAttribIdx_X).offsetInRecord());
+ SkASSERT(offsetof(TriPointInstance, fY) == this->getAttrib(kAttribIdx_Y).offsetInRecord());
+ SkASSERT(sizeof(TriPointInstance) == this->getInstanceStride());
}
- fInstanceAttributes[kInstanceAttribIdx_X] = {"X", xyAttribType};
- fInstanceAttributes[kInstanceAttribIdx_Y] = {"Y", xyAttribType};
- this->setInstanceAttributeCnt(2);
- fVertexAttribute = {"vertexdata", kInt_GrVertexAttribType};
- this->setVertexAttributeCnt(1);
+
+ SkASSERT(kAttribIdx_VertexData == this->numAttribs());
+ this->addVertexAttrib("vertexdata", kInt_GrVertexAttribType);
+ SkASSERT(sizeof(int32_t) == this->getVertexStride());
if (caps.usePrimitiveRestart()) {
fVSTriangleType = GrPrimitiveType::kTriangleStrip;
diff --git a/src/gpu/ccpr/GrCCPathProcessor.cpp b/src/gpu/ccpr/GrCCPathProcessor.cpp
index e180724f8a..b8ebb44059 100644
--- a/src/gpu/ccpr/GrCCPathProcessor.cpp
+++ b/src/gpu/ccpr/GrCCPathProcessor.cpp
@@ -65,9 +65,6 @@ static constexpr uint16_t kOctoIndicesAsTris[] = {
GR_DECLARE_STATIC_UNIQUE_KEY(gIndexBufferKey);
-constexpr GrPrimitiveProcessor::Attribute GrCCPathProcessor::kInstanceAttribs[];
-constexpr GrPrimitiveProcessor::Attribute GrCCPathProcessor::kEdgeNormsAttrib;
-
sk_sp<const GrBuffer> GrCCPathProcessor::FindIndexBuffer(GrOnFlushResourceProvider* onFlushRP) {
GR_DEFINE_STATIC_UNIQUE_KEY(gIndexBufferKey);
if (onFlushRP->caps()->usePrimitiveRestart()) {
@@ -85,19 +82,24 @@ GrCCPathProcessor::GrCCPathProcessor(GrResourceProvider* resourceProvider,
: INHERITED(kGrCCPathProcessor_ClassID)
, fAtlasAccess(std::move(atlas), GrSamplerState::Filter::kNearest,
GrSamplerState::WrapMode::kClamp, kFragment_GrShaderFlag) {
- 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->setVertexAttributeCnt(1);
+ this->addInstanceAttrib("devbounds", kFloat4_GrVertexAttribType);
+ this->addInstanceAttrib("devbounds45", kFloat4_GrVertexAttribType);
+ this->addInstanceAttrib("dev_to_atlas_offset", kInt2_GrVertexAttribType);
+ this->addInstanceAttrib("color", kUByte4_norm_GrVertexAttribType);
+
+ SkASSERT(offsetof(Instance, fDevBounds) ==
+ this->getInstanceAttrib(InstanceAttribs::kDevBounds).offsetInRecord());
+ SkASSERT(offsetof(Instance, fDevBounds45) ==
+ this->getInstanceAttrib(InstanceAttribs::kDevBounds45).offsetInRecord());
+ SkASSERT(offsetof(Instance, fDevToAtlasOffset) ==
+ this->getInstanceAttrib(InstanceAttribs::kDevToAtlasOffset).offsetInRecord());
+ SkASSERT(offsetof(Instance, fColor) ==
+ this->getInstanceAttrib(InstanceAttribs::kColor).offsetInRecord());
+ SkASSERT(sizeof(Instance) == this->getInstanceStride());
+
+ GR_STATIC_ASSERT(4 == kNumInstanceAttribs);
+
+ this->addVertexAttrib("edge_norms", kFloat4_GrVertexAttribType);
fAtlasAccess.instantiate(resourceProvider);
this->addTextureSampler(&fAtlasAccess);
@@ -168,7 +170,7 @@ void GLSLPathProcessor::onEmitCode(EmitArgs& args, GrGPArgs* gpArgs) {
GrGLSLVarying texcoord(kFloat3_GrSLType);
GrGLSLVarying color(kHalf4_GrSLType);
varyingHandler->addVarying("texcoord", &texcoord);
- varyingHandler->addPassThroughAttribute(proc.getInstanceAttrib(InstanceAttribs::kColor),
+ varyingHandler->addPassThroughAttribute(&proc.getInstanceAttrib(InstanceAttribs::kColor),
args.fOutputColor, Interpolation::kCanBeFlat);
// The vertex shader bloats and intersects the devBounds and devBounds45 rectangles, in order to
diff --git a/src/gpu/ccpr/GrCCPathProcessor.h b/src/gpu/ccpr/GrCCPathProcessor.h
index 54c1b7e2ed..785dd2c919 100644
--- a/src/gpu/ccpr/GrCCPathProcessor.h
+++ b/src/gpu/ccpr/GrCCPathProcessor.h
@@ -77,11 +77,16 @@ public:
const GrTexture* atlas() const { return fAtlasAccess.peekTexture(); }
const SkMatrix& localMatrix() const { return fLocalMatrix; }
const Attribute& getInstanceAttrib(InstanceAttribs attribID) const {
- int idx = static_cast<int>(attribID);
- SkASSERT(idx >= 0 && idx < static_cast<int>(SK_ARRAY_COUNT(kInstanceAttribs)));
- return kInstanceAttribs[idx];
+ const Attribute& attrib = this->getAttrib((int)attribID);
+ SkASSERT(Attribute::InputRate::kPerInstance == attrib.inputRate());
+ return attrib;
+ }
+ const Attribute& getEdgeNormsAttrib() const {
+ SkASSERT(1 + kNumInstanceAttribs == this->numAttribs());
+ const Attribute& attrib = this->getAttrib(kNumInstanceAttribs);
+ SkASSERT(Attribute::InputRate::kPerVertex == attrib.inputRate());
+ return attrib;
}
- const Attribute& getEdgeNormsAttrib() const { return kEdgeNormsAttrib; }
void getGLSLProcessorKey(const GrShaderCaps&, GrProcessorKeyBuilder*) const override {}
GrGLSLPrimitiveProcessor* createGLSLInstance(const GrShaderCaps&) const override;
@@ -90,18 +95,8 @@ public:
int baseInstance, int endInstance, 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 fAtlasAccess;
SkMatrix fLocalMatrix;
- static constexpr Attribute kInstanceAttribs[kNumInstanceAttribs] = {
- {"devbounds", kFloat4_GrVertexAttribType},
- {"devbounds45", kFloat4_GrVertexAttribType},
- {"dev_to_atlas_offset", kInt2_GrVertexAttribType},
- {"color", kUByte4_norm_GrVertexAttribType}
- };
- static constexpr Attribute kEdgeNormsAttrib = {"edge_norms", kFloat4_GrVertexAttribType};
typedef GrGeometryProcessor INHERITED;
};