From 648c696438410fe0f0f5db9bb7935006fecf9cad Mon Sep 17 00:00:00 2001 From: bsalomon Date: Fri, 23 Oct 2015 09:06:59 -0700 Subject: [PATCH] Add immediate mode option for gpu configs in dm Review URL: https://codereview.chromium.org/1421853002 --- dm/DMGpuSupport.h | 4 +++- dm/DMSrcSink.cpp | 5 +++++ include/gpu/GrContext.h | 2 +- include/gpu/GrContextOptions.h | 7 ++++++- src/gpu/GrContext.cpp | 8 +++++--- src/gpu/GrDrawTarget.cpp | 11 +++++++++-- src/gpu/GrDrawTarget.h | 8 ++++++-- src/gpu/GrDrawingManager.cpp | 3 ++- src/gpu/GrDrawingManager.h | 15 +++++++++------ src/gpu/GrTest.cpp | 2 +- 10 files changed, 47 insertions(+), 18 deletions(-) diff --git a/dm/DMGpuSupport.h b/dm/DMGpuSupport.h index 9e10231dda..b170a36d10 100644 --- a/dm/DMGpuSupport.h +++ b/dm/DMGpuSupport.h @@ -55,7 +55,9 @@ public: void dumpGpuStats(SkString*) const {} }; -struct GrContextOptions {}; +struct GrContextOptions { + bool fImmediateMode; +}; class GrContextFactory { public: diff --git a/dm/DMSrcSink.cpp b/dm/DMSrcSink.cpp index 9a61b020e8..cf9a6a2a2c 100644 --- a/dm/DMSrcSink.cpp +++ b/dm/DMSrcSink.cpp @@ -917,8 +917,13 @@ int GPUSink::enclave() const { void PreAbandonGpuContextErrorHandler(SkError, void*) {} +DEFINE_bool(imm, false, "Run gpu configs in immediate mode."); + Error GPUSink::draw(const Src& src, SkBitmap* dst, SkWStream*, SkString* log) const { GrContextOptions options; + if (FLAGS_imm) { + options.fImmediateMode = true; + } src.modifyGrContextOptions(&options); GrContextFactory factory(options); diff --git a/include/gpu/GrContext.h b/include/gpu/GrContext.h index 7136ce4ff5..1a2d9e6025 100644 --- a/include/gpu/GrContext.h +++ b/include/gpu/GrContext.h @@ -413,7 +413,7 @@ private: bool init(GrBackend, GrBackendContext, const GrContextOptions& options); void initMockContext(); - void initCommon(); + void initCommon(const GrContextOptions& options); /** * These functions create premul <-> unpremul effects if it is possible to generate a pair diff --git a/include/gpu/GrContextOptions.h b/include/gpu/GrContextOptions.h index 7c723a8434..6b93927af7 100644 --- a/include/gpu/GrContextOptions.h +++ b/include/gpu/GrContextOptions.h @@ -18,7 +18,8 @@ struct GrContextOptions { , fMinTextureSizeOverride(0) , fSuppressDualSourceBlending(false) , fGeometryBufferMapThreshold(-1) - , fUseDrawInsteadOfPartialRenderTargetWrite(false) {} + , fUseDrawInsteadOfPartialRenderTargetWrite(false) + , fImmediateMode(false) {} // EXPERIMENTAL // May be removed in the future, or may become standard depending @@ -43,6 +44,10 @@ struct GrContextOptions { /** some gpus have problems with partial writes of the rendertarget */ bool fUseDrawInsteadOfPartialRenderTargetWrite; + + /** The GrContext operates in immedidate mode. It will issue all draws to the backend API + immediately. Intended to ease debugging. */ + bool fImmediateMode; }; #endif diff --git a/src/gpu/GrContext.cpp b/src/gpu/GrContext.cpp index 2ca3461a69..fee92fe692 100644 --- a/src/gpu/GrContext.cpp +++ b/src/gpu/GrContext.cpp @@ -74,11 +74,11 @@ bool GrContext::init(GrBackend backend, GrBackendContext backendContext, if (!fGpu) { return false; } - this->initCommon(); + this->initCommon(options); return true; } -void GrContext::initCommon() { +void GrContext::initCommon(const GrContextOptions& options) { fCaps = SkRef(fGpu->caps()); fResourceCache = new GrResourceCache(fCaps); fResourceCache->setOverBudgetCallback(OverBudgetCB, this); @@ -88,7 +88,9 @@ void GrContext::initCommon() { fDidTestPMConversions = false; - fDrawingManager.reset(new GrDrawingManager(this)); + GrDrawTarget::Options dtOptions; + dtOptions.fImmediateMode = options.fImmediateMode; + fDrawingManager.reset(new GrDrawingManager(this, dtOptions)); // GrBatchFontCache will eventually replace GrFontCache fBatchFontCache = new GrBatchFontCache(this); diff --git a/src/gpu/GrDrawTarget.cpp b/src/gpu/GrDrawTarget.cpp index f42ee111ce..1dc26bc8c6 100644 --- a/src/gpu/GrDrawTarget.cpp +++ b/src/gpu/GrDrawTarget.cpp @@ -32,13 +32,15 @@ //////////////////////////////////////////////////////////////////////////////// -GrDrawTarget::GrDrawTarget(GrGpu* gpu, GrResourceProvider* resourceProvider) +GrDrawTarget::GrDrawTarget(GrGpu* gpu, GrResourceProvider* resourceProvider, + const Options& options) : fGpu(SkRef(gpu)) , fResourceProvider(resourceProvider) , fFlushState(fGpu, fResourceProvider, 0) , fFlushing(false) , fFirstUnpreparedBatch(0) - , fFlags(0) { + , fFlags(0) + , fOptions(options) { // TODO: Stop extracting the context (currently needed by GrClipMaskManager) fContext = fGpu->getContext(); fClipMaskManager.reset(new GrClipMaskManager(this)); @@ -472,6 +474,8 @@ template static bool intersect(const Left& a, const Ri void GrDrawTarget::recordBatch(GrBatch* batch) { // A closed drawTarget should never receive new/more batches SkASSERT(!this->isClosed()); + // Should never have batches queued up when in immediate mode. + SkASSERT(!fOptions.fImmediateMode || !fBatches.count()); // Check if there is a Batch Draw we can batch with by linearly searching back until we either // 1) check every draw @@ -524,6 +528,9 @@ void GrDrawTarget::recordBatch(GrBatch* batch) { SkASSERT(fBatches.count() - kMaxLookback - fFirstUnpreparedBatch == 1); fBatches[fFirstUnpreparedBatch++]->prepare(&fFlushState); } + if (fOptions.fImmediateMode) { + this->flush(); + } } /////////////////////////////////////////////////////////////////////////////// diff --git a/src/gpu/GrDrawTarget.h b/src/gpu/GrDrawTarget.h index ec94da1f0e..a487785a8b 100644 --- a/src/gpu/GrDrawTarget.h +++ b/src/gpu/GrDrawTarget.h @@ -43,9 +43,13 @@ class GrPathRangeDraw; class GrDrawTarget final : public SkRefCnt { public: + struct Options { + bool fImmediateMode; + }; + // The context may not be fully constructed and should not be used during GrDrawTarget // construction. - GrDrawTarget(GrGpu* gpu, GrResourceProvider*); + GrDrawTarget(GrGpu* gpu, GrResourceProvider*, const Options& options); ~GrDrawTarget() override; @@ -221,7 +225,6 @@ public: const CMMAccess cmmAccess() { return CMMAccess(this); } - private: friend class GrDrawingManager; // for resetFlag & TopoSortTraits @@ -311,6 +314,7 @@ private: SkDEBUGCODE(int fDebugID;) uint32_t fFlags; + Options fOptions; // 'this' drawTarget relies on the output of the drawTargets in 'fDependencies' SkTDArray fDependencies; diff --git a/src/gpu/GrDrawingManager.cpp b/src/gpu/GrDrawingManager.cpp index 682b15511a..0dbd476c79 100644 --- a/src/gpu/GrDrawingManager.cpp +++ b/src/gpu/GrDrawingManager.cpp @@ -105,7 +105,8 @@ GrDrawTarget* GrDrawingManager::newDrawTarget(GrRenderTarget* rt) { } #endif - GrDrawTarget* dt = new GrDrawTarget(fContext->getGpu(), fContext->resourceProvider()); + GrDrawTarget* dt = new GrDrawTarget(fContext->getGpu(), fContext->resourceProvider(), + fOptions); *fDrawTargets.append() = dt; diff --git a/src/gpu/GrDrawingManager.h b/src/gpu/GrDrawingManager.h index d799493c8f..be21d68ea8 100644 --- a/src/gpu/GrDrawingManager.h +++ b/src/gpu/GrDrawingManager.h @@ -8,6 +8,7 @@ #ifndef GrDrawingManager_DEFINED #define GrDrawingManager_DEFINED +#include "GrDrawTarget.h" #include "SkTDArray.h" class GrContext; @@ -40,9 +41,10 @@ public: GrContext* getContext() { return fContext; } private: - GrDrawingManager(GrContext* context) + GrDrawingManager(GrContext* context, GrDrawTarget::Options options) : fContext(context) , fAbandoned(false) + , fOptions(options) , fNVPRTextContext(nullptr) { sk_bzero(fTextContexts, sizeof(fTextContexts)); } @@ -57,13 +59,14 @@ private: static const int kNumPixelGeometries = 5; // The different pixel geometries static const int kNumDFTOptions = 2; // DFT or no DFT - GrContext* fContext; + GrContext* fContext; - bool fAbandoned; - SkTDArray fDrawTargets; + bool fAbandoned; + SkTDArray fDrawTargets; + GrDrawTarget::Options fOptions; - GrTextContext* fNVPRTextContext; - GrTextContext* fTextContexts[kNumPixelGeometries][kNumDFTOptions]; + GrTextContext* fNVPRTextContext; + GrTextContext* fTextContexts[kNumPixelGeometries][kNumDFTOptions]; }; #endif diff --git a/src/gpu/GrTest.cpp b/src/gpu/GrTest.cpp index aafb0b975a..4adc3f7b7b 100644 --- a/src/gpu/GrTest.cpp +++ b/src/gpu/GrTest.cpp @@ -288,7 +288,7 @@ void GrContext::initMockContext() { SkASSERT(nullptr == fGpu); fGpu = new MockGpu(this, options); SkASSERT(fGpu); - this->initCommon(); + this->initCommon(options); // We delete these because we want to test the cache starting with zero resources. Also, none of // these objects are required for any of tests that use this context. TODO: make stop allocating