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