blob: 57777f16ca6e8df32a9a850802513f29e4901090 [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
Adlai Hollerc2bfcff2020-11-06 15:39:36 -050010#include <algorithm>
John Stilesfbd050b2020-08-03 13:21:46 -040011#include <memory>
12
Robert Phillips4d5594d2020-02-21 14:24:40 -050013#include "include/core/SkDeferredDisplayList.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050014#include "include/gpu/GrBackendSemaphore.h"
Robert Phillipsb7bfbc22020-07-01 12:55:01 -040015#include "include/gpu/GrDirectContext.h"
16#include "include/gpu/GrRecordingContext.h"
Robert Phillips7eb0a5f2020-06-09 14:15:09 -040017#include "src/core/SkDeferredDisplayListPriv.h"
Adlai Holler78036082021-01-07 11:41:33 -050018#include "src/core/SkTInternalLList.h"
Brian Salomon9241a6d2019-10-03 13:26:54 -040019#include "src/gpu/GrClientMappedBufferManager.h"
Greg Daniele227fe42019-08-21 13:52:24 -040020#include "src/gpu/GrCopyRenderTask.h"
Robert Phillips07f675d2020-11-16 13:44:01 -050021#include "src/gpu/GrDDLTask.h"
Adlai Hollera0693042020-10-14 11:23:11 -040022#include "src/gpu/GrDirectContextPriv.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050023#include "src/gpu/GrGpu.h"
24#include "src/gpu/GrMemoryPool.h"
25#include "src/gpu/GrOnFlushResourceProvider.h"
Robert Phillips259b4682021-07-20 09:27:00 -040026#include "src/gpu/GrOpFlushState.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050027#include "src/gpu/GrRecordingContextPriv.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040028#include "src/gpu/GrRenderTargetProxy.h"
Chris Dalton6b498102019-08-01 14:14:52 -060029#include "src/gpu/GrRenderTask.h"
Adlai Holler08f53112021-01-20 17:44:15 -050030#include "src/gpu/GrRenderTaskCluster.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050031#include "src/gpu/GrResourceAllocator.h"
32#include "src/gpu/GrResourceProvider.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050033#include "src/gpu/GrSurfaceProxyPriv.h"
Robert Phillipsfbbc3bb2020-11-16 14:58:56 -050034#include "src/gpu/GrTTopoSort.h"
Greg Daniel456f9b52020-03-05 19:14:18 +000035#include "src/gpu/GrTexture.h"
Greg Danielf91aeb22019-06-18 09:58:02 -040036#include "src/gpu/GrTextureProxy.h"
Adlai Holler9e2c50e2021-02-09 14:41:52 -050037#include "src/gpu/GrTextureProxyPriv.h"
Chris Dalton3d770272019-08-14 09:24:37 -060038#include "src/gpu/GrTextureResolveRenderTask.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050039#include "src/gpu/GrTracing.h"
Greg Danielbbfec9d2019-08-20 10:56:51 -040040#include "src/gpu/GrTransferFromRenderTask.h"
Greg Danielc30f1a92019-09-06 15:28:58 -040041#include "src/gpu/GrWaitRenderTask.h"
Brian Salomonbe1084b2021-01-26 13:29:30 -050042#include "src/gpu/GrWritePixelsRenderTask.h"
Herb Derbybf2dd2a2021-03-04 10:13:22 -050043#include "src/gpu/text/GrSDFTControl.h"
Mike Kleinc0bd9f92019-04-23 12:05:21 -050044#include "src/image/SkSurface_Gpu.h"
robertphillips498d7ac2015-10-30 10:11:30 -070045
Robert Phillips7cef6782021-07-01 13:21:37 -040046#if SK_GPU_V1
Robert Phillips3e87a8e2021-08-25 13:22:24 -040047#include "src/gpu/ops/OpsTask.h"
Robert Phillips17dc6582021-08-17 11:57:31 -040048#include "src/gpu/ops/SoftwarePathRenderer.h"
Robert Phillips3674f582021-06-16 12:05:54 -040049#endif
50
Robert Phillips22310d62018-09-05 11:07:21 -040051///////////////////////////////////////////////////////////////////////////////////////////////////
Robert Phillips7cef6782021-07-01 13:21:37 -040052#if SK_GPU_V1
Robert Phillips3674f582021-06-16 12:05:54 -040053GrDrawingManager::GrDrawingManager(GrRecordingContext* rContext,
Robert Phillipsdb0ec082021-08-19 12:30:12 -040054 const PathRendererChain::Options& optionsForPathRendererChain,
Greg Danielf41b2bd2019-08-22 16:19:24 -040055 bool reduceOpsTaskSplitting)
Robert Phillips3674f582021-06-16 12:05:54 -040056 : fContext(rContext)
Robert Phillips22310d62018-09-05 11:07:21 -040057 , fOptionsForPathRendererChain(optionsForPathRendererChain)
Robert Phillips22310d62018-09-05 11:07:21 -040058 , fPathRendererChain(nullptr)
59 , fSoftwarePathRenderer(nullptr)
Robert Phillips3674f582021-06-16 12:05:54 -040060 , fReduceOpsTaskSplitting(reduceOpsTaskSplitting) {
61}
62
63#else
64
65GrDrawingManager::GrDrawingManager(GrRecordingContext* rContext, bool reduceOpsTaskSplitting)
66 : fContext(rContext)
67 , fReduceOpsTaskSplitting(reduceOpsTaskSplitting) {
68}
69
70#endif
Robert Phillips22310d62018-09-05 11:07:21 -040071
robertphillips3dc6ae52015-10-20 09:54:32 -070072GrDrawingManager::~GrDrawingManager() {
Adlai Holler33432272020-11-11 13:54:37 -050073 this->closeAllTasks();
Adlai Hollerc616e1c2021-02-11 15:18:17 -050074 this->removeRenderTasks();
robertphillips3dc6ae52015-10-20 09:54:32 -070075}
76
Robert Phillipsa9162df2019-02-11 14:12:03 -050077bool GrDrawingManager::wasAbandoned() const {
Robert Phillips9eb00022020-06-30 15:30:12 -040078 return fContext->abandoned();
robertphillips3dc6ae52015-10-20 09:54:32 -070079}
80
robertphillips68737822015-10-29 12:12:21 -070081void GrDrawingManager::freeGpuResources() {
Jim Van Verth106b5c42017-09-26 12:45:29 -040082 for (int i = fOnFlushCBObjects.count() - 1; i >= 0; --i) {
83 if (!fOnFlushCBObjects[i]->retainOnFreeGpuResources()) {
84 // it's safe to just do this because we're iterating in reverse
85 fOnFlushCBObjects.removeShuffle(i);
86 }
87 }
88
Robert Phillips7cef6782021-07-01 13:21:37 -040089#if SK_GPU_V1
robertphillips68737822015-10-29 12:12:21 -070090 // a path renderer may be holding onto resources
robertphillips13391dd2015-10-30 05:15:11 -070091 fPathRendererChain = nullptr;
Ben Wagner9ec70c62018-07-12 13:30:47 -040092 fSoftwarePathRenderer = nullptr;
Robert Phillips3674f582021-06-16 12:05:54 -040093#endif
Robert Phillipse3302df2017-04-24 07:31:02 -040094}
95
Adlai Hollerc2bfcff2020-11-06 15:39:36 -050096// MDB TODO: make use of the 'proxies' parameter.
Greg Daniel9efe3862020-06-11 11:51:06 -040097bool GrDrawingManager::flush(
Adlai Hollerc2bfcff2020-11-06 15:39:36 -050098 SkSpan<GrSurfaceProxy*> proxies,
Greg Daniel9efe3862020-06-11 11:51:06 -040099 SkSurface::BackendSurfaceAccess access,
100 const GrFlushInfo& info,
101 const GrBackendSurfaceMutableState* newState) {
Brian Salomon57d2beab2018-09-10 09:35:41 -0400102 GR_CREATE_TRACE_MARKER_CONTEXT("GrDrawingManager", "flush", fContext);
Brian Salomondcbb9d92017-07-19 10:53:20 -0400103
robertphillips7761d612016-05-16 09:14:53 -0700104 if (fFlushing || this->wasAbandoned()) {
Greg Daniel55822f12020-05-26 11:26:45 -0400105 if (info.fSubmittedProc) {
106 info.fSubmittedProc(info.fSubmittedContext, false);
107 }
Greg Daniele6bfb7d2019-04-17 15:26:11 -0400108 if (info.fFinishedProc) {
109 info.fFinishedProc(info.fFinishedContext);
Greg Daniela3aa75a2019-04-12 14:24:55 -0400110 }
Greg Danielfe159622020-04-10 17:43:51 +0000111 return false;
joshualittb8918c42015-12-18 09:59:46 -0800112 }
Robert Phillips602df412019-04-08 11:10:39 -0400113
Robert Phillips38d64b02018-09-04 13:23:26 -0400114 SkDEBUGCODE(this->validate());
115
Adlai Hollerc2bfcff2020-11-06 15:39:36 -0500116 // As of now we only short-circuit if we got an explicit list of surfaces to flush.
117 if (!proxies.empty() && !info.fNumSemaphores && !info.fFinishedProc &&
Greg Danielce9f0162020-06-30 13:42:46 -0400118 access == SkSurface::BackendSurfaceAccess::kNoAccess && !newState) {
Adlai Hollerc2bfcff2020-11-06 15:39:36 -0500119 bool allUnused = std::all_of(proxies.begin(), proxies.end(), [&](GrSurfaceProxy* proxy) {
Adlai Holler33432272020-11-11 13:54:37 -0500120 bool used = std::any_of(fDAG.begin(), fDAG.end(), [&](auto& task) {
121 return task && task->isUsed(proxy);
122 });
Robert Phillips58a8ccc2021-01-11 09:07:55 -0500123 return !used;
Adlai Hollerc2bfcff2020-11-06 15:39:36 -0500124 });
125 if (allUnused) {
Greg Daniel55822f12020-05-26 11:26:45 -0400126 if (info.fSubmittedProc) {
127 info.fSubmittedProc(info.fSubmittedContext, true);
128 }
Greg Danielfe159622020-04-10 17:43:51 +0000129 return false;
Brian Salomonf9a1fdf2019-05-09 10:30:12 -0400130 }
Robert Phillips9313aa72019-04-09 18:41:27 -0400131 }
132
Adlai Hollerca1137b2021-04-08 11:39:55 -0400133 auto dContext = fContext->asDirectContext();
134 SkASSERT(dContext);
135 dContext->priv().clientMappedBufferManager()->process();
Robert Phillips6a6de562019-02-15 15:19:15 -0500136
Adlai Hollerca1137b2021-04-08 11:39:55 -0400137 GrGpu* gpu = dContext->priv().getGpu();
Greg Daniel55822f12020-05-26 11:26:45 -0400138 // We have a non abandoned and direct GrContext. It must have a GrGpu.
139 SkASSERT(gpu);
Greg Daniela3aa75a2019-04-12 14:24:55 -0400140
joshualittb8918c42015-12-18 09:59:46 -0800141 fFlushing = true;
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400142
Adlai Hollerca1137b2021-04-08 11:39:55 -0400143 auto resourceProvider = dContext->priv().resourceProvider();
144 auto resourceCache = dContext->priv().getResourceCache();
Robert Phillips6a6de562019-02-15 15:19:15 -0500145
Chris Dalton6b498102019-08-01 14:14:52 -0600146 // Semi-usually the GrRenderTasks are already closed at this point, but sometimes Ganesh needs
Greg Danielf41b2bd2019-08-22 16:19:24 -0400147 // to flush mid-draw. In that case, the SkGpuDevice's opsTasks won't be closed but need to be
148 // flushed anyway. Closing such opsTasks here will mean new ones will be created to replace them
Chris Dalton6b498102019-08-01 14:14:52 -0600149 // if the SkGpuDevice(s) write to them again.
Adlai Holler33432272020-11-11 13:54:37 -0500150 this->closeAllTasks();
Adlai Holler039f90c2020-11-19 15:20:31 +0000151 fActiveOpsTask = nullptr;
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400152
Adlai Holler33432272020-11-11 13:54:37 -0500153 this->sortTasks();
Adlai Holler78036082021-01-07 11:41:33 -0500154
Brian Salomon601ac802019-02-07 13:37:16 -0500155 if (!fCpuBufferCache) {
156 // We cache more buffers when the backend is using client side arrays. Otherwise, we
157 // expect each pool will use a CPU buffer as a staging buffer before uploading to a GPU
158 // buffer object. Each pool only requires one staging buffer at a time.
159 int maxCachedBuffers = fContext->priv().caps()->preferClientSideDynamicBuffers() ? 2 : 6;
160 fCpuBufferCache = GrBufferAllocPool::CpuBufferCache::Make(maxCachedBuffers);
Brian Salomon58f153c2018-10-18 21:51:15 -0400161 }
Robert Phillipsa4c93ac2017-05-18 11:40:04 -0400162
Robert Phillipse5f73282019-06-18 17:15:04 -0400163 GrOpFlushState flushState(gpu, resourceProvider, &fTokenTracker, fCpuBufferCache);
Robert Phillips40a29d72018-01-18 12:59:22 -0500164
Chris Daltonfe199b72017-05-05 11:26:15 -0400165 GrOnFlushResourceProvider onFlushProvider(this);
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400166
Chris Dalton12658942017-10-05 19:45:25 -0600167 // Prepare any onFlush op lists (e.g. atlases).
Chris Daltonfe199b72017-05-05 11:26:15 -0400168 if (!fOnFlushCBObjects.empty()) {
Robert Phillips07f675d2020-11-16 13:44:01 -0500169 fFlushingRenderTaskIDs.reserve_back(fDAG.count());
170 for (const auto& task : fDAG) {
171 if (task) {
172 task->gatherIDs(&fFlushingRenderTaskIDs);
Adlai Holler33432272020-11-11 13:54:37 -0500173 }
174 }
Robert Phillips22310d62018-09-05 11:07:21 -0400175
Chris Daltonfe199b72017-05-05 11:26:15 -0400176 for (GrOnFlushCallbackObject* onFlushCBObject : fOnFlushCBObjects) {
Brian Osmanae87bf12021-05-11 13:36:10 -0400177 onFlushCBObject->preFlush(&onFlushProvider, SkMakeSpan(fFlushingRenderTaskIDs));
Chris Daltonc4b47352019-08-23 10:10:36 -0600178 }
179 for (const auto& onFlushRenderTask : fOnFlushRenderTasks) {
Chris Daltonaa938ce2021-06-23 18:13:59 -0600180 onFlushRenderTask->makeClosed(fContext);
Chris Dalton706a6ff2017-11-29 22:01:06 -0700181#ifdef SK_DEBUG
Chris Daltonc4b47352019-08-23 10:10:36 -0600182 // OnFlush callbacks are invoked during flush, and are therefore expected to handle
Adlai Holler9e2c50e2021-02-09 14:41:52 -0500183 // resource allocation & usage on their own. (No deferred or lazy proxies!)
Chris Daltonc4b47352019-08-23 10:10:36 -0600184 onFlushRenderTask->visitTargetAndSrcProxies_debugOnly(
Brian Salomon7e67dca2020-07-21 09:27:25 -0400185 [](GrSurfaceProxy* p, GrMipmapped mipMapped) {
Adlai Holler9e2c50e2021-02-09 14:41:52 -0500186 SkASSERT(!p->asTextureProxy() || !p->asTextureProxy()->texPriv().isDeferred());
Brian Salomonbeb7f522019-08-30 16:19:42 -0400187 SkASSERT(!p->isLazy());
Chris Dalton4ece96d2019-08-30 11:26:39 -0600188 if (p->requiresManualMSAAResolve()) {
189 // The onFlush callback is responsible for ensuring MSAA gets resolved.
190 SkASSERT(p->asRenderTargetProxy() && !p->asRenderTargetProxy()->isMSAADirty());
191 }
Brian Salomon7e67dca2020-07-21 09:27:25 -0400192 if (GrMipmapped::kYes == mipMapped) {
Chris Daltonc4b47352019-08-23 10:10:36 -0600193 // The onFlush callback is responsible for regenerating mips if needed.
Brian Salomon8c82a872020-07-21 12:09:58 -0400194 SkASSERT(p->asTextureProxy() && !p->asTextureProxy()->mipmapsAreDirty());
Chris Daltonc4b47352019-08-23 10:10:36 -0600195 }
196 });
Chris Dalton706a6ff2017-11-29 22:01:06 -0700197#endif
Chris Daltonc4b47352019-08-23 10:10:36 -0600198 onFlushRenderTask->prepare(&flushState);
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400199 }
200 }
201
Adlai Holler141b38b2021-05-05 15:16:40 +0000202 bool usingReorderedDAG = false;
203 GrResourceAllocator resourceAllocator(dContext);
204 if (fReduceOpsTaskSplitting) {
205 usingReorderedDAG = this->reorderTasks(&resourceAllocator);
206 if (!usingReorderedDAG) {
207 resourceAllocator.reset();
208 }
209 }
210
robertphillipsa13e2022015-11-11 12:01:09 -0800211#if 0
Brian Salomon09d994e2016-12-21 11:14:46 -0500212 // Enable this to print out verbose GrOp information
Adlai Hollerabdfd392020-10-19 09:00:36 -0400213 SkDEBUGCODE(SkDebugf("onFlush renderTasks (%d):\n", fOnFlushRenderTasks.count()));
Chris Daltonc4b47352019-08-23 10:10:36 -0600214 for (const auto& onFlushRenderTask : fOnFlushRenderTasks) {
Adlai Hollerabdfd392020-10-19 09:00:36 -0400215 SkDEBUGCODE(onFlushRenderTask->dump(/* printDependencies */ true);)
Chris Daltonc4b47352019-08-23 10:10:36 -0600216 }
Adlai Holler33432272020-11-11 13:54:37 -0500217 SkDEBUGCODE(SkDebugf("Normal renderTasks (%d):\n", fDAG.count()));
218 for (const auto& task : fDAG) {
219 SkDEBUGCODE(task->dump(/* printDependencies */ true);)
robertphillips3dc6ae52015-10-20 09:54:32 -0700220 }
robertphillipsa13e2022015-11-11 12:01:09 -0800221#endif
222
Adlai Holler387309c2021-04-15 15:03:27 -0400223 if (!resourceAllocator.failedInstantiation()) {
224 if (!usingReorderedDAG) {
225 for (const auto& task : fDAG) {
226 SkASSERT(task);
227 task->gatherProxyIntervals(&resourceAllocator);
Adlai Hollerfe919742021-04-10 07:42:15 -0400228 }
Adlai Holler387309c2021-04-15 15:03:27 -0400229 resourceAllocator.planAssignment();
Adlai Hollerfe919742021-04-10 07:42:15 -0400230 }
Adlai Holler387309c2021-04-15 15:03:27 -0400231 resourceAllocator.assign();
Greg Danielc42b20b2017-10-04 10:34:49 -0400232 }
Adlai Holler387309c2021-04-15 15:03:27 -0400233 bool flushed = !resourceAllocator.failedInstantiation() &&
234 this->executeRenderTasks(&flushState);
Adlai Holler19fd5142021-03-08 10:19:30 -0700235 this->removeRenderTasks();
robertphillipsa13e2022015-11-11 12:01:09 -0800236
Adlai Hollerc2bfcff2020-11-06 15:39:36 -0500237 gpu->executeFlushInfo(proxies, access, info, newState);
robertphillipsa13e2022015-11-11 12:01:09 -0800238
Brian Salomon57d2beab2018-09-10 09:35:41 -0400239 // Give the cache a chance to purge resources that become purgeable due to flushing.
240 if (flushed) {
Robert Phillips6a6de562019-02-15 15:19:15 -0500241 resourceCache->purgeAsNeeded();
Brian Salomon876a0172019-03-08 11:12:14 -0500242 flushed = false;
bsalomonb77a9072016-09-07 10:02:04 -0700243 }
Chris Daltonfe199b72017-05-05 11:26:15 -0400244 for (GrOnFlushCallbackObject* onFlushCBObject : fOnFlushCBObjects) {
Brian Osmanae87bf12021-05-11 13:36:10 -0400245 onFlushCBObject->postFlush(fTokenTracker.nextTokenToFlush(),
246 SkMakeSpan(fFlushingRenderTaskIDs));
Brian Salomon876a0172019-03-08 11:12:14 -0500247 flushed = true;
248 }
249 if (flushed) {
250 resourceCache->purgeAsNeeded();
Chris Daltonfe199b72017-05-05 11:26:15 -0400251 }
Chris Dalton6b498102019-08-01 14:14:52 -0600252 fFlushingRenderTaskIDs.reset();
joshualittb8918c42015-12-18 09:59:46 -0800253 fFlushing = false;
Greg Daniel51316782017-08-02 15:10:09 +0000254
Greg Danielfe159622020-04-10 17:43:51 +0000255 return true;
256}
257
258bool GrDrawingManager::submitToGpu(bool syncToCpu) {
259 if (fFlushing || this->wasAbandoned()) {
260 return false;
261 }
262
Robert Phillipsf8f45d92020-07-01 11:11:18 -0400263 auto direct = fContext->asDirectContext();
Greg Danielfe159622020-04-10 17:43:51 +0000264 if (!direct) {
265 return false; // Can't submit while DDL recording
266 }
267 GrGpu* gpu = direct->priv().getGpu();
268 return gpu->submitToGpu(syncToCpu);
robertphillips3dc6ae52015-10-20 09:54:32 -0700269}
270
Adlai Hollerc616e1c2021-02-11 15:18:17 -0500271bool GrDrawingManager::executeRenderTasks(GrOpFlushState* flushState) {
Robert Phillips27483912018-04-20 12:43:18 -0400272#if GR_FLUSH_TIME_OP_SPEW
Adlai Hollerc616e1c2021-02-11 15:18:17 -0500273 SkDebugf("Flushing %d opsTasks\n", fDAG.count());
274 for (int i = 0; i < fDAG.count(); ++i) {
Adlai Holler33432272020-11-11 13:54:37 -0500275 if (fDAG[i]) {
Robert Phillips047d5bb2021-01-08 13:39:19 -0500276 SkString label;
277 label.printf("task %d/%d", i, fDAG.count());
278 fDAG[i]->dump(label, {}, true, true);
Robert Phillips1734dd32018-08-21 13:52:09 -0400279 }
Robert Phillips27483912018-04-20 12:43:18 -0400280 }
281#endif
282
Chris Dalton6b498102019-08-01 14:14:52 -0600283 bool anyRenderTasksExecuted = false;
Robert Phillipseafd48a2017-11-16 07:52:08 -0500284
Adlai Hollerc616e1c2021-02-11 15:18:17 -0500285 for (const auto& renderTask : fDAG) {
Greg Daniel15ecdf92019-08-30 15:35:23 -0400286 if (!renderTask || !renderTask->isInstantiated()) {
Robert Phillipseafd48a2017-11-16 07:52:08 -0500287 continue;
288 }
289
Adlai Holler9e2c50e2021-02-09 14:41:52 -0500290 SkASSERT(renderTask->deferredProxiesAreInstantiated());
291
Chris Dalton6b498102019-08-01 14:14:52 -0600292 renderTask->prepare(flushState);
Robert Phillipseafd48a2017-11-16 07:52:08 -0500293 }
294
295 // Upload all data to the GPU
296 flushState->preExecuteDraws();
297
Greg Danield2073452018-12-07 11:20:33 -0500298 // For Vulkan, if we have too many oplists to be flushed we end up allocating a lot of resources
299 // for each command buffer associated with the oplists. If this gets too large we can cause the
300 // devices to go OOM. In practice we usually only hit this case in our tests, but to be safe we
301 // put a cap on the number of oplists we will execute before flushing to the GPU to relieve some
302 // memory pressure.
Chris Dalton6b498102019-08-01 14:14:52 -0600303 static constexpr int kMaxRenderTasksBeforeFlush = 100;
Adlai Hollerc616e1c2021-02-11 15:18:17 -0500304 int numRenderTasksExecuted = 0;
Greg Danield2073452018-12-07 11:20:33 -0500305
Chris Daltonc4b47352019-08-23 10:10:36 -0600306 // Execute the onFlush renderTasks first, if any.
307 for (sk_sp<GrRenderTask>& onFlushRenderTask : fOnFlushRenderTasks) {
308 if (!onFlushRenderTask->execute(flushState)) {
309 SkDebugf("WARNING: onFlushRenderTask failed to execute.\n");
Robert Phillipseafd48a2017-11-16 07:52:08 -0500310 }
Chris Daltonc4b47352019-08-23 10:10:36 -0600311 SkASSERT(onFlushRenderTask->unique());
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400312 onFlushRenderTask->disown(this);
Chris Daltonc4b47352019-08-23 10:10:36 -0600313 onFlushRenderTask = nullptr;
Adlai Hollerc616e1c2021-02-11 15:18:17 -0500314 if (++numRenderTasksExecuted >= kMaxRenderTasksBeforeFlush) {
Greg Danielfe159622020-04-10 17:43:51 +0000315 flushState->gpu()->submitToGpu(false);
Adlai Hollerc616e1c2021-02-11 15:18:17 -0500316 numRenderTasksExecuted = 0;
Greg Danield2073452018-12-07 11:20:33 -0500317 }
Robert Phillipseafd48a2017-11-16 07:52:08 -0500318 }
Chris Daltonc4b47352019-08-23 10:10:36 -0600319 fOnFlushRenderTasks.reset();
Robert Phillipseafd48a2017-11-16 07:52:08 -0500320
321 // Execute the normal op lists.
Adlai Hollerc616e1c2021-02-11 15:18:17 -0500322 for (const auto& renderTask : fDAG) {
323 SkASSERT(renderTask);
324 if (!renderTask->isInstantiated()) {
Robert Phillipseafd48a2017-11-16 07:52:08 -0500325 continue;
326 }
327
Greg Daniel15ecdf92019-08-30 15:35:23 -0400328 if (renderTask->execute(flushState)) {
Chris Dalton6b498102019-08-01 14:14:52 -0600329 anyRenderTasksExecuted = true;
Robert Phillipseafd48a2017-11-16 07:52:08 -0500330 }
Adlai Hollerc616e1c2021-02-11 15:18:17 -0500331 if (++numRenderTasksExecuted >= kMaxRenderTasksBeforeFlush) {
Greg Danielfe159622020-04-10 17:43:51 +0000332 flushState->gpu()->submitToGpu(false);
Adlai Hollerc616e1c2021-02-11 15:18:17 -0500333 numRenderTasksExecuted = 0;
Greg Danield2073452018-12-07 11:20:33 -0500334 }
Robert Phillipseafd48a2017-11-16 07:52:08 -0500335 }
336
Greg Daniel2d41d0d2019-08-26 11:08:51 -0400337 SkASSERT(!flushState->opsRenderPass());
Robert Phillips40a29d72018-01-18 12:59:22 -0500338 SkASSERT(fTokenTracker.nextDrawToken() == fTokenTracker.nextTokenToFlush());
Robert Phillipseafd48a2017-11-16 07:52:08 -0500339
Chris Dalton6b498102019-08-01 14:14:52 -0600340 // We reset the flush state before the RenderTasks so that the last resources to be freed are
341 // those that are written to in the RenderTasks. This helps to make sure the most recently used
342 // resources are the last to be purged by the resource cache.
Robert Phillipseafd48a2017-11-16 07:52:08 -0500343 flushState->reset();
344
Chris Dalton6b498102019-08-01 14:14:52 -0600345 return anyRenderTasksExecuted;
Robert Phillipseafd48a2017-11-16 07:52:08 -0500346}
347
Adlai Hollerc616e1c2021-02-11 15:18:17 -0500348void GrDrawingManager::removeRenderTasks() {
349 for (const auto& task : fDAG) {
350 SkASSERT(task);
Robert Phillips07f675d2020-11-16 13:44:01 -0500351 if (!task->unique() || task->requiresExplicitCleanup()) {
352 // TODO: Eventually uniqueness should be guaranteed: http://skbug.com/7111.
353 // DDLs, however, will always require an explicit notification for when they
354 // can clean up resources.
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400355 task->endFlush(this);
356 }
357 task->disown(this);
358 }
Adlai Hollerc616e1c2021-02-11 15:18:17 -0500359 fDAG.reset();
360 fLastRenderTasks.reset();
Chris Dalton39811682021-03-11 22:45:48 -0700361 for (const sk_sp<GrRenderTask>& onFlushRenderTask : fOnFlushRenderTasks) {
362 onFlushRenderTask->disown(this);
363 }
364 fOnFlushRenderTasks.reset();
Adlai Holler33432272020-11-11 13:54:37 -0500365}
366
367void GrDrawingManager::sortTasks() {
Robert Phillipsfbbc3bb2020-11-16 14:58:56 -0500368 if (!GrTTopoSort<GrRenderTask, GrRenderTask::TopoSortTraits>(&fDAG)) {
Adlai Holler33432272020-11-11 13:54:37 -0500369 SkDEBUGFAIL("Render task topo sort failed.");
370 return;
371 }
372
Robert Phillips364ea352021-08-13 15:21:42 -0400373#if SK_GPU_V1 && defined(SK_DEBUG)
Adlai Holler33432272020-11-11 13:54:37 -0500374 // This block checks for any unnecessary splits in the opsTasks. If two sequential opsTasks
Greg Daniel0b04b6b2021-06-24 19:19:00 -0400375 // could have merged it means the opsTask was artificially split.
Adlai Holler33432272020-11-11 13:54:37 -0500376 if (!fDAG.empty()) {
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400377 auto prevOpsTask = fDAG[0]->asOpsTask();
Adlai Holler33432272020-11-11 13:54:37 -0500378 for (int i = 1; i < fDAG.count(); ++i) {
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400379 auto curOpsTask = fDAG[i]->asOpsTask();
Adlai Holler33432272020-11-11 13:54:37 -0500380
381 if (prevOpsTask && curOpsTask) {
Greg Daniel0b04b6b2021-06-24 19:19:00 -0400382 SkASSERT(!prevOpsTask->canMerge(curOpsTask));
Adlai Holler33432272020-11-11 13:54:37 -0500383 }
384
385 prevOpsTask = curOpsTask;
386 }
387 }
388#endif
389}
390
Adlai Holler78036082021-01-07 11:41:33 -0500391// Reorder the array to match the llist without reffing & unreffing sk_sp's.
Adlai Holler69c57e42021-01-25 15:44:26 +0000392// Both args must contain the same objects.
Adlai Holler78036082021-01-07 11:41:33 -0500393// This is basically a shim because clustering uses LList but the rest of drawmgr uses array.
394template <typename T>
395static void reorder_array_by_llist(const SkTInternalLList<T>& llist, SkTArray<sk_sp<T>>* array) {
396 int i = 0;
397 for (T* t : llist) {
Adlai Holler69c57e42021-01-25 15:44:26 +0000398 // Release the pointer that used to live here so it doesn't get unreffed.
399 [[maybe_unused]] T* old = array->at(i).release();
Adlai Holler78036082021-01-07 11:41:33 -0500400 array->at(i++).reset(t);
401 }
Adlai Holler69c57e42021-01-25 15:44:26 +0000402 SkASSERT(i == array->count());
Adlai Holler78036082021-01-07 11:41:33 -0500403}
404
Adlai Holler387309c2021-04-15 15:03:27 -0400405bool GrDrawingManager::reorderTasks(GrResourceAllocator* resourceAllocator) {
Adlai Holler78036082021-01-07 11:41:33 -0500406 SkASSERT(fReduceOpsTaskSplitting);
407 SkTInternalLList<GrRenderTask> llist;
Brian Osmanae87bf12021-05-11 13:36:10 -0400408 bool clustered = GrClusterRenderTasks(SkMakeSpan(fDAG), &llist);
Adlai Holler78036082021-01-07 11:41:33 -0500409 if (!clustered) {
Adlai Holler387309c2021-04-15 15:03:27 -0400410 return false;
411 }
412
413 for (GrRenderTask* task : llist) {
414 task->gatherProxyIntervals(resourceAllocator);
415 }
416 if (!resourceAllocator->planAssignment()) {
417 return false;
418 }
419 if (!resourceAllocator->makeBudgetHeadroom()) {
420 auto dContext = fContext->asDirectContext();
421 SkASSERT(dContext);
422 dContext->priv().getGpu()->stats()->incNumReorderedDAGsOverBudget();
423 return false;
Adlai Holler78036082021-01-07 11:41:33 -0500424 }
Adlai Holler78036082021-01-07 11:41:33 -0500425 reorder_array_by_llist(llist, &fDAG);
Adlai Holler93439d92021-01-26 09:20:39 -0500426
427 int newCount = 0;
428 for (int i = 0; i < fDAG.count(); i++) {
429 sk_sp<GrRenderTask>& task = fDAG[i];
Robert Phillips364ea352021-08-13 15:21:42 -0400430#if SK_GPU_V1
Adlai Holler93439d92021-01-26 09:20:39 -0500431 if (auto opsTask = task->asOpsTask()) {
432 size_t remaining = fDAG.size() - i - 1;
433 SkSpan<sk_sp<GrRenderTask>> nextTasks{fDAG.end() - remaining, remaining};
434 int removeCount = opsTask->mergeFrom(nextTasks);
435 for (const auto& removed : nextTasks.first(removeCount)) {
436 removed->disown(this);
437 }
438 i += removeCount;
439 }
Robert Phillips364ea352021-08-13 15:21:42 -0400440#endif
Adlai Holler93439d92021-01-26 09:20:39 -0500441 fDAG[newCount++] = std::move(task);
442 }
443 fDAG.resize_back(newCount);
Adlai Holler387309c2021-04-15 15:03:27 -0400444 return true;
Adlai Holler78036082021-01-07 11:41:33 -0500445}
446
Adlai Holler33432272020-11-11 13:54:37 -0500447void GrDrawingManager::closeAllTasks() {
Adlai Holler33432272020-11-11 13:54:37 -0500448 for (auto& task : fDAG) {
449 if (task) {
Chris Daltonaa938ce2021-06-23 18:13:59 -0600450 task->makeClosed(fContext);
Adlai Holler33432272020-11-11 13:54:37 -0500451 }
452 }
453}
454
455GrRenderTask* GrDrawingManager::insertTaskBeforeLast(sk_sp<GrRenderTask> task) {
Adlai Holler33432272020-11-11 13:54:37 -0500456 if (!task) {
457 return nullptr;
458 }
Chris Dalton061aa812021-06-25 13:16:24 -0600459 if (fDAG.empty()) {
460 return fDAG.push_back(std::move(task)).get();
461 }
Adlai Holler33432272020-11-11 13:54:37 -0500462 // Release 'fDAG.back()' and grab the raw pointer, in case the SkTArray grows
463 // and reallocates during emplace_back.
464 // TODO: Either use std::vector that can do this for us, or use SkSTArray to get the
465 // perf win.
466 fDAG.emplace_back(fDAG.back().release());
467 return (fDAG[fDAG.count() - 2] = std::move(task)).get();
468}
469
470GrRenderTask* GrDrawingManager::appendTask(sk_sp<GrRenderTask> task) {
471 if (!task) {
472 return nullptr;
473 }
474 return fDAG.push_back(std::move(task)).get();
475}
476
Robert Phillips7eb0a5f2020-06-09 14:15:09 -0400477static void resolve_and_mipmap(GrGpu* gpu, GrSurfaceProxy* proxy) {
478 if (!proxy->isInstantiated()) {
479 return;
480 }
481
482 // In the flushSurfaces case, we need to resolve MSAA immediately after flush. This is
483 // because clients expect the flushed surface's backing texture to be fully resolved
484 // upon return.
485 if (proxy->requiresManualMSAAResolve()) {
486 auto* rtProxy = proxy->asRenderTargetProxy();
487 SkASSERT(rtProxy);
488 if (rtProxy->isMSAADirty()) {
489 SkASSERT(rtProxy->peekRenderTarget());
Jim Van Verthbb61fe32020-07-07 16:39:04 -0400490 gpu->resolveRenderTarget(rtProxy->peekRenderTarget(), rtProxy->msaaDirtyRect());
491 gpu->submitToGpu(false);
Robert Phillips7eb0a5f2020-06-09 14:15:09 -0400492 rtProxy->markMSAAResolved();
493 }
494 }
495 // If, after a flush, any of the proxies of interest have dirty mipmaps, regenerate them in
496 // case their backend textures are being stolen.
497 // (This special case is exercised by the ReimportImageTextureWithMipLevels test.)
498 // FIXME: It may be more ideal to plumb down a "we're going to steal the backends" flag.
499 if (auto* textureProxy = proxy->asTextureProxy()) {
Brian Salomon8c82a872020-07-21 12:09:58 -0400500 if (textureProxy->mipmapsAreDirty()) {
Robert Phillips7eb0a5f2020-06-09 14:15:09 -0400501 SkASSERT(textureProxy->peekTexture());
502 gpu->regenerateMipMapLevels(textureProxy->peekTexture());
Brian Salomon8c82a872020-07-21 12:09:58 -0400503 textureProxy->markMipmapsClean();
Robert Phillips7eb0a5f2020-06-09 14:15:09 -0400504 }
505 }
506}
507
Greg Daniel9efe3862020-06-11 11:51:06 -0400508GrSemaphoresSubmitted GrDrawingManager::flushSurfaces(
Adlai Hollerc2bfcff2020-11-06 15:39:36 -0500509 SkSpan<GrSurfaceProxy*> proxies,
Greg Daniel9efe3862020-06-11 11:51:06 -0400510 SkSurface::BackendSurfaceAccess access,
511 const GrFlushInfo& info,
512 const GrBackendSurfaceMutableState* newState) {
bsalomon6a2b1942016-09-08 11:28:59 -0700513 if (this->wasAbandoned()) {
Greg Daniel55822f12020-05-26 11:26:45 -0400514 if (info.fSubmittedProc) {
515 info.fSubmittedProc(info.fSubmittedContext, false);
516 }
517 if (info.fFinishedProc) {
518 info.fFinishedProc(info.fFinishedContext);
519 }
Greg Daniel51316782017-08-02 15:10:09 +0000520 return GrSemaphoresSubmitted::kNo;
bsalomon6a2b1942016-09-08 11:28:59 -0700521 }
Robert Phillips38d64b02018-09-04 13:23:26 -0400522 SkDEBUGCODE(this->validate());
bsalomon6a2b1942016-09-08 11:28:59 -0700523
Robert Phillipsf8f45d92020-07-01 11:11:18 -0400524 auto direct = fContext->asDirectContext();
Adlai Holleraee25fd2020-11-06 12:34:56 -0500525 SkASSERT(direct);
Robert Phillips6a6de562019-02-15 15:19:15 -0500526 GrGpu* gpu = direct->priv().getGpu();
Greg Daniel55822f12020-05-26 11:26:45 -0400527 // We have a non abandoned and direct GrContext. It must have a GrGpu.
528 SkASSERT(gpu);
Robert Phillips874b5352018-03-16 08:48:24 -0400529
Robert Phillipsacc10fa2019-04-01 09:50:20 -0400530 // TODO: It is important to upgrade the drawingmanager to just flushing the
Brian Salomonf9a1fdf2019-05-09 10:30:12 -0400531 // portion of the DAG required by 'proxies' in order to restore some of the
Robert Phillipsacc10fa2019-04-01 09:50:20 -0400532 // semantics of this method.
Adlai Hollerc2bfcff2020-11-06 15:39:36 -0500533 bool didFlush = this->flush(proxies, access, info, newState);
534 for (GrSurfaceProxy* proxy : proxies) {
535 resolve_and_mipmap(gpu, proxy);
bsalomon6a2b1942016-09-08 11:28:59 -0700536 }
Robert Phillips38d64b02018-09-04 13:23:26 -0400537
538 SkDEBUGCODE(this->validate());
Greg Danielfe159622020-04-10 17:43:51 +0000539
Greg Daniel04283f32020-05-20 13:16:00 -0400540 if (!didFlush || (!direct->priv().caps()->semaphoreSupport() && info.fNumSemaphores)) {
Greg Danielfe159622020-04-10 17:43:51 +0000541 return GrSemaphoresSubmitted::kNo;
542 }
543 return GrSemaphoresSubmitted::kYes;
bsalomon6a2b1942016-09-08 11:28:59 -0700544}
545
Chris Daltonfe199b72017-05-05 11:26:15 -0400546void GrDrawingManager::addOnFlushCallbackObject(GrOnFlushCallbackObject* onFlushCBObject) {
547 fOnFlushCBObjects.push_back(onFlushCBObject);
Robert Phillipseb35f4d2017-03-21 07:56:47 -0400548}
549
Robert Phillipsdbaf3172019-02-06 15:12:53 -0500550#if GR_TEST_UTILS
551void GrDrawingManager::testingOnly_removeOnFlushCallbackObject(GrOnFlushCallbackObject* cb) {
552 int n = std::find(fOnFlushCBObjects.begin(), fOnFlushCBObjects.end(), cb) -
553 fOnFlushCBObjects.begin();
554 SkASSERT(n < fOnFlushCBObjects.count());
555 fOnFlushCBObjects.removeShuffle(n);
556}
557#endif
558
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400559void GrDrawingManager::setLastRenderTask(const GrSurfaceProxy* proxy, GrRenderTask* task) {
560#ifdef SK_DEBUG
Robert Phillips07f675d2020-11-16 13:44:01 -0500561 if (auto prior = this->getLastRenderTask(proxy)) {
562 SkASSERT(prior->isClosed() || prior == task);
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400563 }
564#endif
Adlai Holler25df1f72020-06-09 13:08:27 -0400565 uint32_t key = proxy->uniqueID().asUInt();
566 if (task) {
567 fLastRenderTasks.set(key, task);
568 } else if (fLastRenderTasks.find(key)) {
569 fLastRenderTasks.remove(key);
570 }
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400571}
572
573GrRenderTask* GrDrawingManager::getLastRenderTask(const GrSurfaceProxy* proxy) const {
574 auto entry = fLastRenderTasks.find(proxy->uniqueID().asUInt());
575 return entry ? *entry : nullptr;
576}
577
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400578skgpu::v1::OpsTask* GrDrawingManager::getLastOpsTask(const GrSurfaceProxy* proxy) const {
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400579 GrRenderTask* task = this->getLastRenderTask(proxy);
580 return task ? task->asOpsTask() : nullptr;
581}
582
583
Chris Dalton6b498102019-08-01 14:14:52 -0600584void GrDrawingManager::moveRenderTasksToDDL(SkDeferredDisplayList* ddl) {
Robert Phillips38d64b02018-09-04 13:23:26 -0400585 SkDEBUGCODE(this->validate());
586
Chris Dalton6b498102019-08-01 14:14:52 -0600587 // no renderTask should receive a new command after this
Adlai Holler33432272020-11-11 13:54:37 -0500588 this->closeAllTasks();
Adlai Holler039f90c2020-11-19 15:20:31 +0000589 fActiveOpsTask = nullptr;
Robert Phillips7a137052018-02-01 11:23:12 -0500590
Robert Phillips07f675d2020-11-16 13:44:01 -0500591 this->sortTasks();
592
Adlai Holler33432272020-11-11 13:54:37 -0500593 fDAG.swap(ddl->fRenderTasks);
594 SkASSERT(fDAG.empty());
Robert Phillips867ce8f2018-06-21 10:28:36 -0400595
Robert Phillips19f466d2020-02-26 10:27:07 -0500596 for (auto& renderTask : ddl->fRenderTasks) {
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400597 renderTask->disown(this);
Robert Phillips29f38542019-10-16 09:20:25 -0400598 renderTask->prePrepare(fContext);
Robert Phillips7327c9d2019-10-08 16:32:56 -0400599 }
600
Michael Ludwig2c316bd2019-12-19 14:50:44 -0500601 ddl->fArenas = std::move(fContext->priv().detachArenas());
Robert Phillips61fc7992019-10-22 11:58:17 -0400602
Robert Phillipsf6a0b452020-02-18 14:26:46 -0500603 fContext->priv().detachProgramData(&ddl->fProgramData);
Robert Phillips576b6a12019-12-06 13:05:49 -0500604
Robert Phillips38d64b02018-09-04 13:23:26 -0400605 SkDEBUGCODE(this->validate());
Robert Phillips62000362018-02-01 09:10:04 -0500606}
607
Robert Phillips07f675d2020-11-16 13:44:01 -0500608void GrDrawingManager::createDDLTask(sk_sp<const SkDeferredDisplayList> ddl,
Robert Phillipseb54bb52021-01-08 17:20:18 -0500609 sk_sp<GrRenderTargetProxy> newDest,
Robert Phillips88b29612020-11-16 15:15:08 -0500610 SkIPoint offset) {
Robert Phillips38d64b02018-09-04 13:23:26 -0400611 SkDEBUGCODE(this->validate());
612
Robert Phillips364ea352021-08-13 15:21:42 -0400613#if SK_GPU_V1
Adlai Holler039f90c2020-11-19 15:20:31 +0000614 if (fActiveOpsTask) {
Adlai Hollerc44e21f2021-02-22 14:08:07 -0500615 // This is a temporary fix for the partial-MDB world. In that world we're not
Adlai Holler039f90c2020-11-19 15:20:31 +0000616 // reordering so ops that (in the single opsTask world) would've just glommed onto the
617 // end of the single opsTask but referred to a far earlier RT need to appear in their
618 // own opsTask.
Chris Daltonaa938ce2021-06-23 18:13:59 -0600619 fActiveOpsTask->makeClosed(fContext);
Adlai Holler039f90c2020-11-19 15:20:31 +0000620 fActiveOpsTask = nullptr;
Robert Phillips38d64b02018-09-04 13:23:26 -0400621 }
Robert Phillips364ea352021-08-13 15:21:42 -0400622#endif
Robert Phillips38d64b02018-09-04 13:23:26 -0400623
Robert Phillips07f675d2020-11-16 13:44:01 -0500624 // Propagate the DDL proxy's state information to the replay target.
Robert Phillips7eb0a5f2020-06-09 14:15:09 -0400625 if (ddl->priv().targetProxy()->isMSAADirty()) {
Brian Salomon982127b2021-01-21 10:43:35 -0500626 auto nativeRect = GrNativeRect::MakeIRectRelativeTo(
627 ddl->characterization().origin(),
628 ddl->priv().targetProxy()->backingStoreDimensions().height(),
629 ddl->priv().targetProxy()->msaaDirtyRect());
630 newDest->markMSAADirty(nativeRect);
Robert Phillips7eb0a5f2020-06-09 14:15:09 -0400631 }
632 GrTextureProxy* newTextureProxy = newDest->asTextureProxy();
Brian Salomon8c82a872020-07-21 12:09:58 -0400633 if (newTextureProxy && GrMipmapped::kYes == newTextureProxy->mipmapped()) {
634 newTextureProxy->markMipmapsDirty();
Robert Phillips7eb0a5f2020-06-09 14:15:09 -0400635 }
636
Robert Phillips62000362018-02-01 09:10:04 -0500637 // Here we jam the proxy that backs the current replay SkSurface into the LazyProxyData.
Robert Phillips07f675d2020-11-16 13:44:01 -0500638 // The lazy proxy that references it (in the DDL opsTasks) will then steal its GrTexture.
Robert Phillipseb54bb52021-01-08 17:20:18 -0500639 ddl->fLazyProxyData->fReplayDest = newDest.get();
Robert Phillips774168e2018-05-31 12:43:27 -0400640
Robert Phillips07f675d2020-11-16 13:44:01 -0500641 // Add a task to handle drawing and lifetime management of the DDL.
642 SkDEBUGCODE(auto ddlTask =) this->appendTask(sk_make_sp<GrDDLTask>(this,
Robert Phillipseb54bb52021-01-08 17:20:18 -0500643 std::move(newDest),
Robert Phillips88b29612020-11-16 15:15:08 -0500644 std::move(ddl),
645 offset));
Robert Phillips07f675d2020-11-16 13:44:01 -0500646 SkASSERT(ddlTask->isClosed());
Adlai Holler7580ad42020-06-24 13:45:25 -0400647
Robert Phillips38d64b02018-09-04 13:23:26 -0400648 SkDEBUGCODE(this->validate());
Robert Phillips62000362018-02-01 09:10:04 -0500649}
650
Robert Phillips38d64b02018-09-04 13:23:26 -0400651#ifdef SK_DEBUG
652void GrDrawingManager::validate() const {
Robert Phillips364ea352021-08-13 15:21:42 -0400653#if SK_GPU_V1
Adlai Holler4ef108e2020-12-30 16:21:13 +0000654 if (fActiveOpsTask) {
655 SkASSERT(!fDAG.empty());
656 SkASSERT(!fActiveOpsTask->isClosed());
657 SkASSERT(fActiveOpsTask == fDAG.back().get());
658 }
Adlai Holler039f90c2020-11-19 15:20:31 +0000659
Adlai Holler4ef108e2020-12-30 16:21:13 +0000660 for (int i = 0; i < fDAG.count(); ++i) {
661 if (fActiveOpsTask != fDAG[i].get()) {
662 // The resolveTask associated with the activeTask remains open for as long as the
663 // activeTask does.
664 bool isActiveResolveTask =
665 fActiveOpsTask && fActiveOpsTask->fTextureResolveTask == fDAG[i].get();
Chris Dalton83420eb2021-06-23 18:47:09 -0600666 bool isAtlas = fDAG[i]->isSetFlag(GrRenderTask::kAtlas_Flag);
667 SkASSERT(isActiveResolveTask || isAtlas || fDAG[i]->isClosed());
Adlai Holler76893192020-12-22 19:41:19 +0000668 }
Adlai Holler4ef108e2020-12-30 16:21:13 +0000669 }
Adlai Holler76893192020-12-22 19:41:19 +0000670
Chris Dalton061aa812021-06-25 13:16:24 -0600671 // The active opsTask, if any, should always be at the back of the DAG.
672 if (!fDAG.empty()) {
673 if (fDAG.back()->isSetFlag(GrRenderTask::kAtlas_Flag)) {
674 SkASSERT(fActiveOpsTask == nullptr);
675 SkASSERT(!fDAG.back()->isClosed());
676 } else if (fDAG.back()->isClosed()) {
677 SkASSERT(fActiveOpsTask == nullptr);
678 } else {
679 SkASSERT(fActiveOpsTask == fDAG.back().get());
680 }
681 } else {
682 SkASSERT(fActiveOpsTask == nullptr);
Robert Phillips38d64b02018-09-04 13:23:26 -0400683 }
Robert Phillips364ea352021-08-13 15:21:42 -0400684#endif // SK_GPU_V1
Robert Phillips38d64b02018-09-04 13:23:26 -0400685}
Robert Phillips364ea352021-08-13 15:21:42 -0400686#endif // SK_DEBUG
Robert Phillips38d64b02018-09-04 13:23:26 -0400687
Adlai Holler4ef108e2020-12-30 16:21:13 +0000688void GrDrawingManager::closeActiveOpsTask() {
Robert Phillips364ea352021-08-13 15:21:42 -0400689#if SK_GPU_V1
Adlai Holler4ef108e2020-12-30 16:21:13 +0000690 if (fActiveOpsTask) {
691 // This is a temporary fix for the partial-MDB world. In that world we're not
Adlai Holler039f90c2020-11-19 15:20:31 +0000692 // reordering so ops that (in the single opsTask world) would've just glommed onto the
Greg Danielf41b2bd2019-08-22 16:19:24 -0400693 // end of the single opsTask but referred to a far earlier RT need to appear in their
694 // own opsTask.
Chris Daltonaa938ce2021-06-23 18:13:59 -0600695 fActiveOpsTask->makeClosed(fContext);
Adlai Holler039f90c2020-11-19 15:20:31 +0000696 fActiveOpsTask = nullptr;
robertphillips3dc6ae52015-10-20 09:54:32 -0700697 }
Robert Phillips364ea352021-08-13 15:21:42 -0400698#endif
Chris Dalton5fe99772019-08-06 11:57:39 -0600699}
700
Robert Phillips364ea352021-08-13 15:21:42 -0400701#if SK_GPU_V1
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400702sk_sp<skgpu::v1::OpsTask> GrDrawingManager::newOpsTask(GrSurfaceProxyView surfaceView,
703 sk_sp<GrArenas> arenas,
704 bool flushTimeOpsTask) {
Chris Dalton5fe99772019-08-06 11:57:39 -0600705 SkDEBUGCODE(this->validate());
706 SkASSERT(fContext);
707
Adlai Holler4ef108e2020-12-30 16:21:13 +0000708 this->closeActiveOpsTask();
robertphillips3dc6ae52015-10-20 09:54:32 -0700709
Robert Phillips3e87a8e2021-08-25 13:22:24 -0400710 sk_sp<skgpu::v1::OpsTask> opsTask(new skgpu::v1::OpsTask(this,
711 std::move(surfaceView),
712 fContext->priv().auditTrail(),
713 std::move(arenas)));
Robert Phillipsa92913e2021-07-12 16:31:52 -0400714
Brian Salomon982127b2021-01-21 10:43:35 -0500715 SkASSERT(this->getLastRenderTask(opsTask->target(0)) == opsTask.get());
robertphillips3dc6ae52015-10-20 09:54:32 -0700716
Robert Phillips19006652020-11-19 14:20:57 -0500717 if (flushTimeOpsTask) {
718 fOnFlushRenderTasks.push_back(opsTask);
719 } else {
Adlai Holler33432272020-11-11 13:54:37 -0500720 this->appendTask(opsTask);
Adlai Holler039f90c2020-11-19 15:20:31 +0000721
Adlai Holler4ef108e2020-12-30 16:21:13 +0000722 fActiveOpsTask = opsTask.get();
Robert Phillips941d1442017-06-14 16:37:02 -0400723 }
robertphillips3dc6ae52015-10-20 09:54:32 -0700724
Robert Phillips38d64b02018-09-04 13:23:26 -0400725 SkDEBUGCODE(this->validate());
Greg Danielf41b2bd2019-08-22 16:19:24 -0400726 return opsTask;
robertphillips3dc6ae52015-10-20 09:54:32 -0700727}
728
Chris Dalton83420eb2021-06-23 18:47:09 -0600729void GrDrawingManager::addAtlasTask(sk_sp<GrRenderTask> atlasTask,
730 GrRenderTask* previousAtlasTask) {
731 SkDEBUGCODE(this->validate());
732 SkASSERT(fContext);
733
734 if (previousAtlasTask) {
735 previousAtlasTask->makeClosed(fContext);
736 for (GrRenderTask* previousAtlasUser : previousAtlasTask->dependents()) {
737 // Make the new atlas depend on everybody who used the old atlas, and close their tasks.
738 // This guarantees that the previous atlas is totally out of service before we render
739 // the next one, meaning there is only ever one atlas active at a time and that they can
740 // all share the same texture.
741 atlasTask->addDependency(previousAtlasUser);
742 previousAtlasUser->makeClosed(fContext);
743 if (previousAtlasUser == fActiveOpsTask) {
744 fActiveOpsTask = nullptr;
745 }
746 }
747 }
748
749 atlasTask->setFlag(GrRenderTask::kAtlas_Flag);
750 this->insertTaskBeforeLast(std::move(atlasTask));
751
752 SkDEBUGCODE(this->validate());
753}
Robert Phillips364ea352021-08-13 15:21:42 -0400754#endif // SK_GPU_V1
Chris Dalton83420eb2021-06-23 18:47:09 -0600755
Adlai Holler039f90c2020-11-19 15:20:31 +0000756GrTextureResolveRenderTask* GrDrawingManager::newTextureResolveRenderTask(const GrCaps& caps) {
Chris Dalton6aeb8e82019-08-27 11:52:19 -0600757 // Unlike in the "new opsTask" case, we do not want to close the active opsTask, nor (if we are
Adlai Holler039f90c2020-11-19 15:20:31 +0000758 // in sorting and opsTask reduction mode) the render tasks that depend on any proxy's current
Greg Danielf41b2bd2019-08-22 16:19:24 -0400759 // state. This is because those opsTasks can still receive new ops and because if they refer to
Adlai Holler039f90c2020-11-19 15:20:31 +0000760 // the mipmapped version of 'proxy', they will then come to depend on the render task being
Chris Dalton4ece96d2019-08-30 11:26:39 -0600761 // created here.
Chris Dalton6aeb8e82019-08-27 11:52:19 -0600762 //
Adlai Holler039f90c2020-11-19 15:20:31 +0000763 // Add the new textureResolveTask before the fActiveOpsTask (if not in
764 // sorting/opsTask-splitting-reduction mode) because it will depend upon this resolve task.
Chris Dalton3d770272019-08-14 09:24:37 -0600765 // NOTE: Putting it here will also reduce the amount of work required by the topological sort.
Adlai Holler33432272020-11-11 13:54:37 -0500766 GrRenderTask* task = this->insertTaskBeforeLast(sk_make_sp<GrTextureResolveRenderTask>());
767 return static_cast<GrTextureResolveRenderTask*>(task);
Chris Dalton3d770272019-08-14 09:24:37 -0600768}
769
Greg Danielc30f1a92019-09-06 15:28:58 -0400770void GrDrawingManager::newWaitRenderTask(sk_sp<GrSurfaceProxy> proxy,
Greg Daniel301015c2019-11-18 14:06:46 -0500771 std::unique_ptr<std::unique_ptr<GrSemaphore>[]> semaphores,
Greg Danielc30f1a92019-09-06 15:28:58 -0400772 int numSemaphores) {
773 SkDEBUGCODE(this->validate());
774 SkASSERT(fContext);
775
Greg Daniel16f5c652019-10-29 11:26:01 -0400776 sk_sp<GrWaitRenderTask> waitTask = sk_make_sp<GrWaitRenderTask>(GrSurfaceProxyView(proxy),
777 std::move(semaphores),
Greg Danielc30f1a92019-09-06 15:28:58 -0400778 numSemaphores);
Greg Danielc30f1a92019-09-06 15:28:58 -0400779
Robert Phillips364ea352021-08-13 15:21:42 -0400780#if SK_GPU_V1
Brian Salomon982127b2021-01-21 10:43:35 -0500781 if (fActiveOpsTask && (fActiveOpsTask->target(0) == proxy.get())) {
Adlai Holler4ef108e2020-12-30 16:21:13 +0000782 SkASSERT(this->getLastRenderTask(proxy.get()) == fActiveOpsTask);
783 this->insertTaskBeforeLast(waitTask);
784 // In this case we keep the current renderTask open but just insert the new waitTask
785 // before it in the list. The waitTask will never need to trigger any resolves or mip
786 // map generation which is the main advantage of going through the proxy version.
787 // Additionally we would've had to temporarily set the wait task as the lastRenderTask
788 // on the proxy, add the dependency, and then reset the lastRenderTask to
789 // fActiveOpsTask. Additionally we make the waitTask depend on all of fActiveOpsTask
790 // dependencies so that we don't unnecessarily reorder the waitTask before them.
791 // Note: Any previous Ops already in fActiveOpsTask will get blocked by the wait
792 // semaphore even though they don't need to be for correctness.
793
794 // Make sure we add the dependencies of fActiveOpsTask to waitTask first or else we'll
795 // get a circular self dependency of waitTask on waitTask.
796 waitTask->addDependenciesFromOtherTask(fActiveOpsTask);
797 fActiveOpsTask->addDependency(waitTask.get());
Robert Phillips364ea352021-08-13 15:21:42 -0400798 } else
799#endif
800 {
Adlai Holler4ef108e2020-12-30 16:21:13 +0000801 // In this case we just close the previous RenderTask and start and append the waitTask
802 // to the DAG. Since it is the last task now we call setLastRenderTask on the proxy. If
803 // there is a lastTask on the proxy we make waitTask depend on that task. This
804 // dependency isn't strictly needed but it does keep the DAG from reordering the
805 // waitTask earlier and blocking more tasks.
806 if (GrRenderTask* lastTask = this->getLastRenderTask(proxy.get())) {
807 waitTask->addDependency(lastTask);
Adlai Holler76893192020-12-22 19:41:19 +0000808 }
Adlai Holler4ef108e2020-12-30 16:21:13 +0000809 this->setLastRenderTask(proxy.get(), waitTask.get());
810 this->closeActiveOpsTask();
811 this->appendTask(waitTask);
Greg Danielc30f1a92019-09-06 15:28:58 -0400812 }
Chris Daltonaa938ce2021-06-23 18:13:59 -0600813 waitTask->makeClosed(fContext);
Greg Danielc30f1a92019-09-06 15:28:58 -0400814
815 SkDEBUGCODE(this->validate());
816}
817
Greg Danielbbfec9d2019-08-20 10:56:51 -0400818void GrDrawingManager::newTransferFromRenderTask(sk_sp<GrSurfaceProxy> srcProxy,
819 const SkIRect& srcRect,
820 GrColorType surfaceColorType,
821 GrColorType dstColorType,
822 sk_sp<GrGpuBuffer> dstBuffer,
823 size_t dstOffset) {
824 SkDEBUGCODE(this->validate());
825 SkASSERT(fContext);
Adlai Holler4ef108e2020-12-30 16:21:13 +0000826 this->closeActiveOpsTask();
Greg Danielbbfec9d2019-08-20 10:56:51 -0400827
Adlai Holler33432272020-11-11 13:54:37 -0500828 GrRenderTask* task = this->appendTask(sk_make_sp<GrTransferFromRenderTask>(
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400829 srcProxy, srcRect, surfaceColorType, dstColorType,
830 std::move(dstBuffer), dstOffset));
Greg Danielbbfec9d2019-08-20 10:56:51 -0400831
832 const GrCaps& caps = *fContext->priv().caps();
833
Brian Salomon7e67dca2020-07-21 09:27:25 -0400834 // We always say GrMipmapped::kNo here since we are always just copying from the base layer. We
Greg Danielbbfec9d2019-08-20 10:56:51 -0400835 // don't need to make sure the whole mip map chain is valid.
Brian Salomon7e67dca2020-07-21 09:27:25 -0400836 task->addDependency(this, srcProxy.get(), GrMipmapped::kNo,
Adlai Hollerd71b7b02020-06-08 15:55:00 -0400837 GrTextureResolveManager(this), caps);
Chris Daltonaa938ce2021-06-23 18:13:59 -0600838 task->makeClosed(fContext);
Greg Danielbbfec9d2019-08-20 10:56:51 -0400839
Greg Danielbbfec9d2019-08-20 10:56:51 -0400840 // We have closed the previous active oplist but since a new oplist isn't being added there
841 // shouldn't be an active one.
Adlai Holler039f90c2020-11-19 15:20:31 +0000842 SkASSERT(!fActiveOpsTask);
Greg Danielbbfec9d2019-08-20 10:56:51 -0400843 SkDEBUGCODE(this->validate());
844}
845
Brian Salomond63638b2021-03-05 14:00:07 -0500846sk_sp<GrRenderTask> GrDrawingManager::newCopyRenderTask(sk_sp<GrSurfaceProxy> src,
847 SkIRect srcRect,
848 sk_sp<GrSurfaceProxy> dst,
849 SkIPoint dstPoint,
850 GrSurfaceOrigin origin) {
Greg Daniele227fe42019-08-21 13:52:24 -0400851 SkDEBUGCODE(this->validate());
852 SkASSERT(fContext);
Greg Daniele227fe42019-08-21 13:52:24 -0400853
Brian Salomon56c78f42021-02-03 16:56:55 -0500854 // It'd be nicer to check this in GrCopyRenderTask::Make. This gets complicated because of
855 // "active ops task" tracking. dst will be the target of our copy task but it might also be the
856 // target of the active ops task. We currently require the active ops task to be closed before
857 // making a new task that targets the same proxy. However, if we first close the active ops
858 // task, then fail to make a copy task, the next active ops task may target the same proxy. This
859 // will trip an assert related to unnecessary ops task splitting.
860 if (src->framebufferOnly()) {
Brian Salomond63638b2021-03-05 14:00:07 -0500861 return nullptr;
Brian Salomon56c78f42021-02-03 16:56:55 -0500862 }
863
Brian Salomon507c5652021-02-03 20:32:06 +0000864 this->closeActiveOpsTask();
865
Brian Salomond63638b2021-03-05 14:00:07 -0500866 sk_sp<GrRenderTask> task = GrCopyRenderTask::Make(this,
867 src,
868 srcRect,
869 std::move(dst),
870 dstPoint,
871 origin);
Greg Daniele227fe42019-08-21 13:52:24 -0400872 if (!task) {
Brian Salomond63638b2021-03-05 14:00:07 -0500873 return nullptr;
Greg Daniele227fe42019-08-21 13:52:24 -0400874 }
875
Brian Salomond63638b2021-03-05 14:00:07 -0500876 this->appendTask(task);
877
Brian Salomon0f9f8002021-01-22 16:30:50 -0500878 const GrCaps& caps = *fContext->priv().caps();
Brian Salomon7e67dca2020-07-21 09:27:25 -0400879 // We always say GrMipmapped::kNo here since we are always just copying from the base layer to
Greg Daniele227fe42019-08-21 13:52:24 -0400880 // another base layer. We don't need to make sure the whole mip map chain is valid.
Brian Salomon507c5652021-02-03 20:32:06 +0000881 task->addDependency(this, src.get(), GrMipmapped::kNo, GrTextureResolveManager(this), caps);
Chris Daltonaa938ce2021-06-23 18:13:59 -0600882 task->makeClosed(fContext);
Greg Daniele227fe42019-08-21 13:52:24 -0400883
Greg Daniele227fe42019-08-21 13:52:24 -0400884 // We have closed the previous active oplist but since a new oplist isn't being added there
885 // shouldn't be an active one.
Adlai Holler039f90c2020-11-19 15:20:31 +0000886 SkASSERT(!fActiveOpsTask);
Greg Daniele227fe42019-08-21 13:52:24 -0400887 SkDEBUGCODE(this->validate());
Brian Salomond63638b2021-03-05 14:00:07 -0500888 return task;
Greg Daniele227fe42019-08-21 13:52:24 -0400889}
890
Brian Salomonbe1084b2021-01-26 13:29:30 -0500891bool GrDrawingManager::newWritePixelsTask(sk_sp<GrSurfaceProxy> dst,
892 SkIRect rect,
893 GrColorType srcColorType,
894 GrColorType dstColorType,
895 const GrMipLevel levels[],
Brian Salomon75ee7372021-04-06 15:04:35 -0400896 int levelCount) {
Brian Salomonbe1084b2021-01-26 13:29:30 -0500897 SkDEBUGCODE(this->validate());
898 SkASSERT(fContext);
899
900 this->closeActiveOpsTask();
901 const GrCaps& caps = *fContext->priv().caps();
902
903 // On platforms that prefer flushes over VRAM use (i.e., ANGLE) we're better off forcing a
904 // complete flush here.
905 if (!caps.preferVRAMUseOverFlushes()) {
906 this->flushSurfaces(SkSpan<GrSurfaceProxy*>{},
907 SkSurface::BackendSurfaceAccess::kNoAccess,
908 GrFlushInfo{},
909 nullptr);
910 }
911
912 GrRenderTask* task = this->appendTask(GrWritePixelsTask::Make(this,
913 std::move(dst),
914 rect,
915 srcColorType,
916 dstColorType,
917 levels,
Brian Salomon75ee7372021-04-06 15:04:35 -0400918 levelCount));
Brian Salomonbe1084b2021-01-26 13:29:30 -0500919 if (!task) {
920 return false;
921 }
922
Chris Daltonaa938ce2021-06-23 18:13:59 -0600923 task->makeClosed(fContext);
Brian Salomonbe1084b2021-01-26 13:29:30 -0500924
925 // We have closed the previous active oplist but since a new oplist isn't being added there
926 // shouldn't be an active one.
927 SkASSERT(!fActiveOpsTask);
928 SkDEBUGCODE(this->validate());
929 return true;
930}
931
Robert Phillips7cef6782021-07-01 13:21:37 -0400932#if SK_GPU_V1
robertphillips68737822015-10-29 12:12:21 -0700933/*
934 * This method finds a path renderer that can draw the specified path on
935 * the provided target.
936 * Due to its expense, the software path renderer has split out so it can
937 * can be individually allowed/disallowed via the "allowSW" boolean.
938 */
Robert Phillipsdb0ec082021-08-19 12:30:12 -0400939skgpu::v1::PathRenderer* GrDrawingManager::getPathRenderer(
940 const PathRenderer::CanDrawPathArgs& args,
941 bool allowSW,
942 PathRendererChain::DrawType drawType,
943 PathRenderer::StencilSupport* stencilSupport) {
robertphillips68737822015-10-29 12:12:21 -0700944
945 if (!fPathRendererChain) {
John Stilesfbd050b2020-08-03 13:21:46 -0400946 fPathRendererChain =
Robert Phillipsdb0ec082021-08-19 12:30:12 -0400947 std::make_unique<PathRendererChain>(fContext, fOptionsForPathRendererChain);
robertphillips68737822015-10-29 12:12:21 -0700948 }
949
Robert Phillipsdb0ec082021-08-19 12:30:12 -0400950 auto pr = fPathRendererChain->getPathRenderer(args, drawType, stencilSupport);
robertphillips68737822015-10-29 12:12:21 -0700951 if (!pr && allowSW) {
Brian Salomone7df0bb2018-05-07 14:44:57 -0400952 auto swPR = this->getSoftwarePathRenderer();
Robert Phillipsdb0ec082021-08-19 12:30:12 -0400953 if (PathRenderer::CanDrawPath::kNo != swPR->canDrawPath(args)) {
Brian Salomone7df0bb2018-05-07 14:44:57 -0400954 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
Robert Phillipsdb0ec082021-08-19 12:30:12 -0400967skgpu::v1::PathRenderer* GrDrawingManager::getSoftwarePathRenderer() {
Brian Salomone7df0bb2018-05-07 14:44:57 -0400968 if (!fSoftwarePathRenderer) {
Robert Phillips17dc6582021-08-17 11:57:31 -0400969 fSoftwarePathRenderer.reset(new skgpu::v1::SoftwarePathRenderer(
970 fContext->priv().proxyProvider(), fOptionsForPathRendererChain.fAllowPathMaskCaching));
Brian Salomone7df0bb2018-05-07 14:44:57 -0400971 }
Ben Wagner9ec70c62018-07-12 13:30:47 -0400972 return fSoftwarePathRenderer.get();
Brian Salomone7df0bb2018-05-07 14:44:57 -0400973}
974
Robert Phillips43e70f12021-08-19 11:12:48 -0400975skgpu::v1::AtlasPathRenderer* GrDrawingManager::getAtlasPathRenderer() {
Chris Daltonc3176002021-07-23 15:33:09 -0600976 if (!fPathRendererChain) {
Robert Phillipsdb0ec082021-08-19 12:30:12 -0400977 fPathRendererChain = std::make_unique<PathRendererChain>(fContext,
978 fOptionsForPathRendererChain);
Chris Daltonc3176002021-07-23 15:33:09 -0600979 }
980 return fPathRendererChain->getAtlasPathRenderer();
981}
982
Robert Phillipsdb0ec082021-08-19 12:30:12 -0400983skgpu::v1::PathRenderer* GrDrawingManager::getTessellationPathRenderer() {
Chris Daltone6ae4762021-02-05 14:56:21 -0700984 if (!fPathRendererChain) {
Robert Phillipsdb0ec082021-08-19 12:30:12 -0400985 fPathRendererChain = std::make_unique<PathRendererChain>(fContext,
986 fOptionsForPathRendererChain);
Chris Daltone6ae4762021-02-05 14:56:21 -0700987 }
988 return fPathRendererChain->getTessellationPathRenderer();
989}
990
Robert Phillips7cef6782021-07-01 13:21:37 -0400991#endif // SK_GPU_V1
Robert Phillips3674f582021-06-16 12:05:54 -0400992
Brian Salomon653f42f2018-07-10 10:07:31 -0400993void GrDrawingManager::flushIfNecessary() {
Robert Phillipsf8f45d92020-07-01 11:11:18 -0400994 auto direct = fContext->asDirectContext();
Robert Phillips6a6de562019-02-15 15:19:15 -0500995 if (!direct) {
996 return;
997 }
998
999 auto resourceCache = direct->priv().getResourceCache();
Brian Salomon653f42f2018-07-10 10:07:31 -04001000 if (resourceCache && resourceCache->requestsFlush()) {
Adlai Hollerc2bfcff2020-11-06 15:39:36 -05001001 if (this->flush({}, SkSurface::BackendSurfaceAccess::kNoAccess, GrFlushInfo(), nullptr)) {
Greg Danielfe159622020-04-10 17:43:51 +00001002 this->submitToGpu(false);
1003 }
Brian Salomon57d2beab2018-09-10 09:35:41 -04001004 resourceCache->purgeAsNeeded();
Brian Salomon653f42f2018-07-10 10:07:31 -04001005 }
1006}