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