Index: src/gpu/GrInOrderDrawBuffer.cpp |
diff --git a/src/gpu/GrInOrderDrawBuffer.cpp b/src/gpu/GrInOrderDrawBuffer.cpp |
index 70d61ecfffba21ef67ab4c8bd1a8fdff53034770..de9635f63c1be7e76804c8f0f0c4a2245c7b373c 100644 |
--- a/src/gpu/GrInOrderDrawBuffer.cpp |
+++ b/src/gpu/GrInOrderDrawBuffer.cpp |
@@ -20,7 +20,8 @@ GrInOrderDrawBuffer::GrInOrderDrawBuffer(GrGpu* gpu, |
: INHERITED(gpu, vertexPool, indexPool) |
, fCmdBuffer(kCmdBufferInitialSizeInBytes) |
, fPrevState(NULL) |
- , fDrawID(0) { |
+ , fDrawID(0) |
+ , fBatchTarget(gpu, vertexPool, indexPool) { |
SkASSERT(vertexPool); |
SkASSERT(indexPool); |
@@ -210,6 +211,7 @@ int GrInOrderDrawBuffer::concatInstancedDraw(const GrPipelineBuilder& pipelineBu |
Draw* draw = static_cast<Draw*>(&fCmdBuffer.back()); |
if (!draw->fInfo.isInstanced() || |
+ draw->fInfo.primitiveType() != info.primitiveType() || |
draw->fInfo.verticesPerInstance() != info.verticesPerInstance() || |
draw->fInfo.indicesPerInstance() != info.indicesPerInstance() || |
draw->fInfo.vertexBuffer() != info.vertexBuffer() || |
@@ -266,6 +268,30 @@ void GrInOrderDrawBuffer::onDraw(const GrPipelineBuilder& pipelineBuilder, |
this->recordTraceMarkersIfNecessary(); |
} |
+void GrInOrderDrawBuffer::onDrawBatch(GrBatch* batch, |
+ const GrPipelineBuilder& pipelineBuilder, |
+ GrPrimitiveType type, |
+ const GrScissorState& scissorState, |
+ const GrDeviceCoordTexture* dstCopy) { |
+ if (!this->recordStateAndShouldDraw(batch, pipelineBuilder, scissorState, dstCopy)) { |
+ return; |
+ } |
+ |
+ // Check if there is a Batch Draw we can batch with |
+ if (kDrawBatch_Cmd != strip_trace_bit(fCmdBuffer.back().fType)) { |
+ GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawBatch, (batch)); |
+ return; |
+ } |
+ |
+ DrawBatch* draw = static_cast<DrawBatch*>(&fCmdBuffer.back()); |
+ if (draw->fBatch->combineIfPossible(batch)) { |
+ return; |
+ } else { |
+ GrNEW_APPEND_TO_RECORDER(fCmdBuffer, DrawBatch, (batch)); |
+ } |
+ this->recordTraceMarkersIfNecessary(); |
+} |
+ |
void GrInOrderDrawBuffer::onStencilPath(const GrPipelineBuilder& pipelineBuilder, |
const GrPathProcessor* pathProc, |
const GrPath* path, |
@@ -410,7 +436,6 @@ void GrInOrderDrawBuffer::onFlush() { |
return; |
} |
- |
CmdBuffer::Iter iter(fCmdBuffer); |
int currCmdMarker = 0; |
@@ -419,6 +444,10 @@ void GrInOrderDrawBuffer::onFlush() { |
// stream. |
SetState* currentState = NULL; |
+ // TODO to prevent flushing the batch buffer too much, we only flush when wasBatch && !isBatch |
+ // In the long term we can delete this and just flush once at the end of all geometry generation |
+ bool wasBatch = false; |
+ |
while (iter.next()) { |
GrGpuTraceMarker newMarker("", -1); |
SkString traceString; |
@@ -429,13 +458,30 @@ void GrInOrderDrawBuffer::onFlush() { |
++currCmdMarker; |
} |
- if (kSetState_Cmd == strip_trace_bit(iter->fType)) { |
+ bool isSetState = kSetState_Cmd == strip_trace_bit(iter->fType); |
+ |
+ if (!isSetState && kDrawBatch_Cmd != strip_trace_bit(iter->fType)) { |
+ // TODO see note above, this gets deleted once everyone uses batch drawing |
+ if (wasBatch) { |
+ wasBatch = false; |
+ fBatchTarget.flush(); |
+ } |
+ } |
+ |
+ if (isSetState) { |
SetState* ss = reinterpret_cast<SetState*>(iter.get()); |
- this->getGpu()->buildProgramDesc(&ss->fDesc, *ss->fPrimitiveProcessor, ss->fPipeline, |
- ss->fPipeline.descInfo(), ss->fBatchTracker); |
+ // TODO sometimes we have a prim proc, othertimes we have a GrBatch. Eventually we will |
+ // only have GrBatch and we can delete this |
+ if (ss->fPrimitiveProcessor) { |
+ this->getGpu()->buildProgramDesc(&ss->fDesc, *ss->fPrimitiveProcessor, |
+ ss->fPipeline, |
+ ss->fPipeline.descInfo(), |
+ ss->fBatchTracker); |
+ } else { |
+ wasBatch = true; |
+ } |
currentState = ss; |
- |
} else { |
iter->execute(this, currentState); |
} |
@@ -445,6 +491,11 @@ void GrInOrderDrawBuffer::onFlush() { |
} |
} |
+ // TODO see note above, one last catch |
+ if (wasBatch) { |
+ fBatchTarget.flush(); |
+ } |
+ |
SkASSERT(fGpuCmdMarkers.count() == currCmdMarker); |
++fDrawID; |
} |
@@ -484,6 +535,11 @@ void GrInOrderDrawBuffer::DrawPaths::execute(GrInOrderDrawBuffer* buf, const Set |
fCount, fStencilSettings); |
} |
+void GrInOrderDrawBuffer::DrawBatch::execute(GrInOrderDrawBuffer* buf, const SetState* state) { |
+ SkASSERT(state); |
+ fBatch->generateGeometry(buf->getBatchTarget(), &state->fPipeline); |
+} |
+ |
void GrInOrderDrawBuffer::SetState::execute(GrInOrderDrawBuffer*, const SetState*) {} |
void GrInOrderDrawBuffer::Clear::execute(GrInOrderDrawBuffer* buf, const SetState*) { |
@@ -531,7 +587,7 @@ bool GrInOrderDrawBuffer::recordStateAndShouldDraw(const GrPipelineBuilder& pipe |
ss->fPrimitiveProcessor->initBatchTracker(&ss->fBatchTracker, |
ss->fPipeline.getInitBatchTracker()); |
- if (fPrevState && |
+ if (fPrevState && fPrevState->fPrimitiveProcessor.get() && |
fPrevState->fPrimitiveProcessor->canMakeEqual(fPrevState->fBatchTracker, |
*ss->fPrimitiveProcessor, |
ss->fBatchTracker) && |
@@ -544,6 +600,33 @@ bool GrInOrderDrawBuffer::recordStateAndShouldDraw(const GrPipelineBuilder& pipe |
return true; |
} |
+bool GrInOrderDrawBuffer::recordStateAndShouldDraw(GrBatch* batch, |
+ const GrPipelineBuilder& pipelineBuilder, |
+ const GrScissorState& scissor, |
+ const GrDeviceCoordTexture* dstCopy) { |
+ // TODO this gets much simpler when we have batches everywhere. |
+ // If the previous command is also a set state, then we check to see if it has a Batch. If so, |
+ // and we can make the two batches equal, and we can combine the states, then we make them equal |
+ SetState* ss = GrNEW_APPEND_TO_RECORDER(fCmdBuffer, SetState, |
+ (batch, pipelineBuilder, *this->getGpu()->caps(), scissor, |
+ dstCopy)); |
+ if (ss->fPipeline.mustSkip()) { |
+ fCmdBuffer.pop_back(); |
+ return false; |
+ } |
+ |
+ batch->initBatchTracker(ss->fPipeline.getInitBatchTracker()); |
+ |
+ if (fPrevState && !fPrevState->fPrimitiveProcessor.get() && |
+ fPrevState->fPipeline.isEqual(ss->fPipeline)) { |
+ fCmdBuffer.pop_back(); |
+ } else { |
+ fPrevState = ss; |
+ this->recordTraceMarkersIfNecessary(); |
+ } |
+ return true; |
+} |
+ |
void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary() { |
SkASSERT(!fCmdBuffer.empty()); |
SkASSERT(!cmd_has_trace_marker(fCmdBuffer.back().fType)); |