Add batchlist managment to GrAuditTrail
BUG=skia: GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1724243004 Review URL: https://codereview.chromium.org/1724243004
This commit is contained in:
parent
42701e98e1
commit
18d6b75829
@ -12,6 +12,9 @@
|
|||||||
#include "SkRect.h"
|
#include "SkRect.h"
|
||||||
#include "SkString.h"
|
#include "SkString.h"
|
||||||
#include "SkTArray.h"
|
#include "SkTArray.h"
|
||||||
|
#include "SkTHash.h"
|
||||||
|
|
||||||
|
class GrBatch;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GrAuditTrail collects a list of draw ops, detailed information about those ops, and can dump them
|
* GrAuditTrail collects a list of draw ops, detailed information about those ops, and can dump them
|
||||||
@ -64,13 +67,30 @@ public:
|
|||||||
GrAuditTrail* fAuditTrail;
|
GrAuditTrail* fAuditTrail;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class AutoManageBatchList {
|
||||||
|
public:
|
||||||
|
AutoManageBatchList(GrAuditTrail* auditTrail)
|
||||||
|
: fAutoEnable(auditTrail)
|
||||||
|
, fAuditTrail(auditTrail) {
|
||||||
|
}
|
||||||
|
|
||||||
|
~AutoManageBatchList() {
|
||||||
|
fAuditTrail->fullReset();
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
AutoEnable fAutoEnable;
|
||||||
|
GrAuditTrail* fAuditTrail;
|
||||||
|
};
|
||||||
|
|
||||||
void pushFrame(const char* name) {
|
void pushFrame(const char* name) {
|
||||||
SkASSERT(fEnabled);
|
SkASSERT(fEnabled);
|
||||||
Frame* frame = new Frame;
|
Frame* frame = new Frame;
|
||||||
|
fEvents.emplace_back(frame);
|
||||||
if (fStack.empty()) {
|
if (fStack.empty()) {
|
||||||
fFrames.emplace_back(frame);
|
fFrames.push_back(frame);
|
||||||
} else {
|
} else {
|
||||||
fStack.back()->fChildren.emplace_back(frame);
|
fStack.back()->fChildren.push_back(frame);
|
||||||
}
|
}
|
||||||
|
|
||||||
frame->fUniqueID = fUniqueID++;
|
frame->fUniqueID = fUniqueID++;
|
||||||
@ -86,17 +106,39 @@ public:
|
|||||||
void addBatch(const char* name, const SkRect& bounds) {
|
void addBatch(const char* name, const SkRect& bounds) {
|
||||||
SkASSERT(fEnabled && !fStack.empty());
|
SkASSERT(fEnabled && !fStack.empty());
|
||||||
Batch* batch = new Batch;
|
Batch* batch = new Batch;
|
||||||
fStack.back()->fChildren.emplace_back(batch);
|
fEvents.emplace_back(batch);
|
||||||
|
fStack.back()->fChildren.push_back(batch);
|
||||||
batch->fName = name;
|
batch->fName = name;
|
||||||
batch->fBounds = bounds;
|
batch->fBounds = bounds;
|
||||||
|
fCurrentBatch = batch;
|
||||||
}
|
}
|
||||||
|
|
||||||
SkString toJson(bool prettyPrint = false) const;
|
void batchingResultCombined(GrBatch* combiner);
|
||||||
|
|
||||||
|
void batchingResultNew(GrBatch* batch);
|
||||||
|
|
||||||
|
SkString toJson(bool batchList = false, bool prettyPrint = false) const;
|
||||||
|
|
||||||
bool isEnabled() { return fEnabled; }
|
bool isEnabled() { return fEnabled; }
|
||||||
void setEnabled(bool enabled) { fEnabled = enabled; }
|
void setEnabled(bool enabled) { fEnabled = enabled; }
|
||||||
|
|
||||||
void reset() { SkASSERT(fEnabled && fStack.empty()); fFrames.reset(); }
|
void reset() {
|
||||||
|
SkASSERT(fEnabled && fStack.empty());
|
||||||
|
fFrames.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
void resetBatchList() {
|
||||||
|
SkASSERT(fEnabled);
|
||||||
|
fBatches.reset();
|
||||||
|
fIDLookup.reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
void fullReset() {
|
||||||
|
SkASSERT(fEnabled);
|
||||||
|
this->reset();
|
||||||
|
this->resetBatchList();
|
||||||
|
fEvents.reset(); // must be last, frees all of the memory
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// TODO if performance becomes an issue, we can move to using SkVarAlloc
|
// TODO if performance becomes an issue, we can move to using SkVarAlloc
|
||||||
@ -108,24 +150,32 @@ private:
|
|||||||
uint64_t fUniqueID;
|
uint64_t fUniqueID;
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef SkTArray<SkAutoTDelete<Event>, true> FrameArray;
|
|
||||||
struct Frame : public Event {
|
struct Frame : public Event {
|
||||||
SkString toJson() const override;
|
SkString toJson() const override;
|
||||||
FrameArray fChildren;
|
SkTArray<Event*> fChildren;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct Batch : public Event {
|
struct Batch : public Event {
|
||||||
SkString toJson() const override;
|
SkString toJson() const override;
|
||||||
SkRect fBounds;
|
SkRect fBounds;
|
||||||
|
SkTArray<Batch*> fChildren;
|
||||||
};
|
};
|
||||||
|
typedef SkTArray<SkAutoTDelete<Event>, true> EventArrayPool;
|
||||||
|
|
||||||
static void JsonifyTArray(SkString* json, const char* name, const FrameArray& array,
|
template <typename T>
|
||||||
|
static void JsonifyTArray(SkString* json, const char* name, const T& array,
|
||||||
bool addComma);
|
bool addComma);
|
||||||
|
|
||||||
|
// We store both an array of frames, and also a flatter array just of the batches
|
||||||
bool fEnabled;
|
bool fEnabled;
|
||||||
FrameArray fFrames;
|
EventArrayPool fEvents; // manages the lifetimes of the events
|
||||||
|
SkTArray<Event*> fFrames;
|
||||||
SkTArray<Frame*> fStack;
|
SkTArray<Frame*> fStack;
|
||||||
uint64_t fUniqueID;
|
uint64_t fUniqueID;
|
||||||
|
|
||||||
|
Batch* fCurrentBatch;
|
||||||
|
SkTHashMap<GrBatch*, int> fIDLookup;
|
||||||
|
SkTArray<Batch*> fBatches;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail, invoke, ...) \
|
#define GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail, invoke, ...) \
|
||||||
@ -142,4 +192,10 @@ private:
|
|||||||
#define GR_AUDIT_TRAIL_ADDBATCH(audit_trail, batchname, bounds) \
|
#define GR_AUDIT_TRAIL_ADDBATCH(audit_trail, batchname, bounds) \
|
||||||
GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail, addBatch, batchname, bounds);
|
GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail, addBatch, batchname, bounds);
|
||||||
|
|
||||||
|
#define GR_AUDIT_TRAIL_BATCHING_RESULT_COMBINED(audit_trail, combiner) \
|
||||||
|
GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail, batchingResultCombined, combiner);
|
||||||
|
|
||||||
|
#define GR_AUDIT_TRAIL_BATCHING_RESULT_NEW(audit_trail, batch) \
|
||||||
|
GR_AUDIT_TRAIL_INVOKE_GUARD(audit_trail, batchingResultNew, batch);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -6,8 +6,35 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "GrAuditTrail.h"
|
#include "GrAuditTrail.h"
|
||||||
|
#include "batches/GrBatch.h"
|
||||||
|
|
||||||
void GrAuditTrail::JsonifyTArray(SkString* json, const char* name, const FrameArray& array,
|
void GrAuditTrail::batchingResultCombined(GrBatch* combiner) {
|
||||||
|
int* indexPtr = fIDLookup.find(combiner);
|
||||||
|
SkASSERT(indexPtr);
|
||||||
|
int index = *indexPtr;
|
||||||
|
SkASSERT(index < fBatches.count());
|
||||||
|
Batch& batch = *fBatches[index];
|
||||||
|
|
||||||
|
// if this is our first child, we also push back a copy of the original batch and its
|
||||||
|
// bounds
|
||||||
|
if (batch.fChildren.empty()) {
|
||||||
|
Batch* firstBatch = new Batch;
|
||||||
|
firstBatch->fName = batch.fName;
|
||||||
|
firstBatch->fBounds = batch.fBounds;
|
||||||
|
fEvents.emplace_back(firstBatch);
|
||||||
|
batch.fChildren.push_back(firstBatch);
|
||||||
|
}
|
||||||
|
batch.fChildren.push_back(fCurrentBatch);
|
||||||
|
batch.fBounds = combiner->bounds();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GrAuditTrail::batchingResultNew(GrBatch* batch) {
|
||||||
|
fIDLookup.set(batch, fBatches.count());
|
||||||
|
fBatches.push_back(fCurrentBatch);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
void GrAuditTrail::JsonifyTArray(SkString* json, const char* name, const T& array,
|
||||||
bool addComma) {
|
bool addComma) {
|
||||||
if (array.count()) {
|
if (array.count()) {
|
||||||
if (addComma) {
|
if (addComma) {
|
||||||
@ -91,10 +118,14 @@ static SkString pretty_print_json(SkString json) {
|
|||||||
return prettyPrintJson.prettify(json);
|
return prettyPrintJson.prettify(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
SkString GrAuditTrail::toJson(bool prettyPrint) const {
|
SkString GrAuditTrail::toJson(bool batchList, bool prettyPrint) const {
|
||||||
SkString json;
|
SkString json;
|
||||||
json.append("{");
|
json.append("{");
|
||||||
JsonifyTArray(&json, "Stacks", fFrames, false);
|
if (!batchList) {
|
||||||
|
JsonifyTArray(&json, "Stacks", fFrames, false);
|
||||||
|
} else {
|
||||||
|
JsonifyTArray(&json, "Batches", fBatches, false);
|
||||||
|
}
|
||||||
json.append("}");
|
json.append("}");
|
||||||
|
|
||||||
if (prettyPrint) {
|
if (prettyPrint) {
|
||||||
@ -122,6 +153,7 @@ SkString GrAuditTrail::Batch::toJson() const {
|
|||||||
json.appendf("\"Right\": %f,", fBounds.fRight);
|
json.appendf("\"Right\": %f,", fBounds.fRight);
|
||||||
json.appendf("\"Top\": %f,", fBounds.fTop);
|
json.appendf("\"Top\": %f,", fBounds.fTop);
|
||||||
json.appendf("\"Bottom\": %f", fBounds.fBottom);
|
json.appendf("\"Bottom\": %f", fBounds.fBottom);
|
||||||
|
JsonifyTArray(&json, "Children", fChildren, true);
|
||||||
json.append("}");
|
json.append("}");
|
||||||
json.append("}");
|
json.append("}");
|
||||||
return json;
|
return json;
|
||||||
|
@ -460,6 +460,7 @@ void GrDrawTarget::recordBatch(GrBatch* batch) {
|
|||||||
if (candidate->combineIfPossible(batch, *this->caps())) {
|
if (candidate->combineIfPossible(batch, *this->caps())) {
|
||||||
GrBATCH_INFO("\t\tCombining with (%s, B%u)\n", candidate->name(),
|
GrBATCH_INFO("\t\tCombining with (%s, B%u)\n", candidate->name(),
|
||||||
candidate->uniqueID());
|
candidate->uniqueID());
|
||||||
|
GR_AUDIT_TRAIL_BATCHING_RESULT_COMBINED(fAuditTrail, candidate);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Stop going backwards if we would cause a painter's order violation.
|
// Stop going backwards if we would cause a painter's order violation.
|
||||||
@ -479,6 +480,7 @@ void GrDrawTarget::recordBatch(GrBatch* batch) {
|
|||||||
} else {
|
} else {
|
||||||
GrBATCH_INFO("\t\tFirstBatch\n");
|
GrBATCH_INFO("\t\tFirstBatch\n");
|
||||||
}
|
}
|
||||||
|
GR_AUDIT_TRAIL_BATCHING_RESULT_NEW(fAuditTrail, batch);
|
||||||
fBatches.push_back().reset(SkRef(batch));
|
fBatches.push_back().reset(SkRef(batch));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user