Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit b948572

Browse files
bsalomonSkia Commit-Bot
authored andcommitted
Store GrMeshDrawOps' meshes in GrOpFlushState's arena.
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 <[email protected]> Commit-Queue: Brian Salomon <[email protected]>
1 parent c0b03d8 commit b948572

29 files changed

+214
-205
lines changed

bench/VertexColorSpaceBench.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ class Op : public GrMeshDrawOp {
199199
}
200200
}
201201

202-
GrMesh mesh(GrPrimitiveType::kTriangleStrip);
203-
mesh.setNonIndexedNonInstanced(kVertexCount);
204-
mesh.setVertexData(vertexBuffer, firstVertex);
202+
GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangleStrip);
203+
mesh->setNonIndexedNonInstanced(kVertexCount);
204+
mesh->setVertexData(vertexBuffer, firstVertex);
205205
auto pipe = target->makePipeline(0, GrProcessorSet::MakeEmptySet(),
206206
target->detachAppliedClip());
207207
target->draw(gp, pipe.fPipeline, pipe.fFixedDynamicState, mesh);

gm/beziereffects.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,9 @@ class BezierCubicTestOp : public BezierTestOp {
9292
: INHERITED(std::move(gp), rect, color, ClassID()) {}
9393

9494
void onPrepareDraws(Target* target) override {
95-
QuadHelper helper;
9695
SkASSERT(this->gp()->debugOnly_vertexStride() == sizeof(SkPoint));
97-
SkPoint* pts = reinterpret_cast<SkPoint*>(helper.init(target, sizeof(SkPoint), 1));
96+
QuadHelper helper(target, sizeof(SkPoint), 1);
97+
SkPoint* pts = reinterpret_cast<SkPoint*>(helper.vertices());
9898
if (!pts) {
9999
return;
100100
}
@@ -284,9 +284,9 @@ class BezierConicTestOp : public BezierTestOp {
284284
};
285285

286286
void onPrepareDraws(Target* target) override {
287-
QuadHelper helper;
288287
SkASSERT(this->gp()->debugOnly_vertexStride() == sizeof(Vertex));
289-
Vertex* verts = reinterpret_cast<Vertex*>(helper.init(target, sizeof(Vertex), 1));
288+
QuadHelper helper(target, sizeof(Vertex), 1);
289+
Vertex* verts = reinterpret_cast<Vertex*>(helper.vertices());
290290
if (!verts) {
291291
return;
292292
}
@@ -506,9 +506,9 @@ class BezierQuadTestOp : public BezierTestOp {
506506
};
507507

508508
void onPrepareDraws(Target* target) override {
509-
QuadHelper helper;
510509
SkASSERT(this->gp()->debugOnly_vertexStride() == sizeof(Vertex));
511-
Vertex* verts = reinterpret_cast<Vertex*>(helper.init(target, sizeof(Vertex), 1));
510+
QuadHelper helper(target, sizeof(Vertex), 1);
511+
Vertex* verts = reinterpret_cast<Vertex*>(helper.vertices());
512512
if (!verts) {
513513
return;
514514
}

gm/convexpolyeffect.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ class PolyBoundsOp : public GrMeshDrawOp {
8787
SkMatrix::I()));
8888

8989
SkASSERT(gp->debugOnly_vertexStride() == sizeof(SkPoint));
90-
QuadHelper helper;
91-
SkPoint* verts = reinterpret_cast<SkPoint*>(helper.init(target, sizeof(SkPoint), 1));
90+
QuadHelper helper(target, sizeof(SkPoint), 1);
91+
SkPoint* verts = reinterpret_cast<SkPoint*>(helper.vertices());
9292
if (!verts) {
9393
return;
9494
}

src/gpu/GrMesh.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ class GrPrimitiveProcessor;
2121
*/
2222
class GrMesh {
2323
public:
24-
GrMesh(GrPrimitiveType primitiveType)
25-
: fPrimitiveType(primitiveType)
26-
, fBaseVertex(0) {
24+
GrMesh(GrPrimitiveType primitiveType = GrPrimitiveType::kTriangles)
25+
: fPrimitiveType(primitiveType), fBaseVertex(0) {
2726
SkDEBUGCODE(fNonIndexNonInstanceData.fVertexCount = -1;)
2827
}
2928

29+
void setPrimitiveType(GrPrimitiveType type) { fPrimitiveType = type; }
3030
GrPrimitiveType primitiveType() const { return fPrimitiveType; }
3131

3232
bool isIndexed() const { return SkToBool(fIndexBuffer.get()); }

src/gpu/GrOpFlushState.cpp

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ void GrOpFlushState::executeDrawsAndUploadsForMeshDrawOp(uint32_t opID, const Sk
4545
SkASSERT(fCurrDraw->fPipeline->proxy() == this->drawOpArgs().fProxy);
4646
this->rtCommandBuffer()->draw(*fCurrDraw->fGeometryProcessor, *fCurrDraw->fPipeline,
4747
fCurrDraw->fFixedDynamicState, fCurrDraw->fDynamicStateArrays,
48-
fMeshes.begin() + fCurrMesh, fCurrDraw->fMeshCnt, opBounds);
49-
fCurrMesh += fCurrDraw->fMeshCnt;
48+
fCurrDraw->fMeshes, fCurrDraw->fMeshCnt, opBounds);
5049
fTokenTracker->flushToken();
5150
++fCurrDraw;
5251
}
@@ -61,7 +60,6 @@ void GrOpFlushState::preExecuteDraws() {
6160
// Setup execution iterators.
6261
fCurrDraw = fDraws.begin();
6362
fCurrUpload = fInlineUploads.begin();
64-
fCurrMesh = 0;
6563
}
6664

6765
void GrOpFlushState::reset() {
@@ -73,8 +71,6 @@ void GrOpFlushState::reset() {
7371
fASAPUploads.reset();
7472
fInlineUploads.reset();
7573
fDraws.reset();
76-
fMeshes.reset();
77-
fCurrMesh = 0;
7874
fBaseDrawToken = GrDeferredUploadToken::AlreadyFlushedToken();
7975
}
8076

@@ -106,37 +102,21 @@ GrDeferredUploadToken GrOpFlushState::addASAPUpload(GrDeferredTextureUploadFn&&
106102

107103
void GrOpFlushState::draw(sk_sp<const GrGeometryProcessor> gp, const GrPipeline* pipeline,
108104
const GrPipeline::FixedDynamicState* fixedDynamicState,
109-
const GrMesh& mesh) {
105+
const GrMesh meshes[], int meshCnt) {
110106
SkASSERT(fOpArgs);
111107
SkASSERT(fOpArgs->fOp);
112-
fMeshes.push_back(mesh);
113108
bool firstDraw = fDraws.begin() == fDraws.end();
114-
if (!firstDraw) {
115-
Draw& lastDraw = *fDraws.begin();
116-
// If the last draw shares a geometry processor and pipeline and there are no intervening
117-
// uploads, add this mesh to it.
118-
// Note, we could attempt to convert fixed dynamic states into dynamic state arrays here
119-
// if everything else is equal. Maybe it's better to rely on Ops to do that?
120-
if (lastDraw.fGeometryProcessor == gp && lastDraw.fPipeline == pipeline &&
121-
lastDraw.fFixedDynamicState == fixedDynamicState) {
122-
if (fInlineUploads.begin() == fInlineUploads.end() ||
123-
fInlineUploads.tail()->fUploadBeforeToken != fTokenTracker->nextDrawToken()) {
124-
++lastDraw.fMeshCnt;
125-
return;
126-
}
127-
}
128-
}
129109
auto& draw = fDraws.append(&fArena);
130110
GrDeferredUploadToken token = fTokenTracker->issueDrawToken();
131-
132111
for (int i = 0; i < gp->numTextureSamplers(); ++i) {
133112
fixedDynamicState->fPrimitiveProcessorTextures[i]->addPendingRead();
134113
}
135114
draw.fGeometryProcessor = std::move(gp);
136115
draw.fPipeline = pipeline;
137116
draw.fFixedDynamicState = fixedDynamicState;
138117
draw.fDynamicStateArrays = nullptr;
139-
draw.fMeshCnt = 1;
118+
draw.fMeshes = meshes;
119+
draw.fMeshCnt = meshCnt;
140120
draw.fOpID = fOpArgs->fOp->uniqueID();
141121
if (firstDraw) {
142122
fBaseDrawToken = token;

src/gpu/GrOpFlushState.h

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,11 @@ class GrOpFlushState final : public GrDeferredUploadTarget, public GrMeshDrawOp:
7373
GrDeferredUploadToken addASAPUpload(GrDeferredTextureUploadFn&&) final;
7474

7575
/** Overrides of GrMeshDrawOp::Target. */
76-
77-
void draw(sk_sp<const GrGeometryProcessor>, const GrPipeline*,
78-
const GrPipeline::FixedDynamicState*, const GrMesh&) final;
76+
void draw(sk_sp<const GrGeometryProcessor>,
77+
const GrPipeline*,
78+
const GrPipeline::FixedDynamicState*,
79+
const GrMesh[],
80+
int meshCount) final;
7981
void* makeVertexSpace(size_t vertexSize, int vertexCount, const GrBuffer**,
8082
int* startVertex) final;
8183
uint16_t* makeIndexSpace(int indexCount, const GrBuffer**, int* startIndex) final;
@@ -123,12 +125,13 @@ class GrOpFlushState final : public GrDeferredUploadTarget, public GrMeshDrawOp:
123125
fFixedDynamicState->fPrimitiveProcessorTextures[i]->completedRead();
124126
}
125127
}
126-
int fMeshCnt = 0;
127128
sk_sp<const GrGeometryProcessor> fGeometryProcessor;
128-
const GrPipeline* fPipeline;
129+
const GrPipeline* fPipeline = nullptr;
129130
const GrPipeline::FixedDynamicState* fFixedDynamicState;
130131
const GrPipeline::DynamicStateArrays* fDynamicStateArrays;
131-
uint32_t fOpID;
132+
const GrMesh* fMeshes = nullptr;
133+
int fMeshCnt = 0;
134+
uint32_t fOpID = SK_InvalidUniqueID;
132135
};
133136

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

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

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

167166
// Used to track the proxies that need to be uninstantiated after we finish a flush

src/gpu/ops/GrAAConvexPathRenderer.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -843,10 +843,10 @@ class AAConvexPathOp final : public GrMeshDrawOp {
843843
extract_lines_only_verts(tess, verts, vertexStride, args.fColor, idxs,
844844
fHelper.compatibleWithAlphaAsCoverage());
845845

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

931-
GrMesh mesh(GrPrimitiveType::kTriangles);
932-
931+
GrMesh* meshes = target->allocMeshes(draws.count());
933932
for (int j = 0; j < draws.count(); ++j) {
934933
const Draw& draw = draws[j];
935-
mesh.setIndexed(indexBuffer, draw.fIndexCnt, firstIndex, 0, draw.fVertexCnt - 1,
936-
GrPrimitiveRestart::kNo);
937-
mesh.setVertexData(vertexBuffer, firstVertex);
938-
target->draw(quadProcessor, pipe.fPipeline, pipe.fFixedDynamicState, mesh);
934+
meshes[j].setPrimitiveType(GrPrimitiveType::kTriangles);
935+
meshes[j].setIndexed(indexBuffer, draw.fIndexCnt, firstIndex, 0,
936+
draw.fVertexCnt - 1, GrPrimitiveRestart::kNo);
937+
meshes[j].setVertexData(vertexBuffer, firstVertex);
939938
firstIndex += draw.fIndexCnt;
940939
firstVertex += draw.fVertexCnt;
941940
}
941+
target->draw(quadProcessor, pipe.fPipeline, pipe.fFixedDynamicState, meshes,
942+
draws.count());
942943
}
943944
}
944945

src/gpu/ops/GrAAFillRectOp.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -265,10 +265,9 @@ class AAFillRectOp final : public GrMeshDrawOp {
265265
SkASSERT(vertexStride == gp->debugOnly_vertexStride());
266266

267267
sk_sp<const GrBuffer> indexBuffer = get_index_buffer(target->resourceProvider());
268-
PatternHelper helper(GrPrimitiveType::kTriangles);
269-
void* vertices =
270-
helper.init(target, vertexStride, indexBuffer.get(), kVertsPerAAFillRect,
271-
kIndicesPerAAFillRect, fRectCnt);
268+
PatternHelper helper(target, GrPrimitiveType::kTriangles, vertexStride, indexBuffer.get(),
269+
kVertsPerAAFillRect, kIndicesPerAAFillRect, fRectCnt);
270+
void* vertices = helper.vertices();
272271
if (!vertices || !indexBuffer) {
273272
SkDebugf("Could not allocate vertices\n");
274273
return;

src/gpu/ops/GrAAHairLinePathRenderer.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -975,10 +975,10 @@ void AAHairlineOp::onPrepareDraws(Target* target) {
975975
add_line(&lines[2*i], toSrc, this->coverage(), &verts);
976976
}
977977

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

@@ -1030,19 +1030,19 @@ void AAHairlineOp::onPrepareDraws(Target* target) {
10301030
}
10311031

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

10411041
if (conicCount > 0) {
1042-
GrMesh mesh(GrPrimitiveType::kTriangles);
1043-
mesh.setIndexedPatterned(quadsIndexBuffer.get(), kIdxsPerQuad, kQuadNumVertices,
1044-
conicCount, kQuadsNumInIdxBuffer);
1045-
mesh.setVertexData(vertexBuffer, firstVertex);
1042+
GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangles);
1043+
mesh->setIndexedPatterned(quadsIndexBuffer.get(), kIdxsPerQuad, kQuadNumVertices,
1044+
conicCount, kQuadsNumInIdxBuffer);
1045+
mesh->setVertexData(vertexBuffer, firstVertex);
10461046
target->draw(std::move(conicGP), pipe.fPipeline, pipe.fFixedDynamicState, mesh);
10471047
}
10481048
}

src/gpu/ops/GrAALinearizingConvexPathRenderer.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ class AAFlatteningConvexPathOp final : public GrMeshDrawOp {
217217
return;
218218
}
219219
const GrBuffer* vertexBuffer;
220-
GrMesh mesh(GrPrimitiveType::kTriangles);
221220
int firstVertex;
222221
void* verts = target->makeVertexSpace(vertexStride, vertexCount, &vertexBuffer,
223222
&firstVertex);
@@ -235,9 +234,10 @@ class AAFlatteningConvexPathOp final : public GrMeshDrawOp {
235234
return;
236235
}
237236
memcpy(idxs, indices, indexCount * sizeof(uint16_t));
238-
mesh.setIndexed(indexBuffer, indexCount, firstIndex, 0, vertexCount - 1,
239-
GrPrimitiveRestart::kNo);
240-
mesh.setVertexData(vertexBuffer, firstVertex);
237+
GrMesh* mesh = target->allocMesh(GrPrimitiveType::kTriangles);
238+
mesh->setIndexed(indexBuffer, indexCount, firstIndex, 0, vertexCount - 1,
239+
GrPrimitiveRestart::kNo);
240+
mesh->setVertexData(vertexBuffer, firstVertex);
241241
target->draw(std::move(gp), pipeline, fixedDynamicState, mesh);
242242
}
243243

0 commit comments

Comments
 (0)