Add Batch logging

BUG=skia:

Review URL: https://codereview.chromium.org/1276913002
This commit is contained in:
joshualitt 2015-08-07 08:11:19 -07:00 committed by Commit bot
parent f1595185e3
commit ca1f07eb5f
7 changed files with 101 additions and 8 deletions

View File

@ -36,7 +36,9 @@ public:
};
}
int32_t GrBatch::gCurrBatchClassID = GrBatch::kIllegalBatchClassID;
int32_t GrBatch::gCurrBatchClassID = GrBatch::kIllegalBatchID;
GrBATCH_SPEW(int32_t GrBatch::gCurrBatchUniqueID = GrBatch::kIllegalBatchID;)
void* GrBatch::operator new(size_t size) {
return MemoryPoolAccessor().pool()->allocate(size);

View File

@ -36,10 +36,24 @@ struct GrInitInvariantOutput;
* the draw, ie whether or not the GrBatch is allowed to tweak alpha for coverage, then this
* information will be communicated to the GrBatch prior to geometry generation.
*/
#define GR_BATCH_SPEW 0
#if GR_BATCH_SPEW
#define GrBATCH_INFO(...) SkDebugf(__VA_ARGS__)
#define GrBATCH_SPEW(code) code
#else
#define GrBATCH_SPEW(code)
#define GrBATCH_INFO(...)
#endif
class GrBatch : public GrNonAtomicRef {
public:
GrBatch() : fClassID(kIllegalBatchClassID), fNumberOfDraws(0) { SkDEBUGCODE(fUsed = false;) }
GrBatch()
: fClassID(kIllegalBatchID)
, fNumberOfDraws(0)
#if GR_BATCH_SPEW
, fUniqueID(GenID(&gCurrBatchUniqueID))
#endif
{ SkDEBUGCODE(fUsed = false;) }
virtual ~GrBatch() {}
virtual const char* name() const = 0;
@ -86,7 +100,7 @@ public:
template <typename T> const T& cast() const { return *static_cast<const T*>(this); }
template <typename T> T* cast() { return static_cast<T*>(this); }
uint32_t classID() const { SkASSERT(kIllegalBatchClassID != fClassID); return fClassID; }
uint32_t classID() const { SkASSERT(kIllegalBatchID != fClassID); return fClassID; }
// TODO no GrPrimitiveProcessors yet read fragment position
bool willReadFragmentPosition() const { return false; }
@ -96,9 +110,13 @@ public:
const GrPipeline* pipeline() const { return fPipeline; }
void setPipeline(const GrPipeline* pipeline) { fPipeline.reset(SkRef(pipeline)); }
#if GR_BATCH_SPEW
uint32_t uniqueID() const { return fUniqueID; }
#endif
protected:
template <typename PROC_SUBCLASS> void initClassID() {
static uint32_t kClassID = GenClassID();
static uint32_t kClassID = GenID(&gCurrBatchClassID);
fClassID = kClassID;
}
@ -152,11 +170,11 @@ protected:
SkRect fBounds;
private:
static uint32_t GenClassID() {
static uint32_t GenID(int32_t* idCounter) {
// fCurrProcessorClassID has been initialized to kIllegalProcessorClassID. The
// atomic inc returns the old value not the incremented value. So we add
// 1 to the returned value.
uint32_t id = static_cast<uint32_t>(sk_atomic_inc(&gCurrBatchClassID)) + 1;
uint32_t id = static_cast<uint32_t>(sk_atomic_inc(idCounter)) + 1;
if (!id) {
SkFAIL("This should never wrap as it should only be called once for each GrBatch "
"subclass.");
@ -165,12 +183,16 @@ private:
}
enum {
kIllegalBatchClassID = 0,
kIllegalBatchID = 0,
};
SkAutoTUnref<const GrPipeline> fPipeline;
static int32_t gCurrBatchClassID;
int fNumberOfDraws;
SkDEBUGCODE(bool fUsed;)
#if GR_BATCH_SPEW
static int32_t gCurrBatchUniqueID;
uint32_t fUniqueID;
#endif
typedef SkRefCnt INHERITED;
};

View File

@ -28,6 +28,7 @@ GrTargetCommands::Cmd* GrCommandBuilder::recordClear(const SkIRect& rect,
GrColorIsPMAssert(color);
clr->fColor = color;
clr->fRect = rect;
GrBATCH_INFO("Recording clear %d\n", clr->uniqueID());
return clr;
}
@ -41,6 +42,7 @@ GrTargetCommands::Cmd* GrCommandBuilder::recordClearStencilClip(const SkIRect& r
(renderTarget));
clr->fRect = rect;
clr->fInsideClip = insideClip;
GrBATCH_INFO("Recording clear stencil clip %d\n", clr->uniqueID());
return clr;
}
@ -49,6 +51,7 @@ GrTargetCommands::Cmd* GrCommandBuilder::recordDiscard(GrRenderTarget* renderTar
Clear* clr = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), Clear, (renderTarget));
clr->fColor = GrColor_ILLEGAL;
GrBATCH_INFO("Recording discard %d\n", clr->uniqueID());
return clr;
}
@ -59,6 +62,7 @@ GrTargetCommands::Cmd* GrCommandBuilder::recordCopySurface(GrSurface* dst,
CopySurface* cs = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), CopySurface, (dst, src));
cs->fSrcRect = srcRect;
cs->fDstPoint = dstPoint;
GrBATCH_INFO("Recording copysurface %d\n", cs->uniqueID());
return cs;
}
@ -75,5 +79,6 @@ GrCommandBuilder::recordXferBarrierIfNecessary(const GrPipeline& pipeline,
XferBarrier* xb = GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), XferBarrier, (rt));
xb->fBarrierType = barrierType;
GrBATCH_INFO("Recording xfer barrier %d\n", xb->uniqueID());
return xb;
}

View File

@ -28,10 +28,13 @@ static bool path_fill_type_is_winding(const GrStencilSettings& pathStencilSettin
GrTargetCommands::Cmd* GrInOrderCommandBuilder::recordDrawBatch(State* state, GrBatch* batch) {
// Check if there is a Batch Draw we can batch with
batch->setPipeline(state->getPipeline());
GrBATCH_INFO("In-Recording (%s, %u)\n", batch->name(), batch->uniqueID());
if (!this->cmdBuffer()->empty() &&
Cmd::kDrawBatch_CmdType == this->cmdBuffer()->back().type()) {
DrawBatch* previous = static_cast<DrawBatch*>(&this->cmdBuffer()->back());
if (previous->fState == state && previous->fBatch->combineIfPossible(batch)) {
GrBATCH_INFO("\tBatching with (%s, %u)\n",
previous->fBatch->name(), previous->fBatch->uniqueID());
return NULL;
}
}

View File

@ -25,6 +25,26 @@ GrTargetCommands::Cmd* GrReorderCommandBuilder::recordDrawBatch(State* state, Gr
int i = 0;
batch->setPipeline(state->getPipeline());
GrRenderTarget* rt = state->getPipeline()->getRenderTarget();
GrBATCH_INFO("Re-Recording (%s, B%u)\n"
"\tRenderTarget %p\n"
"\tBounds (%f, %f, %f, %f)\n",
batch->name(),
batch->uniqueID(), rt,
batch->bounds().fLeft, batch->bounds().fRight,
batch->bounds().fTop, batch->bounds().fBottom);
#if GR_BATCH_SPEW
SkDebugf("\tColorStages:\n");
for (int i = 0; i < state->getPipeline()->numColorFragmentStages(); i++) {
SkDebugf("\t\t%s\n", state->getPipeline()->getColorStage(i).processor()->name());
}
SkDebugf("\tCoverageStages:\n");
for (int i = 0; i < state->getPipeline()->numCoverageFragmentStages(); i++) {
SkDebugf("\t\t%s\n", state->getPipeline()->getCoverageStage(i).processor()->name());
}
SkDebugf("\tXP: %s\n", state->getPipeline()->getXferProcessor()->name());
#endif
GrBATCH_INFO("\tOutcome:\n");
if (!this->cmdBuffer()->empty()) {
GrTargetCommands::CmdBuffer::ReverseIter reverseIter(*this->cmdBuffer());
@ -33,14 +53,20 @@ GrTargetCommands::Cmd* GrReorderCommandBuilder::recordDrawBatch(State* state, Gr
DrawBatch* previous = static_cast<DrawBatch*>(reverseIter.get());
if (previous->fBatch->pipeline()->getRenderTarget() != rt) {
GrBATCH_INFO("\t\tBreaking because of (%s, B%u) Rendertarget\n",
previous->fBatch->name(), previous->fBatch->uniqueID());
break;
}
// We cannot continue to search backwards if the render target changes
if (previous->fBatch->combineIfPossible(batch)) {
GrBATCH_INFO("\t\tCombining with (%s, B%u)\n",
previous->fBatch->name(), previous->fBatch->uniqueID());
return NULL;
}
if (intersect(previous->fBatch->bounds(), batch->bounds())) {
GrBATCH_INFO("\t\tIntersects with (%s, B%u)\n",
previous->fBatch->name(), previous->fBatch->uniqueID());
break;
}
} else if (Cmd::kClear_CmdType == reverseIter->type()) {
@ -48,20 +74,35 @@ GrTargetCommands::Cmd* GrReorderCommandBuilder::recordDrawBatch(State* state, Gr
// We cannot continue to search backwards if the render target changes
if (previous->renderTarget() != rt) {
GrBATCH_INFO("\t\tBreaking because of Clear's Rendertarget change\n");
break;
}
// We set the color to illegal if we are doing a discard.
if (previous->fColor == GrColor_ILLEGAL ||
intersect(batch->bounds(), previous->fRect)) {
GrBATCH_INFO("\t\tBreaking because of Clear intersection\n");
break;
}
} else {
GrBATCH_INFO("\t\tBreaking because of other %08x\n", reverseIter->type());
// TODO temporary until we can navigate the other types of commands
break;
}
} while (reverseIter.previous() && ++i < kMaxLookback);
#if GR_BATCH_SPEW
if (!reverseIter.get()) {
GrBATCH_INFO("\t\tNo more commands to try and batch with\n");
} else if (i >= kMaxLookback) {
GrBATCH_INFO("\t\tReached max lookback %d\n", i);
}
#endif
}
#if GR_BATCH_SPEW
else {
GrBATCH_INFO("\t\tBreaking because empty command buffer\n");
}
#endif
return GrNEW_APPEND_TO_RECORDER(*this->cmdBuffer(), DrawBatch, (state, batch,
this->batchTarget()));

View File

@ -9,12 +9,15 @@
#include "GrBufferedDrawTarget.h"
GrBATCH_SPEW(int32_t GrTargetCommands::Cmd::gUniqueID = 0;)
void GrTargetCommands::reset() {
fCmdBuffer.reset();
fBatchTarget.reset();
}
void GrTargetCommands::flush(GrBufferedDrawTarget* bufferedDrawTarget) {
GrBATCH_INFO("Flushing\n");
if (fCmdBuffer.empty()) {
return;
}

View File

@ -43,7 +43,13 @@ public:
kXferBarrier_CmdType = 9,
};
Cmd(CmdType type) : fMarkerID(-1), fType(type) {}
Cmd(CmdType type)
: fMarkerID(-1)
, fType(type)
#if GR_BATCH_SPEW
, fUniqueID(GenID(&gUniqueID))
#endif
{}
virtual ~Cmd() {}
virtual void execute(GrGpu*) = 0;
@ -54,10 +60,21 @@ public:
bool isTraced() const { return -1 != fMarkerID; }
void setMarkerID(int markerID) { SkASSERT(-1 == fMarkerID); fMarkerID = markerID; }
int markerID() const { return fMarkerID; }
GrBATCH_SPEW(uint32_t uniqueID() const { return fUniqueID;} )
private:
// TODO move this to a common header so it can be shared with GrBatch
static uint32_t GenID(int32_t* idCounter) {
uint32_t id = static_cast<uint32_t>(sk_atomic_inc(idCounter)) + 1;
if (!id) {
SkFAIL("This should never wrap\n");
}
return id;
}
int fMarkerID;
CmdType fType;
GrBATCH_SPEW(uint32_t fUniqueID);
GrBATCH_SPEW(static int32_t gUniqueID;)
};
void reset();