From 489147c78b2091b87a80dac50a3e8f0f8eb42124 Mon Sep 17 00:00:00 2001 From: bsalomon Date: Mon, 14 Dec 2015 12:13:09 -0800 Subject: [PATCH] Add option to control maximum GrBatch lookback Review URL: https://codereview.chromium.org/1498653002 --- dm/DMSrcSink.cpp | 14 +++++--------- include/gpu/GrContextOptions.h | 4 ++++ src/gpu/GrContext.cpp | 1 + src/gpu/GrDrawTarget.cpp | 9 ++++++--- src/gpu/GrDrawTarget.h | 4 +++- 5 files changed, 19 insertions(+), 13 deletions(-) diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp index 2503dc3..e27628a 100644 --- a/dm/DMSrcSink.cpp +++ b/dm/DMSrcSink.cpp @@ -810,19 +810,15 @@ void PreAbandonGpuContextErrorHandler(SkError, void*) {} DEFINE_bool(imm, false, "Run gpu configs in immediate mode."); DEFINE_bool(batchClip, false, "Clip each GrBatch to its device bounds for testing."); DEFINE_bool(batchBounds, false, "Draw a wireframe bounds of each GrBatch."); +DEFINE_int32(batchLookback, -1, "Maximum GrBatch lookback for combining, negative means default."); Error GPUSink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString* log) const { GrContextOptions grOptions; - if (FLAGS_imm) { - grOptions.fImmediateMode = true; - } - if (FLAGS_batchClip) { - grOptions.fClipBatchToBounds = true; - } + grOptions.fImmediateMode = FLAGS_imm; + grOptions.fClipBatchToBounds = FLAGS_batchClip; + grOptions.fDrawBatchBounds = FLAGS_batchBounds; + grOptions.fMaxBatchLookback = FLAGS_batchLookback; - if (FLAGS_batchBounds) { - grOptions.fDrawBatchBounds = true; - } src.modifyGrContextOptions(&grOptions); GrContextFactory factory(grOptions); diff --git a/include/gpu/GrContextOptions.h b/include/gpu/GrContextOptions.h index 2874b52..8e6368a 100644 --- a/include/gpu/GrContextOptions.h +++ b/include/gpu/GrContextOptions.h @@ -22,6 +22,7 @@ struct GrContextOptions { , fImmediateMode(false) , fClipBatchToBounds(false) , fDrawBatchBounds(false) + , fMaxBatchLookback(-1) , fUseShaderSwizzling(false) {} // EXPERIMENTAL @@ -63,6 +64,9 @@ struct GrContextOptions { of their dev bounds. */ bool fDrawBatchBounds; + /** For debugging, override the default maximum look-back window for GrBatch combining. */ + int fMaxBatchLookback; + /** Force us to do all swizzling manually in the shader and don't rely on extensions to do swizzling. */ bool fUseShaderSwizzling; diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index 1c30d54..2b20e17 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -89,6 +89,7 @@ void GrContext::initCommon(const GrContextOptions& options) { GrDrawTarget::Options dtOptions; dtOptions.fClipBatchToBounds = options.fClipBatchToBounds; dtOptions.fDrawBatchBounds = options.fDrawBatchBounds; + dtOptions.fMaxBatchLookback = options.fMaxBatchLookback; fDrawingManager.reset(new GrDrawingManager(this, dtOptions)); // GrBatchFontCache will eventually replace GrFontCache diff --git a/src/gpu/GrDrawTarget.cpp b/src/gpu/GrDrawTarget.cpp index 59488c4..55f6624 100644 --- a/src/gpu/GrDrawTarget.cpp +++ b/src/gpu/GrDrawTarget.cpp @@ -32,6 +32,9 @@ //////////////////////////////////////////////////////////////////////////////// +// Experimentally we have found that most batching occurs within the first 10 comparisons. +static const int kDefaultMaxBatchLookback = 10; + GrDrawTarget::GrDrawTarget(GrRenderTarget* rt, GrGpu* gpu, GrResourceProvider* resourceProvider, const Options& options) : fGpu(SkRef(gpu)) @@ -44,6 +47,8 @@ GrDrawTarget::GrDrawTarget(GrRenderTarget* rt, GrGpu* gpu, GrResourceProvider* r fClipMaskManager.reset(new GrClipMaskManager(this, options.fClipBatchToBounds)); fDrawBatchBounds = options.fDrawBatchBounds; + fMaxBatchLookback = (options.fMaxBatchLookback < 0) ? kDefaultMaxBatchLookback : + options.fMaxBatchLookback; rt->setLastDrawTarget(this); @@ -469,8 +474,6 @@ void GrDrawTarget::recordBatch(GrBatch* batch) { // 1) check every draw // 2) intersect with something // 3) find a 'blocker' - // Experimentally we have found that most batching occurs within the first 10 comparisons. - static const int kMaxLookback = 10; GrBATCH_INFO("Re-Recording (%s, B%u)\n" "\tBounds LRTB (%f, %f, %f, %f)\n", @@ -480,7 +483,7 @@ void GrDrawTarget::recordBatch(GrBatch* batch) { batch->bounds().fTop, batch->bounds().fBottom); GrBATCH_INFO(SkTabString(batch->dumpInfo(), 1).c_str()); GrBATCH_INFO("\tOutcome:\n"); - int maxCandidates = SkTMin(kMaxLookback, fBatches.count()); + int maxCandidates = SkTMin(fMaxBatchLookback, fBatches.count()); if (maxCandidates) { int i = 0; while (true) { diff --git a/src/gpu/GrDrawTarget.h b/src/gpu/GrDrawTarget.h index c80ac34..42a6e79 100644 --- a/src/gpu/GrDrawTarget.h +++ b/src/gpu/GrDrawTarget.h @@ -44,9 +44,10 @@ class GrDrawTarget final : public SkRefCnt { public: /** Options for GrDrawTarget behavior. */ struct Options { - Options () : fClipBatchToBounds(false), fDrawBatchBounds(false) {} + Options () : fClipBatchToBounds(false), fDrawBatchBounds(false), fMaxBatchLookback(-1) {} bool fClipBatchToBounds; bool fDrawBatchBounds; + int fMaxBatchLookback; }; GrDrawTarget(GrRenderTarget*, GrGpu*, GrResourceProvider*, const Options&); @@ -297,6 +298,7 @@ private: GrRenderTarget* fRenderTarget; bool fDrawBatchBounds; + int fMaxBatchLookback; typedef SkRefCnt INHERITED; }; -- 2.7.4