Skip to content

Commit

Permalink
Store GrMeshDrawOps' meshes in GrOpFlushState's arena.
Browse files Browse the repository at this point in the history
Remove late draw consolidation in GrOpFlushState. Rarely did anything
and doesn't work with new allocation strategy. Ops can use GrMesh arrays
to acheive the same thing. (Each Op that cared to would have to implement
but it isn't applicable to most Ops).

Modify GrMeshDrawOp::Target::draw() to take array of meshes, with single
mesh as a special case.

Change-Id: I552677de47b9ffd2fcaf55af85f70f290e5aa9c7
Reviewed-on: https://skia-review.googlesource.com/145426
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Brian Salomon <bsalomon@google.com>
  • Loading branch information
bsalomon authored and Skia Commit-Bot committed Aug 6, 2018
1 parent c0b03d8 commit b948572
Show file tree
Hide file tree
Showing 29 changed files with 214 additions and 205 deletions.
6 changes: 3 additions & 3 deletions bench/VertexColorSpaceBench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,9 @@ class Op : public GrMeshDrawOp {
}
}

GrMesh mesh(GrPrimitiveType::kTriangleStrip);
mesh.setNonIndexedNonInstanced(kVertexCount);
mesh.setVertexData(vertexBuffer, firstVertex);
GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangleStrip);
mesh->setNonIndexedNonInstanced(kVertexCount);
mesh->setVertexData(vertexBuffer, firstVertex);
auto pipe = target->makePipeline(0, GrProcessorSet::MakeEmptySet(),
target->detachAppliedClip());
target->draw(gp, pipe.fPipeline, pipe.fFixedDynamicState, mesh);
Expand Down
12 changes: 6 additions & 6 deletions gm/beziereffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ class BezierCubicTestOp : public BezierTestOp {
: INHERITED(std::move(gp), rect, color, ClassID()) {}

void onPrepareDraws(Target* target) override {
QuadHelper helper;
SkASSERT(this->gp()->debugOnly_vertexStride() == sizeof(SkPoint));
SkPoint* pts = reinterpret_cast<SkPoint*>(helper.init(target, sizeof(SkPoint), 1));
QuadHelper helper(target, sizeof(SkPoint), 1);
SkPoint* pts = reinterpret_cast<SkPoint*>(helper.vertices());
if (!pts) {
return;
}
Expand Down Expand Up @@ -284,9 +284,9 @@ class BezierConicTestOp : public BezierTestOp {
};

void onPrepareDraws(Target* target) override {
QuadHelper helper;
SkASSERT(this->gp()->debugOnly_vertexStride() == sizeof(Vertex));
Vertex* verts = reinterpret_cast<Vertex*>(helper.init(target, sizeof(Vertex), 1));
QuadHelper helper(target, sizeof(Vertex), 1);
Vertex* verts = reinterpret_cast<Vertex*>(helper.vertices());
if (!verts) {
return;
}
Expand Down Expand Up @@ -506,9 +506,9 @@ class BezierQuadTestOp : public BezierTestOp {
};

void onPrepareDraws(Target* target) override {
QuadHelper helper;
SkASSERT(this->gp()->debugOnly_vertexStride() == sizeof(Vertex));
Vertex* verts = reinterpret_cast<Vertex*>(helper.init(target, sizeof(Vertex), 1));
QuadHelper helper(target, sizeof(Vertex), 1);
Vertex* verts = reinterpret_cast<Vertex*>(helper.vertices());
if (!verts) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions gm/convexpolyeffect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ class PolyBoundsOp : public GrMeshDrawOp {
SkMatrix::I()));

SkASSERT(gp->debugOnly_vertexStride() == sizeof(SkPoint));
QuadHelper helper;
SkPoint* verts = reinterpret_cast<SkPoint*>(helper.init(target, sizeof(SkPoint), 1));
QuadHelper helper(target, sizeof(SkPoint), 1);
SkPoint* verts = reinterpret_cast<SkPoint*>(helper.vertices());
if (!verts) {
return;
}
Expand Down
6 changes: 3 additions & 3 deletions src/gpu/GrMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ class GrPrimitiveProcessor;
*/
class GrMesh {
public:
GrMesh(GrPrimitiveType primitiveType)
: fPrimitiveType(primitiveType)
, fBaseVertex(0) {
GrMesh(GrPrimitiveType primitiveType = GrPrimitiveType::kTriangles)
: fPrimitiveType(primitiveType), fBaseVertex(0) {
SkDEBUGCODE(fNonIndexNonInstanceData.fVertexCount = -1;)
}

void setPrimitiveType(GrPrimitiveType type) { fPrimitiveType = type; }
GrPrimitiveType primitiveType() const { return fPrimitiveType; }

bool isIndexed() const { return SkToBool(fIndexBuffer.get()); }
Expand Down
28 changes: 4 additions & 24 deletions src/gpu/GrOpFlushState.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ void GrOpFlushState::executeDrawsAndUploadsForMeshDrawOp(uint32_t opID, const Sk
SkASSERT(fCurrDraw->fPipeline->proxy() == this->drawOpArgs().fProxy);
this->rtCommandBuffer()->draw(*fCurrDraw->fGeometryProcessor, *fCurrDraw->fPipeline,
fCurrDraw->fFixedDynamicState, fCurrDraw->fDynamicStateArrays,
fMeshes.begin() + fCurrMesh, fCurrDraw->fMeshCnt, opBounds);
fCurrMesh += fCurrDraw->fMeshCnt;
fCurrDraw->fMeshes, fCurrDraw->fMeshCnt, opBounds);
fTokenTracker->flushToken();
++fCurrDraw;
}
Expand All @@ -61,7 +60,6 @@ void GrOpFlushState::preExecuteDraws() {
// Setup execution iterators.
fCurrDraw = fDraws.begin();
fCurrUpload = fInlineUploads.begin();
fCurrMesh = 0;
}

void GrOpFlushState::reset() {
Expand All @@ -73,8 +71,6 @@ void GrOpFlushState::reset() {
fASAPUploads.reset();
fInlineUploads.reset();
fDraws.reset();
fMeshes.reset();
fCurrMesh = 0;
fBaseDrawToken = GrDeferredUploadToken::AlreadyFlushedToken();
}

Expand Down Expand Up @@ -106,37 +102,21 @@ GrDeferredUploadToken GrOpFlushState::addASAPUpload(GrDeferredTextureUploadFn&&

void GrOpFlushState::draw(sk_sp<const GrGeometryProcessor> gp, const GrPipeline* pipeline,
const GrPipeline::FixedDynamicState* fixedDynamicState,
const GrMesh& mesh) {
const GrMesh meshes[], int meshCnt) {
SkASSERT(fOpArgs);
SkASSERT(fOpArgs->fOp);
fMeshes.push_back(mesh);
bool firstDraw = fDraws.begin() == fDraws.end();
if (!firstDraw) {
Draw& lastDraw = *fDraws.begin();
// If the last draw shares a geometry processor and pipeline and there are no intervening
// uploads, add this mesh to it.
// Note, we could attempt to convert fixed dynamic states into dynamic state arrays here
// if everything else is equal. Maybe it's better to rely on Ops to do that?
if (lastDraw.fGeometryProcessor == gp && lastDraw.fPipeline == pipeline &&
lastDraw.fFixedDynamicState == fixedDynamicState) {
if (fInlineUploads.begin() == fInlineUploads.end() ||
fInlineUploads.tail()->fUploadBeforeToken != fTokenTracker->nextDrawToken()) {
++lastDraw.fMeshCnt;
return;
}
}
}
auto& draw = fDraws.append(&fArena);
GrDeferredUploadToken token = fTokenTracker->issueDrawToken();

for (int i = 0; i < gp->numTextureSamplers(); ++i) {
fixedDynamicState->fPrimitiveProcessorTextures[i]->addPendingRead();
}
draw.fGeometryProcessor = std::move(gp);
draw.fPipeline = pipeline;
draw.fFixedDynamicState = fixedDynamicState;
draw.fDynamicStateArrays = nullptr;
draw.fMeshCnt = 1;
draw.fMeshes = meshes;
draw.fMeshCnt = meshCnt;
draw.fOpID = fOpArgs->fOp->uniqueID();
if (firstDraw) {
fBaseDrawToken = token;
Expand Down
19 changes: 9 additions & 10 deletions src/gpu/GrOpFlushState.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,11 @@ class GrOpFlushState final : public GrDeferredUploadTarget, public GrMeshDrawOp:
GrDeferredUploadToken addASAPUpload(GrDeferredTextureUploadFn&&) final;

/** Overrides of GrMeshDrawOp::Target. */

void draw(sk_sp<const GrGeometryProcessor>, const GrPipeline*,
const GrPipeline::FixedDynamicState*, const GrMesh&) final;
void draw(sk_sp<const GrGeometryProcessor>,
const GrPipeline*,
const GrPipeline::FixedDynamicState*,
const GrMesh[],
int meshCount) final;
void* makeVertexSpace(size_t vertexSize, int vertexCount, const GrBuffer**,
int* startVertex) final;
uint16_t* makeIndexSpace(int indexCount, const GrBuffer**, int* startIndex) final;
Expand Down Expand Up @@ -123,12 +125,13 @@ class GrOpFlushState final : public GrDeferredUploadTarget, public GrMeshDrawOp:
fFixedDynamicState->fPrimitiveProcessorTextures[i]->completedRead();
}
}
int fMeshCnt = 0;
sk_sp<const GrGeometryProcessor> fGeometryProcessor;
const GrPipeline* fPipeline;
const GrPipeline* fPipeline = nullptr;
const GrPipeline::FixedDynamicState* fFixedDynamicState;
const GrPipeline::DynamicStateArrays* fDynamicStateArrays;
uint32_t fOpID;
const GrMesh* fMeshes = nullptr;
int fMeshCnt = 0;
uint32_t fOpID = SK_InvalidUniqueID;
};

// Storage for ops' pipelines, draws, and inline uploads.
Expand All @@ -142,9 +145,6 @@ class GrOpFlushState final : public GrDeferredUploadTarget, public GrMeshDrawOp:
SkArenaAllocList<GrDeferredTextureUploadFn> fASAPUploads;
SkArenaAllocList<InlineUpload> fInlineUploads;
SkArenaAllocList<Draw> fDraws;
// TODO: These should go in the arena. However, GrGpuCommandBuffer and other classes currently
// accept contiguous arrays of meshes.
SkSTArray<16, GrMesh> fMeshes;

// All draws we store have an implicit draw token. This is the draw token for the first draw
// in fDraws.
Expand All @@ -161,7 +161,6 @@ class GrOpFlushState final : public GrDeferredUploadTarget, public GrMeshDrawOp:

// Variables that are used to track where we are in lists as ops are executed
SkArenaAllocList<Draw>::Iter fCurrDraw;
int fCurrMesh;
SkArenaAllocList<InlineUpload>::Iter fCurrUpload;

// Used to track the proxies that need to be uninstantiated after we finish a flush
Expand Down
21 changes: 11 additions & 10 deletions src/gpu/ops/GrAAConvexPathRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -843,10 +843,10 @@ class AAConvexPathOp final : public GrMeshDrawOp {
extract_lines_only_verts(tess, verts, vertexStride, args.fColor, idxs,
fHelper.compatibleWithAlphaAsCoverage());

GrMesh mesh(GrPrimitiveType::kTriangles);
mesh.setIndexed(indexBuffer, tess.numIndices(), firstIndex, 0, tess.numPts() - 1,
GrPrimitiveRestart::kNo);
mesh.setVertexData(vertexBuffer, firstVertex);
GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangles);
mesh->setIndexed(indexBuffer, tess.numIndices(), firstIndex, 0, tess.numPts() - 1,
GrPrimitiveRestart::kNo);
mesh->setVertexData(vertexBuffer, firstVertex);
target->draw(gp, pipe.fPipeline, pipe.fFixedDynamicState, mesh);
}
}
Expand Down Expand Up @@ -928,17 +928,18 @@ class AAConvexPathOp final : public GrMeshDrawOp {
SkSTArray<kPreallocDrawCnt, Draw, true> draws;
create_vertices(segments, fanPt, args.fColor, &draws, verts, idxs);

GrMesh mesh(GrPrimitiveType::kTriangles);

GrMesh* meshes = target->allocMeshes(draws.count());
for (int j = 0; j < draws.count(); ++j) {
const Draw& draw = draws[j];
mesh.setIndexed(indexBuffer, draw.fIndexCnt, firstIndex, 0, draw.fVertexCnt - 1,
GrPrimitiveRestart::kNo);
mesh.setVertexData(vertexBuffer, firstVertex);
target->draw(quadProcessor, pipe.fPipeline, pipe.fFixedDynamicState, mesh);
meshes[j].setPrimitiveType(GrPrimitiveType::kTriangles);
meshes[j].setIndexed(indexBuffer, draw.fIndexCnt, firstIndex, 0,
draw.fVertexCnt - 1, GrPrimitiveRestart::kNo);
meshes[j].setVertexData(vertexBuffer, firstVertex);
firstIndex += draw.fIndexCnt;
firstVertex += draw.fVertexCnt;
}
target->draw(quadProcessor, pipe.fPipeline, pipe.fFixedDynamicState, meshes,
draws.count());
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/gpu/ops/GrAAFillRectOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,9 @@ class AAFillRectOp final : public GrMeshDrawOp {
SkASSERT(vertexStride == gp->debugOnly_vertexStride());

sk_sp<const GrBuffer> indexBuffer = get_index_buffer(target->resourceProvider());
PatternHelper helper(GrPrimitiveType::kTriangles);
void* vertices =
helper.init(target, vertexStride, indexBuffer.get(), kVertsPerAAFillRect,
kIndicesPerAAFillRect, fRectCnt);
PatternHelper helper(target, GrPrimitiveType::kTriangles, vertexStride, indexBuffer.get(),
kVertsPerAAFillRect, kIndicesPerAAFillRect, fRectCnt);
void* vertices = helper.vertices();
if (!vertices || !indexBuffer) {
SkDebugf("Could not allocate vertices\n");
return;
Expand Down
24 changes: 12 additions & 12 deletions src/gpu/ops/GrAAHairLinePathRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -975,10 +975,10 @@ void AAHairlineOp::onPrepareDraws(Target* target) {
add_line(&lines[2*i], toSrc, this->coverage(), &verts);
}

GrMesh mesh(GrPrimitiveType::kTriangles);
mesh.setIndexedPatterned(linesIndexBuffer.get(), kIdxsPerLineSeg, kLineSegNumVertices,
lineCount, kLineSegsNumInIdxBuffer);
mesh.setVertexData(vertexBuffer, firstVertex);
GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangles);
mesh->setIndexedPatterned(linesIndexBuffer.get(), kIdxsPerLineSeg, kLineSegNumVertices,
lineCount, kLineSegsNumInIdxBuffer);
mesh->setVertexData(vertexBuffer, firstVertex);
target->draw(std::move(lineGP), pipe.fPipeline, pipe.fFixedDynamicState, mesh);
}

Expand Down Expand Up @@ -1030,19 +1030,19 @@ void AAHairlineOp::onPrepareDraws(Target* target) {
}

if (quadCount > 0) {
GrMesh mesh(GrPrimitiveType::kTriangles);
mesh.setIndexedPatterned(quadsIndexBuffer.get(), kIdxsPerQuad, kQuadNumVertices,
quadCount, kQuadsNumInIdxBuffer);
mesh.setVertexData(vertexBuffer, firstVertex);
GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangles);
mesh->setIndexedPatterned(quadsIndexBuffer.get(), kIdxsPerQuad, kQuadNumVertices,
quadCount, kQuadsNumInIdxBuffer);
mesh->setVertexData(vertexBuffer, firstVertex);
target->draw(std::move(quadGP), pipe.fPipeline, pipe.fFixedDynamicState, mesh);
firstVertex += quadCount * kQuadNumVertices;
}

if (conicCount > 0) {
GrMesh mesh(GrPrimitiveType::kTriangles);
mesh.setIndexedPatterned(quadsIndexBuffer.get(), kIdxsPerQuad, kQuadNumVertices,
conicCount, kQuadsNumInIdxBuffer);
mesh.setVertexData(vertexBuffer, firstVertex);
GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangles);
mesh->setIndexedPatterned(quadsIndexBuffer.get(), kIdxsPerQuad, kQuadNumVertices,
conicCount, kQuadsNumInIdxBuffer);
mesh->setVertexData(vertexBuffer, firstVertex);
target->draw(std::move(conicGP), pipe.fPipeline, pipe.fFixedDynamicState, mesh);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,6 @@ class AAFlatteningConvexPathOp final : public GrMeshDrawOp {
return;
}
const GrBuffer* vertexBuffer;
GrMesh mesh(GrPrimitiveType::kTriangles);
int firstVertex;
void* verts = target->makeVertexSpace(vertexStride, vertexCount, &vertexBuffer,
&firstVertex);
Expand All @@ -235,9 +234,10 @@ class AAFlatteningConvexPathOp final : public GrMeshDrawOp {
return;
}
memcpy(idxs, indices, indexCount * sizeof(uint16_t));
mesh.setIndexed(indexBuffer, indexCount, firstIndex, 0, vertexCount - 1,
GrPrimitiveRestart::kNo);
mesh.setVertexData(vertexBuffer, firstVertex);
GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangles);
mesh->setIndexed(indexBuffer, indexCount, firstIndex, 0, vertexCount - 1,
GrPrimitiveRestart::kNo);
mesh->setVertexData(vertexBuffer, firstVertex);
target->draw(std::move(gp), pipeline, fixedDynamicState, mesh);
}

Expand Down
10 changes: 5 additions & 5 deletions src/gpu/ops/GrAAStrokeRectOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,11 +282,11 @@ void AAStrokeRectOp::onPrepareDraws(Target* target) {
int indicesPerInstance = this->miterStroke() ? kMiterIndexCnt : kBevelIndexCnt;
int instanceCount = fRects.count();

sk_sp<const GrBuffer> indexBuffer = GetIndexBuffer(target->resourceProvider(), this->miterStroke());
PatternHelper helper(GrPrimitiveType::kTriangles);
void* vertices =
helper.init(target, vertexStride, indexBuffer.get(),
verticesPerInstance, indicesPerInstance, instanceCount);
sk_sp<const GrBuffer> indexBuffer =
GetIndexBuffer(target->resourceProvider(), this->miterStroke());
PatternHelper helper(target, GrPrimitiveType::kTriangles, vertexStride, indexBuffer.get(),
verticesPerInstance, indicesPerInstance, instanceCount);
void* vertices = helper.vertices();
if (!vertices || !indexBuffer) {
SkDebugf("Could not allocate vertices\n");
return;
Expand Down
8 changes: 4 additions & 4 deletions src/gpu/ops/GrAtlasTextOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,12 +425,12 @@ void GrAtlasTextOp::flush(GrMeshDrawOp::Target* target, FlushInfo* flushInfo) co
samplerState);
}
}
GrMesh mesh(GrPrimitiveType::kTriangles);
int maxGlyphsPerDraw =
static_cast<int>(flushInfo->fIndexBuffer->gpuMemorySize() / sizeof(uint16_t) / 6);
mesh.setIndexedPatterned(flushInfo->fIndexBuffer.get(), kIndicesPerGlyph, kVerticesPerGlyph,
flushInfo->fGlyphsToFlush, maxGlyphsPerDraw);
mesh.setVertexData(flushInfo->fVertexBuffer.get(), flushInfo->fVertexOffset);
GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangles);
mesh->setIndexedPatterned(flushInfo->fIndexBuffer.get(), kIndicesPerGlyph, kVerticesPerGlyph,
flushInfo->fGlyphsToFlush, maxGlyphsPerDraw);
mesh->setVertexData(flushInfo->fVertexBuffer.get(), flushInfo->fVertexOffset);
target->draw(flushInfo->fGeometryProcessor, flushInfo->fPipeline, flushInfo->fFixedDynamicState,
mesh);
flushInfo->fVertexOffset += kVerticesPerGlyph * flushInfo->fGlyphsToFlush;
Expand Down
4 changes: 2 additions & 2 deletions src/gpu/ops/GrDashOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,6 @@ class DashOp final : public GrMeshDrawOp {
return;
}

QuadHelper helper;
size_t vertexStride;
if (fullDash) {
vertexStride =
Expand All @@ -634,7 +633,8 @@ class DashOp final : public GrMeshDrawOp {
vertexStride = sizeof(SkPoint);
}
SkASSERT(vertexStride == gp->debugOnly_vertexStride());
void* vertices = helper.init(target, vertexStride, totalRectCount);
QuadHelper helper(target, vertexStride, totalRectCount);
void* vertices = helper.vertices();
if (!vertices) {
return;
}
Expand Down
Loading

0 comments on commit b948572

Please sign in to comment.