robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 1 | /* |
| 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 Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/gpu/GrDrawingManager.h" |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 9 | |
Adlai Holler | c2bfcff | 2020-11-06 15:39:36 -0500 | [diff] [blame] | 10 | #include <algorithm> |
John Stiles | fbd050b | 2020-08-03 13:21:46 -0400 | [diff] [blame] | 11 | #include <memory> |
| 12 | |
Robert Phillips | 4d5594d | 2020-02-21 14:24:40 -0500 | [diff] [blame] | 13 | #include "include/core/SkDeferredDisplayList.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 14 | #include "include/gpu/GrBackendSemaphore.h" |
Robert Phillips | b7bfbc2 | 2020-07-01 12:55:01 -0400 | [diff] [blame] | 15 | #include "include/gpu/GrDirectContext.h" |
| 16 | #include "include/gpu/GrRecordingContext.h" |
Robert Phillips | 7eb0a5f | 2020-06-09 14:15:09 -0400 | [diff] [blame] | 17 | #include "src/core/SkDeferredDisplayListPriv.h" |
Adlai Holler | 7803608 | 2021-01-07 11:41:33 -0500 | [diff] [blame] | 18 | #include "src/core/SkTInternalLList.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 19 | #include "src/gpu/GrAuditTrail.h" |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 20 | #include "src/gpu/GrClientMappedBufferManager.h" |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 21 | #include "src/gpu/GrCopyRenderTask.h" |
Robert Phillips | 07f675d | 2020-11-16 13:44:01 -0500 | [diff] [blame] | 22 | #include "src/gpu/GrDDLTask.h" |
Adlai Holler | a069304 | 2020-10-14 11:23:11 -0400 | [diff] [blame] | 23 | #include "src/gpu/GrDirectContextPriv.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 24 | #include "src/gpu/GrGpu.h" |
| 25 | #include "src/gpu/GrMemoryPool.h" |
| 26 | #include "src/gpu/GrOnFlushResourceProvider.h" |
| 27 | #include "src/gpu/GrRecordingContextPriv.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 28 | #include "src/gpu/GrRenderTargetProxy.h" |
Chris Dalton | 6b49810 | 2019-08-01 14:14:52 -0600 | [diff] [blame] | 29 | #include "src/gpu/GrRenderTask.h" |
Adlai Holler | 08f5311 | 2021-01-20 17:44:15 -0500 | [diff] [blame] | 30 | #include "src/gpu/GrRenderTaskCluster.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 31 | #include "src/gpu/GrResourceAllocator.h" |
| 32 | #include "src/gpu/GrResourceProvider.h" |
| 33 | #include "src/gpu/GrSoftwarePathRenderer.h" |
Greg Daniel | 46e366a | 2019-12-16 14:38:36 -0500 | [diff] [blame] | 34 | #include "src/gpu/GrSurfaceContext.h" |
Brian Salomon | eebe735 | 2020-12-09 16:37:04 -0500 | [diff] [blame] | 35 | #include "src/gpu/GrSurfaceDrawContext.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 36 | #include "src/gpu/GrSurfaceProxyPriv.h" |
Robert Phillips | fbbc3bb | 2020-11-16 14:58:56 -0500 | [diff] [blame] | 37 | #include "src/gpu/GrTTopoSort.h" |
Greg Daniel | 456f9b5 | 2020-03-05 19:14:18 +0000 | [diff] [blame] | 38 | #include "src/gpu/GrTexture.h" |
Greg Daniel | f91aeb2 | 2019-06-18 09:58:02 -0400 | [diff] [blame] | 39 | #include "src/gpu/GrTextureProxy.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 40 | #include "src/gpu/GrTextureProxyPriv.h" |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 41 | #include "src/gpu/GrTextureResolveRenderTask.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 42 | #include "src/gpu/GrTracing.h" |
Greg Daniel | bbfec9d | 2019-08-20 10:56:51 -0400 | [diff] [blame] | 43 | #include "src/gpu/GrTransferFromRenderTask.h" |
Greg Daniel | c30f1a9 | 2019-09-06 15:28:58 -0400 | [diff] [blame] | 44 | #include "src/gpu/GrWaitRenderTask.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 45 | #include "src/gpu/ccpr/GrCoverageCountingPathRenderer.h" |
Herb Derby | a08bde6 | 2020-06-12 15:46:06 -0400 | [diff] [blame] | 46 | #include "src/gpu/text/GrSDFTOptions.h" |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 47 | #include "src/image/SkSurface_Gpu.h" |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 48 | |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 49 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
Robert Phillips | 6989370 | 2019-02-22 11:16:30 -0500 | [diff] [blame] | 50 | GrDrawingManager::GrDrawingManager(GrRecordingContext* context, |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 51 | const GrPathRendererChain::Options& optionsForPathRendererChain, |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 52 | bool reduceOpsTaskSplitting) |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 53 | : fContext(context) |
| 54 | , fOptionsForPathRendererChain(optionsForPathRendererChain) |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 55 | , fPathRendererChain(nullptr) |
| 56 | , fSoftwarePathRenderer(nullptr) |
Robert Phillips | 6db27c2 | 2019-05-01 10:43:56 -0400 | [diff] [blame] | 57 | , fFlushing(false) |
Herb Derby | 082232b | 2020-06-10 15:08:18 -0400 | [diff] [blame] | 58 | , fReduceOpsTaskSplitting(reduceOpsTaskSplitting) { } |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 59 | |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 60 | GrDrawingManager::~GrDrawingManager() { |
Adlai Holler | 3343227 | 2020-11-11 13:54:37 -0500 | [diff] [blame] | 61 | this->closeAllTasks(); |
| 62 | this->removeRenderTasks(0, fDAG.count()); |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Robert Phillips | a9162df | 2019-02-11 14:12:03 -0500 | [diff] [blame] | 65 | bool GrDrawingManager::wasAbandoned() const { |
Robert Phillips | 9eb0002 | 2020-06-30 15:30:12 -0400 | [diff] [blame] | 66 | return fContext->abandoned(); |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 67 | } |
| 68 | |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 69 | void GrDrawingManager::freeGpuResources() { |
Jim Van Verth | 106b5c4 | 2017-09-26 12:45:29 -0400 | [diff] [blame] | 70 | for (int i = fOnFlushCBObjects.count() - 1; i >= 0; --i) { |
| 71 | if (!fOnFlushCBObjects[i]->retainOnFreeGpuResources()) { |
| 72 | // it's safe to just do this because we're iterating in reverse |
| 73 | fOnFlushCBObjects.removeShuffle(i); |
| 74 | } |
| 75 | } |
| 76 | |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 77 | // a path renderer may be holding onto resources |
robertphillips | 13391dd | 2015-10-30 05:15:11 -0700 | [diff] [blame] | 78 | fPathRendererChain = nullptr; |
Ben Wagner | 9ec70c6 | 2018-07-12 13:30:47 -0400 | [diff] [blame] | 79 | fSoftwarePathRenderer = nullptr; |
Robert Phillips | e3302df | 2017-04-24 07:31:02 -0400 | [diff] [blame] | 80 | } |
| 81 | |
Adlai Holler | c2bfcff | 2020-11-06 15:39:36 -0500 | [diff] [blame] | 82 | // MDB TODO: make use of the 'proxies' parameter. |
Greg Daniel | 9efe386 | 2020-06-11 11:51:06 -0400 | [diff] [blame] | 83 | bool GrDrawingManager::flush( |
Adlai Holler | c2bfcff | 2020-11-06 15:39:36 -0500 | [diff] [blame] | 84 | SkSpan<GrSurfaceProxy*> proxies, |
Greg Daniel | 9efe386 | 2020-06-11 11:51:06 -0400 | [diff] [blame] | 85 | SkSurface::BackendSurfaceAccess access, |
| 86 | const GrFlushInfo& info, |
| 87 | const GrBackendSurfaceMutableState* newState) { |
Brian Salomon | 57d2beab | 2018-09-10 09:35:41 -0400 | [diff] [blame] | 88 | GR_CREATE_TRACE_MARKER_CONTEXT("GrDrawingManager", "flush", fContext); |
Brian Salomon | dcbb9d9 | 2017-07-19 10:53:20 -0400 | [diff] [blame] | 89 | |
robertphillips | 7761d61 | 2016-05-16 09:14:53 -0700 | [diff] [blame] | 90 | if (fFlushing || this->wasAbandoned()) { |
Greg Daniel | 55822f1 | 2020-05-26 11:26:45 -0400 | [diff] [blame] | 91 | if (info.fSubmittedProc) { |
| 92 | info.fSubmittedProc(info.fSubmittedContext, false); |
| 93 | } |
Greg Daniel | e6bfb7d | 2019-04-17 15:26:11 -0400 | [diff] [blame] | 94 | if (info.fFinishedProc) { |
| 95 | info.fFinishedProc(info.fFinishedContext); |
Greg Daniel | a3aa75a | 2019-04-12 14:24:55 -0400 | [diff] [blame] | 96 | } |
Greg Daniel | fe15962 | 2020-04-10 17:43:51 +0000 | [diff] [blame] | 97 | return false; |
joshualitt | b8918c4 | 2015-12-18 09:59:46 -0800 | [diff] [blame] | 98 | } |
Robert Phillips | 602df41 | 2019-04-08 11:10:39 -0400 | [diff] [blame] | 99 | |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 100 | SkDEBUGCODE(this->validate()); |
| 101 | |
Adlai Holler | c2bfcff | 2020-11-06 15:39:36 -0500 | [diff] [blame] | 102 | // As of now we only short-circuit if we got an explicit list of surfaces to flush. |
| 103 | if (!proxies.empty() && !info.fNumSemaphores && !info.fFinishedProc && |
Greg Daniel | ce9f016 | 2020-06-30 13:42:46 -0400 | [diff] [blame] | 104 | access == SkSurface::BackendSurfaceAccess::kNoAccess && !newState) { |
Adlai Holler | c2bfcff | 2020-11-06 15:39:36 -0500 | [diff] [blame] | 105 | bool allUnused = std::all_of(proxies.begin(), proxies.end(), [&](GrSurfaceProxy* proxy) { |
Adlai Holler | 3343227 | 2020-11-11 13:54:37 -0500 | [diff] [blame] | 106 | bool used = std::any_of(fDAG.begin(), fDAG.end(), [&](auto& task) { |
| 107 | return task && task->isUsed(proxy); |
| 108 | }); |
Robert Phillips | 58a8ccc | 2021-01-11 09:07:55 -0500 | [diff] [blame] | 109 | return !used; |
Adlai Holler | c2bfcff | 2020-11-06 15:39:36 -0500 | [diff] [blame] | 110 | }); |
| 111 | if (allUnused) { |
Greg Daniel | 55822f1 | 2020-05-26 11:26:45 -0400 | [diff] [blame] | 112 | if (info.fSubmittedProc) { |
| 113 | info.fSubmittedProc(info.fSubmittedContext, true); |
| 114 | } |
Greg Daniel | fe15962 | 2020-04-10 17:43:51 +0000 | [diff] [blame] | 115 | return false; |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 116 | } |
Robert Phillips | 9313aa7 | 2019-04-09 18:41:27 -0400 | [diff] [blame] | 117 | } |
| 118 | |
Robert Phillips | f8f45d9 | 2020-07-01 11:11:18 -0400 | [diff] [blame] | 119 | auto direct = fContext->asDirectContext(); |
Adlai Holler | aee25fd | 2020-11-06 12:34:56 -0500 | [diff] [blame] | 120 | SkASSERT(direct); |
Brian Salomon | 9241a6d | 2019-10-03 13:26:54 -0400 | [diff] [blame] | 121 | direct->priv().clientMappedBufferManager()->process(); |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 122 | |
| 123 | GrGpu* gpu = direct->priv().getGpu(); |
Greg Daniel | 55822f1 | 2020-05-26 11:26:45 -0400 | [diff] [blame] | 124 | // We have a non abandoned and direct GrContext. It must have a GrGpu. |
| 125 | SkASSERT(gpu); |
Greg Daniel | a3aa75a | 2019-04-12 14:24:55 -0400 | [diff] [blame] | 126 | |
joshualitt | b8918c4 | 2015-12-18 09:59:46 -0800 | [diff] [blame] | 127 | fFlushing = true; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 128 | |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 129 | auto resourceProvider = direct->priv().resourceProvider(); |
| 130 | auto resourceCache = direct->priv().getResourceCache(); |
| 131 | |
Chris Dalton | 6b49810 | 2019-08-01 14:14:52 -0600 | [diff] [blame] | 132 | // Semi-usually the GrRenderTasks are already closed at this point, but sometimes Ganesh needs |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 133 | // to flush mid-draw. In that case, the SkGpuDevice's opsTasks won't be closed but need to be |
| 134 | // flushed anyway. Closing such opsTasks here will mean new ones will be created to replace them |
Chris Dalton | 6b49810 | 2019-08-01 14:14:52 -0600 | [diff] [blame] | 135 | // if the SkGpuDevice(s) write to them again. |
Adlai Holler | 3343227 | 2020-11-11 13:54:37 -0500 | [diff] [blame] | 136 | this->closeAllTasks(); |
Adlai Holler | 039f90c | 2020-11-19 15:20:31 +0000 | [diff] [blame] | 137 | fActiveOpsTask = nullptr; |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 138 | |
Adlai Holler | 3343227 | 2020-11-11 13:54:37 -0500 | [diff] [blame] | 139 | this->sortTasks(); |
Adlai Holler | 7803608 | 2021-01-07 11:41:33 -0500 | [diff] [blame] | 140 | |
| 141 | if (fReduceOpsTaskSplitting) { |
| 142 | this->reorderTasks(); |
| 143 | } |
| 144 | |
Brian Salomon | 601ac80 | 2019-02-07 13:37:16 -0500 | [diff] [blame] | 145 | if (!fCpuBufferCache) { |
| 146 | // We cache more buffers when the backend is using client side arrays. Otherwise, we |
| 147 | // expect each pool will use a CPU buffer as a staging buffer before uploading to a GPU |
| 148 | // buffer object. Each pool only requires one staging buffer at a time. |
| 149 | int maxCachedBuffers = fContext->priv().caps()->preferClientSideDynamicBuffers() ? 2 : 6; |
| 150 | fCpuBufferCache = GrBufferAllocPool::CpuBufferCache::Make(maxCachedBuffers); |
Brian Salomon | 58f153c | 2018-10-18 21:51:15 -0400 | [diff] [blame] | 151 | } |
Robert Phillips | a4c93ac | 2017-05-18 11:40:04 -0400 | [diff] [blame] | 152 | |
Robert Phillips | e5f7328 | 2019-06-18 17:15:04 -0400 | [diff] [blame] | 153 | GrOpFlushState flushState(gpu, resourceProvider, &fTokenTracker, fCpuBufferCache); |
Robert Phillips | 40a29d7 | 2018-01-18 12:59:22 -0500 | [diff] [blame] | 154 | |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 155 | GrOnFlushResourceProvider onFlushProvider(this); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 156 | |
Chris Dalton | 1265894 | 2017-10-05 19:45:25 -0600 | [diff] [blame] | 157 | // Prepare any onFlush op lists (e.g. atlases). |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 158 | if (!fOnFlushCBObjects.empty()) { |
Robert Phillips | 07f675d | 2020-11-16 13:44:01 -0500 | [diff] [blame] | 159 | fFlushingRenderTaskIDs.reserve_back(fDAG.count()); |
| 160 | for (const auto& task : fDAG) { |
| 161 | if (task) { |
| 162 | task->gatherIDs(&fFlushingRenderTaskIDs); |
Adlai Holler | 3343227 | 2020-11-11 13:54:37 -0500 | [diff] [blame] | 163 | } |
| 164 | } |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 165 | |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 166 | for (GrOnFlushCallbackObject* onFlushCBObject : fOnFlushCBObjects) { |
Adlai Holler | 9902cff | 2020-11-11 08:51:25 -0500 | [diff] [blame] | 167 | onFlushCBObject->preFlush(&onFlushProvider, fFlushingRenderTaskIDs); |
Chris Dalton | c4b4735 | 2019-08-23 10:10:36 -0600 | [diff] [blame] | 168 | } |
| 169 | for (const auto& onFlushRenderTask : fOnFlushRenderTasks) { |
| 170 | onFlushRenderTask->makeClosed(*fContext->priv().caps()); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 171 | #ifdef SK_DEBUG |
Chris Dalton | c4b4735 | 2019-08-23 10:10:36 -0600 | [diff] [blame] | 172 | // OnFlush callbacks are invoked during flush, and are therefore expected to handle |
| 173 | // resource allocation & usage on their own. (No deferred or lazy proxies!) |
| 174 | onFlushRenderTask->visitTargetAndSrcProxies_debugOnly( |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 175 | [](GrSurfaceProxy* p, GrMipmapped mipMapped) { |
Chris Dalton | c4b4735 | 2019-08-23 10:10:36 -0600 | [diff] [blame] | 176 | SkASSERT(!p->asTextureProxy() || !p->asTextureProxy()->texPriv().isDeferred()); |
Brian Salomon | beb7f52 | 2019-08-30 16:19:42 -0400 | [diff] [blame] | 177 | SkASSERT(!p->isLazy()); |
Chris Dalton | 4ece96d | 2019-08-30 11:26:39 -0600 | [diff] [blame] | 178 | if (p->requiresManualMSAAResolve()) { |
| 179 | // The onFlush callback is responsible for ensuring MSAA gets resolved. |
| 180 | SkASSERT(p->asRenderTargetProxy() && !p->asRenderTargetProxy()->isMSAADirty()); |
| 181 | } |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 182 | if (GrMipmapped::kYes == mipMapped) { |
Chris Dalton | c4b4735 | 2019-08-23 10:10:36 -0600 | [diff] [blame] | 183 | // The onFlush callback is responsible for regenerating mips if needed. |
Brian Salomon | 8c82a87 | 2020-07-21 12:09:58 -0400 | [diff] [blame] | 184 | SkASSERT(p->asTextureProxy() && !p->asTextureProxy()->mipmapsAreDirty()); |
Chris Dalton | c4b4735 | 2019-08-23 10:10:36 -0600 | [diff] [blame] | 185 | } |
| 186 | }); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 187 | #endif |
Chris Dalton | c4b4735 | 2019-08-23 10:10:36 -0600 | [diff] [blame] | 188 | onFlushRenderTask->prepare(&flushState); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 189 | } |
| 190 | } |
| 191 | |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 192 | #if 0 |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 193 | // Enable this to print out verbose GrOp information |
Adlai Holler | abdfd39 | 2020-10-19 09:00:36 -0400 | [diff] [blame] | 194 | SkDEBUGCODE(SkDebugf("onFlush renderTasks (%d):\n", fOnFlushRenderTasks.count())); |
Chris Dalton | c4b4735 | 2019-08-23 10:10:36 -0600 | [diff] [blame] | 195 | for (const auto& onFlushRenderTask : fOnFlushRenderTasks) { |
Adlai Holler | abdfd39 | 2020-10-19 09:00:36 -0400 | [diff] [blame] | 196 | SkDEBUGCODE(onFlushRenderTask->dump(/* printDependencies */ true);) |
Chris Dalton | c4b4735 | 2019-08-23 10:10:36 -0600 | [diff] [blame] | 197 | } |
Adlai Holler | 3343227 | 2020-11-11 13:54:37 -0500 | [diff] [blame] | 198 | SkDEBUGCODE(SkDebugf("Normal renderTasks (%d):\n", fDAG.count())); |
| 199 | for (const auto& task : fDAG) { |
| 200 | SkDEBUGCODE(task->dump(/* printDependencies */ true);) |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 201 | } |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 202 | #endif |
| 203 | |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 204 | int startIndex, stopIndex; |
| 205 | bool flushed = false; |
| 206 | |
Robert Phillips | f8e2502 | 2017-11-08 15:24:31 -0500 | [diff] [blame] | 207 | { |
Adlai Holler | 3343227 | 2020-11-11 13:54:37 -0500 | [diff] [blame] | 208 | GrResourceAllocator alloc(resourceProvider SkDEBUGCODE(, fDAG.count())); |
| 209 | for (int i = 0; i < fDAG.count(); ++i) { |
| 210 | if (fDAG[i]) { |
| 211 | fDAG[i]->gatherProxyIntervals(&alloc); |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 212 | } |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 213 | alloc.markEndOfOpsTask(i); |
Robert Phillips | f8e2502 | 2017-11-08 15:24:31 -0500 | [diff] [blame] | 214 | } |
Robert Phillips | c73666f | 2019-04-24 08:49:48 -0400 | [diff] [blame] | 215 | alloc.determineRecyclability(); |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 216 | |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 217 | GrResourceAllocator::AssignError error = GrResourceAllocator::AssignError::kNoError; |
Chris Dalton | 6b49810 | 2019-08-01 14:14:52 -0600 | [diff] [blame] | 218 | int numRenderTasksExecuted = 0; |
Brian Salomon | 577aa0f | 2018-11-30 13:32:23 -0500 | [diff] [blame] | 219 | while (alloc.assign(&startIndex, &stopIndex, &error)) { |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 220 | if (GrResourceAllocator::AssignError::kFailedProxyInstantiation == error) { |
| 221 | for (int i = startIndex; i < stopIndex; ++i) { |
Adlai Holler | 3343227 | 2020-11-11 13:54:37 -0500 | [diff] [blame] | 222 | GrRenderTask* renderTask = fDAG[i].get(); |
Chris Dalton | 6b49810 | 2019-08-01 14:14:52 -0600 | [diff] [blame] | 223 | if (!renderTask) { |
| 224 | continue; |
Robert Phillips | 01a9128 | 2018-07-26 08:03:04 -0400 | [diff] [blame] | 225 | } |
Chris Dalton | 6b49810 | 2019-08-01 14:14:52 -0600 | [diff] [blame] | 226 | if (!renderTask->isInstantiated()) { |
Greg Daniel | 15ecdf9 | 2019-08-30 15:35:23 -0400 | [diff] [blame] | 227 | // No need to call the renderTask's handleInternalAllocationFailure |
| 228 | // since we will already skip executing the renderTask since it is not |
| 229 | // instantiated. |
Chris Dalton | 6b49810 | 2019-08-01 14:14:52 -0600 | [diff] [blame] | 230 | continue; |
Robert Phillips | bbcb7f7 | 2018-05-31 11:16:19 -0400 | [diff] [blame] | 231 | } |
Chris Dalton | 6b49810 | 2019-08-01 14:14:52 -0600 | [diff] [blame] | 232 | renderTask->handleInternalAllocationFailure(); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 233 | } |
Adlai Holler | 96ead54 | 2020-06-26 08:50:14 -0400 | [diff] [blame] | 234 | this->removeRenderTasks(startIndex, stopIndex); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 235 | } |
Robert Phillips | 4150eea | 2018-02-07 17:08:21 -0500 | [diff] [blame] | 236 | |
Chris Dalton | 6b49810 | 2019-08-01 14:14:52 -0600 | [diff] [blame] | 237 | if (this->executeRenderTasks( |
| 238 | startIndex, stopIndex, &flushState, &numRenderTasksExecuted)) { |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 239 | flushed = true; |
| 240 | } |
bsalomon | dc43898 | 2016-08-31 11:53:49 -0700 | [diff] [blame] | 241 | } |
Greg Daniel | c42b20b | 2017-10-04 10:34:49 -0400 | [diff] [blame] | 242 | } |
| 243 | |
Chris Dalton | 91ab155 | 2018-04-18 13:24:25 -0600 | [diff] [blame] | 244 | #ifdef SK_DEBUG |
Adlai Holler | 3343227 | 2020-11-11 13:54:37 -0500 | [diff] [blame] | 245 | for (const auto& task : fDAG) { |
Adlai Holler | 96ead54 | 2020-06-26 08:50:14 -0400 | [diff] [blame] | 246 | // All render tasks should have been cleared out by now – we only reset the array below to |
| 247 | // reclaim storage. |
Adlai Holler | 3343227 | 2020-11-11 13:54:37 -0500 | [diff] [blame] | 248 | SkASSERT(!task); |
Chris Dalton | 91ab155 | 2018-04-18 13:24:25 -0600 | [diff] [blame] | 249 | } |
| 250 | #endif |
Adlai Holler | 25df1f7 | 2020-06-09 13:08:27 -0400 | [diff] [blame] | 251 | fLastRenderTasks.reset(); |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 252 | fDAG.reset(); |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 253 | |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 254 | #ifdef SK_DEBUG |
| 255 | // In non-DDL mode this checks that all the flushed ops have been freed from the memory pool. |
| 256 | // When we move to partial flushes this assert will no longer be valid. |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 257 | // In DDL mode this check is somewhat superfluous since the memory for most of the ops/opsTasks |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 258 | // will be stored in the DDL's GrOpMemoryPools. |
Herb Derby | e32e1ab | 2020-10-27 10:29:46 -0400 | [diff] [blame] | 259 | GrMemoryPool* opMemoryPool = fContext->priv().opMemoryPool(); |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 260 | opMemoryPool->isEmpty(); |
| 261 | #endif |
| 262 | |
Adlai Holler | c2bfcff | 2020-11-06 15:39:36 -0500 | [diff] [blame] | 263 | gpu->executeFlushInfo(proxies, access, info, newState); |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 264 | |
Brian Salomon | 57d2beab | 2018-09-10 09:35:41 -0400 | [diff] [blame] | 265 | // Give the cache a chance to purge resources that become purgeable due to flushing. |
| 266 | if (flushed) { |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 267 | resourceCache->purgeAsNeeded(); |
Brian Salomon | 876a017 | 2019-03-08 11:12:14 -0500 | [diff] [blame] | 268 | flushed = false; |
bsalomon | b77a907 | 2016-09-07 10:02:04 -0700 | [diff] [blame] | 269 | } |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 270 | for (GrOnFlushCallbackObject* onFlushCBObject : fOnFlushCBObjects) { |
Adlai Holler | 9902cff | 2020-11-11 08:51:25 -0500 | [diff] [blame] | 271 | onFlushCBObject->postFlush(fTokenTracker.nextTokenToFlush(), fFlushingRenderTaskIDs); |
Brian Salomon | 876a017 | 2019-03-08 11:12:14 -0500 | [diff] [blame] | 272 | flushed = true; |
| 273 | } |
| 274 | if (flushed) { |
| 275 | resourceCache->purgeAsNeeded(); |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 276 | } |
Chris Dalton | 6b49810 | 2019-08-01 14:14:52 -0600 | [diff] [blame] | 277 | fFlushingRenderTaskIDs.reset(); |
joshualitt | b8918c4 | 2015-12-18 09:59:46 -0800 | [diff] [blame] | 278 | fFlushing = false; |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 279 | |
Greg Daniel | fe15962 | 2020-04-10 17:43:51 +0000 | [diff] [blame] | 280 | return true; |
| 281 | } |
| 282 | |
| 283 | bool GrDrawingManager::submitToGpu(bool syncToCpu) { |
| 284 | if (fFlushing || this->wasAbandoned()) { |
| 285 | return false; |
| 286 | } |
| 287 | |
Robert Phillips | f8f45d9 | 2020-07-01 11:11:18 -0400 | [diff] [blame] | 288 | auto direct = fContext->asDirectContext(); |
Greg Daniel | fe15962 | 2020-04-10 17:43:51 +0000 | [diff] [blame] | 289 | if (!direct) { |
| 290 | return false; // Can't submit while DDL recording |
| 291 | } |
| 292 | GrGpu* gpu = direct->priv().getGpu(); |
| 293 | return gpu->submitToGpu(syncToCpu); |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 294 | } |
| 295 | |
Chris Dalton | 6b49810 | 2019-08-01 14:14:52 -0600 | [diff] [blame] | 296 | bool GrDrawingManager::executeRenderTasks(int startIndex, int stopIndex, GrOpFlushState* flushState, |
| 297 | int* numRenderTasksExecuted) { |
Adlai Holler | 3343227 | 2020-11-11 13:54:37 -0500 | [diff] [blame] | 298 | SkASSERT(startIndex <= stopIndex && stopIndex <= fDAG.count()); |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 299 | |
Robert Phillips | 2748391 | 2018-04-20 12:43:18 -0400 | [diff] [blame] | 300 | #if GR_FLUSH_TIME_OP_SPEW |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 301 | SkDebugf("Flushing opsTask: %d to %d out of [%d, %d]\n", |
Adlai Holler | 3343227 | 2020-11-11 13:54:37 -0500 | [diff] [blame] | 302 | startIndex, stopIndex, 0, fDAG.count()); |
Robert Phillips | 2748391 | 2018-04-20 12:43:18 -0400 | [diff] [blame] | 303 | for (int i = startIndex; i < stopIndex; ++i) { |
Adlai Holler | 3343227 | 2020-11-11 13:54:37 -0500 | [diff] [blame] | 304 | if (fDAG[i]) { |
Robert Phillips | 047d5bb | 2021-01-08 13:39:19 -0500 | [diff] [blame] | 305 | SkString label; |
| 306 | label.printf("task %d/%d", i, fDAG.count()); |
| 307 | fDAG[i]->dump(label, {}, true, true); |
Robert Phillips | 1734dd3 | 2018-08-21 13:52:09 -0400 | [diff] [blame] | 308 | } |
Robert Phillips | 2748391 | 2018-04-20 12:43:18 -0400 | [diff] [blame] | 309 | } |
| 310 | #endif |
| 311 | |
Chris Dalton | 6b49810 | 2019-08-01 14:14:52 -0600 | [diff] [blame] | 312 | bool anyRenderTasksExecuted = false; |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 313 | |
| 314 | for (int i = startIndex; i < stopIndex; ++i) { |
Adlai Holler | 3343227 | 2020-11-11 13:54:37 -0500 | [diff] [blame] | 315 | GrRenderTask* renderTask = fDAG[i].get(); |
Greg Daniel | 15ecdf9 | 2019-08-30 15:35:23 -0400 | [diff] [blame] | 316 | if (!renderTask || !renderTask->isInstantiated()) { |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 317 | continue; |
| 318 | } |
| 319 | |
Chris Dalton | 6b49810 | 2019-08-01 14:14:52 -0600 | [diff] [blame] | 320 | SkASSERT(renderTask->deferredProxiesAreInstantiated()); |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 321 | |
Chris Dalton | 6b49810 | 2019-08-01 14:14:52 -0600 | [diff] [blame] | 322 | renderTask->prepare(flushState); |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | // Upload all data to the GPU |
| 326 | flushState->preExecuteDraws(); |
| 327 | |
Greg Daniel | d207345 | 2018-12-07 11:20:33 -0500 | [diff] [blame] | 328 | // For Vulkan, if we have too many oplists to be flushed we end up allocating a lot of resources |
| 329 | // for each command buffer associated with the oplists. If this gets too large we can cause the |
| 330 | // devices to go OOM. In practice we usually only hit this case in our tests, but to be safe we |
| 331 | // put a cap on the number of oplists we will execute before flushing to the GPU to relieve some |
| 332 | // memory pressure. |
Chris Dalton | 6b49810 | 2019-08-01 14:14:52 -0600 | [diff] [blame] | 333 | static constexpr int kMaxRenderTasksBeforeFlush = 100; |
Greg Daniel | d207345 | 2018-12-07 11:20:33 -0500 | [diff] [blame] | 334 | |
Chris Dalton | c4b4735 | 2019-08-23 10:10:36 -0600 | [diff] [blame] | 335 | // Execute the onFlush renderTasks first, if any. |
| 336 | for (sk_sp<GrRenderTask>& onFlushRenderTask : fOnFlushRenderTasks) { |
| 337 | if (!onFlushRenderTask->execute(flushState)) { |
| 338 | SkDebugf("WARNING: onFlushRenderTask failed to execute.\n"); |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 339 | } |
Chris Dalton | c4b4735 | 2019-08-23 10:10:36 -0600 | [diff] [blame] | 340 | SkASSERT(onFlushRenderTask->unique()); |
Adlai Holler | d71b7b0 | 2020-06-08 15:55:00 -0400 | [diff] [blame] | 341 | onFlushRenderTask->disown(this); |
Chris Dalton | c4b4735 | 2019-08-23 10:10:36 -0600 | [diff] [blame] | 342 | onFlushRenderTask = nullptr; |
Chris Dalton | 6b49810 | 2019-08-01 14:14:52 -0600 | [diff] [blame] | 343 | (*numRenderTasksExecuted)++; |
| 344 | if (*numRenderTasksExecuted >= kMaxRenderTasksBeforeFlush) { |
Greg Daniel | fe15962 | 2020-04-10 17:43:51 +0000 | [diff] [blame] | 345 | flushState->gpu()->submitToGpu(false); |
Chris Dalton | 6b49810 | 2019-08-01 14:14:52 -0600 | [diff] [blame] | 346 | *numRenderTasksExecuted = 0; |
Greg Daniel | d207345 | 2018-12-07 11:20:33 -0500 | [diff] [blame] | 347 | } |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 348 | } |
Chris Dalton | c4b4735 | 2019-08-23 10:10:36 -0600 | [diff] [blame] | 349 | fOnFlushRenderTasks.reset(); |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 350 | |
| 351 | // Execute the normal op lists. |
| 352 | for (int i = startIndex; i < stopIndex; ++i) { |
Adlai Holler | 3343227 | 2020-11-11 13:54:37 -0500 | [diff] [blame] | 353 | GrRenderTask* renderTask = fDAG[i].get(); |
Greg Daniel | 15ecdf9 | 2019-08-30 15:35:23 -0400 | [diff] [blame] | 354 | if (!renderTask || !renderTask->isInstantiated()) { |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 355 | continue; |
| 356 | } |
| 357 | |
Greg Daniel | 15ecdf9 | 2019-08-30 15:35:23 -0400 | [diff] [blame] | 358 | if (renderTask->execute(flushState)) { |
Chris Dalton | 6b49810 | 2019-08-01 14:14:52 -0600 | [diff] [blame] | 359 | anyRenderTasksExecuted = true; |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 360 | } |
Chris Dalton | 6b49810 | 2019-08-01 14:14:52 -0600 | [diff] [blame] | 361 | (*numRenderTasksExecuted)++; |
| 362 | if (*numRenderTasksExecuted >= kMaxRenderTasksBeforeFlush) { |
Greg Daniel | fe15962 | 2020-04-10 17:43:51 +0000 | [diff] [blame] | 363 | flushState->gpu()->submitToGpu(false); |
Chris Dalton | 6b49810 | 2019-08-01 14:14:52 -0600 | [diff] [blame] | 364 | *numRenderTasksExecuted = 0; |
Greg Daniel | d207345 | 2018-12-07 11:20:33 -0500 | [diff] [blame] | 365 | } |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 366 | } |
| 367 | |
Greg Daniel | 2d41d0d | 2019-08-26 11:08:51 -0400 | [diff] [blame] | 368 | SkASSERT(!flushState->opsRenderPass()); |
Robert Phillips | 40a29d7 | 2018-01-18 12:59:22 -0500 | [diff] [blame] | 369 | SkASSERT(fTokenTracker.nextDrawToken() == fTokenTracker.nextTokenToFlush()); |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 370 | |
Chris Dalton | 6b49810 | 2019-08-01 14:14:52 -0600 | [diff] [blame] | 371 | // We reset the flush state before the RenderTasks so that the last resources to be freed are |
| 372 | // those that are written to in the RenderTasks. This helps to make sure the most recently used |
| 373 | // resources are the last to be purged by the resource cache. |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 374 | flushState->reset(); |
| 375 | |
Adlai Holler | d71b7b0 | 2020-06-08 15:55:00 -0400 | [diff] [blame] | 376 | this->removeRenderTasks(startIndex, stopIndex); |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 377 | |
Chris Dalton | 6b49810 | 2019-08-01 14:14:52 -0600 | [diff] [blame] | 378 | return anyRenderTasksExecuted; |
Robert Phillips | eafd48a | 2017-11-16 07:52:08 -0500 | [diff] [blame] | 379 | } |
| 380 | |
Adlai Holler | d71b7b0 | 2020-06-08 15:55:00 -0400 | [diff] [blame] | 381 | void GrDrawingManager::removeRenderTasks(int startIndex, int stopIndex) { |
| 382 | for (int i = startIndex; i < stopIndex; ++i) { |
Adlai Holler | 3343227 | 2020-11-11 13:54:37 -0500 | [diff] [blame] | 383 | GrRenderTask* task = fDAG[i].get(); |
Adlai Holler | d71b7b0 | 2020-06-08 15:55:00 -0400 | [diff] [blame] | 384 | if (!task) { |
| 385 | continue; |
| 386 | } |
Robert Phillips | 07f675d | 2020-11-16 13:44:01 -0500 | [diff] [blame] | 387 | if (!task->unique() || task->requiresExplicitCleanup()) { |
| 388 | // TODO: Eventually uniqueness should be guaranteed: http://skbug.com/7111. |
| 389 | // DDLs, however, will always require an explicit notification for when they |
| 390 | // can clean up resources. |
Adlai Holler | d71b7b0 | 2020-06-08 15:55:00 -0400 | [diff] [blame] | 391 | task->endFlush(this); |
| 392 | } |
| 393 | task->disown(this); |
Adlai Holler | 3343227 | 2020-11-11 13:54:37 -0500 | [diff] [blame] | 394 | |
| 395 | // This doesn't cleanup any referring pointers (e.g. dependency pointers in the DAG). |
| 396 | // It works right now bc this is only called after the topological sort is complete |
| 397 | // (so the dangling pointers aren't used). |
| 398 | fDAG[i] = nullptr; |
Adlai Holler | d71b7b0 | 2020-06-08 15:55:00 -0400 | [diff] [blame] | 399 | } |
Adlai Holler | 3343227 | 2020-11-11 13:54:37 -0500 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | void GrDrawingManager::sortTasks() { |
Robert Phillips | fbbc3bb | 2020-11-16 14:58:56 -0500 | [diff] [blame] | 403 | if (!GrTTopoSort<GrRenderTask, GrRenderTask::TopoSortTraits>(&fDAG)) { |
Adlai Holler | 3343227 | 2020-11-11 13:54:37 -0500 | [diff] [blame] | 404 | SkDEBUGFAIL("Render task topo sort failed."); |
| 405 | return; |
| 406 | } |
| 407 | |
| 408 | #ifdef SK_DEBUG |
| 409 | // This block checks for any unnecessary splits in the opsTasks. If two sequential opsTasks |
| 410 | // share the same backing GrSurfaceProxy it means the opsTask was artificially split. |
| 411 | if (!fDAG.empty()) { |
| 412 | GrOpsTask* prevOpsTask = fDAG[0]->asOpsTask(); |
| 413 | for (int i = 1; i < fDAG.count(); ++i) { |
| 414 | GrOpsTask* curOpsTask = fDAG[i]->asOpsTask(); |
| 415 | |
| 416 | if (prevOpsTask && curOpsTask) { |
Brian Salomon | 982127b | 2021-01-21 10:43:35 -0500 | [diff] [blame^] | 417 | SkASSERT(prevOpsTask->target(0) != curOpsTask->target(0)); |
Adlai Holler | 3343227 | 2020-11-11 13:54:37 -0500 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | prevOpsTask = curOpsTask; |
| 421 | } |
| 422 | } |
| 423 | #endif |
| 424 | } |
| 425 | |
Adlai Holler | 7803608 | 2021-01-07 11:41:33 -0500 | [diff] [blame] | 426 | // Reorder the array to match the llist without reffing & unreffing sk_sp's. |
| 427 | // Both args must contain the same objects. |
| 428 | // This is basically a shim because clustering uses LList but the rest of drawmgr uses array. |
| 429 | template <typename T> |
| 430 | static void reorder_array_by_llist(const SkTInternalLList<T>& llist, SkTArray<sk_sp<T>>* array) { |
| 431 | int i = 0; |
| 432 | for (T* t : llist) { |
| 433 | // Release the pointer that used to live here so it doesn't get unreffed. |
| 434 | [[maybe_unused]] T* old = array->at(i).release(); |
| 435 | array->at(i++).reset(t); |
| 436 | } |
| 437 | SkASSERT(i == array->count()); |
| 438 | } |
| 439 | |
| 440 | void GrDrawingManager::reorderTasks() { |
| 441 | SkASSERT(fReduceOpsTaskSplitting); |
| 442 | SkTInternalLList<GrRenderTask> llist; |
Adlai Holler | 08f5311 | 2021-01-20 17:44:15 -0500 | [diff] [blame] | 443 | bool clustered = GrClusterRenderTasks(fDAG, &llist); |
Adlai Holler | 7803608 | 2021-01-07 11:41:33 -0500 | [diff] [blame] | 444 | if (!clustered) { |
| 445 | return; |
| 446 | } |
| 447 | // TODO: Handle case where proposed order would blow our memory budget. |
| 448 | // Such cases are currently pathological, so we could just return here and keep current order. |
| 449 | reorder_array_by_llist(llist, &fDAG); |
| 450 | } |
| 451 | |
Adlai Holler | 3343227 | 2020-11-11 13:54:37 -0500 | [diff] [blame] | 452 | void GrDrawingManager::closeAllTasks() { |
| 453 | const GrCaps& caps = *fContext->priv().caps(); |
| 454 | for (auto& task : fDAG) { |
| 455 | if (task) { |
| 456 | task->makeClosed(caps); |
| 457 | } |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | GrRenderTask* GrDrawingManager::insertTaskBeforeLast(sk_sp<GrRenderTask> task) { |
| 462 | SkASSERT(!fDAG.empty()); |
| 463 | if (!task) { |
| 464 | return nullptr; |
| 465 | } |
| 466 | // Release 'fDAG.back()' and grab the raw pointer, in case the SkTArray grows |
| 467 | // and reallocates during emplace_back. |
| 468 | // TODO: Either use std::vector that can do this for us, or use SkSTArray to get the |
| 469 | // perf win. |
| 470 | fDAG.emplace_back(fDAG.back().release()); |
| 471 | return (fDAG[fDAG.count() - 2] = std::move(task)).get(); |
| 472 | } |
| 473 | |
| 474 | GrRenderTask* GrDrawingManager::appendTask(sk_sp<GrRenderTask> task) { |
| 475 | if (!task) { |
| 476 | return nullptr; |
| 477 | } |
| 478 | return fDAG.push_back(std::move(task)).get(); |
| 479 | } |
| 480 | |
Robert Phillips | 7eb0a5f | 2020-06-09 14:15:09 -0400 | [diff] [blame] | 481 | static void resolve_and_mipmap(GrGpu* gpu, GrSurfaceProxy* proxy) { |
| 482 | if (!proxy->isInstantiated()) { |
| 483 | return; |
| 484 | } |
| 485 | |
| 486 | // In the flushSurfaces case, we need to resolve MSAA immediately after flush. This is |
| 487 | // because clients expect the flushed surface's backing texture to be fully resolved |
| 488 | // upon return. |
| 489 | if (proxy->requiresManualMSAAResolve()) { |
| 490 | auto* rtProxy = proxy->asRenderTargetProxy(); |
| 491 | SkASSERT(rtProxy); |
| 492 | if (rtProxy->isMSAADirty()) { |
| 493 | SkASSERT(rtProxy->peekRenderTarget()); |
Jim Van Verth | bb61fe3 | 2020-07-07 16:39:04 -0400 | [diff] [blame] | 494 | gpu->resolveRenderTarget(rtProxy->peekRenderTarget(), rtProxy->msaaDirtyRect()); |
| 495 | gpu->submitToGpu(false); |
Robert Phillips | 7eb0a5f | 2020-06-09 14:15:09 -0400 | [diff] [blame] | 496 | rtProxy->markMSAAResolved(); |
| 497 | } |
| 498 | } |
| 499 | // If, after a flush, any of the proxies of interest have dirty mipmaps, regenerate them in |
| 500 | // case their backend textures are being stolen. |
| 501 | // (This special case is exercised by the ReimportImageTextureWithMipLevels test.) |
| 502 | // FIXME: It may be more ideal to plumb down a "we're going to steal the backends" flag. |
| 503 | if (auto* textureProxy = proxy->asTextureProxy()) { |
Brian Salomon | 8c82a87 | 2020-07-21 12:09:58 -0400 | [diff] [blame] | 504 | if (textureProxy->mipmapsAreDirty()) { |
Robert Phillips | 7eb0a5f | 2020-06-09 14:15:09 -0400 | [diff] [blame] | 505 | SkASSERT(textureProxy->peekTexture()); |
| 506 | gpu->regenerateMipMapLevels(textureProxy->peekTexture()); |
Brian Salomon | 8c82a87 | 2020-07-21 12:09:58 -0400 | [diff] [blame] | 507 | textureProxy->markMipmapsClean(); |
Robert Phillips | 7eb0a5f | 2020-06-09 14:15:09 -0400 | [diff] [blame] | 508 | } |
| 509 | } |
| 510 | } |
| 511 | |
Greg Daniel | 9efe386 | 2020-06-11 11:51:06 -0400 | [diff] [blame] | 512 | GrSemaphoresSubmitted GrDrawingManager::flushSurfaces( |
Adlai Holler | c2bfcff | 2020-11-06 15:39:36 -0500 | [diff] [blame] | 513 | SkSpan<GrSurfaceProxy*> proxies, |
Greg Daniel | 9efe386 | 2020-06-11 11:51:06 -0400 | [diff] [blame] | 514 | SkSurface::BackendSurfaceAccess access, |
| 515 | const GrFlushInfo& info, |
| 516 | const GrBackendSurfaceMutableState* newState) { |
bsalomon | 6a2b194 | 2016-09-08 11:28:59 -0700 | [diff] [blame] | 517 | if (this->wasAbandoned()) { |
Greg Daniel | 55822f1 | 2020-05-26 11:26:45 -0400 | [diff] [blame] | 518 | if (info.fSubmittedProc) { |
| 519 | info.fSubmittedProc(info.fSubmittedContext, false); |
| 520 | } |
| 521 | if (info.fFinishedProc) { |
| 522 | info.fFinishedProc(info.fFinishedContext); |
| 523 | } |
Greg Daniel | 5131678 | 2017-08-02 15:10:09 +0000 | [diff] [blame] | 524 | return GrSemaphoresSubmitted::kNo; |
bsalomon | 6a2b194 | 2016-09-08 11:28:59 -0700 | [diff] [blame] | 525 | } |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 526 | SkDEBUGCODE(this->validate()); |
bsalomon | 6a2b194 | 2016-09-08 11:28:59 -0700 | [diff] [blame] | 527 | |
Robert Phillips | f8f45d9 | 2020-07-01 11:11:18 -0400 | [diff] [blame] | 528 | auto direct = fContext->asDirectContext(); |
Adlai Holler | aee25fd | 2020-11-06 12:34:56 -0500 | [diff] [blame] | 529 | SkASSERT(direct); |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 530 | GrGpu* gpu = direct->priv().getGpu(); |
Greg Daniel | 55822f1 | 2020-05-26 11:26:45 -0400 | [diff] [blame] | 531 | // We have a non abandoned and direct GrContext. It must have a GrGpu. |
| 532 | SkASSERT(gpu); |
Robert Phillips | 874b535 | 2018-03-16 08:48:24 -0400 | [diff] [blame] | 533 | |
Robert Phillips | acc10fa | 2019-04-01 09:50:20 -0400 | [diff] [blame] | 534 | // TODO: It is important to upgrade the drawingmanager to just flushing the |
Brian Salomon | f9a1fdf | 2019-05-09 10:30:12 -0400 | [diff] [blame] | 535 | // portion of the DAG required by 'proxies' in order to restore some of the |
Robert Phillips | acc10fa | 2019-04-01 09:50:20 -0400 | [diff] [blame] | 536 | // semantics of this method. |
Adlai Holler | c2bfcff | 2020-11-06 15:39:36 -0500 | [diff] [blame] | 537 | bool didFlush = this->flush(proxies, access, info, newState); |
| 538 | for (GrSurfaceProxy* proxy : proxies) { |
| 539 | resolve_and_mipmap(gpu, proxy); |
bsalomon | 6a2b194 | 2016-09-08 11:28:59 -0700 | [diff] [blame] | 540 | } |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 541 | |
| 542 | SkDEBUGCODE(this->validate()); |
Greg Daniel | fe15962 | 2020-04-10 17:43:51 +0000 | [diff] [blame] | 543 | |
Greg Daniel | 04283f3 | 2020-05-20 13:16:00 -0400 | [diff] [blame] | 544 | if (!didFlush || (!direct->priv().caps()->semaphoreSupport() && info.fNumSemaphores)) { |
Greg Daniel | fe15962 | 2020-04-10 17:43:51 +0000 | [diff] [blame] | 545 | return GrSemaphoresSubmitted::kNo; |
| 546 | } |
| 547 | return GrSemaphoresSubmitted::kYes; |
bsalomon | 6a2b194 | 2016-09-08 11:28:59 -0700 | [diff] [blame] | 548 | } |
| 549 | |
Chris Dalton | fe199b7 | 2017-05-05 11:26:15 -0400 | [diff] [blame] | 550 | void GrDrawingManager::addOnFlushCallbackObject(GrOnFlushCallbackObject* onFlushCBObject) { |
| 551 | fOnFlushCBObjects.push_back(onFlushCBObject); |
Robert Phillips | eb35f4d | 2017-03-21 07:56:47 -0400 | [diff] [blame] | 552 | } |
| 553 | |
Robert Phillips | dbaf317 | 2019-02-06 15:12:53 -0500 | [diff] [blame] | 554 | #if GR_TEST_UTILS |
| 555 | void GrDrawingManager::testingOnly_removeOnFlushCallbackObject(GrOnFlushCallbackObject* cb) { |
| 556 | int n = std::find(fOnFlushCBObjects.begin(), fOnFlushCBObjects.end(), cb) - |
| 557 | fOnFlushCBObjects.begin(); |
| 558 | SkASSERT(n < fOnFlushCBObjects.count()); |
| 559 | fOnFlushCBObjects.removeShuffle(n); |
| 560 | } |
| 561 | #endif |
| 562 | |
Adlai Holler | d71b7b0 | 2020-06-08 15:55:00 -0400 | [diff] [blame] | 563 | void GrDrawingManager::setLastRenderTask(const GrSurfaceProxy* proxy, GrRenderTask* task) { |
| 564 | #ifdef SK_DEBUG |
Robert Phillips | 07f675d | 2020-11-16 13:44:01 -0500 | [diff] [blame] | 565 | if (auto prior = this->getLastRenderTask(proxy)) { |
| 566 | SkASSERT(prior->isClosed() || prior == task); |
Adlai Holler | d71b7b0 | 2020-06-08 15:55:00 -0400 | [diff] [blame] | 567 | } |
| 568 | #endif |
Adlai Holler | 25df1f7 | 2020-06-09 13:08:27 -0400 | [diff] [blame] | 569 | uint32_t key = proxy->uniqueID().asUInt(); |
| 570 | if (task) { |
| 571 | fLastRenderTasks.set(key, task); |
| 572 | } else if (fLastRenderTasks.find(key)) { |
| 573 | fLastRenderTasks.remove(key); |
| 574 | } |
Adlai Holler | d71b7b0 | 2020-06-08 15:55:00 -0400 | [diff] [blame] | 575 | } |
| 576 | |
| 577 | GrRenderTask* GrDrawingManager::getLastRenderTask(const GrSurfaceProxy* proxy) const { |
| 578 | auto entry = fLastRenderTasks.find(proxy->uniqueID().asUInt()); |
| 579 | return entry ? *entry : nullptr; |
| 580 | } |
| 581 | |
| 582 | GrOpsTask* GrDrawingManager::getLastOpsTask(const GrSurfaceProxy* proxy) const { |
| 583 | GrRenderTask* task = this->getLastRenderTask(proxy); |
| 584 | return task ? task->asOpsTask() : nullptr; |
| 585 | } |
| 586 | |
| 587 | |
Chris Dalton | 6b49810 | 2019-08-01 14:14:52 -0600 | [diff] [blame] | 588 | void GrDrawingManager::moveRenderTasksToDDL(SkDeferredDisplayList* ddl) { |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 589 | SkDEBUGCODE(this->validate()); |
| 590 | |
Chris Dalton | 6b49810 | 2019-08-01 14:14:52 -0600 | [diff] [blame] | 591 | // no renderTask should receive a new command after this |
Adlai Holler | 3343227 | 2020-11-11 13:54:37 -0500 | [diff] [blame] | 592 | this->closeAllTasks(); |
Adlai Holler | 039f90c | 2020-11-19 15:20:31 +0000 | [diff] [blame] | 593 | fActiveOpsTask = nullptr; |
Robert Phillips | 7a13705 | 2018-02-01 11:23:12 -0500 | [diff] [blame] | 594 | |
Robert Phillips | 07f675d | 2020-11-16 13:44:01 -0500 | [diff] [blame] | 595 | this->sortTasks(); |
| 596 | |
Adlai Holler | 3343227 | 2020-11-11 13:54:37 -0500 | [diff] [blame] | 597 | fDAG.swap(ddl->fRenderTasks); |
| 598 | SkASSERT(fDAG.empty()); |
Robert Phillips | 867ce8f | 2018-06-21 10:28:36 -0400 | [diff] [blame] | 599 | |
Robert Phillips | 19f466d | 2020-02-26 10:27:07 -0500 | [diff] [blame] | 600 | for (auto& renderTask : ddl->fRenderTasks) { |
Adlai Holler | d71b7b0 | 2020-06-08 15:55:00 -0400 | [diff] [blame] | 601 | renderTask->disown(this); |
Robert Phillips | 29f3854 | 2019-10-16 09:20:25 -0400 | [diff] [blame] | 602 | renderTask->prePrepare(fContext); |
Robert Phillips | 7327c9d | 2019-10-08 16:32:56 -0400 | [diff] [blame] | 603 | } |
| 604 | |
Michael Ludwig | 2c316bd | 2019-12-19 14:50:44 -0500 | [diff] [blame] | 605 | ddl->fArenas = std::move(fContext->priv().detachArenas()); |
Robert Phillips | 61fc799 | 2019-10-22 11:58:17 -0400 | [diff] [blame] | 606 | |
Robert Phillips | f6a0b45 | 2020-02-18 14:26:46 -0500 | [diff] [blame] | 607 | fContext->priv().detachProgramData(&ddl->fProgramData); |
Robert Phillips | 576b6a1 | 2019-12-06 13:05:49 -0500 | [diff] [blame] | 608 | |
Robert Phillips | 774168e | 2018-05-31 12:43:27 -0400 | [diff] [blame] | 609 | if (fPathRendererChain) { |
| 610 | if (auto ccpr = fPathRendererChain->getCoverageCountingPathRenderer()) { |
| 611 | ddl->fPendingPaths = ccpr->detachPendingPaths(); |
| 612 | } |
| 613 | } |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 614 | |
| 615 | SkDEBUGCODE(this->validate()); |
Robert Phillips | 6200036 | 2018-02-01 09:10:04 -0500 | [diff] [blame] | 616 | } |
| 617 | |
Robert Phillips | 07f675d | 2020-11-16 13:44:01 -0500 | [diff] [blame] | 618 | void GrDrawingManager::createDDLTask(sk_sp<const SkDeferredDisplayList> ddl, |
Robert Phillips | eb54bb5 | 2021-01-08 17:20:18 -0500 | [diff] [blame] | 619 | sk_sp<GrRenderTargetProxy> newDest, |
Robert Phillips | 88b2961 | 2020-11-16 15:15:08 -0500 | [diff] [blame] | 620 | SkIPoint offset) { |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 621 | SkDEBUGCODE(this->validate()); |
| 622 | |
Adlai Holler | 039f90c | 2020-11-19 15:20:31 +0000 | [diff] [blame] | 623 | if (fActiveOpsTask) { |
| 624 | // This is a temporary fix for the partial-MDB world. In that world we're not |
| 625 | // reordering so ops that (in the single opsTask world) would've just glommed onto the |
| 626 | // end of the single opsTask but referred to a far earlier RT need to appear in their |
| 627 | // own opsTask. |
| 628 | fActiveOpsTask->makeClosed(*fContext->priv().caps()); |
| 629 | fActiveOpsTask = nullptr; |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 630 | } |
| 631 | |
Robert Phillips | 07f675d | 2020-11-16 13:44:01 -0500 | [diff] [blame] | 632 | // Propagate the DDL proxy's state information to the replay target. |
Robert Phillips | 7eb0a5f | 2020-06-09 14:15:09 -0400 | [diff] [blame] | 633 | if (ddl->priv().targetProxy()->isMSAADirty()) { |
Brian Salomon | 982127b | 2021-01-21 10:43:35 -0500 | [diff] [blame^] | 634 | auto nativeRect = GrNativeRect::MakeIRectRelativeTo( |
| 635 | ddl->characterization().origin(), |
| 636 | ddl->priv().targetProxy()->backingStoreDimensions().height(), |
| 637 | ddl->priv().targetProxy()->msaaDirtyRect()); |
| 638 | newDest->markMSAADirty(nativeRect); |
Robert Phillips | 7eb0a5f | 2020-06-09 14:15:09 -0400 | [diff] [blame] | 639 | } |
| 640 | GrTextureProxy* newTextureProxy = newDest->asTextureProxy(); |
Brian Salomon | 8c82a87 | 2020-07-21 12:09:58 -0400 | [diff] [blame] | 641 | if (newTextureProxy && GrMipmapped::kYes == newTextureProxy->mipmapped()) { |
| 642 | newTextureProxy->markMipmapsDirty(); |
Robert Phillips | 7eb0a5f | 2020-06-09 14:15:09 -0400 | [diff] [blame] | 643 | } |
| 644 | |
Robert Phillips | 6200036 | 2018-02-01 09:10:04 -0500 | [diff] [blame] | 645 | // Here we jam the proxy that backs the current replay SkSurface into the LazyProxyData. |
Robert Phillips | 07f675d | 2020-11-16 13:44:01 -0500 | [diff] [blame] | 646 | // The lazy proxy that references it (in the DDL opsTasks) will then steal its GrTexture. |
Robert Phillips | eb54bb5 | 2021-01-08 17:20:18 -0500 | [diff] [blame] | 647 | ddl->fLazyProxyData->fReplayDest = newDest.get(); |
Robert Phillips | 774168e | 2018-05-31 12:43:27 -0400 | [diff] [blame] | 648 | |
| 649 | if (ddl->fPendingPaths.size()) { |
| 650 | GrCoverageCountingPathRenderer* ccpr = this->getCoverageCountingPathRenderer(); |
| 651 | |
| 652 | ccpr->mergePendingPaths(ddl->fPendingPaths); |
| 653 | } |
Robert Phillips | 22310d6 | 2018-09-05 11:07:21 -0400 | [diff] [blame] | 654 | |
Robert Phillips | 07f675d | 2020-11-16 13:44:01 -0500 | [diff] [blame] | 655 | // Add a task to handle drawing and lifetime management of the DDL. |
| 656 | SkDEBUGCODE(auto ddlTask =) this->appendTask(sk_make_sp<GrDDLTask>(this, |
Robert Phillips | eb54bb5 | 2021-01-08 17:20:18 -0500 | [diff] [blame] | 657 | std::move(newDest), |
Robert Phillips | 88b2961 | 2020-11-16 15:15:08 -0500 | [diff] [blame] | 658 | std::move(ddl), |
| 659 | offset)); |
Robert Phillips | 07f675d | 2020-11-16 13:44:01 -0500 | [diff] [blame] | 660 | SkASSERT(ddlTask->isClosed()); |
Adlai Holler | 7580ad4 | 2020-06-24 13:45:25 -0400 | [diff] [blame] | 661 | |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 662 | SkDEBUGCODE(this->validate()); |
Robert Phillips | 6200036 | 2018-02-01 09:10:04 -0500 | [diff] [blame] | 663 | } |
| 664 | |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 665 | #ifdef SK_DEBUG |
| 666 | void GrDrawingManager::validate() const { |
Adlai Holler | 4ef108e | 2020-12-30 16:21:13 +0000 | [diff] [blame] | 667 | if (fActiveOpsTask) { |
| 668 | SkASSERT(!fDAG.empty()); |
| 669 | SkASSERT(!fActiveOpsTask->isClosed()); |
| 670 | SkASSERT(fActiveOpsTask == fDAG.back().get()); |
| 671 | } |
Adlai Holler | 039f90c | 2020-11-19 15:20:31 +0000 | [diff] [blame] | 672 | |
Adlai Holler | 4ef108e | 2020-12-30 16:21:13 +0000 | [diff] [blame] | 673 | for (int i = 0; i < fDAG.count(); ++i) { |
| 674 | if (fActiveOpsTask != fDAG[i].get()) { |
| 675 | // The resolveTask associated with the activeTask remains open for as long as the |
| 676 | // activeTask does. |
| 677 | bool isActiveResolveTask = |
| 678 | fActiveOpsTask && fActiveOpsTask->fTextureResolveTask == fDAG[i].get(); |
| 679 | SkASSERT(isActiveResolveTask || fDAG[i]->isClosed()); |
Adlai Holler | 7689319 | 2020-12-22 19:41:19 +0000 | [diff] [blame] | 680 | } |
Adlai Holler | 4ef108e | 2020-12-30 16:21:13 +0000 | [diff] [blame] | 681 | } |
Adlai Holler | 7689319 | 2020-12-22 19:41:19 +0000 | [diff] [blame] | 682 | |
Adlai Holler | 4ef108e | 2020-12-30 16:21:13 +0000 | [diff] [blame] | 683 | if (!fDAG.empty() && !fDAG.back()->isClosed()) { |
| 684 | SkASSERT(fActiveOpsTask == fDAG.back().get()); |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 685 | } |
| 686 | } |
| 687 | #endif |
| 688 | |
Adlai Holler | 4ef108e | 2020-12-30 16:21:13 +0000 | [diff] [blame] | 689 | void GrDrawingManager::closeActiveOpsTask() { |
| 690 | if (fActiveOpsTask) { |
| 691 | // This is a temporary fix for the partial-MDB world. In that world we're not |
Adlai Holler | 039f90c | 2020-11-19 15:20:31 +0000 | [diff] [blame] | 692 | // reordering so ops that (in the single opsTask world) would've just glommed onto the |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 693 | // end of the single opsTask but referred to a far earlier RT need to appear in their |
| 694 | // own opsTask. |
Adlai Holler | 039f90c | 2020-11-19 15:20:31 +0000 | [diff] [blame] | 695 | fActiveOpsTask->makeClosed(*fContext->priv().caps()); |
| 696 | fActiveOpsTask = nullptr; |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 697 | } |
Chris Dalton | 5fe9977 | 2019-08-06 11:57:39 -0600 | [diff] [blame] | 698 | } |
| 699 | |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 700 | sk_sp<GrOpsTask> GrDrawingManager::newOpsTask(GrSurfaceProxyView surfaceView, |
Robert Phillips | 1900665 | 2020-11-19 14:20:57 -0500 | [diff] [blame] | 701 | bool flushTimeOpsTask) { |
Chris Dalton | 5fe9977 | 2019-08-06 11:57:39 -0600 | [diff] [blame] | 702 | SkDEBUGCODE(this->validate()); |
| 703 | SkASSERT(fContext); |
| 704 | |
Adlai Holler | 4ef108e | 2020-12-30 16:21:13 +0000 | [diff] [blame] | 705 | this->closeActiveOpsTask(); |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 706 | |
Adlai Holler | d71b7b0 | 2020-06-08 15:55:00 -0400 | [diff] [blame] | 707 | sk_sp<GrOpsTask> opsTask(new GrOpsTask(this, fContext->priv().arenas(), |
Michael Ludwig | d0840ec | 2019-12-12 09:48:38 -0500 | [diff] [blame] | 708 | std::move(surfaceView), |
| 709 | fContext->priv().auditTrail())); |
Brian Salomon | 982127b | 2021-01-21 10:43:35 -0500 | [diff] [blame^] | 710 | SkASSERT(this->getLastRenderTask(opsTask->target(0)) == opsTask.get()); |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 711 | |
Robert Phillips | 1900665 | 2020-11-19 14:20:57 -0500 | [diff] [blame] | 712 | if (flushTimeOpsTask) { |
| 713 | fOnFlushRenderTasks.push_back(opsTask); |
| 714 | } else { |
Adlai Holler | 3343227 | 2020-11-11 13:54:37 -0500 | [diff] [blame] | 715 | this->appendTask(opsTask); |
Adlai Holler | 039f90c | 2020-11-19 15:20:31 +0000 | [diff] [blame] | 716 | |
Adlai Holler | 4ef108e | 2020-12-30 16:21:13 +0000 | [diff] [blame] | 717 | fActiveOpsTask = opsTask.get(); |
Robert Phillips | 941d144 | 2017-06-14 16:37:02 -0400 | [diff] [blame] | 718 | } |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 719 | |
Robert Phillips | 38d64b0 | 2018-09-04 13:23:26 -0400 | [diff] [blame] | 720 | SkDEBUGCODE(this->validate()); |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 721 | return opsTask; |
robertphillips | 3dc6ae5 | 2015-10-20 09:54:32 -0700 | [diff] [blame] | 722 | } |
| 723 | |
Adlai Holler | 039f90c | 2020-11-19 15:20:31 +0000 | [diff] [blame] | 724 | GrTextureResolveRenderTask* GrDrawingManager::newTextureResolveRenderTask(const GrCaps& caps) { |
Chris Dalton | 6aeb8e8 | 2019-08-27 11:52:19 -0600 | [diff] [blame] | 725 | // Unlike in the "new opsTask" case, we do not want to close the active opsTask, nor (if we are |
Adlai Holler | 039f90c | 2020-11-19 15:20:31 +0000 | [diff] [blame] | 726 | // in sorting and opsTask reduction mode) the render tasks that depend on any proxy's current |
Greg Daniel | f41b2bd | 2019-08-22 16:19:24 -0400 | [diff] [blame] | 727 | // state. This is because those opsTasks can still receive new ops and because if they refer to |
Adlai Holler | 039f90c | 2020-11-19 15:20:31 +0000 | [diff] [blame] | 728 | // the mipmapped version of 'proxy', they will then come to depend on the render task being |
Chris Dalton | 4ece96d | 2019-08-30 11:26:39 -0600 | [diff] [blame] | 729 | // created here. |
Chris Dalton | 6aeb8e8 | 2019-08-27 11:52:19 -0600 | [diff] [blame] | 730 | // |
Adlai Holler | 039f90c | 2020-11-19 15:20:31 +0000 | [diff] [blame] | 731 | // Add the new textureResolveTask before the fActiveOpsTask (if not in |
| 732 | // sorting/opsTask-splitting-reduction mode) because it will depend upon this resolve task. |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 733 | // NOTE: Putting it here will also reduce the amount of work required by the topological sort. |
Adlai Holler | 3343227 | 2020-11-11 13:54:37 -0500 | [diff] [blame] | 734 | GrRenderTask* task = this->insertTaskBeforeLast(sk_make_sp<GrTextureResolveRenderTask>()); |
| 735 | return static_cast<GrTextureResolveRenderTask*>(task); |
Chris Dalton | 3d77027 | 2019-08-14 09:24:37 -0600 | [diff] [blame] | 736 | } |
| 737 | |
Greg Daniel | c30f1a9 | 2019-09-06 15:28:58 -0400 | [diff] [blame] | 738 | void GrDrawingManager::newWaitRenderTask(sk_sp<GrSurfaceProxy> proxy, |
Greg Daniel | 301015c | 2019-11-18 14:06:46 -0500 | [diff] [blame] | 739 | std::unique_ptr<std::unique_ptr<GrSemaphore>[]> semaphores, |
Greg Daniel | c30f1a9 | 2019-09-06 15:28:58 -0400 | [diff] [blame] | 740 | int numSemaphores) { |
| 741 | SkDEBUGCODE(this->validate()); |
| 742 | SkASSERT(fContext); |
| 743 | |
| 744 | const GrCaps& caps = *fContext->priv().caps(); |
| 745 | |
Greg Daniel | 16f5c65 | 2019-10-29 11:26:01 -0400 | [diff] [blame] | 746 | sk_sp<GrWaitRenderTask> waitTask = sk_make_sp<GrWaitRenderTask>(GrSurfaceProxyView(proxy), |
| 747 | std::move(semaphores), |
Greg Daniel | c30f1a9 | 2019-09-06 15:28:58 -0400 | [diff] [blame] | 748 | numSemaphores); |
Greg Daniel | c30f1a9 | 2019-09-06 15:28:58 -0400 | [diff] [blame] | 749 | |
Brian Salomon | 982127b | 2021-01-21 10:43:35 -0500 | [diff] [blame^] | 750 | if (fActiveOpsTask && (fActiveOpsTask->target(0) == proxy.get())) { |
Adlai Holler | 4ef108e | 2020-12-30 16:21:13 +0000 | [diff] [blame] | 751 | SkASSERT(this->getLastRenderTask(proxy.get()) == fActiveOpsTask); |
| 752 | this->insertTaskBeforeLast(waitTask); |
| 753 | // In this case we keep the current renderTask open but just insert the new waitTask |
| 754 | // before it in the list. The waitTask will never need to trigger any resolves or mip |
| 755 | // map generation which is the main advantage of going through the proxy version. |
| 756 | // Additionally we would've had to temporarily set the wait task as the lastRenderTask |
| 757 | // on the proxy, add the dependency, and then reset the lastRenderTask to |
| 758 | // fActiveOpsTask. Additionally we make the waitTask depend on all of fActiveOpsTask |
| 759 | // dependencies so that we don't unnecessarily reorder the waitTask before them. |
| 760 | // Note: Any previous Ops already in fActiveOpsTask will get blocked by the wait |
| 761 | // semaphore even though they don't need to be for correctness. |
| 762 | |
| 763 | // Make sure we add the dependencies of fActiveOpsTask to waitTask first or else we'll |
| 764 | // get a circular self dependency of waitTask on waitTask. |
| 765 | waitTask->addDependenciesFromOtherTask(fActiveOpsTask); |
| 766 | fActiveOpsTask->addDependency(waitTask.get()); |
Adlai Holler | 7689319 | 2020-12-22 19:41:19 +0000 | [diff] [blame] | 767 | } else { |
Adlai Holler | 4ef108e | 2020-12-30 16:21:13 +0000 | [diff] [blame] | 768 | // In this case we just close the previous RenderTask and start and append the waitTask |
| 769 | // to the DAG. Since it is the last task now we call setLastRenderTask on the proxy. If |
| 770 | // there is a lastTask on the proxy we make waitTask depend on that task. This |
| 771 | // dependency isn't strictly needed but it does keep the DAG from reordering the |
| 772 | // waitTask earlier and blocking more tasks. |
| 773 | if (GrRenderTask* lastTask = this->getLastRenderTask(proxy.get())) { |
| 774 | waitTask->addDependency(lastTask); |
Adlai Holler | 7689319 | 2020-12-22 19:41:19 +0000 | [diff] [blame] | 775 | } |
Adlai Holler | 4ef108e | 2020-12-30 16:21:13 +0000 | [diff] [blame] | 776 | this->setLastRenderTask(proxy.get(), waitTask.get()); |
| 777 | this->closeActiveOpsTask(); |
| 778 | this->appendTask(waitTask); |
Greg Daniel | c30f1a9 | 2019-09-06 15:28:58 -0400 | [diff] [blame] | 779 | } |
| 780 | waitTask->makeClosed(caps); |
| 781 | |
| 782 | SkDEBUGCODE(this->validate()); |
| 783 | } |
| 784 | |
Greg Daniel | bbfec9d | 2019-08-20 10:56:51 -0400 | [diff] [blame] | 785 | void GrDrawingManager::newTransferFromRenderTask(sk_sp<GrSurfaceProxy> srcProxy, |
| 786 | const SkIRect& srcRect, |
| 787 | GrColorType surfaceColorType, |
| 788 | GrColorType dstColorType, |
| 789 | sk_sp<GrGpuBuffer> dstBuffer, |
| 790 | size_t dstOffset) { |
| 791 | SkDEBUGCODE(this->validate()); |
| 792 | SkASSERT(fContext); |
Adlai Holler | 4ef108e | 2020-12-30 16:21:13 +0000 | [diff] [blame] | 793 | this->closeActiveOpsTask(); |
Greg Daniel | bbfec9d | 2019-08-20 10:56:51 -0400 | [diff] [blame] | 794 | |
Adlai Holler | 3343227 | 2020-11-11 13:54:37 -0500 | [diff] [blame] | 795 | GrRenderTask* task = this->appendTask(sk_make_sp<GrTransferFromRenderTask>( |
Adlai Holler | d71b7b0 | 2020-06-08 15:55:00 -0400 | [diff] [blame] | 796 | srcProxy, srcRect, surfaceColorType, dstColorType, |
| 797 | std::move(dstBuffer), dstOffset)); |
Greg Daniel | bbfec9d | 2019-08-20 10:56:51 -0400 | [diff] [blame] | 798 | |
| 799 | const GrCaps& caps = *fContext->priv().caps(); |
| 800 | |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 801 | // We always say GrMipmapped::kNo here since we are always just copying from the base layer. We |
Greg Daniel | bbfec9d | 2019-08-20 10:56:51 -0400 | [diff] [blame] | 802 | // don't need to make sure the whole mip map chain is valid. |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 803 | task->addDependency(this, srcProxy.get(), GrMipmapped::kNo, |
Adlai Holler | d71b7b0 | 2020-06-08 15:55:00 -0400 | [diff] [blame] | 804 | GrTextureResolveManager(this), caps); |
Greg Daniel | bbfec9d | 2019-08-20 10:56:51 -0400 | [diff] [blame] | 805 | task->makeClosed(caps); |
| 806 | |
Greg Daniel | bbfec9d | 2019-08-20 10:56:51 -0400 | [diff] [blame] | 807 | // We have closed the previous active oplist but since a new oplist isn't being added there |
| 808 | // shouldn't be an active one. |
Adlai Holler | 039f90c | 2020-11-19 15:20:31 +0000 | [diff] [blame] | 809 | SkASSERT(!fActiveOpsTask); |
Greg Daniel | bbfec9d | 2019-08-20 10:56:51 -0400 | [diff] [blame] | 810 | SkDEBUGCODE(this->validate()); |
| 811 | } |
| 812 | |
Brian Salomon | 982127b | 2021-01-21 10:43:35 -0500 | [diff] [blame^] | 813 | bool GrDrawingManager::newCopyRenderTask(sk_sp<GrSurfaceProxy> src, |
| 814 | SkIRect srcRect, |
| 815 | sk_sp<GrSurfaceProxy> dst, |
| 816 | SkIPoint dstPoint) { |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 817 | SkDEBUGCODE(this->validate()); |
| 818 | SkASSERT(fContext); |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 819 | |
Adlai Holler | 4ef108e | 2020-12-30 16:21:13 +0000 | [diff] [blame] | 820 | this->closeActiveOpsTask(); |
Brian Salomon | e4bce01 | 2019-09-20 15:34:23 -0400 | [diff] [blame] | 821 | const GrCaps& caps = *fContext->priv().caps(); |
| 822 | |
Brian Salomon | 982127b | 2021-01-21 10:43:35 -0500 | [diff] [blame^] | 823 | GrRenderTask* task = this->appendTask(GrCopyRenderTask::Make(this, |
| 824 | src, |
| 825 | srcRect, |
| 826 | std::move(dst), |
| 827 | dstPoint, |
| 828 | &caps)); |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 829 | if (!task) { |
| 830 | return false; |
| 831 | } |
| 832 | |
Brian Salomon | 7e67dca | 2020-07-21 09:27:25 -0400 | [diff] [blame] | 833 | // We always say GrMipmapped::kNo here since we are always just copying from the base layer to |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 834 | // another base layer. We don't need to make sure the whole mip map chain is valid. |
Brian Salomon | 982127b | 2021-01-21 10:43:35 -0500 | [diff] [blame^] | 835 | task->addDependency(this, src.get(), GrMipmapped::kNo, GrTextureResolveManager(this), caps); |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 836 | task->makeClosed(caps); |
| 837 | |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 838 | // We have closed the previous active oplist but since a new oplist isn't being added there |
| 839 | // shouldn't be an active one. |
Adlai Holler | 039f90c | 2020-11-19 15:20:31 +0000 | [diff] [blame] | 840 | SkASSERT(!fActiveOpsTask); |
Greg Daniel | e227fe4 | 2019-08-21 13:52:24 -0400 | [diff] [blame] | 841 | SkDEBUGCODE(this->validate()); |
| 842 | return true; |
| 843 | } |
| 844 | |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 845 | /* |
| 846 | * This method finds a path renderer that can draw the specified path on |
| 847 | * the provided target. |
| 848 | * Due to its expense, the software path renderer has split out so it can |
| 849 | * can be individually allowed/disallowed via the "allowSW" boolean. |
| 850 | */ |
| 851 | GrPathRenderer* GrDrawingManager::getPathRenderer(const GrPathRenderer::CanDrawPathArgs& args, |
| 852 | bool allowSW, |
| 853 | GrPathRendererChain::DrawType drawType, |
| 854 | GrPathRenderer::StencilSupport* stencilSupport) { |
| 855 | |
| 856 | if (!fPathRendererChain) { |
John Stiles | fbd050b | 2020-08-03 13:21:46 -0400 | [diff] [blame] | 857 | fPathRendererChain = |
| 858 | std::make_unique<GrPathRendererChain>(fContext, fOptionsForPathRendererChain); |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | GrPathRenderer* pr = fPathRendererChain->getPathRenderer(args, drawType, stencilSupport); |
| 862 | if (!pr && allowSW) { |
Brian Salomon | e7df0bb | 2018-05-07 14:44:57 -0400 | [diff] [blame] | 863 | auto swPR = this->getSoftwarePathRenderer(); |
| 864 | if (GrPathRenderer::CanDrawPath::kNo != swPR->canDrawPath(args)) { |
| 865 | pr = swPR; |
Brian Salomon | 0e8fc8b | 2016-12-09 15:10:07 -0500 | [diff] [blame] | 866 | } |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 867 | } |
| 868 | |
Robert Phillips | d81379d | 2020-04-21 10:39:02 -0400 | [diff] [blame] | 869 | #if GR_PATH_RENDERER_SPEW |
| 870 | if (pr) { |
| 871 | SkDebugf("getPathRenderer: %s\n", pr->name()); |
| 872 | } |
| 873 | #endif |
| 874 | |
robertphillips | 6873782 | 2015-10-29 12:12:21 -0700 | [diff] [blame] | 875 | return pr; |
| 876 | } |
| 877 | |
Brian Salomon | e7df0bb | 2018-05-07 14:44:57 -0400 | [diff] [blame] | 878 | GrPathRenderer* GrDrawingManager::getSoftwarePathRenderer() { |
| 879 | if (!fSoftwarePathRenderer) { |
Ben Wagner | 9ec70c6 | 2018-07-12 13:30:47 -0400 | [diff] [blame] | 880 | fSoftwarePathRenderer.reset( |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 881 | new GrSoftwarePathRenderer(fContext->priv().proxyProvider(), |
Ben Wagner | 9ec70c6 | 2018-07-12 13:30:47 -0400 | [diff] [blame] | 882 | fOptionsForPathRendererChain.fAllowPathMaskCaching)); |
Brian Salomon | e7df0bb | 2018-05-07 14:44:57 -0400 | [diff] [blame] | 883 | } |
Ben Wagner | 9ec70c6 | 2018-07-12 13:30:47 -0400 | [diff] [blame] | 884 | return fSoftwarePathRenderer.get(); |
Brian Salomon | e7df0bb | 2018-05-07 14:44:57 -0400 | [diff] [blame] | 885 | } |
| 886 | |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 887 | GrCoverageCountingPathRenderer* GrDrawingManager::getCoverageCountingPathRenderer() { |
| 888 | if (!fPathRendererChain) { |
Adlai Holler | c2bfcff | 2020-11-06 15:39:36 -0500 | [diff] [blame] | 889 | fPathRendererChain = std::make_unique<GrPathRendererChain>(fContext, |
| 890 | fOptionsForPathRendererChain); |
Chris Dalton | fddb6c0 | 2017-11-04 15:22:22 -0600 | [diff] [blame] | 891 | } |
| 892 | return fPathRendererChain->getCoverageCountingPathRenderer(); |
| 893 | } |
| 894 | |
Brian Salomon | 653f42f | 2018-07-10 10:07:31 -0400 | [diff] [blame] | 895 | void GrDrawingManager::flushIfNecessary() { |
Robert Phillips | f8f45d9 | 2020-07-01 11:11:18 -0400 | [diff] [blame] | 896 | auto direct = fContext->asDirectContext(); |
Robert Phillips | 6a6de56 | 2019-02-15 15:19:15 -0500 | [diff] [blame] | 897 | if (!direct) { |
| 898 | return; |
| 899 | } |
| 900 | |
| 901 | auto resourceCache = direct->priv().getResourceCache(); |
Brian Salomon | 653f42f | 2018-07-10 10:07:31 -0400 | [diff] [blame] | 902 | if (resourceCache && resourceCache->requestsFlush()) { |
Adlai Holler | c2bfcff | 2020-11-06 15:39:36 -0500 | [diff] [blame] | 903 | if (this->flush({}, SkSurface::BackendSurfaceAccess::kNoAccess, GrFlushInfo(), nullptr)) { |
Greg Daniel | fe15962 | 2020-04-10 17:43:51 +0000 | [diff] [blame] | 904 | this->submitToGpu(false); |
| 905 | } |
Brian Salomon | 57d2beab | 2018-09-10 09:35:41 -0400 | [diff] [blame] | 906 | resourceCache->purgeAsNeeded(); |
Brian Salomon | 653f42f | 2018-07-10 10:07:31 -0400 | [diff] [blame] | 907 | } |
| 908 | } |