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

Side by Side Diff: src/gpu/GrVertices.h

Issue 1806983002: Update how we send draws to gpu backend to reduce state setting. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: rebase Created 4 years, 9 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
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 #ifndef GrVertices_DEFINED 8 #ifndef GrVertices_DEFINED
9 #define GrVertices_DEFINED 9 #define GrVertices_DEFINED
10 10
11 #include "GrIndexBuffer.h" 11 #include "GrIndexBuffer.h"
12 #include "GrVertexBuffer.h" 12 #include "GrVertexBuffer.h"
13 13
14 class GrNonInstancedVertices { 14 class GrNonInstancedVertices {
15 public: 15 public:
16 GrPrimitiveType primitiveType() const { return fPrimitiveType; }
17 int startVertex() const { return fStartVertex; } 16 int startVertex() const { return fStartVertex; }
18 int startIndex() const { return fStartIndex; } 17 int startIndex() const { return fStartIndex; }
19 int vertexCount() const { return fVertexCount; } 18 int vertexCount() const { return fVertexCount; }
20 int indexCount() const { return fIndexCount; } 19 int indexCount() const { return fIndexCount; }
21 bool isIndexed() const { return fIndexCount > 0; } 20 bool isIndexed() const { return fIndexCount > 0; }
22 21
23 const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get(); } 22 const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get(); }
24 const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); } 23 const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); }
25 24
26 protected: 25 protected:
27 GrPrimitiveType fPrimitiveType;
28 int fStartVertex; 26 int fStartVertex;
29 int fStartIndex; 27 int fStartIndex;
30 int fVertexCount; 28 int fVertexCount;
31 int fIndexCount; 29 int fIndexCount;
32 GrPendingIOResource<const GrVertexBuffer, kRead_GrIOType> fVertexBuffer; 30 GrPendingIOResource<const GrVertexBuffer, kRead_GrIOType> fVertexBuffer;
33 GrPendingIOResource<const GrIndexBuffer, kRead_GrIOType> fIndexBuffer; 31 GrPendingIOResource<const GrIndexBuffer, kRead_GrIOType> fIndexBuffer;
34 friend class GrVertices; 32 friend class GrVertices;
35 }; 33 };
36 34
37 /** 35 /**
38 * Used to communicate index and vertex buffers, counts, and offsets for a draw from GrBatch to 36 * Used to communicate index and vertex buffers, counts, and offsets for a draw from GrBatch to
39 * GrGpu. It also holds the primitive type for the draw. TODO: Consider moving o wnership of this 37 * GrGpu. It also holds the primitive type for the draw. TODO: Consider moving o wnership of this
40 * and draw-issuing responsibility to GrPrimitiveProcessor. The rest of the vert ex info lives there 38 * and draw-issuing responsibility to GrPrimitiveProcessor. The rest of the vert ex info lives there
41 * already (stride, attribute mappings). 39 * already (stride, attribute mappings).
42 */ 40 */
43 class GrVertices : public GrNonInstancedVertices { 41 class GrVertices : public GrNonInstancedVertices {
44 public: 42 public:
45 GrVertices() {} 43 GrVertices() {}
46 GrVertices(const GrVertices& di) { (*this) = di; } 44 GrVertices(const GrVertices& di) { (*this) = di; }
47 GrVertices& operator =(const GrVertices& di); 45 GrVertices& operator =(const GrVertices& di);
48 46
49 void init(GrPrimitiveType primType, const GrVertexBuffer* vertexBuffer, int startVertex, 47 void init(const GrVertexBuffer* vertexBuffer, int startVertex, int vertexCou nt) {
50 int vertexCount) {
51 SkASSERT(vertexBuffer); 48 SkASSERT(vertexBuffer);
52 SkASSERT(vertexCount); 49 SkASSERT(vertexCount);
53 SkASSERT(startVertex >= 0); 50 SkASSERT(startVertex >= 0);
54 fPrimitiveType = primType;
55 fVertexBuffer.reset(vertexBuffer); 51 fVertexBuffer.reset(vertexBuffer);
56 fIndexBuffer.reset(nullptr); 52 fIndexBuffer.reset(nullptr);
57 fStartVertex = startVertex; 53 fStartVertex = startVertex;
58 fStartIndex = 0; 54 fStartIndex = 0;
59 fVertexCount = vertexCount; 55 fVertexCount = vertexCount;
60 fIndexCount = 0; 56 fIndexCount = 0;
61 fInstanceCount = 0; 57 fInstanceCount = 0;
62 fVerticesPerInstance = 0; 58 fVerticesPerInstance = 0;
63 fIndicesPerInstance = 0; 59 fIndicesPerInstance = 0;
64 fMaxInstancesPerDraw = 0; 60 fMaxInstancesPerDraw = 0;
65 } 61 }
66 62
67 void initIndexed(GrPrimitiveType primType, 63 void initIndexed(const GrVertexBuffer* vertexBuffer,
68 const GrVertexBuffer* vertexBuffer, 64 const GrIndexBuffer* indexBuffer,
69 const GrIndexBuffer* indexBuffer, 65 int startVertex,
70 int startVertex, 66 int startIndex,
71 int startIndex, 67 int vertexCount,
72 int vertexCount, 68 int indexCount) {
73 int indexCount) {
74 SkASSERT(indexBuffer); 69 SkASSERT(indexBuffer);
75 SkASSERT(vertexBuffer); 70 SkASSERT(vertexBuffer);
76 SkASSERT(indexCount); 71 SkASSERT(indexCount);
77 SkASSERT(vertexCount); 72 SkASSERT(vertexCount);
78 SkASSERT(startIndex >= 0); 73 SkASSERT(startIndex >= 0);
79 SkASSERT(startVertex >= 0); 74 SkASSERT(startVertex >= 0);
80 fPrimitiveType = primType;
81 fVertexBuffer.reset(vertexBuffer); 75 fVertexBuffer.reset(vertexBuffer);
82 fIndexBuffer.reset(indexBuffer); 76 fIndexBuffer.reset(indexBuffer);
83 fStartVertex = startVertex; 77 fStartVertex = startVertex;
84 fStartIndex = startIndex; 78 fStartIndex = startIndex;
85 fVertexCount = vertexCount; 79 fVertexCount = vertexCount;
86 fIndexCount = indexCount; 80 fIndexCount = indexCount;
87 fInstanceCount = 0; 81 fInstanceCount = 0;
88 fVerticesPerInstance = 0; 82 fVerticesPerInstance = 0;
89 fIndicesPerInstance = 0; 83 fIndicesPerInstance = 0;
90 fMaxInstancesPerDraw = 0; 84 fMaxInstancesPerDraw = 0;
91 } 85 }
92 86
93 87
94 /** Variation of the above that may be used when the total number of instanc es may exceed 88 /** Variation of the above that may be used when the total number of instanc es may exceed
95 the number of instances supported by the index buffer. To be used with 89 the number of instances supported by the index buffer. To be used with
96 nextInstances() to draw in max-sized batches.*/ 90 nextInstances() to draw in max-sized batches.*/
97 void initInstanced(GrPrimitiveType primType, 91 void initInstanced(const GrVertexBuffer* vertexBuffer,
98 const GrVertexBuffer* vertexBuffer, 92 const GrIndexBuffer* indexBuffer,
99 const GrIndexBuffer* indexBuffer, 93 int startVertex,
100 int startVertex, 94 int verticesPerInstance,
101 int verticesPerInstance, 95 int indicesPerInstance,
102 int indicesPerInstance, 96 int instanceCount,
103 int instanceCount, 97 int maxInstancesPerDraw) {
104 int maxInstancesPerDraw) {
105 SkASSERT(vertexBuffer); 98 SkASSERT(vertexBuffer);
106 SkASSERT(indexBuffer); 99 SkASSERT(indexBuffer);
107 SkASSERT(instanceCount); 100 SkASSERT(instanceCount);
108 SkASSERT(verticesPerInstance); 101 SkASSERT(verticesPerInstance);
109 SkASSERT(indicesPerInstance); 102 SkASSERT(indicesPerInstance);
110 SkASSERT(startVertex >= 0); 103 SkASSERT(startVertex >= 0);
111 fPrimitiveType = primType;
112 fVertexBuffer.reset(vertexBuffer); 104 fVertexBuffer.reset(vertexBuffer);
113 fIndexBuffer.reset(indexBuffer); 105 fIndexBuffer.reset(indexBuffer);
114 fStartVertex = startVertex; 106 fStartVertex = startVertex;
115 fStartIndex = 0; 107 fStartIndex = 0;
116 fVerticesPerInstance = verticesPerInstance; 108 fVerticesPerInstance = verticesPerInstance;
117 fIndicesPerInstance = indicesPerInstance; 109 fIndicesPerInstance = indicesPerInstance;
118 fInstanceCount = instanceCount; 110 fInstanceCount = instanceCount;
119 fVertexCount = instanceCount * fVerticesPerInstance; 111 fVertexCount = instanceCount * fVerticesPerInstance;
120 fIndexCount = instanceCount * fIndicesPerInstance; 112 fIndexCount = instanceCount * fIndicesPerInstance;
121 fMaxInstancesPerDraw = maxInstancesPerDraw; 113 fMaxInstancesPerDraw = maxInstancesPerDraw;
(...skipping 16 matching lines...) Expand all
138 // Note, this also covers the non-instanced case! 130 // Note, this also covers the non-instanced case!
139 return &vertices; 131 return &vertices;
140 } 132 }
141 SkASSERT(vertices.isInstanced()); 133 SkASSERT(vertices.isInstanced());
142 fInstanceBatch.fIndexBuffer.reset(vertices.fIndexBuffer.get()); 134 fInstanceBatch.fIndexBuffer.reset(vertices.fIndexBuffer.get());
143 fInstanceBatch.fVertexBuffer.reset(vertices.fVertexBuffer.get()); 135 fInstanceBatch.fVertexBuffer.reset(vertices.fVertexBuffer.get());
144 fInstanceBatch.fIndexCount = vertices.fMaxInstancesPerDraw * 136 fInstanceBatch.fIndexCount = vertices.fMaxInstancesPerDraw *
145 vertices.fIndicesPerInstance; 137 vertices.fIndicesPerInstance;
146 fInstanceBatch.fVertexCount = vertices.fMaxInstancesPerDraw * 138 fInstanceBatch.fVertexCount = vertices.fMaxInstancesPerDraw *
147 vertices.fVerticesPerInstance; 139 vertices.fVerticesPerInstance;
148 fInstanceBatch.fPrimitiveType = vertices.fPrimitiveType;
149 fInstanceBatch.fStartIndex = vertices.fStartIndex; 140 fInstanceBatch.fStartIndex = vertices.fStartIndex;
150 fInstanceBatch.fStartVertex = vertices.fStartVertex; 141 fInstanceBatch.fStartVertex = vertices.fStartVertex;
151 fInstancesRemaining = vertices.fInstanceCount - vertices.fMaxInstanc esPerDraw; 142 fInstancesRemaining = vertices.fInstanceCount - vertices.fMaxInstanc esPerDraw;
152 return &fInstanceBatch; 143 return &fInstanceBatch;
153 } 144 }
154 145
155 const GrNonInstancedVertices* next() { 146 const GrNonInstancedVertices* next() {
156 if (!fInstancesRemaining) { 147 if (!fInstancesRemaining) {
157 return nullptr; 148 return nullptr;
158 } 149 }
(...skipping 11 matching lines...) Expand all
170 }; 161 };
171 162
172 private: 163 private:
173 int fInstanceCount; 164 int fInstanceCount;
174 int fVerticesPerInstance; 165 int fVerticesPerInstance;
175 int fIndicesPerInstance; 166 int fIndicesPerInstance;
176 int fMaxInstancesPerDraw; 167 int fMaxInstancesPerDraw;
177 }; 168 };
178 169
179 #endif 170 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698