Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(643)

Side by Side Diff: src/gpu/batches/GrVertexBatch.cpp

Issue 1835283002: Simplify GrDrawBatch uploads and token uage. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/batches/GrVertexBatch.h ('k') | src/gpu/effects/GrDashingEffect.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 Google Inc.
3 * 3 *
4 * Use of this source code is governed by a BSD-style license that can be 4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file. 5 * found in the LICENSE file.
6 */ 6 */
7 7
8 #include "GrVertexBatch.h" 8 #include "GrVertexBatch.h"
9 #include "GrBatchFlushState.h" 9 #include "GrBatchFlushState.h"
10 #include "GrResourceProvider.h" 10 #include "GrResourceProvider.h"
11 11
12 GrVertexBatch::GrVertexBatch(uint32_t classID) : INHERITED(classID) {} 12 GrVertexBatch::GrVertexBatch(uint32_t classID)
13 : INHERITED(classID)
14 , fBaseDrawToken(GrBatchDrawToken::AlreadyFlushedToken()) {
15 }
13 16
14 void GrVertexBatch::onPrepare(GrBatchFlushState* state) { 17 void GrVertexBatch::onPrepare(GrBatchFlushState* state) {
15 Target target(state, this); 18 Target target(state, this);
16 this->onPrepareDraws(&target); 19 this->onPrepareDraws(&target);
17 } 20 }
18 21
19 void* GrVertexBatch::InstancedHelper::init(Target* target, GrPrimitiveType primT ype, 22 void* GrVertexBatch::InstancedHelper::init(Target* target, GrPrimitiveType primT ype,
20 size_t vertexStride, const GrBuffer* indexBuffer, 23 size_t vertexStride, const GrBuffer* indexBuffer,
21 int verticesPerInstance, int indicesP erInstance, 24 int verticesPerInstance, int indicesP erInstance,
22 int instancesToDraw) { 25 int instancesToDraw) {
(...skipping 12 matching lines...) Expand all
35 SkASSERT(vertexBuffer); 38 SkASSERT(vertexBuffer);
36 size_t ibSize = indexBuffer->gpuMemorySize(); 39 size_t ibSize = indexBuffer->gpuMemorySize();
37 int maxInstancesPerDraw = static_cast<int>(ibSize / (sizeof(uint16_t) * indi cesPerInstance)); 40 int maxInstancesPerDraw = static_cast<int>(ibSize / (sizeof(uint16_t) * indi cesPerInstance));
38 41
39 fMesh.initInstanced(primType, vertexBuffer, indexBuffer, 42 fMesh.initInstanced(primType, vertexBuffer, indexBuffer,
40 firstVertex, verticesPerInstance, indicesPerInstance, instancesToDraw, 43 firstVertex, verticesPerInstance, indicesPerInstance, instancesToDraw,
41 maxInstancesPerDraw); 44 maxInstancesPerDraw);
42 return vertices; 45 return vertices;
43 } 46 }
44 47
45 void GrVertexBatch::InstancedHelper::recordDraw(Target* target) { 48 void GrVertexBatch::InstancedHelper::recordDraw(Target* target, const GrGeometry Processor* gp) {
46 SkASSERT(fMesh.instanceCount()); 49 SkASSERT(fMesh.instanceCount());
47 target->draw(fMesh); 50 target->draw(gp, fMesh);
48 } 51 }
49 52
50 void* GrVertexBatch::QuadHelper::init(Target* target, size_t vertexStride, 53 void* GrVertexBatch::QuadHelper::init(Target* target, size_t vertexStride,
51 int quadsToDraw) { 54 int quadsToDraw) {
52 SkAutoTUnref<const GrBuffer> quadIndexBuffer( 55 SkAutoTUnref<const GrBuffer> quadIndexBuffer(
53 target->resourceProvider()->refQuadIndexBuffer()); 56 target->resourceProvider()->refQuadIndexBuffer());
54 if (!quadIndexBuffer) { 57 if (!quadIndexBuffer) {
55 SkDebugf("Could not get quad index buffer."); 58 SkDebugf("Could not get quad index buffer.");
56 return nullptr; 59 return nullptr;
57 } 60 }
58 return this->INHERITED::init(target, kTriangles_GrPrimitiveType, vertexStrid e, 61 return this->INHERITED::init(target, kTriangles_GrPrimitiveType, vertexStrid e,
59 quadIndexBuffer, kVerticesPerQuad, kIndicesPerQ uad, quadsToDraw); 62 quadIndexBuffer, kVerticesPerQuad, kIndicesPerQ uad, quadsToDraw);
60 } 63 }
61 64
62 void GrVertexBatch::onDraw(GrBatchFlushState* state) { 65 void GrVertexBatch::onDraw(GrBatchFlushState* state) {
63 int uploadCnt = fInlineUploads.count(); 66 int currUploadIdx = 0;
64 int currUpload = 0; 67 int currMeshIdx = 0;
65 68
66 // Iterate of all the drawArrays. Before issuing the draws in each array, pe rform any inline 69 SkASSERT(fQueuedDraws.empty() || fBaseDrawToken == state->nextTokenToFlush() );
67 // uploads. 70
68 for (DrawArrayList::Iter da(fDrawArrays); da.get(); da.next()) { 71 for (int currDrawIdx = 0; currDrawIdx < fQueuedDraws.count(); ++currDrawIdx) {
69 state->advanceLastFlushedToken(); 72 GrBatchDrawToken drawToken = state->nextTokenToFlush();
70 while (currUpload < uploadCnt && 73 while (currUploadIdx < fInlineUploads.count() &&
71 fInlineUploads[currUpload]->lastUploadToken() <= state->lastFlush edToken()) { 74 fInlineUploads[currUploadIdx].fUploadBeforeToken == drawToken) {
72 fInlineUploads[currUpload++]->upload(state->uploader()); 75 state->doUpload(fInlineUploads[currUploadIdx++].fUpload);
73 } 76 }
74 const GrVertexBatch::DrawArray& drawArray = *da.get(); 77 const QueuedDraw &draw = fQueuedDraws[currDrawIdx];
78 state->gpu()->draw(*this->pipeline(), *draw.fGeometryProcessor.get(),
79 fMeshes.begin() + currMeshIdx, draw.fMeshCnt);
80 currMeshIdx += draw.fMeshCnt;
81 state->flushToken();
82 }
83 SkASSERT(currUploadIdx == fInlineUploads.count());
84 SkASSERT(currMeshIdx == fMeshes.count());
85 fQueuedDraws.reset();
86 fInlineUploads.reset();
87 }
75 88
76 state->gpu()->draw(*this->pipeline(), 89 //////////////////////////////////////////////////////////////////////////////
77 *drawArray.fPrimitiveProcessor.get(), 90
78 drawArray.fDraws.begin(), 91 void GrVertexBatch::Target::draw(const GrGeometryProcessor* gp, const GrMesh& me sh) {
79 drawArray.fDraws.count()); 92 GrVertexBatch* batch = this->vertexBatch();
93 batch->fMeshes.push_back(mesh);
94 if (!batch->fQueuedDraws.empty()) {
95 // If the last draw shares a geometry processor and there are no interve ning uploads,
96 // add this mesh to it.
97 GrVertexBatch::QueuedDraw& lastDraw = this->vertexBatch()->fQueuedDraws. back();
98 if (lastDraw.fGeometryProcessor == gp &&
99 (batch->fInlineUploads.empty() ||
100 batch->fInlineUploads.back().fUploadBeforeToken != this->nextDrawTo ken())) {
101 ++lastDraw.fMeshCnt;
102 return;
103 }
104 }
105 GrVertexBatch::QueuedDraw& draw = this->vertexBatch()->fQueuedDraws.push_bac k();
106 GrBatchDrawToken token = this->state()->issueDrawToken();
107 draw.fGeometryProcessor.reset(gp);
108 draw.fMeshCnt = 1;
109 if (batch->fQueuedDraws.count() == 1) {
110 batch->fBaseDrawToken = token;
80 } 111 }
81 } 112 }
OLDNEW
« no previous file with comments | « src/gpu/batches/GrVertexBatch.h ('k') | src/gpu/effects/GrDashingEffect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698