reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 1 | /* |
epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 2 | * Copyright 2010 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. |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "include/private/GrAuditTrail.h" |
| 9 | #include "include/private/GrRecordingContext.h" |
| 10 | #include "src/core/SkExchange.h" |
| 11 | #include "src/core/SkRectPriv.h" |
| 12 | #include "src/core/SkTraceEvent.h" |
| 13 | #include "src/gpu/GrCaps.h" |
| 14 | #include "src/gpu/GrGpu.h" |
| 15 | #include "src/gpu/GrGpuCommandBuffer.h" |
| 16 | #include "src/gpu/GrMemoryPool.h" |
| 17 | #include "src/gpu/GrRecordingContextPriv.h" |
| 18 | #include "src/gpu/GrRect.h" |
| 19 | #include "src/gpu/GrRenderTargetContext.h" |
| 20 | #include "src/gpu/GrRenderTargetOpList.h" |
| 21 | #include "src/gpu/GrResourceAllocator.h" |
| 22 | #include "src/gpu/ops/GrClearOp.h" |
| 23 | #include "src/gpu/ops/GrCopySurfaceOp.h" |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 24 | |
reed@google.com | ac10a2d | 2010-12-22 21:39:39 +0000 | [diff] [blame] | 25 | //////////////////////////////////////////////////////////////////////////////// |
| 26 | |
Brian Salomon | 09d994e | 2016-12-21 11:14:46 -0500 | [diff] [blame] | 27 | // Experimentally we have found that most combining occurs within the first 10 comparisons. |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 28 | static const int kMaxOpMergeDistance = 10; |
| 29 | static const int kMaxOpChainDistance = 10; |
| 30 | |
| 31 | //////////////////////////////////////////////////////////////////////////////// |
| 32 | |
| 33 | using DstProxy = GrXferProcessor::DstProxy; |
| 34 | |
| 35 | //////////////////////////////////////////////////////////////////////////////// |
| 36 | |
| 37 | static inline bool can_reorder(const SkRect& a, const SkRect& b) { return !GrRectsOverlap(a, b); } |
| 38 | |
| 39 | //////////////////////////////////////////////////////////////////////////////// |
| 40 | |
| 41 | inline GrRenderTargetOpList::OpChain::List::List(std::unique_ptr<GrOp> op) |
| 42 | : fHead(std::move(op)), fTail(fHead.get()) { |
| 43 | this->validate(); |
| 44 | } |
| 45 | |
| 46 | inline GrRenderTargetOpList::OpChain::List::List(List&& that) { *this = std::move(that); } |
| 47 | |
| 48 | inline GrRenderTargetOpList::OpChain::List& GrRenderTargetOpList::OpChain::List::operator=( |
| 49 | List&& that) { |
| 50 | fHead = std::move(that.fHead); |
| 51 | fTail = that.fTail; |
| 52 | that.fTail = nullptr; |
| 53 | this->validate(); |
| 54 | return *this; |
| 55 | } |
| 56 | |
| 57 | inline std::unique_ptr<GrOp> GrRenderTargetOpList::OpChain::List::popHead() { |
| 58 | SkASSERT(fHead); |
| 59 | auto temp = fHead->cutChain(); |
| 60 | std::swap(temp, fHead); |
| 61 | if (!fHead) { |
| 62 | SkASSERT(fTail == temp.get()); |
| 63 | fTail = nullptr; |
| 64 | } |
| 65 | return temp; |
| 66 | } |
| 67 | |
| 68 | inline std::unique_ptr<GrOp> GrRenderTargetOpList::OpChain::List::removeOp(GrOp* op) { |
| 69 | #ifdef SK_DEBUG |
| 70 | auto head = op; |
| 71 | while (head->prevInChain()) { head = head->prevInChain(); } |
| 72 | SkASSERT(head == fHead.get()); |
| 73 | #endif |
| 74 | auto prev = op->prevInChain(); |
| 75 | if (!prev) { |
| 76 | SkASSERT(op == fHead.get()); |
| 77 | return this->popHead(); |
| 78 | } |
| 79 | auto temp = prev->cutChain(); |
| 80 | if (auto next = temp->cutChain()) { |
| 81 | prev->chainConcat(std::move(next)); |
| 82 | } else { |
| 83 | SkASSERT(fTail == op); |
| 84 | fTail = prev; |
| 85 | } |
| 86 | this->validate(); |
| 87 | return temp; |
| 88 | } |
| 89 | |
| 90 | inline void GrRenderTargetOpList::OpChain::List::pushHead(std::unique_ptr<GrOp> op) { |
| 91 | SkASSERT(op); |
| 92 | SkASSERT(op->isChainHead()); |
| 93 | SkASSERT(op->isChainTail()); |
| 94 | if (fHead) { |
| 95 | op->chainConcat(std::move(fHead)); |
| 96 | fHead = std::move(op); |
| 97 | } else { |
| 98 | fHead = std::move(op); |
| 99 | fTail = fHead.get(); |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | inline void GrRenderTargetOpList::OpChain::List::pushTail(std::unique_ptr<GrOp> op) { |
| 104 | SkASSERT(op->isChainTail()); |
| 105 | fTail->chainConcat(std::move(op)); |
| 106 | fTail = fTail->nextInChain(); |
| 107 | } |
| 108 | |
| 109 | inline void GrRenderTargetOpList::OpChain::List::validate() const { |
| 110 | #ifdef SK_DEBUG |
| 111 | if (fHead) { |
| 112 | SkASSERT(fTail); |
| 113 | fHead->validateChain(fTail); |
| 114 | } |
| 115 | #endif |
| 116 | } |
| 117 | |
| 118 | //////////////////////////////////////////////////////////////////////////////// |
| 119 | |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 120 | GrRenderTargetOpList::OpChain::OpChain(std::unique_ptr<GrOp> op, |
| 121 | GrProcessorSet::Analysis processorAnalysis, |
| 122 | GrAppliedClip* appliedClip, const DstProxy* dstProxy) |
| 123 | : fList{std::move(op)} |
| 124 | , fProcessorAnalysis(processorAnalysis) |
| 125 | , fAppliedClip(appliedClip) { |
| 126 | if (fProcessorAnalysis.requiresDstTexture()) { |
| 127 | SkASSERT(dstProxy && dstProxy->proxy()); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 128 | fDstProxy = *dstProxy; |
| 129 | } |
| 130 | fBounds = fList.head()->bounds(); |
| 131 | } |
| 132 | |
| 133 | void GrRenderTargetOpList::OpChain::visitProxies(const GrOp::VisitProxyFunc& func, |
| 134 | GrOp::VisitorType visitor) const { |
| 135 | if (fList.empty()) { |
| 136 | return; |
| 137 | } |
| 138 | for (const auto& op : GrOp::ChainRange<>(fList.head())) { |
| 139 | op.visitProxies(func, visitor); |
| 140 | } |
| 141 | if (fDstProxy.proxy()) { |
| 142 | func(fDstProxy.proxy()); |
| 143 | } |
| 144 | if (fAppliedClip) { |
| 145 | fAppliedClip->visitProxies(func); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | void GrRenderTargetOpList::OpChain::deleteOps(GrOpMemoryPool* pool) { |
| 150 | while (!fList.empty()) { |
| 151 | pool->release(fList.popHead()); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | // Concatenates two op chains and attempts to merge ops across the chains. Assumes that we know that |
| 156 | // the two chains are chainable. Returns the new chain. |
| 157 | GrRenderTargetOpList::OpChain::List GrRenderTargetOpList::OpChain::DoConcat( |
| 158 | List chainA, List chainB, const GrCaps& caps, GrOpMemoryPool* pool, |
| 159 | GrAuditTrail* auditTrail) { |
| 160 | // We process ops in chain b from head to tail. We attempt to merge with nodes in a, starting |
| 161 | // at chain a's tail and working toward the head. We produce one of the following outcomes: |
| 162 | // 1) b's head is merged into an op in a. |
| 163 | // 2) An op from chain a is merged into b's head. (In this case b's head gets processed again.) |
| 164 | // 3) b's head is popped from chain a and added at the tail of a. |
| 165 | // After result 3 we don't want to attempt to merge the next head of b with the new tail of a, |
| 166 | // as we assume merges were already attempted when chain b was created. So we keep track of the |
| 167 | // original tail of a and start our iteration of a there. We also track the bounds of the nodes |
| 168 | // appended to chain a that will be skipped for bounds testing. If the original tail of a is |
| 169 | // merged into an op in b (case 2) then we advance the "original tail" towards the head of a. |
| 170 | GrOp* origATail = chainA.tail(); |
| 171 | SkRect skipBounds = SkRectPriv::MakeLargestInverted(); |
| 172 | do { |
| 173 | int numMergeChecks = 0; |
| 174 | bool merged = false; |
| 175 | bool noSkip = (origATail == chainA.tail()); |
| 176 | SkASSERT(noSkip == (skipBounds == SkRectPriv::MakeLargestInverted())); |
| 177 | bool canBackwardMerge = noSkip || can_reorder(chainB.head()->bounds(), skipBounds); |
| 178 | SkRect forwardMergeBounds = skipBounds; |
| 179 | GrOp* a = origATail; |
| 180 | while (a) { |
| 181 | bool canForwardMerge = |
| 182 | (a == chainA.tail()) || can_reorder(a->bounds(), forwardMergeBounds); |
| 183 | if (canForwardMerge || canBackwardMerge) { |
| 184 | auto result = a->combineIfPossible(chainB.head(), caps); |
| 185 | SkASSERT(result != GrOp::CombineResult::kCannotCombine); |
| 186 | merged = (result == GrOp::CombineResult::kMerged); |
Robert Phillips | 9548c3b42 | 2019-01-08 12:35:43 -0500 | [diff] [blame] | 187 | GrOP_INFO("\t\t: (%s opID: %u) -> Combining with (%s, opID: %u)\n", |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 188 | chainB.head()->name(), chainB.head()->uniqueID(), a->name(), |
| 189 | a->uniqueID()); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 190 | } |
| 191 | if (merged) { |
Brian Salomon | 52a6ed3 | 2018-11-26 10:30:58 -0500 | [diff] [blame] | 192 | GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(auditTrail, a, chainB.head()); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 193 | if (canBackwardMerge) { |
| 194 | pool->release(chainB.popHead()); |
| 195 | } else { |
| 196 | // We merged the contents of b's head into a. We will replace b's head with a in |
| 197 | // chain b. |
| 198 | SkASSERT(canForwardMerge); |
| 199 | if (a == origATail) { |
| 200 | origATail = a->prevInChain(); |
| 201 | } |
| 202 | std::unique_ptr<GrOp> detachedA = chainA.removeOp(a); |
| 203 | pool->release(chainB.popHead()); |
| 204 | chainB.pushHead(std::move(detachedA)); |
| 205 | if (chainA.empty()) { |
| 206 | // We merged all the nodes in chain a to chain b. |
| 207 | return chainB; |
| 208 | } |
| 209 | } |
| 210 | break; |
| 211 | } else { |
| 212 | if (++numMergeChecks == kMaxOpMergeDistance) { |
| 213 | break; |
| 214 | } |
| 215 | forwardMergeBounds.joinNonEmptyArg(a->bounds()); |
| 216 | canBackwardMerge = |
| 217 | canBackwardMerge && can_reorder(chainB.head()->bounds(), a->bounds()); |
| 218 | a = a->prevInChain(); |
| 219 | } |
| 220 | } |
| 221 | // If we weren't able to merge b's head then pop b's head from chain b and make it the new |
| 222 | // tail of a. |
| 223 | if (!merged) { |
| 224 | chainA.pushTail(chainB.popHead()); |
| 225 | skipBounds.joinNonEmptyArg(chainA.tail()->bounds()); |
| 226 | } |
| 227 | } while (!chainB.empty()); |
| 228 | return chainA; |
| 229 | } |
| 230 | |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 231 | // Attempts to concatenate the given chain onto our own and merge ops across the chains. Returns |
| 232 | // whether the operation succeeded. On success, the provided list will be returned empty. |
Chris Dalton | 6f6ae6a | 2019-01-18 12:10:36 -0700 | [diff] [blame] | 233 | bool GrRenderTargetOpList::OpChain::tryConcat( |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 234 | List* list, GrProcessorSet::Analysis processorAnalysis, const DstProxy& dstProxy, |
| 235 | const GrAppliedClip* appliedClip, const SkRect& bounds, const GrCaps& caps, |
| 236 | GrOpMemoryPool* pool, GrAuditTrail* auditTrail) { |
Chris Dalton | 6f6ae6a | 2019-01-18 12:10:36 -0700 | [diff] [blame] | 237 | SkASSERT(!fList.empty()); |
| 238 | SkASSERT(!list->empty()); |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 239 | SkASSERT(fProcessorAnalysis.requiresDstTexture() == SkToBool(fDstProxy.proxy())); |
| 240 | SkASSERT(processorAnalysis.requiresDstTexture() == SkToBool(dstProxy.proxy())); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 241 | // All returns use explicit tuple constructor rather than {a, b} to work around old GCC bug. |
Chris Dalton | 6f6ae6a | 2019-01-18 12:10:36 -0700 | [diff] [blame] | 242 | if (fList.head()->classID() != list->head()->classID() || |
| 243 | SkToBool(fAppliedClip) != SkToBool(appliedClip) || |
| 244 | (fAppliedClip && *fAppliedClip != *appliedClip) || |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 245 | (fProcessorAnalysis.requiresNonOverlappingDraws() != |
| 246 | processorAnalysis.requiresNonOverlappingDraws()) || |
| 247 | (fProcessorAnalysis.requiresNonOverlappingDraws() && |
| 248 | // Non-overlaping draws are only required when Ganesh will either insert a barrier, |
| 249 | // or read back a new dst texture between draws. In either case, we can neither |
| 250 | // chain nor combine overlapping Ops. |
| 251 | GrRectsTouchOrOverlap(fBounds, bounds)) || |
| 252 | (fProcessorAnalysis.requiresDstTexture() != processorAnalysis.requiresDstTexture()) || |
| 253 | (fProcessorAnalysis.requiresDstTexture() && fDstProxy != dstProxy)) { |
Chris Dalton | 6f6ae6a | 2019-01-18 12:10:36 -0700 | [diff] [blame] | 254 | return false; |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 255 | } |
Chris Dalton | ee21e6b | 2019-01-22 14:04:43 -0700 | [diff] [blame] | 256 | |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 257 | SkDEBUGCODE(bool first = true;) |
| 258 | do { |
Chris Dalton | 6f6ae6a | 2019-01-18 12:10:36 -0700 | [diff] [blame] | 259 | switch (fList.tail()->combineIfPossible(list->head(), caps)) { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 260 | case GrOp::CombineResult::kCannotCombine: |
| 261 | // If an op supports chaining then it is required that chaining is transitive and |
| 262 | // that if any two ops in two different chains can merge then the two chains |
| 263 | // may also be chained together. Thus, we should only hit this on the first |
| 264 | // iteration. |
| 265 | SkASSERT(first); |
Chris Dalton | 6f6ae6a | 2019-01-18 12:10:36 -0700 | [diff] [blame] | 266 | return false; |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 267 | case GrOp::CombineResult::kMayChain: |
Chris Dalton | ee21e6b | 2019-01-22 14:04:43 -0700 | [diff] [blame] | 268 | fList = DoConcat(std::move(fList), skstd::exchange(*list, List()), caps, pool, |
| 269 | auditTrail); |
| 270 | // The above exchange cleared out 'list'. The list needs to be empty now for the |
| 271 | // loop to terminate. |
| 272 | SkASSERT(list->empty()); |
| 273 | break; |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 274 | case GrOp::CombineResult::kMerged: { |
Robert Phillips | 9548c3b42 | 2019-01-08 12:35:43 -0500 | [diff] [blame] | 275 | GrOP_INFO("\t\t: (%s opID: %u) -> Combining with (%s, opID: %u)\n", |
Chris Dalton | 6f6ae6a | 2019-01-18 12:10:36 -0700 | [diff] [blame] | 276 | list->tail()->name(), list->tail()->uniqueID(), list->head()->name(), |
| 277 | list->head()->uniqueID()); |
| 278 | GR_AUDIT_TRAIL_OPS_RESULT_COMBINED(auditTrail, fList.tail(), list->head()); |
| 279 | pool->release(list->popHead()); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 280 | break; |
| 281 | } |
| 282 | } |
| 283 | SkDEBUGCODE(first = false); |
Chris Dalton | 6f6ae6a | 2019-01-18 12:10:36 -0700 | [diff] [blame] | 284 | } while (!list->empty()); |
Chris Dalton | ee21e6b | 2019-01-22 14:04:43 -0700 | [diff] [blame] | 285 | |
| 286 | // The new ops were successfully merged and/or chained onto our own. |
| 287 | fBounds.joinPossiblyEmptyRect(bounds); |
Chris Dalton | 6f6ae6a | 2019-01-18 12:10:36 -0700 | [diff] [blame] | 288 | return true; |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 289 | } |
| 290 | |
| 291 | bool GrRenderTargetOpList::OpChain::prependChain(OpChain* that, const GrCaps& caps, |
| 292 | GrOpMemoryPool* pool, GrAuditTrail* auditTrail) { |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 293 | if (!that->tryConcat( |
| 294 | &fList, fProcessorAnalysis, fDstProxy, fAppliedClip, fBounds, caps, pool, auditTrail)) { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 295 | this->validate(); |
| 296 | // append failed |
| 297 | return false; |
| 298 | } |
Chris Dalton | 6f6ae6a | 2019-01-18 12:10:36 -0700 | [diff] [blame] | 299 | |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 300 | // 'that' owns the combined chain. Move it into 'this'. |
Chris Dalton | 6f6ae6a | 2019-01-18 12:10:36 -0700 | [diff] [blame] | 301 | SkASSERT(fList.empty()); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 302 | fList = std::move(that->fList); |
Chris Dalton | ee21e6b | 2019-01-22 14:04:43 -0700 | [diff] [blame] | 303 | fBounds = that->fBounds; |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 304 | |
| 305 | that->fDstProxy.setProxy(nullptr); |
| 306 | if (that->fAppliedClip) { |
| 307 | for (int i = 0; i < that->fAppliedClip->numClipCoverageFragmentProcessors(); ++i) { |
| 308 | that->fAppliedClip->detachClipCoverageFragmentProcessor(i); |
| 309 | } |
| 310 | } |
| 311 | this->validate(); |
| 312 | return true; |
| 313 | } |
| 314 | |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 315 | std::unique_ptr<GrOp> GrRenderTargetOpList::OpChain::appendOp( |
| 316 | std::unique_ptr<GrOp> op, GrProcessorSet::Analysis processorAnalysis, |
| 317 | const DstProxy* dstProxy, const GrAppliedClip* appliedClip, const GrCaps& caps, |
| 318 | GrOpMemoryPool* pool, GrAuditTrail* auditTrail) { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 319 | const GrXferProcessor::DstProxy noDstProxy; |
| 320 | if (!dstProxy) { |
| 321 | dstProxy = &noDstProxy; |
| 322 | } |
| 323 | SkASSERT(op->isChainHead() && op->isChainTail()); |
| 324 | SkRect opBounds = op->bounds(); |
| 325 | List chain(std::move(op)); |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 326 | if (!this->tryConcat( |
| 327 | &chain, processorAnalysis, *dstProxy, appliedClip, opBounds, caps, pool, auditTrail)) { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 328 | // append failed, give the op back to the caller. |
| 329 | this->validate(); |
| 330 | return chain.popHead(); |
| 331 | } |
Chris Dalton | 6f6ae6a | 2019-01-18 12:10:36 -0700 | [diff] [blame] | 332 | |
| 333 | SkASSERT(chain.empty()); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 334 | this->validate(); |
| 335 | return nullptr; |
| 336 | } |
| 337 | |
| 338 | inline void GrRenderTargetOpList::OpChain::validate() const { |
| 339 | #ifdef SK_DEBUG |
| 340 | fList.validate(); |
| 341 | for (const auto& op : GrOp::ChainRange<>(fList.head())) { |
| 342 | // Not using SkRect::contains because we allow empty rects. |
| 343 | SkASSERT(fBounds.fLeft <= op.bounds().fLeft && fBounds.fTop <= op.bounds().fTop && |
| 344 | fBounds.fRight >= op.bounds().fRight && fBounds.fBottom >= op.bounds().fBottom); |
| 345 | } |
| 346 | #endif |
| 347 | } |
| 348 | |
| 349 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon | 489147c | 2015-12-14 12:13:09 -0800 | [diff] [blame] | 350 | |
Robert Phillips | 12c4629 | 2019-04-23 07:36:17 -0400 | [diff] [blame] | 351 | GrRenderTargetOpList::GrRenderTargetOpList(sk_sp<GrOpMemoryPool> opMemoryPool, |
Robert Phillips | 831a293 | 2019-04-12 17:18:39 -0400 | [diff] [blame] | 352 | sk_sp<GrRenderTargetProxy> proxy, |
Robert Phillips | 8185f59 | 2017-04-26 08:31:08 -0400 | [diff] [blame] | 353 | GrAuditTrail* auditTrail) |
Robert Phillips | 12c4629 | 2019-04-23 07:36:17 -0400 | [diff] [blame] | 354 | : INHERITED(std::move(opMemoryPool), std::move(proxy), auditTrail) |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 355 | , fLastClipStackGenID(SK_InvalidUniqueID) |
Robert Phillips | b6deea8 | 2017-05-11 14:14:30 -0400 | [diff] [blame] | 356 | SkDEBUGCODE(, fNumClips(0)) { |
bsalomon | 4061b12 | 2015-05-29 10:26:19 -0700 | [diff] [blame] | 357 | } |
| 358 | |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 359 | void GrRenderTargetOpList::deleteOps() { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 360 | for (auto& chain : fOpChains) { |
| 361 | chain.deleteOps(fOpMemoryPool.get()); |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 362 | } |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 363 | fOpChains.reset(); |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 364 | } |
| 365 | |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 366 | GrRenderTargetOpList::~GrRenderTargetOpList() { |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 367 | this->deleteOps(); |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 368 | } |
| 369 | |
| 370 | //////////////////////////////////////////////////////////////////////////////// |
| 371 | |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 372 | #ifdef SK_DEBUG |
Robert Phillips | 2748391 | 2018-04-20 12:43:18 -0400 | [diff] [blame] | 373 | void GrRenderTargetOpList::dump(bool printDependencies) const { |
| 374 | INHERITED::dump(printDependencies); |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 375 | |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 376 | SkDebugf("ops (%d):\n", fOpChains.count()); |
| 377 | for (int i = 0; i < fOpChains.count(); ++i) { |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 378 | SkDebugf("*******************************\n"); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 379 | if (!fOpChains[i].head()) { |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 380 | SkDebugf("%d: <combined forward or failed instantiation>\n", i); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 381 | } else { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 382 | SkDebugf("%d: %s\n", i, fOpChains[i].head()->name()); |
| 383 | SkRect bounds = fOpChains[i].bounds(); |
Brian Salomon | 9e50f7b | 2017-03-06 12:02:34 -0500 | [diff] [blame] | 384 | SkDebugf("ClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", bounds.fLeft, |
| 385 | bounds.fTop, bounds.fRight, bounds.fBottom); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 386 | for (const auto& op : GrOp::ChainRange<>(fOpChains[i].head())) { |
| 387 | SkString info = SkTabString(op.dumpInfo(), 1); |
| 388 | SkDebugf("%s\n", info.c_str()); |
| 389 | bounds = op.bounds(); |
| 390 | SkDebugf("\tClippedBounds: [L: %.2f, T: %.2f, R: %.2f, B: %.2f]\n", bounds.fLeft, |
| 391 | bounds.fTop, bounds.fRight, bounds.fBottom); |
| 392 | } |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 393 | } |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 394 | } |
| 395 | } |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 396 | |
| 397 | void GrRenderTargetOpList::visitProxies_debugOnly(const GrOp::VisitProxyFunc& func) const { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 398 | for (const OpChain& chain : fOpChains) { |
| 399 | chain.visitProxies(func, GrOp::VisitorType::kOther); |
Chris Dalton | 706a6ff | 2017-11-29 22:01:06 -0700 | [diff] [blame] | 400 | } |
| 401 | } |
Brian Salomon | c525d4f | 2018-09-17 15:48:20 -0400 | [diff] [blame] | 402 | |
robertphillips | 4beb5c1 | 2015-10-20 07:50:00 -0700 | [diff] [blame] | 403 | #endif |
| 404 | |
Brian Osman | 407b342 | 2017-08-22 15:01:32 -0400 | [diff] [blame] | 405 | void GrRenderTargetOpList::onPrepare(GrOpFlushState* flushState) { |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 406 | SkASSERT(fTarget.get()->peekRenderTarget()); |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 407 | SkASSERT(this->isClosed()); |
Stan Iliev | 2af578d | 2017-08-16 13:00:28 -0400 | [diff] [blame] | 408 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 409 | TRACE_EVENT0("skia", TRACE_FUNC); |
| 410 | #endif |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 411 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 412 | // Loop over the ops that haven't yet been prepared. |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 413 | for (const auto& chain : fOpChains) { |
| 414 | if (chain.head()) { |
Stan Iliev | 2af578d | 2017-08-16 13:00:28 -0400 | [diff] [blame] | 415 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 416 | TRACE_EVENT0("skia", chain.head()->name()); |
Stan Iliev | 2af578d | 2017-08-16 13:00:28 -0400 | [diff] [blame] | 417 | #endif |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 418 | GrOpFlushState::OpArgs opArgs = { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 419 | chain.head(), |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 420 | fTarget.get()->asRenderTargetProxy(), |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 421 | chain.appliedClip(), |
| 422 | chain.dstProxy() |
Robert Phillips | 318c419 | 2017-05-17 09:36:38 -0400 | [diff] [blame] | 423 | }; |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 424 | flushState->setOpArgs(&opArgs); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 425 | chain.head()->prepare(flushState); |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 426 | flushState->setOpArgs(nullptr); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 427 | } |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 428 | } |
robertphillips | a13e202 | 2015-11-11 12:01:09 -0800 | [diff] [blame] | 429 | } |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 430 | |
Michael Ludwig | 6e17f1d | 2019-05-15 14:00:20 +0000 | [diff] [blame^] | 431 | static GrGpuRTCommandBuffer* create_command_buffer(GrGpu* gpu, |
| 432 | GrRenderTarget* rt, |
| 433 | GrSurfaceOrigin origin, |
| 434 | const SkRect& bounds, |
| 435 | GrLoadOp colorLoadOp, |
| 436 | const SkPMColor4f& loadClearColor, |
| 437 | GrLoadOp stencilLoadOp) { |
Robert Phillips | cb2e235 | 2017-08-30 16:44:40 -0400 | [diff] [blame] | 438 | const GrGpuRTCommandBuffer::LoadAndStoreInfo kColorLoadStoreInfo { |
Robert Phillips | 6b47c7d | 2017-08-29 07:24:09 -0400 | [diff] [blame] | 439 | colorLoadOp, |
| 440 | GrStoreOp::kStore, |
| 441 | loadClearColor |
Robert Phillips | 178ce3e | 2017-04-13 09:15:47 -0400 | [diff] [blame] | 442 | }; |
| 443 | |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 444 | // TODO: |
| 445 | // We would like to (at this level) only ever clear & discard. We would need |
| 446 | // to stop splitting up higher level opLists for copyOps to achieve that. |
| 447 | // Note: we would still need SB loads and stores but they would happen at a |
| 448 | // lower level (inside the VK command buffer). |
Greg Daniel | 500d58b | 2017-08-24 15:59:33 -0400 | [diff] [blame] | 449 | const GrGpuRTCommandBuffer::StencilLoadAndStoreInfo stencilLoadAndStoreInfo { |
Robert Phillips | 6b47c7d | 2017-08-29 07:24:09 -0400 | [diff] [blame] | 450 | stencilLoadOp, |
Michael Ludwig | 6e17f1d | 2019-05-15 14:00:20 +0000 | [diff] [blame^] | 451 | GrStoreOp::kStore, |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 452 | }; |
| 453 | |
Ethan Nicholas | 56d19a5 | 2018-10-15 11:26:20 -0400 | [diff] [blame] | 454 | return gpu->getCommandBuffer(rt, origin, bounds, kColorLoadStoreInfo, stencilLoadAndStoreInfo); |
Robert Phillips | 178ce3e | 2017-04-13 09:15:47 -0400 | [diff] [blame] | 455 | } |
| 456 | |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 457 | // TODO: this is where GrOp::renderTarget is used (which is fine since it |
Robert Phillips | 294870f | 2016-11-11 12:38:40 -0500 | [diff] [blame] | 458 | // is at flush time). However, we need to store the RenderTargetProxy in the |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 459 | // Ops and instantiate them here. |
Brian Osman | 407b342 | 2017-08-22 15:01:32 -0400 | [diff] [blame] | 460 | bool GrRenderTargetOpList::onExecute(GrOpFlushState* flushState) { |
Greg Daniel | dbdba60 | 2018-04-20 11:52:43 -0400 | [diff] [blame] | 461 | // TODO: Forcing the execution of the discard here isn't ideal since it will cause us to do a |
| 462 | // discard and then store the data back in memory so that the load op on future draws doesn't |
| 463 | // think the memory is unitialized. Ideally we would want a system where we are tracking whether |
| 464 | // the proxy itself has valid data or not, and then use that as a signal on whether we should be |
| 465 | // loading or discarding. In that world we wouldni;t need to worry about executing oplists with |
| 466 | // no ops just to do a discard. |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 467 | if (fOpChains.empty() && GrLoadOp::kClear != fColorLoadOp && |
Greg Daniel | dbdba60 | 2018-04-20 11:52:43 -0400 | [diff] [blame] | 468 | GrLoadOp::kDiscard != fColorLoadOp) { |
bsalomon | dc43898 | 2016-08-31 11:53:49 -0700 | [diff] [blame] | 469 | return false; |
egdaniel | b4021cf | 2016-07-28 08:53:07 -0700 | [diff] [blame] | 470 | } |
Robert Phillips | 4a39504 | 2017-04-24 16:27:17 +0000 | [diff] [blame] | 471 | |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 472 | SkASSERT(fTarget.get()->peekRenderTarget()); |
Stan Iliev | 2af578d | 2017-08-16 13:00:28 -0400 | [diff] [blame] | 473 | TRACE_EVENT0("skia", TRACE_FUNC); |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 474 | |
Michael Ludwig | 6e17f1d | 2019-05-15 14:00:20 +0000 | [diff] [blame^] | 475 | // TODO: at the very least, we want the stencil store op to always be discard (at this |
| 476 | // level). In Vulkan, sub-command buffers would still need to load & store the stencil buffer. |
| 477 | |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 478 | // Make sure load ops are not kClear if the GPU needs to use draws for clears |
| 479 | SkASSERT(fColorLoadOp != GrLoadOp::kClear || |
| 480 | !flushState->gpu()->caps()->performColorClearsAsDraws()); |
| 481 | SkASSERT(fStencilLoadOp != GrLoadOp::kClear || |
| 482 | !flushState->gpu()->caps()->performStencilClearsAsDraws()); |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 483 | GrGpuRTCommandBuffer* commandBuffer = create_command_buffer( |
Michael Ludwig | 6e17f1d | 2019-05-15 14:00:20 +0000 | [diff] [blame^] | 484 | flushState->gpu(), |
| 485 | fTarget.get()->peekRenderTarget(), |
| 486 | fTarget.get()->origin(), |
| 487 | fTarget.get()->getBoundsRect(), |
| 488 | fColorLoadOp, |
| 489 | fLoadClearColor, |
| 490 | fStencilLoadOp); |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 491 | flushState->setCommandBuffer(commandBuffer); |
Robert Phillips | 9521447 | 2017-08-08 18:00:03 -0400 | [diff] [blame] | 492 | commandBuffer->begin(); |
Robert Phillips | 6cdc22c | 2017-05-11 16:29:14 -0400 | [diff] [blame] | 493 | |
| 494 | // Draw all the generated geometry. |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 495 | for (const auto& chain : fOpChains) { |
| 496 | if (!chain.head()) { |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 497 | continue; |
| 498 | } |
Stan Iliev | 2af578d | 2017-08-16 13:00:28 -0400 | [diff] [blame] | 499 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 500 | TRACE_EVENT0("skia", chain.head()->name()); |
Stan Iliev | 2af578d | 2017-08-16 13:00:28 -0400 | [diff] [blame] | 501 | #endif |
Robert Phillips | 178ce3e | 2017-04-13 09:15:47 -0400 | [diff] [blame] | 502 | |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 503 | GrOpFlushState::OpArgs opArgs { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 504 | chain.head(), |
Robert Phillips | 2890fbf | 2017-07-26 15:48:41 -0400 | [diff] [blame] | 505 | fTarget.get()->asRenderTargetProxy(), |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 506 | chain.appliedClip(), |
| 507 | chain.dstProxy() |
Robert Phillips | 178ce3e | 2017-04-13 09:15:47 -0400 | [diff] [blame] | 508 | }; |
| 509 | |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 510 | flushState->setOpArgs(&opArgs); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 511 | chain.head()->execute(flushState, chain.bounds()); |
Brian Salomon | 29b60c9 | 2017-10-31 14:42:10 -0400 | [diff] [blame] | 512 | flushState->setOpArgs(nullptr); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 513 | } |
Robert Phillips | 178ce3e | 2017-04-13 09:15:47 -0400 | [diff] [blame] | 514 | |
Robert Phillips | 5b5d84c | 2018-08-09 15:12:18 -0400 | [diff] [blame] | 515 | commandBuffer->end(); |
| 516 | flushState->gpu()->submit(commandBuffer); |
Robert Phillips | 178ce3e | 2017-04-13 09:15:47 -0400 | [diff] [blame] | 517 | flushState->setCommandBuffer(nullptr); |
ethannicholas | 2279325 | 2016-01-30 09:59:10 -0800 | [diff] [blame] | 518 | |
bsalomon | dc43898 | 2016-08-31 11:53:49 -0700 | [diff] [blame] | 519 | return true; |
bsalomon | a73239a | 2015-04-28 13:35:17 -0700 | [diff] [blame] | 520 | } |
| 521 | |
Chris Dalton | a84cacf | 2017-10-04 10:30:29 -0600 | [diff] [blame] | 522 | void GrRenderTargetOpList::endFlush() { |
Brian Salomon | c3833b4 | 2018-07-09 18:23:58 +0000 | [diff] [blame] | 523 | fLastClipStackGenID = SK_InvalidUniqueID; |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 524 | this->deleteOps(); |
Chris Dalton | c82dd4e | 2017-11-20 18:20:28 -0700 | [diff] [blame] | 525 | fClipAllocator.reset(); |
Chris Dalton | a84cacf | 2017-10-04 10:30:29 -0600 | [diff] [blame] | 526 | INHERITED::endFlush(); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 527 | } |
| 528 | |
Robert Phillips | 380b90c | 2017-08-30 07:41:07 -0400 | [diff] [blame] | 529 | void GrRenderTargetOpList::discard() { |
| 530 | // Discard calls to in-progress opLists are ignored. Calls at the start update the |
| 531 | // opLists' color & stencil load ops. |
| 532 | if (this->isEmpty()) { |
| 533 | fColorLoadOp = GrLoadOp::kDiscard; |
| 534 | fStencilLoadOp = GrLoadOp::kDiscard; |
| 535 | } |
| 536 | } |
| 537 | |
Michael Ludwig | 6e17f1d | 2019-05-15 14:00:20 +0000 | [diff] [blame^] | 538 | void GrRenderTargetOpList::setStencilLoadOp(GrLoadOp op) { |
| 539 | fStencilLoadOp = op; |
| 540 | } |
| 541 | |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 542 | void GrRenderTargetOpList::setColorLoadOp(GrLoadOp op, const SkPMColor4f& color) { |
| 543 | fColorLoadOp = op; |
| 544 | fLoadClearColor = color; |
| 545 | } |
| 546 | |
| 547 | bool GrRenderTargetOpList::resetForFullscreenClear() { |
| 548 | // Mark the color load op as discard (this may be followed by a clearColorOnLoad call to make |
| 549 | // the load op kClear, or it may be followed by an explicit op). In the event of an absClear() |
| 550 | // after a regular clear(), we could end up with a clear load op and a real clear op in the list |
| 551 | // if the load op were not reset here. |
| 552 | fColorLoadOp = GrLoadOp::kDiscard; |
| 553 | |
| 554 | // Regardless of how the clear is implemented (native clear or a fullscreen quad), all prior ops |
| 555 | // would be overwritten, so discard them entirely. The one exception is if the opList is marked |
| 556 | // as needing a stencil buffer then there may be a prior op that writes to the stencil buffer. |
| 557 | // Although the clear will ignore the stencil buffer, following draw ops may not so we can't get |
| 558 | // rid of all the preceding ops. Beware! If we ever add any ops that have a side effect beyond |
| 559 | // modifying the stencil buffer we will need a more elaborate tracking system (skbug.com/7002). |
Greg Daniel | cb32415 | 2019-02-25 11:36:53 -0500 | [diff] [blame] | 560 | // Additionally, if we previously recorded a wait op, we cannot delete the wait op. Until we |
| 561 | // track the wait ops separately from normal ops, we have to avoid clearing out any ops. |
| 562 | if (this->isEmpty() || (!fTarget.get()->asRenderTargetProxy()->needsStencil() && !fHasWaitOp)) { |
Robert Phillips | c994a93 | 2018-06-19 13:09:54 -0400 | [diff] [blame] | 563 | this->deleteOps(); |
Brian Osman | 099fa0f | 2017-10-02 16:38:32 -0400 | [diff] [blame] | 564 | fDeferredProxies.reset(); |
Greg Daniel | 070cbaf | 2019-01-03 17:35:54 -0500 | [diff] [blame] | 565 | |
| 566 | // If the opList is using a render target which wraps a vulkan command buffer, we can't do a |
| 567 | // clear load since we cannot change the render pass that we are using. Thus we fall back to |
| 568 | // making a clear op in this case. |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 569 | return !fTarget.get()->asRenderTargetProxy()->wrapsVkSecondaryCB(); |
bsalomon | fd8d013 | 2016-08-11 11:25:33 -0700 | [diff] [blame] | 570 | } |
Robert Phillips | 380b90c | 2017-08-30 07:41:07 -0400 | [diff] [blame] | 571 | |
Michael Ludwig | c39d0c8 | 2019-01-15 10:03:43 -0500 | [diff] [blame] | 572 | // Could not empty the list, so an op must be added to handle the clear |
| 573 | return false; |
bsalomon | 9f129de | 2016-08-10 16:31:05 -0700 | [diff] [blame] | 574 | } |
| 575 | |
bsalomon@google.com | 25fb21f | 2011-06-21 18:17:25 +0000 | [diff] [blame] | 576 | //////////////////////////////////////////////////////////////////////////////// |
bsalomon@google.com | 86afc2a | 2011-02-16 16:12:19 +0000 | [diff] [blame] | 577 | |
Robert Phillips | 81dd3e0 | 2017-06-23 11:59:24 -0400 | [diff] [blame] | 578 | // This closely parallels GrTextureOpList::copySurface but renderTargetOpLists |
| 579 | // also store the applied clip and dest proxy with the op |
Robert Phillips | be9aff2 | 2019-02-15 11:33:22 -0500 | [diff] [blame] | 580 | bool GrRenderTargetOpList::copySurface(GrRecordingContext* context, |
Robert Phillips | a16f6cb | 2017-06-01 11:06:13 -0400 | [diff] [blame] | 581 | GrSurfaceProxy* dst, |
Robert Phillips | bf25d43 | 2017-04-07 10:08:53 -0400 | [diff] [blame] | 582 | GrSurfaceProxy* src, |
Robert Phillips | f2361d2 | 2016-10-25 14:20:06 -0400 | [diff] [blame] | 583 | const SkIRect& srcRect, |
| 584 | const SkIPoint& dstPoint) { |
Robert Phillips | 5efd5ea | 2017-05-30 13:47:32 -0400 | [diff] [blame] | 585 | SkASSERT(dst->asRenderTargetProxy() == fTarget.get()); |
Robert Phillips | 7c525e6 | 2018-06-12 10:11:12 -0400 | [diff] [blame] | 586 | std::unique_ptr<GrOp> op = GrCopySurfaceOp::Make(context, dst, src, srcRect, dstPoint); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 587 | if (!op) { |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 588 | return false; |
| 589 | } |
robertphillips | 498d7ac | 2015-10-30 10:11:30 -0700 | [diff] [blame] | 590 | |
Robert Phillips | 9da87e0 | 2019-02-04 13:26:26 -0500 | [diff] [blame] | 591 | this->addOp(std::move(op), *context->priv().caps()); |
bsalomon | b8fea97 | 2016-02-16 07:34:17 -0800 | [diff] [blame] | 592 | return true; |
bsalomon@google.com | eb85117 | 2013-04-15 13:51:00 +0000 | [diff] [blame] | 593 | } |
| 594 | |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 595 | void GrRenderTargetOpList::purgeOpsWithUninstantiatedProxies() { |
| 596 | bool hasUninstantiatedProxy = false; |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 597 | auto checkInstantiation = [&hasUninstantiatedProxy](GrSurfaceProxy* p) { |
| 598 | if (!p->isInstantiated()) { |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 599 | hasUninstantiatedProxy = true; |
| 600 | } |
| 601 | }; |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 602 | for (OpChain& recordedOp : fOpChains) { |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 603 | hasUninstantiatedProxy = false; |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 604 | recordedOp.visitProxies(checkInstantiation, GrOp::VisitorType::kOther); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 605 | if (hasUninstantiatedProxy) { |
| 606 | // When instantiation of the proxy fails we drop the Op |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 607 | recordedOp.deleteOps(fOpMemoryPool.get()); |
Greg Daniel | aa3dfbe | 2018-01-29 10:34:25 -0500 | [diff] [blame] | 608 | } |
| 609 | } |
| 610 | } |
| 611 | |
Robert Phillips | 9313aa7 | 2019-04-09 18:41:27 -0400 | [diff] [blame] | 612 | bool GrRenderTargetOpList::onIsUsed(GrSurfaceProxy* proxyToCheck) const { |
| 613 | bool used = false; |
| 614 | |
| 615 | auto visit = [ proxyToCheck, &used ] (GrSurfaceProxy* p) { |
| 616 | if (p == proxyToCheck) { |
| 617 | used = true; |
| 618 | } |
| 619 | }; |
| 620 | for (const OpChain& recordedOp : fOpChains) { |
| 621 | recordedOp.visitProxies(visit, GrOp::VisitorType::kOther); |
| 622 | } |
| 623 | |
| 624 | return used; |
| 625 | } |
| 626 | |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 627 | void GrRenderTargetOpList::gatherProxyIntervals(GrResourceAllocator* alloc) const { |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 628 | |
Robert Phillips | 51b20f2 | 2017-12-01 15:32:35 -0500 | [diff] [blame] | 629 | for (int i = 0; i < fDeferredProxies.count(); ++i) { |
Brian Salomon | fd98c2c | 2018-07-31 17:25:29 -0400 | [diff] [blame] | 630 | SkASSERT(!fDeferredProxies[i]->isInstantiated()); |
Robert Phillips | 51b20f2 | 2017-12-01 15:32:35 -0500 | [diff] [blame] | 631 | // We give all the deferred proxies a write usage at the very start of flushing. This |
| 632 | // locks them out of being reused for the entire flush until they are read - and then |
| 633 | // they can be recycled. This is a bit unfortunate because a flush can proceed in waves |
| 634 | // with sub-flushes. The deferred proxies only need to be pinned from the start of |
| 635 | // the sub-flush in which they appear. |
Robert Phillips | c73666f | 2019-04-24 08:49:48 -0400 | [diff] [blame] | 636 | alloc->addInterval(fDeferredProxies[i], 0, 0, GrResourceAllocator::ActualUse::kNo); |
Robert Phillips | 51b20f2 | 2017-12-01 15:32:35 -0500 | [diff] [blame] | 637 | } |
| 638 | |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 639 | // Add the interval for all the writes to this opList's target |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 640 | if (fOpChains.count()) { |
Robert Phillips | 3bf3d4a | 2019-03-27 07:09:09 -0400 | [diff] [blame] | 641 | unsigned int cur = alloc->curOp(); |
| 642 | |
Robert Phillips | c73666f | 2019-04-24 08:49:48 -0400 | [diff] [blame] | 643 | alloc->addInterval(fTarget.get(), cur, cur + fOpChains.count() - 1, |
| 644 | GrResourceAllocator::ActualUse::kYes); |
Robert Phillips | f8e2502 | 2017-11-08 15:24:31 -0500 | [diff] [blame] | 645 | } else { |
| 646 | // This can happen if there is a loadOp (e.g., a clear) but no other draws. In this case we |
| 647 | // still need to add an interval for the destination so we create a fake op# for |
| 648 | // the missing clear op. |
Robert Phillips | c73666f | 2019-04-24 08:49:48 -0400 | [diff] [blame] | 649 | alloc->addInterval(fTarget.get(), alloc->curOp(), alloc->curOp(), |
| 650 | GrResourceAllocator::ActualUse::kYes); |
Robert Phillips | f8e2502 | 2017-11-08 15:24:31 -0500 | [diff] [blame] | 651 | alloc->incOps(); |
| 652 | } |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 653 | |
Chris Dalton | 8816b93 | 2017-11-29 16:48:25 -0700 | [diff] [blame] | 654 | auto gather = [ alloc SkDEBUGCODE(, this) ] (GrSurfaceProxy* p) { |
Robert Phillips | c73666f | 2019-04-24 08:49:48 -0400 | [diff] [blame] | 655 | alloc->addInterval(p, alloc->curOp(), alloc->curOp(), GrResourceAllocator::ActualUse::kYes |
| 656 | SkDEBUGCODE(, fTarget.get() == p)); |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 657 | }; |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 658 | for (const OpChain& recordedOp : fOpChains) { |
Brian Salomon | 7d94bb5 | 2018-10-12 14:37:19 -0400 | [diff] [blame] | 659 | // only diff from the GrTextureOpList version |
| 660 | recordedOp.visitProxies(gather, GrOp::VisitorType::kAllocatorGather); |
Robert Phillips | f8e2502 | 2017-11-08 15:24:31 -0500 | [diff] [blame] | 661 | |
Robert Phillips | 3bf3d4a | 2019-03-27 07:09:09 -0400 | [diff] [blame] | 662 | // Even though the op may have been (re)moved we still need to increment the op count to |
Robert Phillips | f8e2502 | 2017-11-08 15:24:31 -0500 | [diff] [blame] | 663 | // keep all the math consistent. |
| 664 | alloc->incOps(); |
Robert Phillips | d375dbf | 2017-09-14 12:45:25 -0400 | [diff] [blame] | 665 | } |
| 666 | } |
| 667 | |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 668 | void GrRenderTargetOpList::recordOp( |
| 669 | std::unique_ptr<GrOp> op, GrProcessorSet::Analysis processorAnalysis, GrAppliedClip* clip, |
| 670 | const DstProxy* dstProxy, const GrCaps& caps) { |
Ethan Nicholas | 029b22c | 2018-10-18 16:49:56 -0400 | [diff] [blame] | 671 | SkDEBUGCODE(op->validate();) |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 672 | SkASSERT(processorAnalysis.requiresDstTexture() == (dstProxy && dstProxy->proxy())); |
Robert Phillips | 318c419 | 2017-05-17 09:36:38 -0400 | [diff] [blame] | 673 | SkASSERT(fTarget.get()); |
Robert Phillips | ee68365 | 2017-04-26 11:53:10 -0400 | [diff] [blame] | 674 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 675 | // A closed GrOpList should never receive new/more ops |
robertphillips | 6a18665 | 2015-10-20 07:37:58 -0700 | [diff] [blame] | 676 | SkASSERT(!this->isClosed()); |
Brian Salomon | 19ec80f | 2018-11-16 13:27:30 -0500 | [diff] [blame] | 677 | if (!op->bounds().isFinite()) { |
| 678 | fOpMemoryPool->release(std::move(op)); |
| 679 | return; |
| 680 | } |
robertphillips | a106c62 | 2015-10-16 09:07:06 -0700 | [diff] [blame] | 681 | |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 682 | // Check if there is an op we can combine with by linearly searching back until we either |
| 683 | // 1) check every op |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 684 | // 2) intersect with something |
| 685 | // 3) find a 'blocker' |
Robert Phillips | 5efd5ea | 2017-05-30 13:47:32 -0400 | [diff] [blame] | 686 | GR_AUDIT_TRAIL_ADD_OP(fAuditTrail, op.get(), fTarget.get()->uniqueID()); |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 687 | GrOP_INFO("opList: %d Recording (%s, opID: %u)\n" |
| 688 | "\tBounds [L: %.2f, T: %.2f R: %.2f B: %.2f]\n", |
| 689 | this->uniqueID(), |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 690 | op->name(), |
| 691 | op->uniqueID(), |
Robert Phillips | 1119dc3 | 2017-04-11 12:54:57 -0400 | [diff] [blame] | 692 | op->bounds().fLeft, op->bounds().fTop, |
| 693 | op->bounds().fRight, op->bounds().fBottom); |
Brian Salomon | 1e41f4a | 2016-12-07 15:05:04 -0500 | [diff] [blame] | 694 | GrOP_INFO(SkTabString(op->dumpInfo(), 1).c_str()); |
Brian Salomon | 25a8809 | 2016-12-01 09:36:50 -0500 | [diff] [blame] | 695 | GrOP_INFO("\tOutcome:\n"); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 696 | int maxCandidates = SkTMin(kMaxOpChainDistance, fOpChains.count()); |
Robert Phillips | 318c419 | 2017-05-17 09:36:38 -0400 | [diff] [blame] | 697 | if (maxCandidates) { |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 698 | int i = 0; |
| 699 | while (true) { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 700 | OpChain& candidate = fOpChains.fromBack(i); |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 701 | op = candidate.appendOp(std::move(op), processorAnalysis, dstProxy, clip, caps, |
| 702 | fOpMemoryPool.get(), fAuditTrail); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 703 | if (!op) { |
| 704 | return; |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 705 | } |
Brian Salomon | a7682c8 | 2018-10-24 10:04:37 -0400 | [diff] [blame] | 706 | // Stop going backwards if we would cause a painter's order violation. |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 707 | if (!can_reorder(candidate.bounds(), op->bounds())) { |
| 708 | GrOP_INFO("\t\tBackward: Intersects with chain (%s, head opID: %u)\n", |
| 709 | candidate.head()->name(), candidate.head()->uniqueID()); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 710 | break; |
| 711 | } |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 712 | if (++i == maxCandidates) { |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 713 | GrOP_INFO("\t\tBackward: Reached max lookback or beginning of op array %d\n", i); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 714 | break; |
| 715 | } |
| 716 | } |
| 717 | } else { |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 718 | GrOP_INFO("\t\tBackward: FirstOp\n"); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 719 | } |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 720 | if (clip) { |
| 721 | clip = fClipAllocator.make<GrAppliedClip>(std::move(*clip)); |
Robert Phillips | c84c030 | 2017-05-08 15:35:11 -0400 | [diff] [blame] | 722 | SkDEBUGCODE(fNumClips++;) |
Brian Salomon | 54d212e | 2017-03-21 14:22:38 -0400 | [diff] [blame] | 723 | } |
Chris Dalton | 945ee65 | 2019-01-23 09:10:36 -0700 | [diff] [blame] | 724 | fOpChains.emplace_back(std::move(op), processorAnalysis, clip, dstProxy); |
bsalomon | 512be53 | 2015-09-10 10:42:55 -0700 | [diff] [blame] | 725 | } |
| 726 | |
Robert Phillips | ee68365 | 2017-04-26 11:53:10 -0400 | [diff] [blame] | 727 | void GrRenderTargetOpList::forwardCombine(const GrCaps& caps) { |
Robert Phillips | f5442bb | 2017-04-17 14:18:34 -0400 | [diff] [blame] | 728 | SkASSERT(!this->isClosed()); |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 729 | GrOP_INFO("opList: %d ForwardCombine %d ops:\n", this->uniqueID(), fOpChains.count()); |
Robert Phillips | 48567ac | 2017-06-01 08:46:00 -0400 | [diff] [blame] | 730 | |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 731 | for (int i = 0; i < fOpChains.count() - 1; ++i) { |
| 732 | OpChain& chain = fOpChains[i]; |
| 733 | int maxCandidateIdx = SkTMin(i + kMaxOpChainDistance, fOpChains.count() - 1); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 734 | int j = i + 1; |
| 735 | while (true) { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 736 | OpChain& candidate = fOpChains[j]; |
| 737 | if (candidate.prependChain(&chain, caps, fOpMemoryPool.get(), fAuditTrail)) { |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 738 | break; |
| 739 | } |
Robert Phillips | c84c030 | 2017-05-08 15:35:11 -0400 | [diff] [blame] | 740 | // Stop traversing if we would cause a painter's order violation. |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 741 | if (!can_reorder(chain.bounds(), candidate.bounds())) { |
| 742 | GrOP_INFO( |
| 743 | "\t\t%d: chain (%s head opID: %u) -> " |
| 744 | "Intersects with chain (%s, head opID: %u)\n", |
| 745 | i, chain.head()->name(), chain.head()->uniqueID(), candidate.head()->name(), |
| 746 | candidate.head()->uniqueID()); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 747 | break; |
| 748 | } |
Brian Salomon | a7682c8 | 2018-10-24 10:04:37 -0400 | [diff] [blame] | 749 | if (++j > maxCandidateIdx) { |
Brian Salomon | 588cec7 | 2018-11-14 13:56:37 -0500 | [diff] [blame] | 750 | GrOP_INFO("\t\t%d: chain (%s opID: %u) -> Reached max lookahead or end of array\n", |
| 751 | i, chain.head()->name(), chain.head()->uniqueID()); |
bsalomon | aecc018 | 2016-03-07 11:50:44 -0800 | [diff] [blame] | 752 | break; |
| 753 | } |
| 754 | } |
| 755 | } |
| 756 | } |
| 757 | |