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