Skip to content

Commit

Permalink
Hairline batch
Browse files Browse the repository at this point in the history
  • Loading branch information
joshualitt authored and Commit bot committed Feb 3, 2015
1 parent 532faa9 commit 658d55c
Show file tree
Hide file tree
Showing 7 changed files with 475 additions and 294 deletions.
683 changes: 436 additions & 247 deletions src/gpu/GrAAHairLinePathRenderer.cpp

Large diffs are not rendered by default.

25 changes: 0 additions & 25 deletions src/gpu/GrAAHairLinePathRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,6 @@ class GrAAHairLinePathRenderer : public GrPathRenderer {
const GrIndexBuffer* fLinesIndexBuffer,
const GrIndexBuffer* fQuadsIndexBuffer);

bool createLineGeom(GrDrawTarget* target,
GrPipelineBuilder*,
const SkMatrix& viewMatrix,
uint8_t coverage,
size_t vertexStride,
GrDrawTarget::AutoReleaseGeometry* arg,
SkRect* devBounds,
const SkPath& path,
const PtArray& lines,
int lineCnt);

bool createBezierGeom(GrDrawTarget* target,
GrPipelineBuilder*,
const SkMatrix& viewMatrix,
GrDrawTarget::AutoReleaseGeometry* arg,
SkRect* devBounds,
const SkPath& path,
const PtArray& quads,
int quadCnt,
const PtArray& conics,
int conicCnt,
const IntArray& qSubdivs,
const FloatArray& cWeights,
size_t vertexStride);

const GrIndexBuffer* fLinesIndexBuffer;
const GrIndexBuffer* fQuadsIndexBuffer;

Expand Down
5 changes: 1 addition & 4 deletions src/gpu/GrAARectRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,7 @@ class AAFillRectBatch : public GrBatch {
return false;
}

if (this->usesLocalCoords() != that->usesLocalCoords()) {
return false;
}

SkASSERT(this->usesLocalCoords() == that->usesLocalCoords());
// We apply the viewmatrix to the rect points on the cpu. However, if the pipeline uses
// local coords then we won't be able to batch. We could actually upload the viewmatrix
// using vertex attributes in these cases, but haven't investigated that
Expand Down
8 changes: 7 additions & 1 deletion src/gpu/GrBatch.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ struct GrBatchOpt {
class GrBatch : public SkRefCnt {
public:
SK_DECLARE_INST_COUNT(GrBatch)
GrBatch() { SkDEBUGCODE(fUsed = false;) }
GrBatch() : fNumberOfDraws(0) { SkDEBUGCODE(fUsed = false;) }
virtual ~GrBatch() {}

virtual const char* name() const = 0;
Expand Down Expand Up @@ -75,6 +75,10 @@ class GrBatch : public SkRefCnt {

virtual void generateGeometry(GrBatchTarget*, const GrPipeline*) = 0;

// TODO this goes away when batches are everywhere
void setNumberOfDraws(int numberOfDraws) { fNumberOfDraws = numberOfDraws; }
int numberOfDraws() const { return fNumberOfDraws; }

void* operator new(size_t size);
void operator delete(void* target);

Expand Down Expand Up @@ -126,6 +130,8 @@ class GrBatch : public SkRefCnt {

SkDEBUGCODE(bool fUsed;)

int fNumberOfDraws;

typedef SkRefCnt INHERITED;
};

Expand Down
25 changes: 14 additions & 11 deletions src/gpu/GrBatchTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,20 @@ void GrBatchTarget::flush() {
fFlushBuffer.reset();
}*/

void GrBatchTarget::flushNext() {
fIter.next();
GrProgramDesc desc;
BufferedFlush* bf = fIter.get();
const GrPipeline* pipeline = bf->fPipeline;
const GrPrimitiveProcessor* primProc = bf->fPrimitiveProcessor.get();
fGpu->buildProgramDesc(&desc, *primProc, *pipeline, pipeline->descInfo(),
bf->fBatchTracker);
void GrBatchTarget::flushNext(int n) {
for (; n > 0; n--) {
SkDEBUGCODE(bool verify =) fIter.next();
SkASSERT(verify);
GrProgramDesc desc;
BufferedFlush* bf = fIter.get();
const GrPipeline* pipeline = bf->fPipeline;
const GrPrimitiveProcessor* primProc = bf->fPrimitiveProcessor.get();
fGpu->buildProgramDesc(&desc, *primProc, *pipeline, pipeline->descInfo(),
bf->fBatchTracker);

GrGpu::DrawArgs args(primProc, pipeline, &desc, &bf->fBatchTracker);
for (int i = 0; i < bf->fDraws.count(); i++) {
fGpu->draw(args, bf->fDraws[i]);
GrGpu::DrawArgs args(primProc, pipeline, &desc, &bf->fBatchTracker);
for (int i = 0; i < bf->fDraws.count(); i++) {
fGpu->draw(args, bf->fDraws[i]);
}
}
}
18 changes: 13 additions & 5 deletions src/gpu/GrBatchTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
* that render their batch.
*/

class GrIndexBufferAllocPool;
class GrVertexBufferAllocPool;

class GrBatchTarget : public SkNoncopyable {
public:
GrBatchTarget(GrGpu* gpu,
Expand All @@ -26,11 +29,13 @@ class GrBatchTarget : public SkNoncopyable {
, fVertexPool(vpool)
, fIndexPool(ipool)
, fFlushBuffer(kFlushBufferInitialSizeInBytes)
, fIter(fFlushBuffer) {}
, fIter(fFlushBuffer)
, fNumberOfDraws(0) {}

typedef GrDrawTarget::DrawInfo DrawInfo;
void initDraw(const GrPrimitiveProcessor* primProc, const GrPipeline* pipeline) {
GrNEW_APPEND_TO_RECORDER(fFlushBuffer, BufferedFlush, (primProc, pipeline));
fNumberOfDraws++;
}

void draw(const GrDrawTarget::DrawInfo& draw) {
Expand All @@ -39,8 +44,10 @@ class GrBatchTarget : public SkNoncopyable {

// TODO this is temporary until batch is everywhere
//void flush();
void resetNumberOfDraws() { fNumberOfDraws = 0; }
int numberOfDraws() const { return fNumberOfDraws; }
void preFlush() { fIter = FlushBuffer::Iter(fFlushBuffer); }
void flushNext();
void flushNext(int n);
void postFlush() { SkASSERT(!fIter.next()); fFlushBuffer.reset(); }

// TODO This goes away when everything uses batch
Expand All @@ -49,6 +56,8 @@ class GrBatchTarget : public SkNoncopyable {
return &fFlushBuffer.back().fBatchTracker;
}

const GrDrawTargetCaps& caps() const { return *fGpu->caps(); }

GrVertexBufferAllocPool* vertexPool() { return fVertexPool; }
GrIndexBufferAllocPool* indexPool() { return fIndexPool; }

Expand All @@ -62,8 +71,7 @@ class GrBatchTarget : public SkNoncopyable {
struct BufferedFlush {
BufferedFlush(const GrPrimitiveProcessor* primProc, const GrPipeline* pipeline)
: fPrimitiveProcessor(primProc)
, fPipeline(pipeline)
, fDraws(kDrawRecorderInitialSizeInBytes) {}
, fPipeline(pipeline) {}
typedef GrPendingProgramElement<const GrPrimitiveProcessor> ProgramPrimitiveProcessor;
ProgramPrimitiveProcessor fPrimitiveProcessor;
const GrPipeline* fPipeline;
Expand All @@ -73,14 +81,14 @@ class GrBatchTarget : public SkNoncopyable {

enum {
kFlushBufferInitialSizeInBytes = 8 * sizeof(BufferedFlush),
kDrawRecorderInitialSizeInBytes = 8 * sizeof(DrawInfo),
};

typedef GrTRecorder<BufferedFlush, TBufferAlign> FlushBuffer;

FlushBuffer fFlushBuffer;
// TODO this is temporary
FlushBuffer::Iter fIter;
int fNumberOfDraws;
};

#endif
5 changes: 4 additions & 1 deletion src/gpu/GrInOrderDrawBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,8 @@ void GrInOrderDrawBuffer::onFlush() {

// TODO temporary hack
if (kDrawBatch_Cmd == strip_trace_bit(iter->fType)) {
fBatchTarget.flushNext();
DrawBatch* db = reinterpret_cast<DrawBatch*>(iter.get());
fBatchTarget.flushNext(db->fBatch->numberOfDraws());
continue;
}

Expand Down Expand Up @@ -646,7 +647,9 @@ void GrInOrderDrawBuffer::recordTraceMarkersIfNecessary() {

void GrInOrderDrawBuffer::closeBatch() {
if (fDrawBatch) {
fBatchTarget.resetNumberOfDraws();
fDrawBatch->execute(this, fPrevState);
fDrawBatch->fBatch->setNumberOfDraws(fBatchTarget.numberOfDraws());
fDrawBatch = NULL;
}
}
Expand Down

0 comments on commit 658d55c

Please sign in to comment.