aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/gpu
diff options
context:
space:
mode:
authorGravatar robertphillips <robertphillips@google.com>2015-10-30 10:11:30 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2015-10-30 10:11:30 -0700
commit498d7ac86bfb45bdfc8f9aa7424f7236235987b5 (patch)
tree06399d60167e7b037ddcb73a01789919d5a21f79 /src/gpu
parentf93982a4775763fbc754c5feb96f11ef65612f46 (diff)
Dependencies are now added between the drawTargets in GrPipeline
Diffstat (limited to 'src/gpu')
-rw-r--r--src/gpu/GrDrawTarget.cpp20
-rw-r--r--src/gpu/GrDrawTarget.h9
-rw-r--r--src/gpu/GrDrawingManager.cpp4
-rw-r--r--src/gpu/GrPipeline.cpp30
-rw-r--r--src/gpu/GrPipeline.h3
-rw-r--r--src/gpu/GrRenderTarget.cpp19
6 files changed, 77 insertions, 8 deletions
diff --git a/src/gpu/GrDrawTarget.cpp b/src/gpu/GrDrawTarget.cpp
index 5a3feccc17..7b1464ca7f 100644
--- a/src/gpu/GrDrawTarget.cpp
+++ b/src/gpu/GrDrawTarget.cpp
@@ -32,7 +32,7 @@
////////////////////////////////////////////////////////////////////////////////
-GrDrawTarget::GrDrawTarget(GrGpu* gpu, GrResourceProvider* resourceProvider,
+GrDrawTarget::GrDrawTarget(GrRenderTarget* rt, GrGpu* gpu, GrResourceProvider* resourceProvider,
const Options& options)
: fGpu(SkRef(gpu))
, fResourceProvider(resourceProvider)
@@ -40,7 +40,8 @@ GrDrawTarget::GrDrawTarget(GrGpu* gpu, GrResourceProvider* resourceProvider,
, fFlushing(false)
, fFirstUnpreparedBatch(0)
, fFlags(0)
- , fOptions(options) {
+ , fOptions(options)
+ , fRenderTarget(rt) {
// TODO: Stop extracting the context (currently needed by GrClipMaskManager)
fContext = fGpu->getContext();
fClipMaskManager.reset(new GrClipMaskManager(this));
@@ -52,6 +53,10 @@ GrDrawTarget::GrDrawTarget(GrGpu* gpu, GrResourceProvider* resourceProvider,
}
GrDrawTarget::~GrDrawTarget() {
+ if (fRenderTarget && this == fRenderTarget->getLastDrawTarget()) {
+ fRenderTarget->setLastDrawTarget(nullptr);
+ }
+
fGpu->unref();
}
@@ -184,7 +189,7 @@ void GrDrawTarget::flush() {
// drawTargets will be created to replace them if the SkGpuDevice(s) write to them again.
this->makeClosed();
- // Loop over all batches and generate geometry
+ // Loop over the batches that haven't yet generated their geometry
for (; fFirstUnpreparedBatch < fBatches.count(); ++fFirstUnpreparedBatch) {
fBatches[fFirstUnpreparedBatch]->prepare(&fFlushState);
}
@@ -227,6 +232,11 @@ void GrDrawTarget::drawBatch(const GrPipelineBuilder& pipelineBuilder, GrDrawBat
return;
}
+#ifdef ENABLE_MDB
+ SkASSERT(fRenderTarget);
+ batch->pipeline()->addDependenciesTo(fRenderTarget);
+#endif
+
this->recordBatch(batch);
}
@@ -455,6 +465,10 @@ void GrDrawTarget::copySurface(GrSurface* dst,
const SkIPoint& dstPoint) {
GrBatch* batch = GrCopySurfaceBatch::Create(dst, src, srcRect, dstPoint);
if (batch) {
+#ifdef ENABLE_MDB
+ this->addDependency(src);
+#endif
+
this->recordBatch(batch);
batch->unref();
}
diff --git a/src/gpu/GrDrawTarget.h b/src/gpu/GrDrawTarget.h
index a487785a8b..d77615e655 100644
--- a/src/gpu/GrDrawTarget.h
+++ b/src/gpu/GrDrawTarget.h
@@ -33,6 +33,8 @@
#include "SkTypes.h"
#include "SkXfermode.h"
+//#define ENABLE_MDB 1
+
class GrBatch;
class GrBatchFlushState;
class GrClip;
@@ -49,7 +51,7 @@ public:
// The context may not be fully constructed and should not be used during GrDrawTarget
// construction.
- GrDrawTarget(GrGpu* gpu, GrResourceProvider*, const Options& options);
+ GrDrawTarget(GrRenderTarget* rt, GrGpu* gpu, GrResourceProvider*, const Options& options);
~GrDrawTarget() override;
@@ -62,6 +64,10 @@ public:
}
bool isClosed() const { return this->isSetFlag(kClosed_Flag); }
+ // TODO: this entry point is only needed in the non-MDB world. Remove when
+ // we make the switch to MDB
+ void clearRT() { fRenderTarget = nullptr; }
+
/*
* Notify this drawTarget that it relies on the contents of 'dependedOn'
*/
@@ -318,6 +324,7 @@ private:
// 'this' drawTarget relies on the output of the drawTargets in 'fDependencies'
SkTDArray<GrDrawTarget*> fDependencies;
+ GrRenderTarget* fRenderTarget;
typedef SkRefCnt INHERITED;
};
diff --git a/src/gpu/GrDrawingManager.cpp b/src/gpu/GrDrawingManager.cpp
index 4483a15934..bfb586b8c1 100644
--- a/src/gpu/GrDrawingManager.cpp
+++ b/src/gpu/GrDrawingManager.cpp
@@ -14,6 +14,8 @@
#include "GrStencilAndCoverTextContext.h"
#include "SkTTopoSort.h"
+//#define ENABLE_MDB 1
+
void GrDrawingManager::cleanup() {
for (int i = 0; i < fDrawTargets.count(); ++i) {
fDrawTargets[i]->unref();
@@ -117,7 +119,7 @@ GrDrawTarget* GrDrawingManager::newDrawTarget(GrRenderTarget* rt) {
}
#endif
- GrDrawTarget* dt = new GrDrawTarget(fContext->getGpu(), fContext->resourceProvider(),
+ GrDrawTarget* dt = new GrDrawTarget(rt, fContext->getGpu(), fContext->resourceProvider(),
fOptions);
*fDrawTargets.append() = dt;
diff --git a/src/gpu/GrPipeline.cpp b/src/gpu/GrPipeline.cpp
index 80e3cbdf69..073349be1e 100644
--- a/src/gpu/GrPipeline.cpp
+++ b/src/gpu/GrPipeline.cpp
@@ -8,6 +8,7 @@
#include "GrPipeline.h"
#include "GrCaps.h"
+#include "GrDrawTarget.h"
#include "GrGpu.h"
#include "GrPipelineBuilder.h"
#include "GrProcOptInfo.h"
@@ -130,6 +131,35 @@ GrPipeline* GrPipeline::CreateAt(void* memory, const CreateArgs& args,
return pipeline;
}
+static void add_dependencies_for_processor(const GrFragmentProcessor* proc, GrRenderTarget* rt) {
+ for (int i = 0; i < proc->numChildProcessors(); ++i) {
+ // need to recurse
+ add_dependencies_for_processor(&proc->childProcessor(i), rt);
+ }
+
+ for (int i = 0; i < proc->numTextures(); ++i) {
+ GrTexture* texture = proc->textureAccess(i).getTexture();
+ SkASSERT(rt->getLastDrawTarget());
+ rt->getLastDrawTarget()->addDependency(texture);
+ }
+}
+
+void GrPipeline::addDependenciesTo(GrRenderTarget* rt) const {
+ for (int i = 0; i < fFragmentProcessors.count(); ++i) {
+ add_dependencies_for_processor(fFragmentProcessors[i].get(), rt);
+ }
+
+ if (fXferProcessor.get()) {
+ const GrXferProcessor* xfer = fXferProcessor.get();
+
+ for (int i = 0; i < xfer->numTextures(); ++i) {
+ GrTexture* texture = xfer->textureAccess(i).getTexture();
+ SkASSERT(rt->getLastDrawTarget());
+ rt->getLastDrawTarget()->addDependency(texture);
+ }
+ }
+}
+
void GrPipeline::adjustProgramFromOptimizations(const GrPipelineBuilder& pipelineBuilder,
GrXferProcessor::OptFlags flags,
const GrProcOptInfo& colorPOI,
diff --git a/src/gpu/GrPipeline.h b/src/gpu/GrPipeline.h
index df44ba680c..8781058247 100644
--- a/src/gpu/GrPipeline.h
+++ b/src/gpu/GrPipeline.h
@@ -84,6 +84,9 @@ public:
///////////////////////////////////////////////////////////////////////////
/// @name GrFragmentProcessors
+ // Make the renderTarget's drawTarget (if it exists) be dependent on any
+ // drawTargets in this pipeline
+ void addDependenciesTo(GrRenderTarget* rt) const;
int numColorFragmentProcessors() const { return fNumColorProcessors; }
int numCoverageFragmentProcessors() const {
diff --git a/src/gpu/GrRenderTarget.cpp b/src/gpu/GrRenderTarget.cpp
index ad56cf761f..e547021227 100644
--- a/src/gpu/GrRenderTarget.cpp
+++ b/src/gpu/GrRenderTarget.cpp
@@ -16,6 +16,13 @@
#include "GrRenderTargetPriv.h"
#include "GrStencilAttachment.h"
+GrRenderTarget::~GrRenderTarget() {
+ if (fLastDrawTarget) {
+ fLastDrawTarget->clearRT();
+ }
+ SkSafeUnref(fLastDrawTarget);
+}
+
void GrRenderTarget::discard() {
// go through context so that all necessary flushing occurs
GrContext* context = this->getContext();
@@ -57,24 +64,30 @@ void GrRenderTarget::overrideResolveRect(const SkIRect rect) {
void GrRenderTarget::onRelease() {
SkSafeSetNull(fStencilAttachment);
- fLastDrawTarget = nullptr;
INHERITED::onRelease();
}
void GrRenderTarget::onAbandon() {
SkSafeSetNull(fStencilAttachment);
- fLastDrawTarget = nullptr;
+
+ // The contents of this renderTarget are gone/invalid. It isn't useful to point back
+ // the creating drawTarget.
+ this->setLastDrawTarget(nullptr);
INHERITED::onAbandon();
}
void GrRenderTarget::setLastDrawTarget(GrDrawTarget* dt) {
if (fLastDrawTarget) {
+ // The non-MDB world never closes so we can't check this condition
+#ifdef ENABLE_MDB
SkASSERT(fLastDrawTarget->isClosed());
+#endif
+ fLastDrawTarget->clearRT();
}
- fLastDrawTarget = dt;
+ SkRefCnt_SafeAssign(fLastDrawTarget, dt);
}
///////////////////////////////////////////////////////////////////////////////