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