aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu/ops/GrTextureOp.cpp
diff options
context:
space:
mode:
authorGravatar Brian Salomon <bsalomon@google.com>2018-06-19 14:33:47 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-06-19 20:01:29 +0000
commit92be2f74db81f0ed480b55c58cbde39270f9b772 (patch)
treed2b7135f511a318f10c5c86f2537c07051c922bd /src/gpu/ops/GrTextureOp.cpp
parentf5ac906476cd26f2967a48340940e6af580fa71f (diff)
Revert "Revert "Change how vertex/instance attributes are handled in geometry processors.""
This reverts commit 5045e501d2aec23e5f1e4b46346033ac3202c6b0. TBR=csmartdalton@google.com Change-Id: Ifbf5f1d8f8ef340fdc69653e931b6d68d4bf0854 Reviewed-on: https://skia-review.googlesource.com/135862 Reviewed-by: Brian Salomon <bsalomon@google.com> Commit-Queue: Brian Salomon <bsalomon@google.com>
Diffstat (limited to 'src/gpu/ops/GrTextureOp.cpp')
-rw-r--r--src/gpu/ops/GrTextureOp.cpp112
1 files changed, 66 insertions, 46 deletions
diff --git a/src/gpu/ops/GrTextureOp.cpp b/src/gpu/ops/GrTextureOp.cpp
index e06d94f806..a895230241 100644
--- a/src/gpu/ops/GrTextureOp.cpp
+++ b/src/gpu/ops/GrTextureOp.cpp
@@ -163,16 +163,14 @@ public:
args.fUniformHandler,
textureGP.fTextureCoords.asShaderVar(),
args.fFPCoordTransformHandler);
- args.fVaryingHandler->addPassThroughAttribute(&textureGP.fColors,
- args.fOutputColor,
- Interpolation::kCanBeFlat);
+ args.fVaryingHandler->addPassThroughAttribute(
+ textureGP.fColors, args.fOutputColor, Interpolation::kCanBeFlat);
args.fFragBuilder->codeAppend("float2 texCoord;");
- args.fVaryingHandler->addPassThroughAttribute(&textureGP.fTextureCoords,
- "texCoord");
+ args.fVaryingHandler->addPassThroughAttribute(textureGP.fTextureCoords, "texCoord");
if (textureGP.fDomain.isInitialized()) {
args.fFragBuilder->codeAppend("float4 domain;");
args.fVaryingHandler->addPassThroughAttribute(
- &textureGP.fDomain, "domain",
+ textureGP.fDomain, "domain",
GrGLSLVaryingHandler::Interpolation::kCanBeFlat);
args.fFragBuilder->codeAppend(
"texCoord = clamp(texCoord, domain.xy, domain.zw);");
@@ -182,7 +180,7 @@ public:
SkASSERT(kInt_GrVertexAttribType == textureGP.fTextureIdx.type());
SkASSERT(args.fShaderCaps->integerSupport());
args.fFragBuilder->codeAppend("int texIdx;");
- args.fVaryingHandler->addPassThroughAttribute(&textureGP.fTextureIdx, "texIdx",
+ args.fVaryingHandler->addPassThroughAttribute(textureGP.fTextureIdx, "texIdx",
Interpolation::kMustBeFlat);
args.fFragBuilder->codeAppend("switch (texIdx) {");
for (int i = 0; i < textureGP.numTextureSamplers(); ++i) {
@@ -316,12 +314,13 @@ private:
}
if (perspective) {
- fPositions = this->addVertexAttrib("position", kFloat3_GrVertexAttribType);
+ fPositions = {"position", kFloat3_GrVertexAttribType};
} else {
- fPositions = this->addVertexAttrib("position", kFloat2_GrVertexAttribType);
+ fPositions = {"position", kFloat2_GrVertexAttribType};
}
- fColors = this->addVertexAttrib("color", kUByte4_norm_GrVertexAttribType);
- fTextureCoords = this->addVertexAttrib("textureCoords", kFloat2_GrVertexAttribType);
+ fColors = {"color", kUByte4_norm_GrVertexAttribType};
+ fTextureCoords = {"textureCoords", kFloat2_GrVertexAttribType};
+ int vertexAttributeCnt = 3;
if (samplerCnt > 1) {
// Here we initialize any extra samplers by repeating the last one samplerCnt - proxyCnt
@@ -332,17 +331,26 @@ private:
this->addTextureSampler(&fSamplers[i]);
}
SkASSERT(caps.integerSupport());
- fTextureIdx = this->addVertexAttrib("textureIdx", kInt_GrVertexAttribType);
+ fTextureIdx = {"textureIdx", kInt_GrVertexAttribType};
+ ++vertexAttributeCnt;
}
if (domain == Domain::kYes) {
- fDomain = this->addVertexAttrib("domain", kFloat4_GrVertexAttribType);
+ fDomain = {"domain", kFloat4_GrVertexAttribType};
+ ++vertexAttributeCnt;
}
if (coverageAA) {
- fAAEdges[0] = this->addVertexAttrib("aaEdge0", kFloat3_GrVertexAttribType);
- fAAEdges[1] = this->addVertexAttrib("aaEdge1", kFloat3_GrVertexAttribType);
- fAAEdges[2] = this->addVertexAttrib("aaEdge2", kFloat3_GrVertexAttribType);
- fAAEdges[3] = this->addVertexAttrib("aaEdge3", kFloat3_GrVertexAttribType);
+ fAAEdges[0] = {"aaEdge0", kFloat3_GrVertexAttribType};
+ fAAEdges[1] = {"aaEdge1", kFloat3_GrVertexAttribType};
+ fAAEdges[2] = {"aaEdge2", kFloat3_GrVertexAttribType};
+ fAAEdges[3] = {"aaEdge3", kFloat3_GrVertexAttribType};
+ vertexAttributeCnt += 4;
}
+ this->setVertexAttributeCnt(vertexAttributeCnt);
+ }
+
+ const Attribute& onVertexAttribute(int i) const override {
+ return IthInitializedAttribute(i, fPositions, fColors, fTextureCoords, fTextureIdx, fDomain,
+ fAAEdges[0], fAAEdges[1], fAAEdges[2], fAAEdges[3]);
}
Attribute fPositions;
@@ -746,7 +754,7 @@ __attribute__((no_sanitize("float-cast-overflow")))
template <typename Pos, MultiTexture MT, Domain D, GrAA AA>
void tess(void* v, const float iw[], const float ih[], const GrGeometryProcessor* gp) {
using Vertex = TextureGeometryProcessor::Vertex<Pos, MT, D, AA>;
- SkASSERT(gp->getVertexStride() == sizeof(Vertex));
+ SkASSERT(gp->debugOnly_vertexStride() == sizeof(Vertex));
auto vertices = static_cast<Vertex*>(v);
auto proxies = this->proxies();
auto filters = this->filters();
@@ -787,10 +795,47 @@ __attribute__((no_sanitize("float-cast-overflow")))
const GrPipeline* pipeline = target->allocPipeline(args, GrProcessorSet::MakeEmptySet(),
target->detachAppliedClip());
+ using TessFn =
+ decltype(&TextureOp::tess<SkPoint, MultiTexture::kNo, Domain::kNo, GrAA::kNo>);
+#define TESS_FN_AND_VERTEX_SIZE(Point, MT, Domain, AA) \
+ { \
+ &TextureOp::tess<Point, MT, Domain, AA>, \
+ sizeof(TextureGeometryProcessor::Vertex<Point, MT, Domain, AA>) \
+ }
+ static constexpr struct {
+ TessFn fTessFn;
+ size_t fVertexSize;
+ } kTessFnsAndVertexSizes[] = {
+ TESS_FN_AND_VERTEX_SIZE(SkPoint, MultiTexture::kNo, Domain::kNo, GrAA::kNo),
+ TESS_FN_AND_VERTEX_SIZE(SkPoint, MultiTexture::kNo, Domain::kNo, GrAA::kYes),
+ TESS_FN_AND_VERTEX_SIZE(SkPoint, MultiTexture::kNo, Domain::kYes, GrAA::kNo),
+ TESS_FN_AND_VERTEX_SIZE(SkPoint, MultiTexture::kNo, Domain::kYes, GrAA::kYes),
+ TESS_FN_AND_VERTEX_SIZE(SkPoint, MultiTexture::kYes, Domain::kNo, GrAA::kNo),
+ TESS_FN_AND_VERTEX_SIZE(SkPoint, MultiTexture::kYes, Domain::kNo, GrAA::kYes),
+ TESS_FN_AND_VERTEX_SIZE(SkPoint, MultiTexture::kYes, Domain::kYes, GrAA::kNo),
+ TESS_FN_AND_VERTEX_SIZE(SkPoint, MultiTexture::kYes, Domain::kYes, GrAA::kYes),
+ TESS_FN_AND_VERTEX_SIZE(SkPoint3, MultiTexture::kNo, Domain::kNo, GrAA::kNo),
+ TESS_FN_AND_VERTEX_SIZE(SkPoint3, MultiTexture::kNo, Domain::kNo, GrAA::kYes),
+ TESS_FN_AND_VERTEX_SIZE(SkPoint3, MultiTexture::kNo, Domain::kYes, GrAA::kNo),
+ TESS_FN_AND_VERTEX_SIZE(SkPoint3, MultiTexture::kNo, Domain::kYes, GrAA::kYes),
+ TESS_FN_AND_VERTEX_SIZE(SkPoint3, MultiTexture::kYes, Domain::kNo, GrAA::kNo),
+ TESS_FN_AND_VERTEX_SIZE(SkPoint3, MultiTexture::kYes, Domain::kNo, GrAA::kYes),
+ TESS_FN_AND_VERTEX_SIZE(SkPoint3, MultiTexture::kYes, Domain::kYes, GrAA::kNo),
+ TESS_FN_AND_VERTEX_SIZE(SkPoint3, MultiTexture::kYes, Domain::kYes, GrAA::kYes),
+ };
+#undef TESS_FN_AND_VERTEX_SIZE
+ int tessFnIdx = 0;
+ tessFnIdx |= coverageAA ? 0x1 : 0x0;
+ tessFnIdx |= fDomain ? 0x2 : 0x0;
+ tessFnIdx |= (fProxyCnt > 1) ? 0x4 : 0x0;
+ tessFnIdx |= fPerspective ? 0x8 : 0x0;
+
+ SkASSERT(kTessFnsAndVertexSizes[tessFnIdx].fVertexSize == gp->debugOnly_vertexStride());
+
int vstart;
const GrBuffer* vbuffer;
- void* vdata = target->makeVertexSpace(gp->getVertexStride(), 4 * fDraws.count(), &vbuffer,
- &vstart);
+ void* vdata = target->makeVertexSpace(kTessFnsAndVertexSizes[tessFnIdx].fVertexSize,
+ 4 * fDraws.count(), &vbuffer, &vstart);
if (!vdata) {
SkDebugf("Could not allocate vertices\n");
return;
@@ -804,32 +849,7 @@ __attribute__((no_sanitize("float-cast-overflow")))
ih[t] = 1.f / texture->height();
}
- using TessFn =
- decltype(&TextureOp::tess<SkPoint, MultiTexture::kNo, Domain::kNo, GrAA::kNo>);
- static constexpr TessFn kTessFns[] = {
- &TextureOp::tess<SkPoint, MultiTexture::kNo, Domain::kNo, GrAA::kNo>,
- &TextureOp::tess<SkPoint, MultiTexture::kNo, Domain::kNo, GrAA::kYes>,
- &TextureOp::tess<SkPoint, MultiTexture::kNo, Domain::kYes, GrAA::kNo>,
- &TextureOp::tess<SkPoint, MultiTexture::kNo, Domain::kYes, GrAA::kYes>,
- &TextureOp::tess<SkPoint, MultiTexture::kYes, Domain::kNo, GrAA::kNo>,
- &TextureOp::tess<SkPoint, MultiTexture::kYes, Domain::kNo, GrAA::kYes>,
- &TextureOp::tess<SkPoint, MultiTexture::kYes, Domain::kYes, GrAA::kNo>,
- &TextureOp::tess<SkPoint, MultiTexture::kYes, Domain::kYes, GrAA::kYes>,
- &TextureOp::tess<SkPoint3, MultiTexture::kNo, Domain::kNo, GrAA::kNo>,
- &TextureOp::tess<SkPoint3, MultiTexture::kNo, Domain::kNo, GrAA::kYes>,
- &TextureOp::tess<SkPoint3, MultiTexture::kNo, Domain::kYes, GrAA::kNo>,
- &TextureOp::tess<SkPoint3, MultiTexture::kNo, Domain::kYes, GrAA::kYes>,
- &TextureOp::tess<SkPoint3, MultiTexture::kYes, Domain::kNo, GrAA::kNo>,
- &TextureOp::tess<SkPoint3, MultiTexture::kYes, Domain::kNo, GrAA::kYes>,
- &TextureOp::tess<SkPoint3, MultiTexture::kYes, Domain::kYes, GrAA::kNo>,
- &TextureOp::tess<SkPoint3, MultiTexture::kYes, Domain::kYes, GrAA::kYes>,
- };
- int tessFnIdx = 0;
- tessFnIdx |= coverageAA ? 0x1 : 0x0;
- tessFnIdx |= fDomain ? 0x2 : 0x0;
- tessFnIdx |= (fProxyCnt > 1) ? 0x4 : 0x0;
- tessFnIdx |= fPerspective ? 0x8 : 0x0;
- (this->*(kTessFns[tessFnIdx]))(vdata, iw, ih, gp.get());
+ (this->*(kTessFnsAndVertexSizes[tessFnIdx].fTessFn))(vdata, iw, ih, gp.get());
GrPrimitiveType primitiveType =
fDraws.count() > 1 ? GrPrimitiveType::kTriangles : GrPrimitiveType::kTriangleStrip;