Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 02dd0ed

Browse files
rphilliSkia Commit-Bot
authored andcommitted
Change UnrefDDLTask to just be the DDLTask
Change-Id: Ib5ff9f3f3d9cbc8860e3a2ba74e6da4355197662 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/332600 Commit-Queue: Robert Phillips <[email protected]> Reviewed-by: Greg Daniel <[email protected]>
1 parent 5b85989 commit 02dd0ed

14 files changed

+238
-104
lines changed

gn/gpu.gni

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ skia_gpu_sources = [
7878
"$_src/gpu/GrCopyRenderTask.h",
7979
"$_src/gpu/GrCpuBuffer.h",
8080
"$_src/gpu/GrDDLContext.cpp",
81+
"$_src/gpu/GrDDLTask.cpp",
82+
"$_src/gpu/GrDDLTask.h",
8183
"$_src/gpu/GrDataUtils.cpp",
8284
"$_src/gpu/GrDataUtils.h",
8385
"$_src/gpu/GrDefaultGeoProcFactory.cpp",
@@ -258,7 +260,6 @@ skia_gpu_sources = [
258260
"$_src/gpu/GrTriangulator.h",
259261
"$_src/gpu/GrUniformDataManager.cpp",
260262
"$_src/gpu/GrUniformDataManager.h",
261-
"$_src/gpu/GrUnrefDDLTask.h",
262263
"$_src/gpu/GrUserStencilSettings.h",
263264
"$_src/gpu/GrUtil.cpp",
264265
"$_src/gpu/GrUtil.h",

src/core/SkDeferredDisplayListPriv.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ class SkDeferredDisplayListPriv {
3333
const SkTArray<GrRecordingContext::ProgramData>& programData() const {
3434
return fDDL->programData();
3535
}
36+
37+
const SkTArray<sk_sp<GrRenderTask>>& renderTasks() const {
38+
return fDDL->fRenderTasks;
39+
}
3640
#endif
3741

3842
private:

src/gpu/GrDDLTask.cpp

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
4+
* Use of this source code is governed by a BSD-style license that can be
5+
* found in the LICENSE file.
6+
*/
7+
8+
#include "src/gpu/GrDDLTask.h"
9+
10+
#include "include/core/SkDeferredDisplayList.h"
11+
#include "src/core/SkDeferredDisplayListPriv.h"
12+
#include "src/gpu/GrResourceAllocator.h"
13+
14+
GrDDLTask::GrDDLTask(GrDrawingManager* drawingMgr,
15+
sk_sp<GrRenderTargetProxy> ddlTarget,
16+
sk_sp<const SkDeferredDisplayList> ddl)
17+
: fDDL(std::move(ddl))
18+
, fDDLTarget(std::move(ddlTarget)) {
19+
for (auto& task : fDDL->priv().renderTasks()) {
20+
SkASSERT(task->isClosed());
21+
22+
for (int i = 0; i < task->numTargets(); ++i) {
23+
this->addTarget(drawingMgr, task->target(i));
24+
}
25+
}
26+
27+
// The DDL task never accepts additional tasks
28+
this->setFlag(kClosed_Flag);
29+
}
30+
31+
GrDDLTask::~GrDDLTask() { }
32+
33+
void GrDDLTask::endFlush(GrDrawingManager* drawingManager) {
34+
for (auto& task : fDDL->priv().renderTasks()) {
35+
task->endFlush(drawingManager);
36+
}
37+
38+
INHERITED::endFlush(drawingManager);
39+
}
40+
41+
void GrDDLTask::disown(GrDrawingManager* drawingManager) {
42+
for (auto& task : fDDL->priv().renderTasks()) {
43+
task->disown(drawingManager);
44+
}
45+
46+
INHERITED::disown(drawingManager);
47+
}
48+
49+
bool GrDDLTask::onIsUsed(GrSurfaceProxy* proxy) const {
50+
// In the ctor we've added all the targets from the sub-renderTasks into the targets list
51+
// of the this task. The base class' 'isUsed' call checks those so we don't want to check
52+
// them again here. The following 'onIsUsed' methods just check the other (non-target) proxies.
53+
for (auto& task : fDDL->priv().renderTasks()) {
54+
if (task->onIsUsed(proxy)) {
55+
return true;
56+
}
57+
}
58+
59+
return false;
60+
}
61+
62+
void GrDDLTask::handleInternalAllocationFailure() {
63+
for (auto& task : fDDL->priv().renderTasks()) {
64+
task->handleInternalAllocationFailure();
65+
}
66+
}
67+
68+
void GrDDLTask::gatherProxyIntervals(GrResourceAllocator* alloc) const {
69+
// We don't have any proxies, but the resource allocator will still bark
70+
// if a task doesn't claim any op indices, so we oblige it.
71+
alloc->incOps();
72+
73+
for (auto& task : fDDL->priv().renderTasks()) {
74+
task->gatherProxyIntervals(alloc);
75+
}
76+
}
77+
78+
GrRenderTask::ExpectedOutcome GrDDLTask::onMakeClosed(const GrCaps& caps,
79+
SkIRect* targetUpdateBounds) {
80+
SkASSERT(0);
81+
return ExpectedOutcome::kTargetUnchanged;
82+
}
83+
84+
void GrDDLTask::gatherIDs(SkSTArray<8, uint32_t, true>* idArray) const {
85+
for (auto& task : fDDL->priv().renderTasks()) {
86+
task->gatherIDs(idArray);
87+
}
88+
}
89+
90+
void GrDDLTask::onPrepare(GrOpFlushState* flushState) {
91+
for (auto& task : fDDL->priv().renderTasks()) {
92+
task->prepare(flushState);
93+
}
94+
}
95+
96+
bool GrDDLTask::onExecute(GrOpFlushState* flushState) {
97+
bool anyCommandsIssued = false;
98+
for (auto& task : fDDL->priv().renderTasks()) {
99+
if (task->execute(flushState)) {
100+
anyCommandsIssued = true;
101+
}
102+
}
103+
104+
return anyCommandsIssued;
105+
}

src/gpu/GrDDLTask.h

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright 2020 Google LLC
3+
*
4+
* Use of this source code is governed by a BSD-style license that can be
5+
* found in the LICENSE file.
6+
*/
7+
8+
#ifndef GrDDLTask_DEFINED
9+
#define GrDDLTask_DEFINED
10+
11+
#include "src/gpu/GrRenderTask.h"
12+
13+
class GrRenderTargetProxy;
14+
15+
/**
16+
* This render task isolates the DDL's tasks from the rest of the DAG. This means that
17+
* the DDL's tasks cannot be reordered by the topological sort and are always executed
18+
* as a single block.
19+
* It almost entirely just forwards calls down to the DDL's render tasks.
20+
*/
21+
class GrDDLTask final : public GrRenderTask {
22+
public:
23+
GrDDLTask(GrDrawingManager*,
24+
sk_sp<GrRenderTargetProxy> ddlTarget,
25+
sk_sp<const SkDeferredDisplayList>);
26+
27+
~GrDDLTask() override;
28+
29+
// The render tasks w/in the DDL don't appear in the DAG so need explicit notification
30+
// when they can free their contents.
31+
bool requiresExplicitCleanup() const override { return true; }
32+
33+
void endFlush(GrDrawingManager*) override;
34+
35+
void disown(GrDrawingManager*) override;
36+
37+
private:
38+
bool onIsUsed(GrSurfaceProxy* proxy) const override;
39+
40+
void handleInternalAllocationFailure() override;
41+
42+
void gatherProxyIntervals(GrResourceAllocator*) const override;
43+
44+
ExpectedOutcome onMakeClosed(const GrCaps&, SkIRect* targetUpdateBounds) override;
45+
46+
void gatherIDs(SkSTArray<8, uint32_t, true>* idArray) const override;
47+
48+
void onPrePrepare(GrRecordingContext*) override {
49+
// This entry point is only called when a DDL is snapped off of a recorder.
50+
// Since DDL tasks should never recursively appear within a DDL this should never
51+
// be called.
52+
SkASSERT(0);
53+
}
54+
55+
void onPrepare(GrOpFlushState*) override;
56+
57+
bool onExecute(GrOpFlushState*) override;
58+
59+
#if GR_TEST_UTILS
60+
const char* name() const final { return "DDL"; }
61+
#endif
62+
#ifdef SK_DEBUG
63+
void visitProxies_debugOnly(const GrOp::VisitProxyFunc& fn) const override {}
64+
#endif
65+
66+
sk_sp<const SkDeferredDisplayList> fDDL;
67+
sk_sp<GrRenderTargetProxy> fDDLTarget;
68+
69+
typedef GrRenderTask INHERITED;
70+
};
71+
72+
#endif

src/gpu/GrDirectContextPriv.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ void GrDirectContextPriv::flushSurface(GrSurfaceProxy* proxy) {
5959
this->flushSurfaces({&proxy, size}, {});
6060
}
6161

62-
void GrDirectContextPriv::copyRenderTasksFromDDL(sk_sp<const SkDeferredDisplayList> ddl,
63-
GrRenderTargetProxy* newDest) {
64-
fContext->drawingManager()->copyRenderTasksFromDDL(std::move(ddl), newDest);
62+
void GrDirectContextPriv::createDDLTask(sk_sp<const SkDeferredDisplayList> ddl,
63+
GrRenderTargetProxy* newDest) {
64+
fContext->drawingManager()->createDDLTask(std::move(ddl), newDest);
6565
}
6666

6767
bool GrDirectContextPriv::compile(const GrProgramDesc& desc, const GrProgramInfo& info) {

src/gpu/GrDirectContextPriv.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ class GrDirectContextPriv {
120120
return fContext->onGetSmallPathAtlasMgr();
121121
}
122122

123-
void copyRenderTasksFromDDL(sk_sp<const SkDeferredDisplayList>, GrRenderTargetProxy* newDest);
123+
void createDDLTask(sk_sp<const SkDeferredDisplayList>, GrRenderTargetProxy* newDest);
124124

125125
bool compile(const GrProgramDesc&, const GrProgramInfo&);
126126

src/gpu/GrDrawingManager.cpp

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "src/gpu/GrAuditTrail.h"
2020
#include "src/gpu/GrClientMappedBufferManager.h"
2121
#include "src/gpu/GrCopyRenderTask.h"
22+
#include "src/gpu/GrDDLTask.h"
2223
#include "src/gpu/GrDirectContextPriv.h"
2324
#include "src/gpu/GrGpu.h"
2425
#include "src/gpu/GrMemoryPool.h"
@@ -38,7 +39,6 @@
3839
#include "src/gpu/GrTextureResolveRenderTask.h"
3940
#include "src/gpu/GrTracing.h"
4041
#include "src/gpu/GrTransferFromRenderTask.h"
41-
#include "src/gpu/GrUnrefDDLTask.h"
4242
#include "src/gpu/GrWaitRenderTask.h"
4343
#include "src/gpu/ccpr/GrCoverageCountingPathRenderer.h"
4444
#include "src/gpu/text/GrSDFTOptions.h"
@@ -48,7 +48,7 @@ void GrDrawingManager::RenderTaskDAG::gatherIDs(SkSTArray<8, uint32_t, true>* id
4848
idArray->reset(fRenderTasks.count());
4949
for (int i = 0; i < fRenderTasks.count(); ++i) {
5050
if (fRenderTasks[i]) {
51-
(*idArray)[i] = fRenderTasks[i]->uniqueID();
51+
fRenderTasks[i]->gatherIDs(idArray);
5252
}
5353
}
5454
}
@@ -464,8 +464,10 @@ void GrDrawingManager::removeRenderTasks(int startIndex, int stopIndex) {
464464
if (!task) {
465465
continue;
466466
}
467-
if (!task->unique()) {
468-
// TODO: Eventually this should be guaranteed unique: http://skbug.com/7111
467+
if (!task->unique() || task->requiresExplicitCleanup()) {
468+
// TODO: Eventually uniqueness should be guaranteed: http://skbug.com/7111.
469+
// DDLs, however, will always require an explicit notification for when they
470+
// can clean up resources.
469471
task->endFlush(this);
470472
}
471473
task->disown(this);
@@ -557,8 +559,8 @@ void GrDrawingManager::testingOnly_removeOnFlushCallbackObject(GrOnFlushCallback
557559

558560
void GrDrawingManager::setLastRenderTask(const GrSurfaceProxy* proxy, GrRenderTask* task) {
559561
#ifdef SK_DEBUG
560-
if (GrRenderTask* prior = this->getLastRenderTask(proxy)) {
561-
SkASSERT(prior->isClosed());
562+
if (auto prior = this->getLastRenderTask(proxy)) {
563+
SkASSERT(prior->isClosed() || prior == task);
562564
}
563565
#endif
564566
uint32_t key = proxy->uniqueID().asUInt();
@@ -587,6 +589,8 @@ void GrDrawingManager::moveRenderTasksToDDL(SkDeferredDisplayList* ddl) {
587589
fDAG.closeAll(fContext->priv().caps());
588590
fActiveOpsTask = nullptr;
589591

592+
fDAG.prepForFlush();
593+
590594
fDAG.swap(&ddl->fRenderTasks);
591595
SkASSERT(!fDAG.numRenderTasks());
592596

@@ -608,8 +612,8 @@ void GrDrawingManager::moveRenderTasksToDDL(SkDeferredDisplayList* ddl) {
608612
SkDEBUGCODE(this->validate());
609613
}
610614

611-
void GrDrawingManager::copyRenderTasksFromDDL(sk_sp<const SkDeferredDisplayList> ddl,
612-
GrRenderTargetProxy* newDest) {
615+
void GrDrawingManager::createDDLTask(sk_sp<const SkDeferredDisplayList> ddl,
616+
GrRenderTargetProxy* newDest) {
613617
SkDEBUGCODE(this->validate());
614618

615619
if (fActiveOpsTask) {
@@ -621,7 +625,7 @@ void GrDrawingManager::copyRenderTasksFromDDL(sk_sp<const SkDeferredDisplayList>
621625
fActiveOpsTask = nullptr;
622626
}
623627

624-
// Propagate the DDL proxy's state information to the replaying DDL.
628+
// Propagate the DDL proxy's state information to the replay target.
625629
if (ddl->priv().targetProxy()->isMSAADirty()) {
626630
newDest->markMSAADirty(ddl->priv().targetProxy()->msaaDirtyRect(),
627631
ddl->characterization().origin());
@@ -634,7 +638,7 @@ void GrDrawingManager::copyRenderTasksFromDDL(sk_sp<const SkDeferredDisplayList>
634638
this->addDDLTarget(newDest, ddl->priv().targetProxy());
635639

636640
// Here we jam the proxy that backs the current replay SkSurface into the LazyProxyData.
637-
// The lazy proxy that references it (in the copied opsTasks) will steal its GrTexture.
641+
// The lazy proxy that references it (in the DDL opsTasks) will then steal its GrTexture.
638642
ddl->fLazyProxyData->fReplayDest = newDest;
639643

640644
if (ddl->fPendingPaths.size()) {
@@ -643,11 +647,11 @@ void GrDrawingManager::copyRenderTasksFromDDL(sk_sp<const SkDeferredDisplayList>
643647
ccpr->mergePendingPaths(ddl->fPendingPaths);
644648
}
645649

646-
fDAG.add(ddl->fRenderTasks);
647-
648-
// Add a task to unref the DDL after flush.
649-
GrRenderTask* unrefTask = fDAG.add(sk_make_sp<GrUnrefDDLTask>(std::move(ddl)));
650-
unrefTask->makeClosed(*fContext->priv().caps());
650+
// Add a task to handle drawing and lifetime management of the DDL.
651+
SkDEBUGCODE(auto ddlTask =) fDAG.add(sk_make_sp<GrDDLTask>(this,
652+
sk_ref_sp(newDest),
653+
std::move(ddl)));
654+
SkASSERT(ddlTask->isClosed());
651655

652656
SkDEBUGCODE(this->validate());
653657
}

src/gpu/GrDrawingManager.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ class GrDrawingManager {
117117
void setLastRenderTask(const GrSurfaceProxy*, GrRenderTask*);
118118

119119
void moveRenderTasksToDDL(SkDeferredDisplayList* ddl);
120-
void copyRenderTasksFromDDL(sk_sp<const SkDeferredDisplayList>, GrRenderTargetProxy* newDest);
120+
void createDDLTask(sk_sp<const SkDeferredDisplayList>, GrRenderTargetProxy* newDest);
121121

122122
private:
123123
// This class encapsulates maintenance and manipulation of the drawing manager's DAG of
@@ -204,7 +204,8 @@ class GrDrawingManager {
204204

205205
RenderTaskDAG fDAG;
206206
GrOpsTask* fActiveOpsTask = nullptr;
207-
// These are the IDs of the opsTask currently being flushed (in internalFlush)
207+
// These are the IDs of the opsTask currently being flushed (in internalFlush). They are
208+
// only stored here to prevent memory thrashing.
208209
SkSTArray<8, uint32_t, true> fFlushingRenderTaskIDs;
209210
// These are the new renderTasks generated by the onFlush CBs
210211
SkSTArray<4, sk_sp<GrRenderTask>> fOnFlushRenderTasks;

src/gpu/GrOpsTask.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -875,8 +875,8 @@ void GrOpsTask::forwardCombine(const GrCaps& caps) {
875875
}
876876
}
877877

878-
GrRenderTask::ExpectedOutcome GrOpsTask::onMakeClosed(
879-
const GrCaps& caps, SkIRect* targetUpdateBounds) {
878+
GrRenderTask::ExpectedOutcome GrOpsTask::onMakeClosed(const GrCaps& caps,
879+
SkIRect* targetUpdateBounds) {
880880
this->forwardCombine(caps);
881881
if (!this->isNoOp()) {
882882
GrSurfaceProxy* proxy = this->target(0).proxy();

0 commit comments

Comments
 (0)