blob: 5061780d74113de772c9e21de5603a840648ea72 [file] [log] [blame]
robertphillips3dc6ae52015-10-20 09:54:32 -07001/*
2 * Copyright 2015 Google Inc.
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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/gpu/GrDrawingManager.h"
Robert Phillips69893702019-02-22 11:16:30 -05009
Robert Phillips4d5594d2020-02-21 14:24:40 -050010#include "include/core/SkDeferredDisplayList.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "include/gpu/GrBackendSemaphore.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050012#include "include/private/GrRecordingContext.h"
Robert Phillips7eb0a5f2020-06-09 14:15:09 -040013#include "src/core/SkDeferredDisplayListPriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "src/core/SkTTopoSort.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040015#include "src/gpu/GrAuditTrail.h"
Brian Salomon9241a6d2019-10-03 13:26:54 -040016#include "src/gpu/GrClientMappedBufferManager.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050017#include "src/gpu/GrContextPriv.h"
Greg Daniele227fe42019-08-21 13:52:24 -040018#include "src/gpu/GrCopyRenderTask.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050019#include "src/gpu/GrGpu.h"
20#include "src/gpu/GrMemoryPool.h"
21#include "src/gpu/GrOnFlushResourceProvider.h"
22#include "src/gpu/GrRecordingContextPriv.h"
23#include "src/gpu/GrRenderTargetContext.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040024#include "src/gpu/GrRenderTargetProxy.h"
Chris Dalton6b498102019-08-01 14:14:52 -060025#include "src/gpu/GrRenderTask.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050026#include "src/gpu/GrResourceAllocator.h"
27#include "src/gpu/GrResourceProvider.h"
28#include "src/gpu/GrSoftwarePathRenderer.h"
Greg Daniel46e366a2019-12-16 14:38:36 -050029#include "src/gpu/GrSurfaceContext.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050030#include "src/gpu/GrSurfaceProxyPriv.h"
Greg Daniel456f9b52020-03-05 19:14:18 +000031#include "src/gpu/GrTexture.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050032#include "src/gpu/GrTexturePriv.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040033#include "src/gpu/GrTextureProxy.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050034#include "src/gpu/GrTextureProxyPriv.h"
Chris Dalton3d770272019-08-14 09:24:37 -060035#include "src/gpu/GrTextureResolveRenderTask.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050036#include "src/gpu/GrTracing.h"
Greg Danielbbfec9d2019-08-20 10:56:51 -040037#include "src/gpu/GrTransferFromRenderTask.h"
Greg Danielc30f1a92019-09-06 15:28:58 -040038#include "src/gpu/GrWaitRenderTask.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050039#include "src/gpu/ccpr/GrCoverageCountingPathRenderer.h"
Herb Derbya08bde62020-06-12 15:46:06 -040040#include "src/gpu/text/GrSDFTOptions.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050041#include "src/image/SkSurface_Gpu.h"
robertphillips498d7ac2015-10-30 10:11:30 -070042
Chris Dalton6b498102019-08-01 14:14:52 -060043GrDrawingManager::RenderTaskDAG::RenderTaskDAG(bool sortRenderTasks)
44 : fSortRenderTasks(sortRenderTasks) {}
Robert Phillipsa3f70262018-02-08 10:59:38 -050045
Chris Dalton6b498102019-08-01 14:14:52 -060046GrDrawingManager::RenderTaskDAG::~RenderTaskDAG() {}
Robert Phillips22310d62018-09-05 11:07:21 -040047
Chris Dalton6b498102019-08-01 14:14:52 -060048void GrDrawingManager::RenderTaskDAG::gatherIDs(SkSTArray<8, uint32_t, true>* idArray) const {
49 idArray->reset(fRenderTasks.count());
50 for (int i = 0; i < fRenderTasks.count(); ++i) {
51 if (fRenderTasks[i]) {
52 (*idArray)[i] = fRenderTasks[i]->uniqueID();
Robert Phillips22310d62018-09-05 11:07:21 -040053 }
54 }
55}
56
Chris Dalton6b498102019-08-01 14:14:52 -060057void GrDrawingManager::RenderTaskDAG::reset() {
58 fRenderTasks.reset();
Robert Phillips22310d62018-09-05 11:07:21 -040059}
60
Chris Dalton6b498102019-08-01 14:14:52 -060061void GrDrawingManager::RenderTaskDAG::removeRenderTasks(int startIndex, int stopIndex) {
Robert Phillips22310d62018-09-05 11:07:21 -040062 for (int i = startIndex; i < stopIndex; ++i) {
Adlai Hollerd71b7b02020-06-08 15:55:00 -040063 fRenderTasks[i] = nullptr;
Robert Phillips22310d62018-09-05 11:07:21 -040064 }
65}
66
Chris Dalton6b498102019-08-01 14:14:52 -060067bool GrDrawingManager::RenderTaskDAG::isUsed(GrSurfaceProxy* proxy) const {
68 for (int i = 0; i < fRenderTasks.count(); ++i) {
69 if (fRenderTasks[i] && fRenderTasks[i]->isUsed(proxy)) {
Robert Phillips9313aa72019-04-09 18:41:27 -040070 return true;
71 }
72 }
73
74 return false;
75}
76
Chris Dalton3d770272019-08-14 09:24:37 -060077GrRenderTask* GrDrawingManager::RenderTaskDAG::add(sk_sp<GrRenderTask> renderTask) {
Chris Dalton6aeb8e82019-08-27 11:52:19 -060078 if (renderTask) {
79 return fRenderTasks.emplace_back(std::move(renderTask)).get();
80 }
81 return nullptr;
Chris Dalton3d770272019-08-14 09:24:37 -060082}
83
84GrRenderTask* GrDrawingManager::RenderTaskDAG::addBeforeLast(sk_sp<GrRenderTask> renderTask) {
85 SkASSERT(!fRenderTasks.empty());
Chris Dalton6aeb8e82019-08-27 11:52:19 -060086 if (renderTask) {
87 // Release 'fRenderTasks.back()' and grab the raw pointer, in case the SkTArray grows
88 // and reallocates during emplace_back.
89 fRenderTasks.emplace_back(fRenderTasks.back().release());
90 return (fRenderTasks[fRenderTasks.count() - 2] = std::move(renderTask)).get();
91 }
92 return nullptr;
Robert Phillips22310d62018-09-05 11:07:21 -040093}
94
Greg Danielf41b2bd2019-08-22 16:19:24 -040095void GrDrawingManager::RenderTaskDAG::add(const SkTArray<sk_sp<GrRenderTask>>& renderTasks) {
Robert Phillips19f466d2020-02-26 10:27:07 -050096#ifdef SK_DEBUG
97 for (auto& renderTask : renderTasks) {
98 SkASSERT(renderTask->unique());
99 }
100#endif
101
Greg Danielf41b2bd2019-08-22 16:19:24 -0400102 fRenderTasks.push_back_n(renderTasks.count(), renderTasks.begin());
Robert Phillips22310d62018-09-05 11:07:21 -0400103}
104
Greg Danielf41b2bd2019-08-22 16:19:24 -0400105void GrDrawingManager::RenderTaskDAG::swap(SkTArray<sk_sp<GrRenderTask>>* renderTasks) {
106 SkASSERT(renderTasks->empty());
107 renderTasks->swap(fRenderTasks);
Robert Phillips22310d62018-09-05 11:07:21 -0400108}
109
Chris Dalton6b498102019-08-01 14:14:52 -0600110void GrDrawingManager::RenderTaskDAG::prepForFlush() {
111 if (fSortRenderTasks) {
112 SkDEBUGCODE(bool result =) SkTTopoSort<GrRenderTask, GrRenderTask::TopoSortTraits>(
113 &fRenderTasks);
Robert Phillips22310d62018-09-05 11:07:21 -0400114 SkASSERT(result);
115 }
116
117#ifdef SK_DEBUG
Greg Danielf41b2bd2019-08-22 16:19:24 -0400118 // This block checks for any unnecessary splits in the opsTasks. If two sequential opsTasks
119 // share the same backing GrSurfaceProxy it means the opsTask was artificially split.
Chris Dalton6b498102019-08-01 14:14:52 -0600120 if (fRenderTasks.count()) {
Greg Danielf41b2bd2019-08-22 16:19:24 -0400121 GrOpsTask* prevOpsTask = fRenderTasks[0]->asOpsTask();
Chris Dalton6b498102019-08-01 14:14:52 -0600122 for (int i = 1; i < fRenderTasks.count(); ++i) {
Greg Danielf41b2bd2019-08-22 16:19:24 -0400123 GrOpsTask* curOpsTask = fRenderTasks[i]->asOpsTask();
Robert Phillips22310d62018-09-05 11:07:21 -0400124
Greg Danielf41b2bd2019-08-22 16:19:24 -0400125 if (prevOpsTask && curOpsTask) {
Greg Daniel16f5c652019-10-29 11:26:01 -0400126 SkASSERT(prevOpsTask->fTargetView != curOpsTask->fTargetView);
Robert Phillips22310d62018-09-05 11:07:21 -0400127 }
128
Greg Danielf41b2bd2019-08-22 16:19:24 -0400129 prevOpsTask = curOpsTask;
Robert Phillips22310d62018-09-05 11:07:21 -0400130 }
131 }
132#endif
133}
134
Chris Dalton6b498102019-08-01 14:14:52 -0600135void GrDrawingManager::RenderTaskDAG::closeAll(const GrCaps* caps) {
136 for (int i = 0; i < fRenderTasks.count(); ++i) {
137 if (fRenderTasks[i]) {
138 fRenderTasks[i]->makeClosed(*caps);
Robert Phillips22310d62018-09-05 11:07:21 -0400139 }
140 }
141}
142
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400143void GrDrawingManager::RenderTaskDAG::cleanup(GrDrawingManager* drawingMgr, const GrCaps* caps) {
Chris Dalton6b498102019-08-01 14:14:52 -0600144 for (int i = 0; i < fRenderTasks.count(); ++i) {
145 if (!fRenderTasks[i]) {
Robert Phillips22310d62018-09-05 11:07:21 -0400146 continue;
147 }
148
Chris Dalton6b498102019-08-01 14:14:52 -0600149 // no renderTask should receive a dependency
150 fRenderTasks[i]->makeClosed(*caps);
robertphillips0dfa62c2015-11-16 06:23:31 -0800151
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400152 fRenderTasks[i]->disown(drawingMgr);
153
Greg Danielf41b2bd2019-08-22 16:19:24 -0400154 // We shouldn't need to do this, but it turns out some clients still hold onto opsTasks
Robert Phillips6cdc22c2017-05-11 16:29:14 -0400155 // after a cleanup.
156 // MDB TODO: is this still true?
Chris Dalton6b498102019-08-01 14:14:52 -0600157 if (!fRenderTasks[i]->unique()) {
Chris Daltona84cacf2017-10-04 10:30:29 -0600158 // TODO: Eventually this should be guaranteed unique.
159 // https://bugs.chromium.org/p/skia/issues/detail?id=7111
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400160 fRenderTasks[i]->endFlush(drawingMgr);
Chris Daltona84cacf2017-10-04 10:30:29 -0600161 }
robertphillips3dc6ae52015-10-20 09:54:32 -0700162 }
163
Chris Dalton6b498102019-08-01 14:14:52 -0600164 fRenderTasks.reset();
Robert Phillips22310d62018-09-05 11:07:21 -0400165}
166
167///////////////////////////////////////////////////////////////////////////////////////////////////
Robert Phillips69893702019-02-22 11:16:30 -0500168GrDrawingManager::GrDrawingManager(GrRecordingContext* context,
Robert Phillips22310d62018-09-05 11:07:21 -0400169 const GrPathRendererChain::Options& optionsForPathRendererChain,
Chris Dalton6b498102019-08-01 14:14:52 -0600170 bool sortRenderTasks,
Greg Danielf41b2bd2019-08-22 16:19:24 -0400171 bool reduceOpsTaskSplitting)
Robert Phillips22310d62018-09-05 11:07:21 -0400172 : fContext(context)
173 , fOptionsForPathRendererChain(optionsForPathRendererChain)
Chris Dalton6b498102019-08-01 14:14:52 -0600174 , fDAG(sortRenderTasks)
Robert Phillips22310d62018-09-05 11:07:21 -0400175 , fPathRendererChain(nullptr)
176 , fSoftwarePathRenderer(nullptr)
Robert Phillips6db27c22019-05-01 10:43:56 -0400177 , fFlushing(false)
Herb Derby082232b2020-06-10 15:08:18 -0400178 , fReduceOpsTaskSplitting(reduceOpsTaskSplitting) { }
Robert Phillips22310d62018-09-05 11:07:21 -0400179
180void GrDrawingManager::cleanup() {
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400181 fDAG.cleanup(this, fContext->priv().caps());
robertphillips3dc6ae52015-10-20 09:54:32 -0700182
robertphillips13391dd2015-10-30 05:15:11 -0700183 fPathRendererChain = nullptr;
Ben Wagner9ec70c62018-07-12 13:30:47 -0400184 fSoftwarePathRenderer = nullptr;
Jim Van Verth106b5c42017-09-26 12:45:29 -0400185
186 fOnFlushCBObjects.reset();
robertphillips3dc6ae52015-10-20 09:54:32 -0700187}
188
189GrDrawingManager::~GrDrawingManager() {
190 this->cleanup();
191}
192
Robert Phillipsa9162df2019-02-11 14:12:03 -0500193bool GrDrawingManager::wasAbandoned() const {
Robert Phillips6a6de562019-02-15 15:19:15 -0500194 return fContext->priv().abandoned();
robertphillips3dc6ae52015-10-20 09:54:32 -0700195}
196
robertphillips68737822015-10-29 12:12:21 -0700197void GrDrawingManager::freeGpuResources() {
Jim Van Verth106b5c42017-09-26 12:45:29 -0400198 for (int i = fOnFlushCBObjects.count() - 1; i >= 0; --i) {
199 if (!fOnFlushCBObjects[i]->retainOnFreeGpuResources()) {
200 // it's safe to just do this because we're iterating in reverse
201 fOnFlushCBObjects.removeShuffle(i);
202 }
203 }
204
robertphillips68737822015-10-29 12:12:21 -0700205 // a path renderer may be holding onto resources
robertphillips13391dd2015-10-30 05:15:11 -0700206 fPathRendererChain = nullptr;
Ben Wagner9ec70c62018-07-12 13:30:47 -0400207 fSoftwarePathRenderer = nullptr;
Robert Phillipse3302df2017-04-24 07:31:02 -0400208}
209
Robert Phillips7ee385e2017-03-30 08:02:11 -0400210// MDB TODO: make use of the 'proxy' parameter.
Greg Daniel9efe3862020-06-11 11:51:06 -0400211bool GrDrawingManager::flush(
212 GrSurfaceProxy* proxies[],
213 int numProxies,
214 SkSurface::BackendSurfaceAccess access,
215 const GrFlushInfo& info,
216 const GrBackendSurfaceMutableState* newState) {
Brian Salomonf9a1fdf2019-05-09 10:30:12 -0400217 SkASSERT(numProxies >= 0);
218 SkASSERT(!numProxies || proxies);
Brian Salomon57d2beab2018-09-10 09:35:41 -0400219 GR_CREATE_TRACE_MARKER_CONTEXT("GrDrawingManager", "flush", fContext);
Brian Salomondcbb9d92017-07-19 10:53:20 -0400220
robertphillips7761d612016-05-16 09:14:53 -0700221 if (fFlushing || this->wasAbandoned()) {
Greg Daniel55822f12020-05-26 11:26:45 -0400222 if (info.fSubmittedProc) {
223 info.fSubmittedProc(info.fSubmittedContext, false);
224 }
Greg Daniele6bfb7d2019-04-17 15:26:11 -0400225 if (info.fFinishedProc) {
226 info.fFinishedProc(info.fFinishedContext);
Greg Daniela3aa75a2019-04-12 14:24:55 -0400227 }
Greg Danielfe159622020-04-10 17:43:51 +0000228 return false;
joshualittb8918c42015-12-18 09:59:46 -0800229 }
Robert Phillips602df412019-04-08 11:10:39 -0400230
Robert Phillips38d64b02018-09-04 13:23:26 -0400231 SkDEBUGCODE(this->validate());
232
Greg Daniel797efca2019-05-09 14:04:20 -0400233 if (kNone_GrFlushFlags == info.fFlags && !info.fNumSemaphores && !info.fFinishedProc &&
Greg Daniel9efe3862020-06-11 11:51:06 -0400234 access == SkSurface::BackendSurfaceAccess::kNoAccess && !newState) {
Brian Salomonf9a1fdf2019-05-09 10:30:12 -0400235 bool canSkip = numProxies > 0;
236 for (int i = 0; i < numProxies && canSkip; ++i) {
237 canSkip = !fDAG.isUsed(proxies[i]) && !this->isDDLTarget(proxies[i]);
238 }
239 if (canSkip) {
Greg Daniel55822f12020-05-26 11:26:45 -0400240 if (info.fSubmittedProc) {
241 info.fSubmittedProc(info.fSubmittedContext, true);
242 }
Greg Danielfe159622020-04-10 17:43:51 +0000243 return false;
Brian Salomonf9a1fdf2019-05-09 10:30:12 -0400244 }
Robert Phillips9313aa72019-04-09 18:41:27 -0400245 }
246
Robert Phillips6a6de562019-02-15 15:19:15 -0500247 auto direct = fContext->priv().asDirectContext();
248 if (!direct) {
Greg Daniel55822f12020-05-26 11:26:45 -0400249 if (info.fSubmittedProc) {
250 info.fSubmittedProc(info.fSubmittedContext, false);
251 }
Greg Daniele6bfb7d2019-04-17 15:26:11 -0400252 if (info.fFinishedProc) {
253 info.fFinishedProc(info.fFinishedContext);
Greg Daniela3aa75a2019-04-12 14:24:55 -0400254 }
Greg Danielfe159622020-04-10 17:43:51 +0000255 return false; // Can't flush while DDL recording
Robert Phillips6a6de562019-02-15 15:19:15 -0500256 }
Brian Salomon9241a6d2019-10-03 13:26:54 -0400257 direct->priv().clientMappedBufferManager()->process();
Robert Phillips6a6de562019-02-15 15:19:15 -0500258
259 GrGpu* gpu = direct->priv().getGpu();
Greg Daniel55822f12020-05-26 11:26:45 -0400260 // We have a non abandoned and direct GrContext. It must have a GrGpu.
261 SkASSERT(gpu);
Greg Daniela3aa75a2019-04-12 14:24:55 -0400262
joshualittb8918c42015-12-18 09:59:46 -0800263 fFlushing = true;
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400264
Robert Phillips6a6de562019-02-15 15:19:15 -0500265 auto resourceProvider = direct->priv().resourceProvider();
266 auto resourceCache = direct->priv().getResourceCache();
267
Chris Dalton6b498102019-08-01 14:14:52 -0600268 // Semi-usually the GrRenderTasks are already closed at this point, but sometimes Ganesh needs
Greg Danielf41b2bd2019-08-22 16:19:24 -0400269 // to flush mid-draw. In that case, the SkGpuDevice's opsTasks won't be closed but need to be
270 // flushed anyway. Closing such opsTasks here will mean new ones will be created to replace them
Chris Dalton6b498102019-08-01 14:14:52 -0600271 // if the SkGpuDevice(s) write to them again.
Robert Phillips9da87e02019-02-04 13:26:26 -0500272 fDAG.closeAll(fContext->priv().caps());
Greg Danielf41b2bd2019-08-22 16:19:24 -0400273 fActiveOpsTask = nullptr;
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400274
Robert Phillips22310d62018-09-05 11:07:21 -0400275 fDAG.prepForFlush();
Brian Salomon601ac802019-02-07 13:37:16 -0500276 if (!fCpuBufferCache) {
277 // We cache more buffers when the backend is using client side arrays. Otherwise, we
278 // expect each pool will use a CPU buffer as a staging buffer before uploading to a GPU
279 // buffer object. Each pool only requires one staging buffer at a time.
280 int maxCachedBuffers = fContext->priv().caps()->preferClientSideDynamicBuffers() ? 2 : 6;
281 fCpuBufferCache = GrBufferAllocPool::CpuBufferCache::Make(maxCachedBuffers);
Brian Salomon58f153c2018-10-18 21:51:15 -0400282 }
Robert Phillipsa4c93ac2017-05-18 11:40:04 -0400283
Robert Phillipse5f73282019-06-18 17:15:04 -0400284 GrOpFlushState flushState(gpu, resourceProvider, &fTokenTracker, fCpuBufferCache);
Robert Phillips40a29d72018-01-18 12:59:22 -0500285
Chris Daltonfe199b72017-05-05 11:26:15 -0400286 GrOnFlushResourceProvider onFlushProvider(this);
Robert Phillipseafd48a2017-11-16 07:52:08 -0500287 // TODO: AFAICT the only reason fFlushState is on GrDrawingManager rather than on the
288 // stack here is to preserve the flush tokens.
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400289
Chris Dalton12658942017-10-05 19:45:25 -0600290 // Prepare any onFlush op lists (e.g. atlases).
Chris Daltonfe199b72017-05-05 11:26:15 -0400291 if (!fOnFlushCBObjects.empty()) {
Chris Dalton6b498102019-08-01 14:14:52 -0600292 fDAG.gatherIDs(&fFlushingRenderTaskIDs);
Robert Phillips22310d62018-09-05 11:07:21 -0400293
Chris Daltonfe199b72017-05-05 11:26:15 -0400294 for (GrOnFlushCallbackObject* onFlushCBObject : fOnFlushCBObjects) {
Chris Dalton6b498102019-08-01 14:14:52 -0600295 onFlushCBObject->preFlush(&onFlushProvider, fFlushingRenderTaskIDs.begin(),
Chris Daltonc4b47352019-08-23 10:10:36 -0600296 fFlushingRenderTaskIDs.count());
297 }
298 for (const auto& onFlushRenderTask : fOnFlushRenderTasks) {
299 onFlushRenderTask->makeClosed(*fContext->priv().caps());
Chris Dalton706a6ff2017-11-29 22:01:06 -0700300#ifdef SK_DEBUG
Chris Daltonc4b47352019-08-23 10:10:36 -0600301 // OnFlush callbacks are invoked during flush, and are therefore expected to handle
302 // resource allocation & usage on their own. (No deferred or lazy proxies!)
303 onFlushRenderTask->visitTargetAndSrcProxies_debugOnly(
304 [](GrSurfaceProxy* p, GrMipMapped mipMapped) {
305 SkASSERT(!p->asTextureProxy() || !p->asTextureProxy()->texPriv().isDeferred());
Brian Salomonbeb7f522019-08-30 16:19:42 -0400306 SkASSERT(!p->isLazy());
Chris Dalton4ece96d2019-08-30 11:26:39 -0600307 if (p->requiresManualMSAAResolve()) {
308 // The onFlush callback is responsible for ensuring MSAA gets resolved.
309 SkASSERT(p->asRenderTargetProxy() && !p->asRenderTargetProxy()->isMSAADirty());
310 }
Chris Daltonc4b47352019-08-23 10:10:36 -0600311 if (GrMipMapped::kYes == mipMapped) {
312 // The onFlush callback is responsible for regenerating mips if needed.
313 SkASSERT(p->asTextureProxy() && !p->asTextureProxy()->mipMapsAreDirty());
314 }
315 });
Chris Dalton706a6ff2017-11-29 22:01:06 -0700316#endif
Chris Daltonc4b47352019-08-23 10:10:36 -0600317 onFlushRenderTask->prepare(&flushState);
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400318 }
319 }
320
robertphillipsa13e2022015-11-11 12:01:09 -0800321#if 0
Brian Salomon09d994e2016-12-21 11:14:46 -0500322 // Enable this to print out verbose GrOp information
Chris Daltonc4b47352019-08-23 10:10:36 -0600323 SkDEBUGCODE(SkDebugf("onFlush renderTasks:"));
324 for (const auto& onFlushRenderTask : fOnFlushRenderTasks) {
325 SkDEBUGCODE(onFlushRenderTask->dump();)
326 }
327 SkDEBUGCODE(SkDebugf("Normal renderTasks:"));
Chris Dalton6b498102019-08-01 14:14:52 -0600328 for (int i = 0; i < fRenderTasks.count(); ++i) {
329 SkDEBUGCODE(fRenderTasks[i]->dump();)
robertphillips3dc6ae52015-10-20 09:54:32 -0700330 }
robertphillipsa13e2022015-11-11 12:01:09 -0800331#endif
332
Robert Phillipseafd48a2017-11-16 07:52:08 -0500333 int startIndex, stopIndex;
334 bool flushed = false;
335
Robert Phillipsf8e25022017-11-08 15:24:31 -0500336 {
Brian Salomonbeb7f522019-08-30 16:19:42 -0400337 GrResourceAllocator alloc(resourceProvider SkDEBUGCODE(, fDAG.numRenderTasks()));
Chris Dalton6b498102019-08-01 14:14:52 -0600338 for (int i = 0; i < fDAG.numRenderTasks(); ++i) {
339 if (fDAG.renderTask(i)) {
340 fDAG.renderTask(i)->gatherProxyIntervals(&alloc);
Robert Phillips22310d62018-09-05 11:07:21 -0400341 }
Greg Danielf41b2bd2019-08-22 16:19:24 -0400342 alloc.markEndOfOpsTask(i);
Robert Phillipsf8e25022017-11-08 15:24:31 -0500343 }
Robert Phillipsc73666f2019-04-24 08:49:48 -0400344 alloc.determineRecyclability();
Robert Phillipsd375dbf2017-09-14 12:45:25 -0400345
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500346 GrResourceAllocator::AssignError error = GrResourceAllocator::AssignError::kNoError;
Chris Dalton6b498102019-08-01 14:14:52 -0600347 int numRenderTasksExecuted = 0;
Brian Salomon577aa0f2018-11-30 13:32:23 -0500348 while (alloc.assign(&startIndex, &stopIndex, &error)) {
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500349 if (GrResourceAllocator::AssignError::kFailedProxyInstantiation == error) {
350 for (int i = startIndex; i < stopIndex; ++i) {
Chris Dalton6b498102019-08-01 14:14:52 -0600351 GrRenderTask* renderTask = fDAG.renderTask(i);
352 if (!renderTask) {
353 continue;
Robert Phillips01a91282018-07-26 08:03:04 -0400354 }
Chris Dalton6b498102019-08-01 14:14:52 -0600355 if (!renderTask->isInstantiated()) {
Greg Daniel15ecdf92019-08-30 15:35:23 -0400356 // No need to call the renderTask's handleInternalAllocationFailure
357 // since we will already skip executing the renderTask since it is not
358 // instantiated.
Chris Dalton6b498102019-08-01 14:14:52 -0600359 continue;
Robert Phillipsbbcb7f72018-05-31 11:16:19 -0400360 }
Chris Dalton6b498102019-08-01 14:14:52 -0600361 renderTask->handleInternalAllocationFailure();
Greg Danielaa3dfbe2018-01-29 10:34:25 -0500362 }
363 }
Robert Phillips4150eea2018-02-07 17:08:21 -0500364
Chris Dalton6b498102019-08-01 14:14:52 -0600365 if (this->executeRenderTasks(
366 startIndex, stopIndex, &flushState, &numRenderTasksExecuted)) {
Robert Phillipseafd48a2017-11-16 07:52:08 -0500367 flushed = true;
368 }
bsalomondc438982016-08-31 11:53:49 -0700369 }
Greg Danielc42b20b2017-10-04 10:34:49 -0400370 }
371
Chris Dalton91ab1552018-04-18 13:24:25 -0600372#ifdef SK_DEBUG
Chris Dalton6b498102019-08-01 14:14:52 -0600373 for (int i = 0; i < fDAG.numRenderTasks(); ++i) {
Greg Danielf41b2bd2019-08-22 16:19:24 -0400374 // If there are any remaining opsTaskss at this point, make sure they will not survive the
Chris Dalton91ab1552018-04-18 13:24:25 -0600375 // flush. Otherwise we need to call endFlush() on them.
376 // http://skbug.com/7111
Chris Dalton6b498102019-08-01 14:14:52 -0600377 SkASSERT(!fDAG.renderTask(i) || fDAG.renderTask(i)->unique());
Chris Dalton91ab1552018-04-18 13:24:25 -0600378 }
379#endif
Adlai Holler25df1f72020-06-09 13:08:27 -0400380 fLastRenderTasks.reset();
Robert Phillips22310d62018-09-05 11:07:21 -0400381 fDAG.reset();
Robert Phillips15c91422019-05-07 16:54:48 -0400382 this->clearDDLTargets();
robertphillipsa13e2022015-11-11 12:01:09 -0800383
Robert Phillipsc994a932018-06-19 13:09:54 -0400384#ifdef SK_DEBUG
385 // In non-DDL mode this checks that all the flushed ops have been freed from the memory pool.
386 // When we move to partial flushes this assert will no longer be valid.
Greg Danielf41b2bd2019-08-22 16:19:24 -0400387 // In DDL mode this check is somewhat superfluous since the memory for most of the ops/opsTasks
Robert Phillipsc994a932018-06-19 13:09:54 -0400388 // will be stored in the DDL's GrOpMemoryPools.
Robert Phillips9da87e02019-02-04 13:26:26 -0500389 GrOpMemoryPool* opMemoryPool = fContext->priv().opMemoryPool();
Robert Phillipsc994a932018-06-19 13:09:54 -0400390 opMemoryPool->isEmpty();
391#endif
392
Greg Daniel9efe3862020-06-11 11:51:06 -0400393 gpu->executeFlushInfo(proxies, numProxies, access, info, newState);
robertphillipsa13e2022015-11-11 12:01:09 -0800394
Brian Salomon57d2beab2018-09-10 09:35:41 -0400395 // Give the cache a chance to purge resources that become purgeable due to flushing.
396 if (flushed) {
Robert Phillips6a6de562019-02-15 15:19:15 -0500397 resourceCache->purgeAsNeeded();
Brian Salomon876a0172019-03-08 11:12:14 -0500398 flushed = false;
bsalomonb77a9072016-09-07 10:02:04 -0700399 }
Chris Daltonfe199b72017-05-05 11:26:15 -0400400 for (GrOnFlushCallbackObject* onFlushCBObject : fOnFlushCBObjects) {
Chris Dalton6b498102019-08-01 14:14:52 -0600401 onFlushCBObject->postFlush(fTokenTracker.nextTokenToFlush(), fFlushingRenderTaskIDs.begin(),
402 fFlushingRenderTaskIDs.count());
Brian Salomon876a0172019-03-08 11:12:14 -0500403 flushed = true;
404 }
405 if (flushed) {
406 resourceCache->purgeAsNeeded();
Chris Daltonfe199b72017-05-05 11:26:15 -0400407 }
Chris Dalton6b498102019-08-01 14:14:52 -0600408 fFlushingRenderTaskIDs.reset();
joshualittb8918c42015-12-18 09:59:46 -0800409 fFlushing = false;
Greg Daniel51316782017-08-02 15:10:09 +0000410
Greg Danielfe159622020-04-10 17:43:51 +0000411 return true;
412}
413
414bool GrDrawingManager::submitToGpu(bool syncToCpu) {
415 if (fFlushing || this->wasAbandoned()) {
416 return false;
417 }
418
419 auto direct = fContext->priv().asDirectContext();
420 if (!direct) {
421 return false; // Can't submit while DDL recording
422 }
423 GrGpu* gpu = direct->priv().getGpu();
424 return gpu->submitToGpu(syncToCpu);
robertphillips3dc6ae52015-10-20 09:54:32 -0700425}
426
Chris Dalton6b498102019-08-01 14:14:52 -0600427bool GrDrawingManager::executeRenderTasks(int startIndex, int stopIndex, GrOpFlushState* flushState,
428 int* numRenderTasksExecuted) {
429 SkASSERT(startIndex <= stopIndex && stopIndex <= fDAG.numRenderTasks());
Robert Phillipseafd48a2017-11-16 07:52:08 -0500430
Robert Phillips27483912018-04-20 12:43:18 -0400431#if GR_FLUSH_TIME_OP_SPEW
Greg Danielf41b2bd2019-08-22 16:19:24 -0400432 SkDebugf("Flushing opsTask: %d to %d out of [%d, %d]\n",
Chris Dalton6b498102019-08-01 14:14:52 -0600433 startIndex, stopIndex, 0, fDAG.numRenderTasks());
Robert Phillips27483912018-04-20 12:43:18 -0400434 for (int i = startIndex; i < stopIndex; ++i) {
Chris Dalton6b498102019-08-01 14:14:52 -0600435 if (fDAG.renderTask(i)) {
436 fDAG.renderTask(i)->dump(true);
Robert Phillips1734dd32018-08-21 13:52:09 -0400437 }
Robert Phillips27483912018-04-20 12:43:18 -0400438 }
439#endif
440
Chris Dalton6b498102019-08-01 14:14:52 -0600441 bool anyRenderTasksExecuted = false;
Robert Phillipseafd48a2017-11-16 07:52:08 -0500442
443 for (int i = startIndex; i < stopIndex; ++i) {
Greg Daniel15ecdf92019-08-30 15:35:23 -0400444 GrRenderTask* renderTask = fDAG.renderTask(i);
445 if (!renderTask || !renderTask->isInstantiated()) {
Robert Phillipseafd48a2017-11-16 07:52:08 -0500446 continue;
447 }
448
Chris Dalton6b498102019-08-01 14:14:52 -0600449 SkASSERT(renderTask->deferredProxiesAreInstantiated());
Robert Phillips22310d62018-09-05 11:07:21 -0400450
Chris Dalton6b498102019-08-01 14:14:52 -0600451 renderTask->prepare(flushState);
Robert Phillipseafd48a2017-11-16 07:52:08 -0500452 }
453
454 // Upload all data to the GPU
455 flushState->preExecuteDraws();
456
Greg Danield2073452018-12-07 11:20:33 -0500457 // For Vulkan, if we have too many oplists to be flushed we end up allocating a lot of resources
458 // for each command buffer associated with the oplists. If this gets too large we can cause the
459 // devices to go OOM. In practice we usually only hit this case in our tests, but to be safe we
460 // put a cap on the number of oplists we will execute before flushing to the GPU to relieve some
461 // memory pressure.
Chris Dalton6b498102019-08-01 14:14:52 -0600462 static constexpr int kMaxRenderTasksBeforeFlush = 100;
Greg Danield2073452018-12-07 11:20:33 -0500463
Chris Daltonc4b47352019-08-23 10:10:36 -0600464 // Execute the onFlush renderTasks first, if any.
465 for (sk_sp<GrRenderTask>& onFlushRenderTask : fOnFlushRenderTasks) {
466 if (!onFlushRenderTask->execute(flushState)) {
467 SkDebugf("WARNING: onFlushRenderTask failed to execute.\n");
Robert Phillipseafd48a2017-11-16 07:52:08 -0500468 }
Chris Daltonc4b47352019-08-23 10:10:36 -0600469 SkASSERT(onFlushRenderTask->unique());
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400470 onFlushRenderTask->disown(this);
Chris Daltonc4b47352019-08-23 10:10:36 -0600471 onFlushRenderTask = nullptr;
Chris Dalton6b498102019-08-01 14:14:52 -0600472 (*numRenderTasksExecuted)++;
473 if (*numRenderTasksExecuted >= kMaxRenderTasksBeforeFlush) {
Greg Danielfe159622020-04-10 17:43:51 +0000474 flushState->gpu()->submitToGpu(false);
Chris Dalton6b498102019-08-01 14:14:52 -0600475 *numRenderTasksExecuted = 0;
Greg Danield2073452018-12-07 11:20:33 -0500476 }
Robert Phillipseafd48a2017-11-16 07:52:08 -0500477 }
Chris Daltonc4b47352019-08-23 10:10:36 -0600478 fOnFlushRenderTasks.reset();
Robert Phillipseafd48a2017-11-16 07:52:08 -0500479
480 // Execute the normal op lists.
481 for (int i = startIndex; i < stopIndex; ++i) {
Greg Daniel15ecdf92019-08-30 15:35:23 -0400482 GrRenderTask* renderTask = fDAG.renderTask(i);
483 if (!renderTask || !renderTask->isInstantiated()) {
Robert Phillipseafd48a2017-11-16 07:52:08 -0500484 continue;
485 }
486
Greg Daniel15ecdf92019-08-30 15:35:23 -0400487 if (renderTask->execute(flushState)) {
Chris Dalton6b498102019-08-01 14:14:52 -0600488 anyRenderTasksExecuted = true;
Robert Phillipseafd48a2017-11-16 07:52:08 -0500489 }
Chris Dalton6b498102019-08-01 14:14:52 -0600490 (*numRenderTasksExecuted)++;
491 if (*numRenderTasksExecuted >= kMaxRenderTasksBeforeFlush) {
Greg Danielfe159622020-04-10 17:43:51 +0000492 flushState->gpu()->submitToGpu(false);
Chris Dalton6b498102019-08-01 14:14:52 -0600493 *numRenderTasksExecuted = 0;
Greg Danield2073452018-12-07 11:20:33 -0500494 }
Robert Phillipseafd48a2017-11-16 07:52:08 -0500495 }
496
Greg Daniel2d41d0d2019-08-26 11:08:51 -0400497 SkASSERT(!flushState->opsRenderPass());
Robert Phillips40a29d72018-01-18 12:59:22 -0500498 SkASSERT(fTokenTracker.nextDrawToken() == fTokenTracker.nextTokenToFlush());
Robert Phillipseafd48a2017-11-16 07:52:08 -0500499
Chris Dalton6b498102019-08-01 14:14:52 -0600500 // We reset the flush state before the RenderTasks so that the last resources to be freed are
501 // those that are written to in the RenderTasks. This helps to make sure the most recently used
502 // resources are the last to be purged by the resource cache.
Robert Phillipseafd48a2017-11-16 07:52:08 -0500503 flushState->reset();
504
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400505 this->removeRenderTasks(startIndex, stopIndex);
Robert Phillipseafd48a2017-11-16 07:52:08 -0500506
Chris Dalton6b498102019-08-01 14:14:52 -0600507 return anyRenderTasksExecuted;
Robert Phillipseafd48a2017-11-16 07:52:08 -0500508}
509
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400510void GrDrawingManager::removeRenderTasks(int startIndex, int stopIndex) {
511 for (int i = startIndex; i < stopIndex; ++i) {
512 GrRenderTask* task = fDAG.renderTask(i);
513 if (!task) {
514 continue;
515 }
516 if (!task->unique()) {
517 // TODO: Eventually this should be guaranteed unique: http://skbug.com/7111
518 task->endFlush(this);
519 }
520 task->disown(this);
521 }
522 fDAG.removeRenderTasks(startIndex, stopIndex);
523}
524
Robert Phillips7eb0a5f2020-06-09 14:15:09 -0400525static void resolve_and_mipmap(GrGpu* gpu, GrSurfaceProxy* proxy) {
526 if (!proxy->isInstantiated()) {
527 return;
528 }
529
530 // In the flushSurfaces case, we need to resolve MSAA immediately after flush. This is
531 // because clients expect the flushed surface's backing texture to be fully resolved
532 // upon return.
533 if (proxy->requiresManualMSAAResolve()) {
534 auto* rtProxy = proxy->asRenderTargetProxy();
535 SkASSERT(rtProxy);
536 if (rtProxy->isMSAADirty()) {
537 SkASSERT(rtProxy->peekRenderTarget());
538 gpu->resolveRenderTarget(rtProxy->peekRenderTarget(), rtProxy->msaaDirtyRect(),
539 GrGpu::ForExternalIO::kYes);
540 rtProxy->markMSAAResolved();
541 }
542 }
543 // If, after a flush, any of the proxies of interest have dirty mipmaps, regenerate them in
544 // case their backend textures are being stolen.
545 // (This special case is exercised by the ReimportImageTextureWithMipLevels test.)
546 // FIXME: It may be more ideal to plumb down a "we're going to steal the backends" flag.
547 if (auto* textureProxy = proxy->asTextureProxy()) {
548 if (textureProxy->mipMapsAreDirty()) {
549 SkASSERT(textureProxy->peekTexture());
550 gpu->regenerateMipMapLevels(textureProxy->peekTexture());
551 textureProxy->markMipMapsClean();
552 }
553 }
554}
555
Greg Daniel9efe3862020-06-11 11:51:06 -0400556GrSemaphoresSubmitted GrDrawingManager::flushSurfaces(
557 GrSurfaceProxy* proxies[],
558 int numProxies,
559 SkSurface::BackendSurfaceAccess access,
560 const GrFlushInfo& info,
561 const GrBackendSurfaceMutableState* newState) {
bsalomon6a2b1942016-09-08 11:28:59 -0700562 if (this->wasAbandoned()) {
Greg Daniel55822f12020-05-26 11:26:45 -0400563 if (info.fSubmittedProc) {
564 info.fSubmittedProc(info.fSubmittedContext, false);
565 }
566 if (info.fFinishedProc) {
567 info.fFinishedProc(info.fFinishedContext);
568 }
Greg Daniel51316782017-08-02 15:10:09 +0000569 return GrSemaphoresSubmitted::kNo;
bsalomon6a2b1942016-09-08 11:28:59 -0700570 }
Robert Phillips38d64b02018-09-04 13:23:26 -0400571 SkDEBUGCODE(this->validate());
Brian Salomonf9a1fdf2019-05-09 10:30:12 -0400572 SkASSERT(numProxies >= 0);
573 SkASSERT(!numProxies || proxies);
bsalomon6a2b1942016-09-08 11:28:59 -0700574
Robert Phillips6a6de562019-02-15 15:19:15 -0500575 auto direct = fContext->priv().asDirectContext();
576 if (!direct) {
Greg Daniel55822f12020-05-26 11:26:45 -0400577 if (info.fSubmittedProc) {
578 info.fSubmittedProc(info.fSubmittedContext, false);
579 }
580 if (info.fFinishedProc) {
581 info.fFinishedProc(info.fFinishedContext);
582 }
Robert Phillips6a6de562019-02-15 15:19:15 -0500583 return GrSemaphoresSubmitted::kNo; // Can't flush while DDL recording
584 }
585
586 GrGpu* gpu = direct->priv().getGpu();
Greg Daniel55822f12020-05-26 11:26:45 -0400587 // We have a non abandoned and direct GrContext. It must have a GrGpu.
588 SkASSERT(gpu);
Robert Phillips874b5352018-03-16 08:48:24 -0400589
Robert Phillipsacc10fa2019-04-01 09:50:20 -0400590 // TODO: It is important to upgrade the drawingmanager to just flushing the
Brian Salomonf9a1fdf2019-05-09 10:30:12 -0400591 // portion of the DAG required by 'proxies' in order to restore some of the
Robert Phillipsacc10fa2019-04-01 09:50:20 -0400592 // semantics of this method.
Greg Daniel9efe3862020-06-11 11:51:06 -0400593 bool didFlush = this->flush(proxies, numProxies, access, info, newState);
Brian Salomonf9a1fdf2019-05-09 10:30:12 -0400594 for (int i = 0; i < numProxies; ++i) {
Robert Phillips7eb0a5f2020-06-09 14:15:09 -0400595 resolve_and_mipmap(gpu, proxies[i]);
bsalomon6a2b1942016-09-08 11:28:59 -0700596 }
Robert Phillips38d64b02018-09-04 13:23:26 -0400597
598 SkDEBUGCODE(this->validate());
Greg Danielfe159622020-04-10 17:43:51 +0000599
Greg Daniel04283f32020-05-20 13:16:00 -0400600 if (!didFlush || (!direct->priv().caps()->semaphoreSupport() && info.fNumSemaphores)) {
Greg Danielfe159622020-04-10 17:43:51 +0000601 return GrSemaphoresSubmitted::kNo;
602 }
603 return GrSemaphoresSubmitted::kYes;
bsalomon6a2b1942016-09-08 11:28:59 -0700604}
605
Chris Daltonfe199b72017-05-05 11:26:15 -0400606void GrDrawingManager::addOnFlushCallbackObject(GrOnFlushCallbackObject* onFlushCBObject) {
607 fOnFlushCBObjects.push_back(onFlushCBObject);
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400608}
609
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500610#if GR_TEST_UTILS
611void GrDrawingManager::testingOnly_removeOnFlushCallbackObject(GrOnFlushCallbackObject* cb) {
612 int n = std::find(fOnFlushCBObjects.begin(), fOnFlushCBObjects.end(), cb) -
613 fOnFlushCBObjects.begin();
614 SkASSERT(n < fOnFlushCBObjects.count());
615 fOnFlushCBObjects.removeShuffle(n);
616}
617#endif
618
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400619void GrDrawingManager::setLastRenderTask(const GrSurfaceProxy* proxy, GrRenderTask* task) {
620#ifdef SK_DEBUG
621 if (GrRenderTask* prior = this->getLastRenderTask(proxy)) {
622 SkASSERT(prior->isClosed());
623 }
624#endif
Adlai Holler25df1f72020-06-09 13:08:27 -0400625 uint32_t key = proxy->uniqueID().asUInt();
626 if (task) {
627 fLastRenderTasks.set(key, task);
628 } else if (fLastRenderTasks.find(key)) {
629 fLastRenderTasks.remove(key);
630 }
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400631}
632
633GrRenderTask* GrDrawingManager::getLastRenderTask(const GrSurfaceProxy* proxy) const {
634 auto entry = fLastRenderTasks.find(proxy->uniqueID().asUInt());
635 return entry ? *entry : nullptr;
636}
637
638GrOpsTask* GrDrawingManager::getLastOpsTask(const GrSurfaceProxy* proxy) const {
639 GrRenderTask* task = this->getLastRenderTask(proxy);
640 return task ? task->asOpsTask() : nullptr;
641}
642
643
Chris Dalton6b498102019-08-01 14:14:52 -0600644void GrDrawingManager::moveRenderTasksToDDL(SkDeferredDisplayList* ddl) {
Robert Phillips38d64b02018-09-04 13:23:26 -0400645 SkDEBUGCODE(this->validate());
646
Chris Dalton6b498102019-08-01 14:14:52 -0600647 // no renderTask should receive a new command after this
Robert Phillips9da87e02019-02-04 13:26:26 -0500648 fDAG.closeAll(fContext->priv().caps());
Greg Danielf41b2bd2019-08-22 16:19:24 -0400649 fActiveOpsTask = nullptr;
Robert Phillips7a137052018-02-01 11:23:12 -0500650
Chris Dalton6b498102019-08-01 14:14:52 -0600651 fDAG.swap(&ddl->fRenderTasks);
Robert Phillips19f466d2020-02-26 10:27:07 -0500652 SkASSERT(!fDAG.numRenderTasks());
Robert Phillips867ce8f2018-06-21 10:28:36 -0400653
Robert Phillips19f466d2020-02-26 10:27:07 -0500654 for (auto& renderTask : ddl->fRenderTasks) {
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400655 renderTask->disown(this);
Robert Phillips29f38542019-10-16 09:20:25 -0400656 renderTask->prePrepare(fContext);
Robert Phillips7327c9d2019-10-08 16:32:56 -0400657 }
658
Michael Ludwig2c316bd2019-12-19 14:50:44 -0500659 ddl->fArenas = std::move(fContext->priv().detachArenas());
Robert Phillips61fc7992019-10-22 11:58:17 -0400660
Robert Phillipsf6a0b452020-02-18 14:26:46 -0500661 fContext->priv().detachProgramData(&ddl->fProgramData);
Robert Phillips576b6a12019-12-06 13:05:49 -0500662
Robert Phillips774168e2018-05-31 12:43:27 -0400663 if (fPathRendererChain) {
664 if (auto ccpr = fPathRendererChain->getCoverageCountingPathRenderer()) {
665 ddl->fPendingPaths = ccpr->detachPendingPaths();
666 }
667 }
Robert Phillips38d64b02018-09-04 13:23:26 -0400668
669 SkDEBUGCODE(this->validate());
Robert Phillips62000362018-02-01 09:10:04 -0500670}
671
Chris Dalton6b498102019-08-01 14:14:52 -0600672void GrDrawingManager::copyRenderTasksFromDDL(const SkDeferredDisplayList* ddl,
Robert Phillips933484f2019-11-26 09:38:55 -0500673 GrRenderTargetProxy* newDest) {
Robert Phillips38d64b02018-09-04 13:23:26 -0400674 SkDEBUGCODE(this->validate());
675
Greg Danielf41b2bd2019-08-22 16:19:24 -0400676 if (fActiveOpsTask) {
Robert Phillips38d64b02018-09-04 13:23:26 -0400677 // This is a temporary fix for the partial-MDB world. In that world we're not
Greg Danielf41b2bd2019-08-22 16:19:24 -0400678 // reordering so ops that (in the single opsTask world) would've just glommed onto the
679 // end of the single opsTask but referred to a far earlier RT need to appear in their
680 // own opsTask.
681 fActiveOpsTask->makeClosed(*fContext->priv().caps());
682 fActiveOpsTask = nullptr;
Robert Phillips38d64b02018-09-04 13:23:26 -0400683 }
684
Robert Phillips7eb0a5f2020-06-09 14:15:09 -0400685 // Propagate the DDL proxy's state information to the replaying DDL.
686 if (ddl->priv().targetProxy()->isMSAADirty()) {
687 newDest->markMSAADirty(ddl->priv().targetProxy()->msaaDirtyRect(),
688 ddl->characterization().origin());
689 }
690 GrTextureProxy* newTextureProxy = newDest->asTextureProxy();
691 if (newTextureProxy && GrMipMapped::kYes == newTextureProxy->mipMapped()) {
692 newTextureProxy->markMipMapsDirty();
693 }
694
695 this->addDDLTarget(newDest, ddl->priv().targetProxy());
Robert Phillips15c91422019-05-07 16:54:48 -0400696
Robert Phillips62000362018-02-01 09:10:04 -0500697 // Here we jam the proxy that backs the current replay SkSurface into the LazyProxyData.
Greg Danielf41b2bd2019-08-22 16:19:24 -0400698 // The lazy proxy that references it (in the copied opsTasks) will steal its GrTexture.
Robert Phillips62000362018-02-01 09:10:04 -0500699 ddl->fLazyProxyData->fReplayDest = newDest;
Robert Phillips774168e2018-05-31 12:43:27 -0400700
701 if (ddl->fPendingPaths.size()) {
702 GrCoverageCountingPathRenderer* ccpr = this->getCoverageCountingPathRenderer();
703
704 ccpr->mergePendingPaths(ddl->fPendingPaths);
705 }
Robert Phillips22310d62018-09-05 11:07:21 -0400706
Chris Dalton6b498102019-08-01 14:14:52 -0600707 fDAG.add(ddl->fRenderTasks);
Robert Phillips38d64b02018-09-04 13:23:26 -0400708
709 SkDEBUGCODE(this->validate());
Robert Phillips62000362018-02-01 09:10:04 -0500710}
711
Robert Phillips38d64b02018-09-04 13:23:26 -0400712#ifdef SK_DEBUG
713void GrDrawingManager::validate() const {
Greg Danielf41b2bd2019-08-22 16:19:24 -0400714 if (fDAG.sortingRenderTasks() && fReduceOpsTaskSplitting) {
715 SkASSERT(!fActiveOpsTask);
Robert Phillipsb7a98ef2018-10-10 09:26:00 -0400716 } else {
Greg Danielf41b2bd2019-08-22 16:19:24 -0400717 if (fActiveOpsTask) {
Robert Phillipsb7a98ef2018-10-10 09:26:00 -0400718 SkASSERT(!fDAG.empty());
Greg Danielf41b2bd2019-08-22 16:19:24 -0400719 SkASSERT(!fActiveOpsTask->isClosed());
720 SkASSERT(fActiveOpsTask == fDAG.back());
Robert Phillips38d64b02018-09-04 13:23:26 -0400721 }
Robert Phillips38d64b02018-09-04 13:23:26 -0400722
Chris Dalton6b498102019-08-01 14:14:52 -0600723 for (int i = 0; i < fDAG.numRenderTasks(); ++i) {
Greg Danielf41b2bd2019-08-22 16:19:24 -0400724 if (fActiveOpsTask != fDAG.renderTask(i)) {
Chris Daltone2a903e2019-09-18 13:41:50 -0600725 // The resolveTask associated with the activeTask remains open for as long as the
726 // activeTask does.
727 bool isActiveResolveTask =
728 fActiveOpsTask && fActiveOpsTask->fTextureResolveTask == fDAG.renderTask(i);
729 SkASSERT(isActiveResolveTask || fDAG.renderTask(i)->isClosed());
Robert Phillipsb7a98ef2018-10-10 09:26:00 -0400730 }
731 }
732
733 if (!fDAG.empty() && !fDAG.back()->isClosed()) {
Greg Danielf41b2bd2019-08-22 16:19:24 -0400734 SkASSERT(fActiveOpsTask == fDAG.back());
Robert Phillipsb7a98ef2018-10-10 09:26:00 -0400735 }
Robert Phillips38d64b02018-09-04 13:23:26 -0400736 }
737}
738#endif
739
Greg Danielbbfec9d2019-08-20 10:56:51 -0400740void GrDrawingManager::closeRenderTasksForNewRenderTask(GrSurfaceProxy* target) {
Greg Danielf41b2bd2019-08-22 16:19:24 -0400741 if (target && fDAG.sortingRenderTasks() && fReduceOpsTaskSplitting) {
Chris Dalton5fe99772019-08-06 11:57:39 -0600742 // In this case we need to close all the renderTasks that rely on the current contents of
743 // 'target'. That is bc we're going to update the content of the proxy so they need to be
744 // split in case they use both the old and new content. (This is a bit of an overkill: they
745 // really only need to be split if they ever reference proxy's contents again but that is
746 // hard to predict/handle).
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400747 if (GrRenderTask* lastRenderTask = this->getLastRenderTask(target)) {
Chris Dalton6b498102019-08-01 14:14:52 -0600748 lastRenderTask->closeThoseWhoDependOnMe(*fContext->priv().caps());
Robert Phillips46acf9d2018-10-09 09:31:40 -0400749 }
Greg Danielf41b2bd2019-08-22 16:19:24 -0400750 } else if (fActiveOpsTask) {
Robert Phillipsb7a98ef2018-10-10 09:26:00 -0400751 // This is a temporary fix for the partial-MDB world. In that world we're not
Greg Danielf41b2bd2019-08-22 16:19:24 -0400752 // reordering so ops that (in the single opsTask world) would've just glommed onto the
753 // end of the single opsTask but referred to a far earlier RT need to appear in their
754 // own opsTask.
755 fActiveOpsTask->makeClosed(*fContext->priv().caps());
756 fActiveOpsTask = nullptr;
robertphillips3dc6ae52015-10-20 09:54:32 -0700757 }
Chris Dalton5fe99772019-08-06 11:57:39 -0600758}
759
Greg Daniel16f5c652019-10-29 11:26:01 -0400760sk_sp<GrOpsTask> GrDrawingManager::newOpsTask(GrSurfaceProxyView surfaceView,
761 bool managedOpsTask) {
Chris Dalton5fe99772019-08-06 11:57:39 -0600762 SkDEBUGCODE(this->validate());
763 SkASSERT(fContext);
764
Greg Daniel16f5c652019-10-29 11:26:01 -0400765 GrSurfaceProxy* proxy = surfaceView.proxy();
766 this->closeRenderTasksForNewRenderTask(proxy);
robertphillips3dc6ae52015-10-20 09:54:32 -0700767
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400768 sk_sp<GrOpsTask> opsTask(new GrOpsTask(this, fContext->priv().arenas(),
Michael Ludwigd0840ec2019-12-12 09:48:38 -0500769 std::move(surfaceView),
770 fContext->priv().auditTrail()));
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400771 SkASSERT(this->getLastRenderTask(proxy) == opsTask.get());
robertphillips3dc6ae52015-10-20 09:54:32 -0700772
Greg Danielf41b2bd2019-08-22 16:19:24 -0400773 if (managedOpsTask) {
774 fDAG.add(opsTask);
Robert Phillipsb7a98ef2018-10-10 09:26:00 -0400775
Greg Danielf41b2bd2019-08-22 16:19:24 -0400776 if (!fDAG.sortingRenderTasks() || !fReduceOpsTaskSplitting) {
777 fActiveOpsTask = opsTask.get();
Robert Phillipsb7a98ef2018-10-10 09:26:00 -0400778 }
Robert Phillips941d1442017-06-14 16:37:02 -0400779 }
robertphillips3dc6ae52015-10-20 09:54:32 -0700780
Robert Phillips38d64b02018-09-04 13:23:26 -0400781 SkDEBUGCODE(this->validate());
Greg Danielf41b2bd2019-08-22 16:19:24 -0400782 return opsTask;
robertphillips3dc6ae52015-10-20 09:54:32 -0700783}
784
Chris Daltone2a903e2019-09-18 13:41:50 -0600785GrTextureResolveRenderTask* GrDrawingManager::newTextureResolveRenderTask(const GrCaps& caps) {
Chris Dalton6aeb8e82019-08-27 11:52:19 -0600786 // Unlike in the "new opsTask" case, we do not want to close the active opsTask, nor (if we are
Chris Daltone2a903e2019-09-18 13:41:50 -0600787 // in sorting and opsTask reduction mode) the render tasks that depend on any proxy's current
Greg Danielf41b2bd2019-08-22 16:19:24 -0400788 // state. This is because those opsTasks can still receive new ops and because if they refer to
Chris Dalton4ece96d2019-08-30 11:26:39 -0600789 // the mipmapped version of 'proxy', they will then come to depend on the render task being
790 // created here.
Chris Dalton6aeb8e82019-08-27 11:52:19 -0600791 //
Greg Danielf41b2bd2019-08-22 16:19:24 -0400792 // Add the new textureResolveTask before the fActiveOpsTask (if not in
793 // sorting/opsTask-splitting-reduction mode) because it will depend upon this resolve task.
Chris Dalton3d770272019-08-14 09:24:37 -0600794 // NOTE: Putting it here will also reduce the amount of work required by the topological sort.
Chris Daltone2a903e2019-09-18 13:41:50 -0600795 return static_cast<GrTextureResolveRenderTask*>(fDAG.addBeforeLast(
796 sk_make_sp<GrTextureResolveRenderTask>()));
Chris Dalton3d770272019-08-14 09:24:37 -0600797}
798
Greg Danielc30f1a92019-09-06 15:28:58 -0400799void GrDrawingManager::newWaitRenderTask(sk_sp<GrSurfaceProxy> proxy,
Greg Daniel301015c2019-11-18 14:06:46 -0500800 std::unique_ptr<std::unique_ptr<GrSemaphore>[]> semaphores,
Greg Danielc30f1a92019-09-06 15:28:58 -0400801 int numSemaphores) {
802 SkDEBUGCODE(this->validate());
803 SkASSERT(fContext);
804
805 const GrCaps& caps = *fContext->priv().caps();
806
Greg Daniel16f5c652019-10-29 11:26:01 -0400807 sk_sp<GrWaitRenderTask> waitTask = sk_make_sp<GrWaitRenderTask>(GrSurfaceProxyView(proxy),
808 std::move(semaphores),
Greg Danielc30f1a92019-09-06 15:28:58 -0400809 numSemaphores);
810 if (fReduceOpsTaskSplitting) {
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400811 GrRenderTask* lastTask = this->getLastRenderTask(proxy.get());
Greg Danielc30f1a92019-09-06 15:28:58 -0400812 if (lastTask && !lastTask->isClosed()) {
813 // We directly make the currently open renderTask depend on waitTask instead of using
814 // the proxy version of addDependency. The waitTask will never need to trigger any
815 // resolves or mip map generation which is the main advantage of going through the proxy
816 // version. Additionally we would've had to temporarily set the wait task as the
817 // lastRenderTask on the proxy, add the dependency, and then reset the lastRenderTask to
818 // lastTask. Additionally we add all dependencies of lastTask to waitTask so that the
819 // waitTask doesn't get reordered before them and unnecessarily block those tasks.
820 // Note: Any previous Ops already in lastTask will get blocked by the wait semaphore
821 // even though they don't need to be for correctness.
822
823 // Make sure we add the dependencies of lastTask to waitTask first or else we'll get a
824 // circular self dependency of waitTask on waitTask.
825 waitTask->addDependenciesFromOtherTask(lastTask);
826 lastTask->addDependency(waitTask.get());
827 } else {
828 // If there is a last task we set the waitTask to depend on it so that it doesn't get
829 // reordered in front of the lastTask causing the lastTask to be blocked by the
830 // semaphore. Again we directly just go through adding the dependency to the task and
831 // not the proxy since we don't need to worry about resolving anything.
832 if (lastTask) {
833 waitTask->addDependency(lastTask);
834 }
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400835 this->setLastRenderTask(proxy.get(), waitTask.get());
Greg Danielc30f1a92019-09-06 15:28:58 -0400836 }
837 fDAG.add(waitTask);
838 } else {
Greg Daniel16f5c652019-10-29 11:26:01 -0400839 if (fActiveOpsTask && (fActiveOpsTask->fTargetView.proxy() == proxy.get())) {
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400840 SkASSERT(this->getLastRenderTask(proxy.get()) == fActiveOpsTask);
Greg Danielc30f1a92019-09-06 15:28:58 -0400841 fDAG.addBeforeLast(waitTask);
842 // In this case we keep the current renderTask open but just insert the new waitTask
843 // before it in the list. The waitTask will never need to trigger any resolves or mip
844 // map generation which is the main advantage of going through the proxy version.
845 // Additionally we would've had to temporarily set the wait task as the lastRenderTask
846 // on the proxy, add the dependency, and then reset the lastRenderTask to
847 // fActiveOpsTask. Additionally we make the waitTask depend on all of fActiveOpsTask
848 // dependencies so that we don't unnecessarily reorder the waitTask before them.
849 // Note: Any previous Ops already in fActiveOpsTask will get blocked by the wait
850 // semaphore even though they don't need to be for correctness.
851
852 // Make sure we add the dependencies of fActiveOpsTask to waitTask first or else we'll
853 // get a circular self dependency of waitTask on waitTask.
854 waitTask->addDependenciesFromOtherTask(fActiveOpsTask);
855 fActiveOpsTask->addDependency(waitTask.get());
856 } else {
857 // In this case we just close the previous RenderTask and start and append the waitTask
858 // to the DAG. Since it is the last task now we call setLastRenderTask on the proxy. If
859 // there is a lastTask on the proxy we make waitTask depend on that task. This
860 // dependency isn't strictly needed but it does keep the DAG from reordering the
861 // waitTask earlier and blocking more tasks.
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400862 if (GrRenderTask* lastTask = this->getLastRenderTask(proxy.get())) {
Greg Danielc30f1a92019-09-06 15:28:58 -0400863 waitTask->addDependency(lastTask);
864 }
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400865 this->setLastRenderTask(proxy.get(), waitTask.get());
Greg Danielc30f1a92019-09-06 15:28:58 -0400866 this->closeRenderTasksForNewRenderTask(proxy.get());
867 fDAG.add(waitTask);
868 }
869 }
870 waitTask->makeClosed(caps);
871
872 SkDEBUGCODE(this->validate());
873}
874
Greg Danielbbfec9d2019-08-20 10:56:51 -0400875void GrDrawingManager::newTransferFromRenderTask(sk_sp<GrSurfaceProxy> srcProxy,
876 const SkIRect& srcRect,
877 GrColorType surfaceColorType,
878 GrColorType dstColorType,
879 sk_sp<GrGpuBuffer> dstBuffer,
880 size_t dstOffset) {
881 SkDEBUGCODE(this->validate());
882 SkASSERT(fContext);
883 // This copies from srcProxy to dstBuffer so it doesn't have a real target.
884 this->closeRenderTasksForNewRenderTask(nullptr);
885
Chris Dalton6aeb8e82019-08-27 11:52:19 -0600886 GrRenderTask* task = fDAG.add(sk_make_sp<GrTransferFromRenderTask>(
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400887 srcProxy, srcRect, surfaceColorType, dstColorType,
888 std::move(dstBuffer), dstOffset));
Greg Danielbbfec9d2019-08-20 10:56:51 -0400889
890 const GrCaps& caps = *fContext->priv().caps();
891
892 // We always say GrMipMapped::kNo here since we are always just copying from the base layer. We
893 // don't need to make sure the whole mip map chain is valid.
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400894 task->addDependency(this, srcProxy.get(), GrMipMapped::kNo,
895 GrTextureResolveManager(this), caps);
Greg Danielbbfec9d2019-08-20 10:56:51 -0400896 task->makeClosed(caps);
897
Greg Danielbbfec9d2019-08-20 10:56:51 -0400898 // We have closed the previous active oplist but since a new oplist isn't being added there
899 // shouldn't be an active one.
Greg Danielf41b2bd2019-08-22 16:19:24 -0400900 SkASSERT(!fActiveOpsTask);
Greg Danielbbfec9d2019-08-20 10:56:51 -0400901 SkDEBUGCODE(this->validate());
902}
903
Greg Daniel16f5c652019-10-29 11:26:01 -0400904bool GrDrawingManager::newCopyRenderTask(GrSurfaceProxyView srcView,
Greg Daniele227fe42019-08-21 13:52:24 -0400905 const SkIRect& srcRect,
Greg Daniel16f5c652019-10-29 11:26:01 -0400906 GrSurfaceProxyView dstView,
Greg Daniele227fe42019-08-21 13:52:24 -0400907 const SkIPoint& dstPoint) {
908 SkDEBUGCODE(this->validate());
909 SkASSERT(fContext);
Greg Daniele227fe42019-08-21 13:52:24 -0400910
Greg Daniel16f5c652019-10-29 11:26:01 -0400911 this->closeRenderTasksForNewRenderTask(dstView.proxy());
Brian Salomone4bce012019-09-20 15:34:23 -0400912 const GrCaps& caps = *fContext->priv().caps();
913
Greg Daniel16f5c652019-10-29 11:26:01 -0400914 GrSurfaceProxy* srcProxy = srcView.proxy();
915
Brian Salomone4bce012019-09-20 15:34:23 -0400916 GrRenderTask* task =
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400917 fDAG.add(GrCopyRenderTask::Make(this, std::move(srcView), srcRect, std::move(dstView),
Greg Daniel16f5c652019-10-29 11:26:01 -0400918 dstPoint, &caps));
Greg Daniele227fe42019-08-21 13:52:24 -0400919 if (!task) {
920 return false;
921 }
922
Greg Daniele227fe42019-08-21 13:52:24 -0400923 // We always say GrMipMapped::kNo here since we are always just copying from the base layer to
924 // another base layer. We don't need to make sure the whole mip map chain is valid.
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400925 task->addDependency(this, srcProxy, GrMipMapped::kNo, GrTextureResolveManager(this), caps);
Greg Daniele227fe42019-08-21 13:52:24 -0400926 task->makeClosed(caps);
927
Greg Daniele227fe42019-08-21 13:52:24 -0400928 // We have closed the previous active oplist but since a new oplist isn't being added there
929 // shouldn't be an active one.
Greg Danielf41b2bd2019-08-22 16:19:24 -0400930 SkASSERT(!fActiveOpsTask);
Greg Daniele227fe42019-08-21 13:52:24 -0400931 SkDEBUGCODE(this->validate());
932 return true;
933}
934
robertphillips68737822015-10-29 12:12:21 -0700935/*
936 * This method finds a path renderer that can draw the specified path on
937 * the provided target.
938 * Due to its expense, the software path renderer has split out so it can
939 * can be individually allowed/disallowed via the "allowSW" boolean.
940 */
941GrPathRenderer* GrDrawingManager::getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args,
942 bool allowSW,
943 GrPathRendererChain::DrawType drawType,
944 GrPathRenderer::StencilSupport* stencilSupport) {
945
946 if (!fPathRendererChain) {
Ben Wagner9ec70c62018-07-12 13:30:47 -0400947 fPathRendererChain.reset(new GrPathRendererChain(fContext, fOptionsForPathRendererChain));
robertphillips68737822015-10-29 12:12:21 -0700948 }
949
950 GrPathRenderer* pr = fPathRendererChain->getPathRenderer(args, drawType, stencilSupport);
951 if (!pr && allowSW) {
Brian Salomone7df0bb2018-05-07 14:44:57 -0400952 auto swPR = this->getSoftwarePathRenderer();
953 if (GrPathRenderer::CanDrawPath::kNo != swPR->canDrawPath(args)) {
954 pr = swPR;
Brian Salomon0e8fc8b2016-12-09 15:10:07 -0500955 }
robertphillips68737822015-10-29 12:12:21 -0700956 }
957
Robert Phillipsd81379d2020-04-21 10:39:02 -0400958#if GR_PATH_RENDERER_SPEW
959 if (pr) {
960 SkDebugf("getPathRenderer: %s\n", pr->name());
961 }
962#endif
963
robertphillips68737822015-10-29 12:12:21 -0700964 return pr;
965}
966
Brian Salomone7df0bb2018-05-07 14:44:57 -0400967GrPathRenderer* GrDrawingManager::getSoftwarePathRenderer() {
968 if (!fSoftwarePathRenderer) {
Ben Wagner9ec70c62018-07-12 13:30:47 -0400969 fSoftwarePathRenderer.reset(
Robert Phillips9da87e02019-02-04 13:26:26 -0500970 new GrSoftwarePathRenderer(fContext->priv().proxyProvider(),
Ben Wagner9ec70c62018-07-12 13:30:47 -0400971 fOptionsForPathRendererChain.fAllowPathMaskCaching));
Brian Salomone7df0bb2018-05-07 14:44:57 -0400972 }
Ben Wagner9ec70c62018-07-12 13:30:47 -0400973 return fSoftwarePathRenderer.get();
Brian Salomone7df0bb2018-05-07 14:44:57 -0400974}
975
Chris Daltonfddb6c02017-11-04 15:22:22 -0600976GrCoverageCountingPathRenderer* GrDrawingManager::getCoverageCountingPathRenderer() {
977 if (!fPathRendererChain) {
Ben Wagner9ec70c62018-07-12 13:30:47 -0400978 fPathRendererChain.reset(new GrPathRendererChain(fContext, fOptionsForPathRendererChain));
Chris Daltonfddb6c02017-11-04 15:22:22 -0600979 }
980 return fPathRendererChain->getCoverageCountingPathRenderer();
981}
982
Brian Salomon653f42f2018-07-10 10:07:31 -0400983void GrDrawingManager::flushIfNecessary() {
Robert Phillips6a6de562019-02-15 15:19:15 -0500984 auto direct = fContext->priv().asDirectContext();
985 if (!direct) {
986 return;
987 }
988
989 auto resourceCache = direct->priv().getResourceCache();
Brian Salomon653f42f2018-07-10 10:07:31 -0400990 if (resourceCache && resourceCache->requestsFlush()) {
Greg Daniel9efe3862020-06-11 11:51:06 -0400991 if (this->flush(nullptr, 0, SkSurface::BackendSurfaceAccess::kNoAccess, GrFlushInfo(),
992 nullptr)) {
Greg Danielfe159622020-04-10 17:43:51 +0000993 this->submitToGpu(false);
994 }
Brian Salomon57d2beab2018-09-10 09:35:41 -0400995 resourceCache->purgeAsNeeded();
Brian Salomon653f42f2018-07-10 10:07:31 -0400996 }
997}
998