Iterate over instanced draws in GrGpu rather than above GrBatchTarget
Review URL: https://codereview.chromium.org/1127273007
This commit is contained in:
parent
3b58d75170
commit
e64eb570a5
@ -81,7 +81,7 @@ private:
|
||||
verts[v].fKLM[1] = eval_line(verts[v].fPosition, fKlmEqs + 3, fSign);
|
||||
verts[v].fKLM[2] = eval_line(verts[v].fPosition, fKlmEqs + 6, 1.f);
|
||||
}
|
||||
helper.issueDraws(batchTarget);
|
||||
helper.issueDraw(batchTarget);
|
||||
}
|
||||
|
||||
Geometry fGeometry;
|
||||
@ -464,7 +464,7 @@ private:
|
||||
fGeometry.fBounds.fRight, fGeometry.fBounds.fBottom,
|
||||
sizeof(Vertex));
|
||||
fDevToUV.apply<4, sizeof(Vertex), sizeof(SkPoint)>(verts);
|
||||
helper.issueDraws(batchTarget);
|
||||
helper.issueDraw(batchTarget);
|
||||
}
|
||||
|
||||
Geometry fGeometry;
|
||||
|
@ -64,7 +64,7 @@ private:
|
||||
fGeometry.fBounds.outset(5.f, 5.f);
|
||||
fGeometry.fBounds.toQuad(verts);
|
||||
|
||||
helper.issueDraws(batchTarget);
|
||||
helper.issueDraw(batchTarget);
|
||||
}
|
||||
|
||||
Geometry fGeometry;
|
||||
|
@ -794,9 +794,10 @@ public:
|
||||
int firstVertex;
|
||||
|
||||
size_t vertexStride = quadProcessor->getVertexStride();
|
||||
void *vertices = batchTarget->makeVertSpace(vertexStride, vertexCount,
|
||||
&vertexBuffer, &firstVertex);
|
||||
if (!vertices) {
|
||||
QuadVertex* verts = reinterpret_cast<QuadVertex*>(batchTarget->makeVertSpace(
|
||||
vertexStride, vertexCount, &vertexBuffer, &firstVertex));
|
||||
|
||||
if (!verts) {
|
||||
SkDebugf("Could not allocate vertices\n");
|
||||
return;
|
||||
}
|
||||
@ -810,18 +811,16 @@ public:
|
||||
return;
|
||||
}
|
||||
|
||||
QuadVertex* verts = reinterpret_cast<QuadVertex*>(vertices);
|
||||
|
||||
SkSTArray<kPreallocDrawCnt, Draw, true> draws;
|
||||
create_vertices(segments, fanPt, &draws, verts, idxs);
|
||||
|
||||
GrVertices info;
|
||||
GrVertices vertices;
|
||||
|
||||
for (int i = 0; i < draws.count(); ++i) {
|
||||
const Draw& draw = draws[i];
|
||||
info.initIndexed(kTriangles_GrPrimitiveType, vertexBuffer, indexBuffer, firstVertex,
|
||||
firstIndex, draw.fVertexCnt, draw.fIndexCnt);
|
||||
batchTarget->draw(info);
|
||||
vertices.initIndexed(kTriangles_GrPrimitiveType, vertexBuffer, indexBuffer,
|
||||
firstVertex, firstIndex, draw.fVertexCnt, draw.fIndexCnt);
|
||||
batchTarget->draw(vertices);
|
||||
firstVertex += draw.fVertexCnt;
|
||||
firstIndex += draw.fIndexCnt;
|
||||
}
|
||||
|
@ -507,14 +507,11 @@ private:
|
||||
|
||||
void flush(GrBatchTarget* batchTarget, FlushInfo* flushInfo) {
|
||||
GrVertices vertices;
|
||||
int instancesToFlush = flushInfo->fInstancesToFlush;
|
||||
int maxInstancesPerDraw = flushInfo->fIndexBuffer->maxQuads();
|
||||
vertices.initInstanced(kTriangles_GrPrimitiveType, flushInfo->fVertexBuffer,
|
||||
flushInfo->fIndexBuffer, flushInfo->fVertexOffset, kVerticesPerQuad,
|
||||
kIndicesPerQuad, &instancesToFlush, maxInstancesPerDraw);
|
||||
do {
|
||||
batchTarget->draw(vertices);
|
||||
} while (vertices.nextInstances(&instancesToFlush, maxInstancesPerDraw));
|
||||
kIndicesPerQuad, flushInfo->fInstancesToFlush, maxInstancesPerDraw);
|
||||
batchTarget->draw(vertices);
|
||||
flushInfo->fVertexOffset += kVerticesPerQuad * flushInfo->fInstancesToFlush;
|
||||
flushInfo->fInstancesToFlush = 0;
|
||||
}
|
||||
|
@ -869,30 +869,26 @@ void AAHairlineBatch::generateGeometry(GrBatchTarget* batchTarget, const GrPipel
|
||||
|
||||
size_t vertexStride = lineGP->getVertexStride();
|
||||
int vertexCount = kLineSegNumVertices * lineCount;
|
||||
void *vertices = batchTarget->makeVertSpace(vertexStride, vertexCount,
|
||||
&vertexBuffer, &firstVertex);
|
||||
LineVertex* verts = reinterpret_cast<LineVertex*>(
|
||||
batchTarget->makeVertSpace(vertexStride, vertexCount, &vertexBuffer, &firstVertex));
|
||||
|
||||
if (!vertices || !linesIndexBuffer) {
|
||||
if (!verts|| !linesIndexBuffer) {
|
||||
SkDebugf("Could not allocate vertices\n");
|
||||
return;
|
||||
}
|
||||
|
||||
SkASSERT(lineGP->getVertexStride() == sizeof(LineVertex));
|
||||
|
||||
LineVertex* verts = reinterpret_cast<LineVertex*>(vertices);
|
||||
for (int i = 0; i < lineCount; ++i) {
|
||||
add_line(&lines[2*i], toSrc, this->coverage(), &verts);
|
||||
}
|
||||
|
||||
{
|
||||
int linesLeft = lineCount;
|
||||
GrVertices info;
|
||||
info.initInstanced(kTriangles_GrPrimitiveType, vertexBuffer, linesIndexBuffer,
|
||||
firstVertex, kLineSegNumVertices, kIdxsPerLineSeg, &linesLeft,
|
||||
kLineSegsNumInIdxBuffer);
|
||||
do {
|
||||
batchTarget->draw(info);
|
||||
} while (info.nextInstances(&linesLeft, kLineSegsNumInIdxBuffer));
|
||||
GrVertices vertices;
|
||||
vertices.initInstanced(kTriangles_GrPrimitiveType, vertexBuffer, linesIndexBuffer,
|
||||
firstVertex, kLineSegNumVertices, kIdxsPerLineSeg, lineCount,
|
||||
kLineSegsNumInIdxBuffer);
|
||||
batchTarget->draw(vertices);
|
||||
}
|
||||
}
|
||||
|
||||
@ -939,15 +935,12 @@ void AAHairlineBatch::generateGeometry(GrBatchTarget* batchTarget, const GrPipel
|
||||
quadGP->initBatchTracker(batchTarget->currentBatchTracker(), init);
|
||||
|
||||
{
|
||||
int quadsLeft = quadCount;
|
||||
GrVertices info;
|
||||
info.initInstanced(kTriangles_GrPrimitiveType, vertexBuffer, quadsIndexBuffer,
|
||||
firstVertex, kQuadNumVertices, kIdxsPerQuad, &quadsLeft,
|
||||
kQuadsNumInIdxBuffer);
|
||||
do {
|
||||
batchTarget->draw(info);
|
||||
} while (info.nextInstances(&quadsLeft, kQuadsNumInIdxBuffer));
|
||||
firstVertex += quadCount * kQuadNumVertices;
|
||||
GrVertices verts;
|
||||
verts.initInstanced(kTriangles_GrPrimitiveType, vertexBuffer, quadsIndexBuffer,
|
||||
firstVertex, kQuadNumVertices, kIdxsPerQuad, quadCount,
|
||||
kQuadsNumInIdxBuffer);
|
||||
batchTarget->draw(verts);
|
||||
firstVertex += quadCount * kQuadNumVertices;
|
||||
}
|
||||
}
|
||||
|
||||
@ -963,14 +956,11 @@ void AAHairlineBatch::generateGeometry(GrBatchTarget* batchTarget, const GrPipel
|
||||
conicGP->initBatchTracker(batchTarget->currentBatchTracker(), init);
|
||||
|
||||
{
|
||||
int conicsLeft = conicCount;
|
||||
GrVertices info;
|
||||
info.initInstanced(kTriangles_GrPrimitiveType, vertexBuffer, quadsIndexBuffer,
|
||||
firstVertex, kQuadNumVertices, kIdxsPerQuad, &conicsLeft,
|
||||
kQuadsNumInIdxBuffer);
|
||||
do {
|
||||
batchTarget->draw(info);
|
||||
} while (info.nextInstances(&conicsLeft, kQuadsNumInIdxBuffer));
|
||||
GrVertices verts;
|
||||
verts.initInstanced(kTriangles_GrPrimitiveType, vertexBuffer, quadsIndexBuffer,
|
||||
firstVertex, kQuadNumVertices, kIdxsPerQuad, conicCount,
|
||||
kQuadsNumInIdxBuffer);
|
||||
batchTarget->draw(verts);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -140,7 +140,7 @@ public:
|
||||
canTweakAlphaForCoverage);
|
||||
}
|
||||
|
||||
helper.issueDraws(batchTarget);
|
||||
helper.issueDraw(batchTarget);
|
||||
}
|
||||
|
||||
SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
|
||||
@ -505,7 +505,7 @@ public:
|
||||
args.fMiterStroke,
|
||||
canTweakAlphaForCoverage);
|
||||
}
|
||||
helper.issueDraws(batchTarget);
|
||||
helper.issueDraw(batchTarget);
|
||||
}
|
||||
|
||||
SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
|
||||
|
@ -1838,15 +1838,12 @@ private:
|
||||
|
||||
void flush(GrBatchTarget* batchTarget, FlushInfo* flushInfo) {
|
||||
GrVertices vertices;
|
||||
int glyphsToFlush = flushInfo->fGlyphsToFlush;
|
||||
int maxGlyphsPerDraw = flushInfo->fIndexBuffer->maxQuads();
|
||||
vertices.initInstanced(kTriangles_GrPrimitiveType, flushInfo->fVertexBuffer,
|
||||
flushInfo->fIndexBuffer, flushInfo->fVertexOffset,
|
||||
kVerticesPerGlyph, kIndicesPerGlyph, &glyphsToFlush,
|
||||
kVerticesPerGlyph, kIndicesPerGlyph, flushInfo->fGlyphsToFlush,
|
||||
maxGlyphsPerDraw);
|
||||
do {
|
||||
batchTarget->draw(vertices);
|
||||
} while (vertices.nextInstances(&glyphsToFlush, maxGlyphsPerDraw));
|
||||
batchTarget->draw(vertices);
|
||||
flushInfo->fVertexOffset += kVerticesPerGlyph * flushInfo->fGlyphsToFlush;
|
||||
flushInfo->fGlyphsToFlush = 0;
|
||||
}
|
||||
|
@ -50,7 +50,6 @@ void* GrBatch::InstancedHelper::init(GrBatchTarget* batchTarget, GrPrimitiveType
|
||||
size_t vertexStride, const GrIndexBuffer* indexBuffer,
|
||||
int verticesPerInstance, int indicesPerInstance,
|
||||
int instancesToDraw) {
|
||||
SkASSERT(!fInstancesRemaining);
|
||||
SkASSERT(batchTarget);
|
||||
if (!indexBuffer) {
|
||||
return NULL;
|
||||
@ -65,14 +64,12 @@ void* GrBatch::InstancedHelper::init(GrBatchTarget* batchTarget, GrPrimitiveType
|
||||
return NULL;
|
||||
}
|
||||
SkASSERT(vertexBuffer);
|
||||
fInstancesRemaining = instancesToDraw;
|
||||
size_t ibSize = indexBuffer->gpuMemorySize();
|
||||
fMaxInstancesPerDraw = static_cast<int>(ibSize / (sizeof(uint16_t) * indicesPerInstance));
|
||||
int maxInstancesPerDraw = static_cast<int>(ibSize / (sizeof(uint16_t) * indicesPerInstance));
|
||||
|
||||
fVertices.initInstanced(primType, vertexBuffer, indexBuffer,
|
||||
firstVertex, verticesPerInstance, indicesPerInstance, &fInstancesRemaining,
|
||||
fMaxInstancesPerDraw);
|
||||
SkASSERT(fMaxInstancesPerDraw > 0);
|
||||
firstVertex, verticesPerInstance, indicesPerInstance, instancesToDraw,
|
||||
maxInstancesPerDraw);
|
||||
return vertices;
|
||||
}
|
||||
|
||||
|
@ -114,7 +114,7 @@ protected:
|
||||
space for the vertices and flushes the draws to the batch target.*/
|
||||
class InstancedHelper {
|
||||
public:
|
||||
InstancedHelper() : fInstancesRemaining(0) {}
|
||||
InstancedHelper() {}
|
||||
/** Returns the allocated storage for the vertices. The caller should populate the before
|
||||
vertices before calling issueDraws(). */
|
||||
void* init(GrBatchTarget* batchTarget, GrPrimitiveType, size_t vertexStride,
|
||||
@ -122,15 +122,11 @@ protected:
|
||||
int instancesToDraw);
|
||||
|
||||
/** Call after init() to issue draws to the batch target.*/
|
||||
void issueDraws(GrBatchTarget* batchTarget) {
|
||||
void issueDraw(GrBatchTarget* batchTarget) {
|
||||
SkASSERT(fVertices.instanceCount());
|
||||
do {
|
||||
batchTarget->draw(fVertices);
|
||||
} while (fVertices.nextInstances(&fInstancesRemaining, fMaxInstancesPerDraw));
|
||||
batchTarget->draw(fVertices);
|
||||
}
|
||||
private:
|
||||
int fInstancesRemaining;
|
||||
int fMaxInstancesPerDraw;
|
||||
GrVertices fVertices;
|
||||
};
|
||||
|
||||
@ -146,7 +142,7 @@ protected:
|
||||
calling issueDraws(). */
|
||||
void* init(GrBatchTarget* batchTarget, size_t vertexStride, int quadsToDraw);
|
||||
|
||||
using InstancedHelper::issueDraws;
|
||||
using InstancedHelper::issueDraw;
|
||||
|
||||
private:
|
||||
typedef InstancedHelper INHERITED;
|
||||
|
@ -29,6 +29,7 @@ GrVertices& GrVertices::operator =(const GrVertices& di) {
|
||||
fInstanceCount = di.fInstanceCount;
|
||||
fVerticesPerInstance = di.fVerticesPerInstance;
|
||||
fIndicesPerInstance = di.fIndicesPerInstance;
|
||||
fMaxInstancesPerDraw = di.fMaxInstancesPerDraw;
|
||||
|
||||
fVertexBuffer.reset(di.vertexBuffer());
|
||||
fIndexBuffer.reset(di.indexBuffer());
|
||||
@ -288,7 +289,11 @@ void GrGpu::removeGpuTraceMarker(const GrGpuTraceMarker* marker) {
|
||||
|
||||
void GrGpu::draw(const DrawArgs& args, const GrVertices& vertices) {
|
||||
this->handleDirtyContext();
|
||||
this->onDraw(args, vertices);
|
||||
GrVertices::Iterator iter;
|
||||
const GrNonInstancedVertices* verts = iter.init(vertices);
|
||||
do {
|
||||
this->onDraw(args, *verts);
|
||||
} while ((verts = iter.next()));
|
||||
}
|
||||
|
||||
void GrGpu::stencilPath(const GrPath* path, const StencilPathState& state) {
|
||||
|
@ -14,6 +14,7 @@
|
||||
#include "SkPath.h"
|
||||
|
||||
class GrContext;
|
||||
class GrNonInstancedVertices;
|
||||
class GrPath;
|
||||
class GrPathRange;
|
||||
class GrPathRenderer;
|
||||
@ -433,7 +434,7 @@ private:
|
||||
virtual void onClearStencilClip(GrRenderTarget*, const SkIRect& rect, bool insideClip) = 0;
|
||||
|
||||
// overridden by backend-specific derived class to perform the draw call.
|
||||
virtual void onDraw(const DrawArgs&, const GrVertices&) = 0;
|
||||
virtual void onDraw(const DrawArgs&, const GrNonInstancedVertices&) = 0;
|
||||
virtual void onStencilPath(const GrPath*, const StencilPathState&) = 0;
|
||||
|
||||
virtual void onDrawPath(const DrawArgs&, const GrPath*, const GrStencilSettings&) = 0;
|
||||
|
@ -784,7 +784,7 @@ public:
|
||||
|
||||
verts += kVerticesPerQuad;
|
||||
}
|
||||
helper.issueDraws(batchTarget);
|
||||
helper.issueDraw(batchTarget);
|
||||
}
|
||||
|
||||
SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
|
||||
@ -1013,7 +1013,7 @@ public:
|
||||
|
||||
verts += kVerticesPerQuad;
|
||||
}
|
||||
helper.issueDraws(batchTarget);
|
||||
helper.issueDraw(batchTarget);
|
||||
}
|
||||
|
||||
SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
|
||||
@ -1277,7 +1277,7 @@ public:
|
||||
|
||||
verts += kVerticesPerQuad;
|
||||
}
|
||||
helper.issueDraws(batchTarget);
|
||||
helper.issueDraw(batchTarget);
|
||||
}
|
||||
|
||||
SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
|
||||
@ -1661,7 +1661,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
helper.issueDraws(batchTarget);
|
||||
helper.issueDraw(batchTarget);
|
||||
}
|
||||
|
||||
SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
|
||||
@ -1853,7 +1853,7 @@ public:
|
||||
verts++;
|
||||
}
|
||||
}
|
||||
helper.issueDraws(batchTarget);
|
||||
helper.issueDraw(batchTarget);
|
||||
}
|
||||
|
||||
SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
|
||||
|
@ -156,7 +156,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
helper.issueDraws(batchTarget);
|
||||
helper.issueDraw(batchTarget);
|
||||
}
|
||||
|
||||
SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
|
||||
|
@ -199,7 +199,7 @@ private:
|
||||
|
||||
void onClearStencilClip(GrRenderTarget*, const SkIRect& rect, bool insideClip) override {}
|
||||
|
||||
void onDraw(const DrawArgs&, const GrVertices&) override {}
|
||||
void onDraw(const DrawArgs&, const GrNonInstancedVertices&) override {}
|
||||
|
||||
void onStencilPath(const GrPath* path, const StencilPathState& state) override {}
|
||||
|
||||
|
@ -11,13 +11,36 @@
|
||||
#include "GrIndexBuffer.h"
|
||||
#include "GrVertexBuffer.h"
|
||||
|
||||
class GrNonInstancedVertices {
|
||||
public:
|
||||
GrPrimitiveType primitiveType() const { return fPrimitiveType; }
|
||||
int startVertex() const { return fStartVertex; }
|
||||
int startIndex() const { return fStartIndex; }
|
||||
int vertexCount() const { return fVertexCount; }
|
||||
int indexCount() const { return fIndexCount; }
|
||||
bool isIndexed() const { return fIndexCount > 0; }
|
||||
|
||||
const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get(); }
|
||||
const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); }
|
||||
|
||||
protected:
|
||||
GrPrimitiveType fPrimitiveType;
|
||||
int fStartVertex;
|
||||
int fStartIndex;
|
||||
int fVertexCount;
|
||||
int fIndexCount;
|
||||
GrPendingIOResource<const GrVertexBuffer, kRead_GrIOType> fVertexBuffer;
|
||||
GrPendingIOResource<const GrIndexBuffer, kRead_GrIOType> fIndexBuffer;
|
||||
friend class GrVertices;
|
||||
};
|
||||
|
||||
/**
|
||||
* Used to communicate index and vertex buffers, counts, and offsets for a draw from GrBatch to
|
||||
* GrGpu. It also holds the primitive type for the draw. TODO: Consider moving ownership of this
|
||||
* and draw-issuing responsibility to GrPrimitiveProcessor. The rest of the vertex info lives there
|
||||
* already (stride, attribute mappings).
|
||||
*/
|
||||
class GrVertices {
|
||||
class GrVertices : public GrNonInstancedVertices {
|
||||
public:
|
||||
GrVertices() {}
|
||||
GrVertices(const GrVertices& di) { (*this) = di; }
|
||||
@ -38,6 +61,7 @@ public:
|
||||
fInstanceCount = 0;
|
||||
fVerticesPerInstance = 0;
|
||||
fIndicesPerInstance = 0;
|
||||
fMaxInstancesPerDraw = 0;
|
||||
}
|
||||
|
||||
void initIndexed(GrPrimitiveType primType,
|
||||
@ -63,15 +87,21 @@ public:
|
||||
fInstanceCount = 0;
|
||||
fVerticesPerInstance = 0;
|
||||
fIndicesPerInstance = 0;
|
||||
fMaxInstancesPerDraw = 0;
|
||||
}
|
||||
|
||||
|
||||
/** Variation of the above that may be used when the total number of instances may exceed
|
||||
the number of instances supported by the index buffer. To be used with
|
||||
nextInstances() to draw in max-sized batches.*/
|
||||
void initInstanced(GrPrimitiveType primType,
|
||||
const GrVertexBuffer* vertexBuffer,
|
||||
const GrIndexBuffer* indexBuffer,
|
||||
int startVertex,
|
||||
int verticesPerInstance,
|
||||
int indicesPerInstance,
|
||||
int instanceCount) {
|
||||
int instanceCount,
|
||||
int maxInstancesPerDraw) {
|
||||
SkASSERT(vertexBuffer);
|
||||
SkASSERT(indexBuffer);
|
||||
SkASSERT(instanceCount);
|
||||
@ -88,74 +118,62 @@ public:
|
||||
fInstanceCount = instanceCount;
|
||||
fVertexCount = instanceCount * fVerticesPerInstance;
|
||||
fIndexCount = instanceCount * fIndicesPerInstance;
|
||||
fMaxInstancesPerDraw = maxInstancesPerDraw;
|
||||
}
|
||||
|
||||
/** Variation of the above that may be used when the total number of instances may exceed
|
||||
the number of instances supported by the index buffer. To be used with
|
||||
nextInstances() to draw in max-sized batches.*/
|
||||
void initInstanced(GrPrimitiveType primType,
|
||||
const GrVertexBuffer* vertexBuffer,
|
||||
const GrIndexBuffer* indexBuffer,
|
||||
int startVertex,
|
||||
int verticesPerInstance,
|
||||
int indicesPerInstance,
|
||||
int* instancesRemaining,
|
||||
int maxInstancesPerDraw) {
|
||||
int instanceCount = SkTMin(*instancesRemaining, maxInstancesPerDraw);
|
||||
*instancesRemaining -= instanceCount;
|
||||
this->initInstanced(primType, vertexBuffer, indexBuffer, startVertex,
|
||||
verticesPerInstance, indicesPerInstance, instanceCount);
|
||||
}
|
||||
|
||||
GrPrimitiveType primitiveType() const { return fPrimitiveType; }
|
||||
int startVertex() const { return fStartVertex; }
|
||||
int startIndex() const { return fStartIndex; }
|
||||
int vertexCount() const { return fVertexCount; }
|
||||
int indexCount() const { return fIndexCount; }
|
||||
|
||||
/** These return 0 if initInstanced was not used to initialize the GrVertices. */
|
||||
int verticesPerInstance() const { return fVerticesPerInstance; }
|
||||
int indicesPerInstance() const { return fIndicesPerInstance; }
|
||||
int instanceCount() const { return fInstanceCount; }
|
||||
|
||||
bool isIndexed() const { return fIndexCount > 0; }
|
||||
bool isInstanced() const { return fInstanceCount > 0; }
|
||||
|
||||
/** Called after using this draw info to draw the next set of instances.
|
||||
The vertex offset is advanced while the index buffer is reused at the same
|
||||
position. instancesRemaining is number of instances that remain, maxInstances is
|
||||
the most number of instances that can be used with the index buffer. If there
|
||||
are no instances remaining, the GrVertices is unmodified and false is returned.*/
|
||||
bool nextInstances(int* instancesRemaining, int maxInstances) {
|
||||
SkASSERT(this->isInstanced());
|
||||
if (!*instancesRemaining) {
|
||||
return false;
|
||||
class Iterator {
|
||||
public:
|
||||
const GrNonInstancedVertices* init(const GrVertices& vertices) {
|
||||
fVertices = &vertices;
|
||||
if (vertices.fInstanceCount <= vertices.fMaxInstancesPerDraw) {
|
||||
fInstancesRemaining = 0;
|
||||
// Note, this also covers the non-instanced case!
|
||||
return &vertices;
|
||||
}
|
||||
SkASSERT(vertices.isInstanced());
|
||||
fInstanceBatch.fIndexBuffer.reset(vertices.fIndexBuffer.get());
|
||||
fInstanceBatch.fVertexBuffer.reset(vertices.fVertexBuffer.get());
|
||||
fInstanceBatch.fIndexCount = vertices.fMaxInstancesPerDraw *
|
||||
vertices.fIndicesPerInstance;
|
||||
fInstanceBatch.fVertexCount = vertices.fMaxInstancesPerDraw *
|
||||
vertices.fVerticesPerInstance;
|
||||
fInstanceBatch.fPrimitiveType = vertices.fPrimitiveType;
|
||||
fInstanceBatch.fStartIndex = vertices.fStartIndex;
|
||||
fInstanceBatch.fStartVertex = vertices.fStartVertex;
|
||||
fInstancesRemaining = vertices.fInstanceCount - vertices.fMaxInstancesPerDraw;
|
||||
return &fInstanceBatch;
|
||||
}
|
||||
fStartVertex += fVertexCount;
|
||||
fInstanceCount = SkTMin(*instancesRemaining, maxInstances);
|
||||
fVertexCount = fInstanceCount * fVerticesPerInstance;
|
||||
fIndexCount = fInstanceCount * fIndicesPerInstance;
|
||||
*instancesRemaining -= fInstanceCount;
|
||||
return true;
|
||||
}
|
||||
|
||||
const GrVertexBuffer* vertexBuffer() const { return fVertexBuffer.get(); }
|
||||
const GrIndexBuffer* indexBuffer() const { return fIndexBuffer.get(); }
|
||||
const GrNonInstancedVertices* next() {
|
||||
if (!fInstancesRemaining) {
|
||||
return NULL;
|
||||
}
|
||||
fInstanceBatch.fStartVertex += fInstanceBatch.fVertexCount;
|
||||
int instances = SkTMin(fInstancesRemaining, fVertices->fMaxInstancesPerDraw);
|
||||
fInstanceBatch.fIndexCount = instances * fVertices->fIndicesPerInstance;
|
||||
fInstanceBatch.fVertexCount = instances * fVertices->fVerticesPerInstance;
|
||||
fInstancesRemaining -= instances;
|
||||
return &fInstanceBatch;
|
||||
}
|
||||
private:
|
||||
GrNonInstancedVertices fInstanceBatch;
|
||||
const GrVertices* fVertices;
|
||||
int fInstancesRemaining;
|
||||
};
|
||||
|
||||
private:
|
||||
GrPrimitiveType fPrimitiveType;
|
||||
|
||||
int fStartVertex;
|
||||
int fStartIndex;
|
||||
int fVertexCount;
|
||||
int fIndexCount;
|
||||
|
||||
int fInstanceCount;
|
||||
int fVerticesPerInstance;
|
||||
int fIndicesPerInstance;
|
||||
|
||||
GrPendingIOResource<const GrVertexBuffer, kRead_GrIOType> fVertexBuffer;
|
||||
GrPendingIOResource<const GrIndexBuffer, kRead_GrIOType> fIndexBuffer;
|
||||
int fMaxInstancesPerDraw;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -599,7 +599,7 @@ public:
|
||||
rectIndex++;
|
||||
}
|
||||
SkASSERT(0 == (curVIdx % 4) && (curVIdx / 4) == totalRectCount);
|
||||
helper.issueDraws(batchTarget);
|
||||
helper.issueDraw(batchTarget);
|
||||
}
|
||||
|
||||
SkSTArray<1, Geometry, true>* geoData() { return &fGeoData; }
|
||||
|
@ -1452,20 +1452,20 @@ bool GrGLGpu::flushGLState(const DrawArgs& args) {
|
||||
}
|
||||
|
||||
void GrGLGpu::setupGeometry(const GrPrimitiveProcessor& primProc,
|
||||
const GrVertices& info,
|
||||
const GrNonInstancedVertices& vertices,
|
||||
size_t* indexOffsetInBytes) {
|
||||
GrGLVertexBuffer* vbuf;
|
||||
vbuf = (GrGLVertexBuffer*) info.vertexBuffer();
|
||||
vbuf = (GrGLVertexBuffer*) vertices.vertexBuffer();
|
||||
|
||||
SkASSERT(vbuf);
|
||||
SkASSERT(!vbuf->isMapped());
|
||||
|
||||
GrGLIndexBuffer* ibuf = NULL;
|
||||
if (info.isIndexed()) {
|
||||
if (vertices.isIndexed()) {
|
||||
SkASSERT(indexOffsetInBytes);
|
||||
|
||||
*indexOffsetInBytes = 0;
|
||||
ibuf = (GrGLIndexBuffer*)info.indexBuffer();
|
||||
ibuf = (GrGLIndexBuffer*)vertices.indexBuffer();
|
||||
|
||||
SkASSERT(ibuf);
|
||||
SkASSERT(!ibuf->isMapped());
|
||||
@ -1479,7 +1479,7 @@ void GrGLGpu::setupGeometry(const GrPrimitiveProcessor& primProc,
|
||||
|
||||
GrGLsizei stride = static_cast<GrGLsizei>(primProc.getVertexStride());
|
||||
|
||||
size_t vertexOffsetInBytes = stride * info.startVertex();
|
||||
size_t vertexOffsetInBytes = stride * vertices.startVertex();
|
||||
|
||||
vertexOffsetInBytes += vbuf->baseOffset();
|
||||
|
||||
@ -1895,7 +1895,7 @@ GrGLenum gPrimitiveType2GLMode[] = {
|
||||
#endif
|
||||
#endif
|
||||
|
||||
void GrGLGpu::onDraw(const DrawArgs& args, const GrVertices& vertices) {
|
||||
void GrGLGpu::onDraw(const DrawArgs& args, const GrNonInstancedVertices& vertices) {
|
||||
if (!this->flushGLState(args)) {
|
||||
return;
|
||||
}
|
||||
|
@ -24,7 +24,7 @@
|
||||
#include "SkTypes.h"
|
||||
|
||||
class GrPipeline;
|
||||
class GrVertices;
|
||||
class GrNonInstancedVertices;
|
||||
|
||||
#ifdef SK_DEVELOPER
|
||||
#define PROGRAM_CACHE_STATS
|
||||
@ -149,7 +149,7 @@ private:
|
||||
|
||||
void onResolveRenderTarget(GrRenderTarget* target) override;
|
||||
|
||||
void onDraw(const DrawArgs&, const GrVertices&) override;
|
||||
void onDraw(const DrawArgs&, const GrNonInstancedVertices&) override;
|
||||
void onStencilPath(const GrPath*, const StencilPathState&) override;
|
||||
void onDrawPath(const DrawArgs&, const GrPath*, const GrStencilSettings&) override;
|
||||
void onDrawPaths(const DrawArgs&,
|
||||
@ -177,7 +177,7 @@ private:
|
||||
// an into the index buffer. It does not account for vertices.startIndex() but rather the start
|
||||
// index is relative to the returned offset.
|
||||
void setupGeometry(const GrPrimitiveProcessor&,
|
||||
const GrVertices& vertices,
|
||||
const GrNonInstancedVertices& vertices,
|
||||
size_t* indexOffsetInBytes);
|
||||
|
||||
// Subclasses should call this to flush the blend state.
|
||||
|
Loading…
Reference in New Issue
Block a user